// easing
jQuery.extend(jQuery.easing, {
	swap1: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t + 1) + b;
		}
});
	
$(document).ready(function(){

	if ($.browser.opera) {
		$("body").addClass("body-opera")
	}
	// text inputs hints
	$(".text_hint[value!=]")
		.each(function(){this.hint=this.value})
		.bind("focus",function(){if(this.hint==this.value){$(this).attr("value","").removeClass("text_hint").parents(".search-input:eq(0)").removeClass("search-input_hint")}})
		.bind("blur",function(){if(this.value==""){	$(this).attr("value",this.hint).addClass("text_hint").parents(".search-input:eq(0)").addClass("search-input_hint")}})

	
	// tabs
	// class=".js-tabs .js-tabs_xxx" where xxx is tabs class
	// qty & order should be equal
	$(".js-tabs LI").click(function(e){
		$t = $(this)
		if (!$t.hasClass("cur")) {
			$t.addClass("cur").siblings(".cur").removeClass("cur")
			$("."+$t.parents(".js-tabs:eq(0)").get(0).className.split("js-tabs_")[1]).hide().eq($t.prevAll("LI").length).show()
			}
		return false
		}).filter(".cur").removeClass("cur").click()

	// nav
	$(".b-nav > UL > LI:not(:has(>strong))").hover(
		function(){
			$(this).addClass("hover")
			a = $(this).children("A")
			anim(a, {"borderBottomColor":"#999999", "color":"#999999"}, 400)
			anim($(this).parents("UL:eq(0)").find("STRONG"), {"borderBottomColor":"#272727", "color":"#999999"}, 600)
			},
		function(){
			$(this).removeClass("hover")
			a = $(this).children("A")
			anim(a, {"borderBottomColor":"#272727", "color":"#f2f1f1"}, 600)
			anim($(this).parents("UL:eq(0)").find("STRONG"), {"borderBottomColor":"#999999"}, 2000)
			})
	$(".b-nav > UL > LI").hover(
		function(){
			$(this).addClass("hover")
			},
		function(){
			$(this).removeClass("hover")
			})
	
	// ictinus
	if ($(".img-round").length) {
		$(window).bind("load", function(){
			ictinus.roundCorners.RADIUS = 7;
			$(".img-round").each(function(){
				ictinus.roundCorners(this);	
				})
			})
		}
	
	// isel
	$(".b-isel").addClass("b-isel_js")
	$("body").delegate(".b-isel LI:not(.cur)", "click", function(){
		$(this).addClass("cur").siblings(".cur").removeClass("cur")
		$(this).parents(".b-isel").find("SELECT OPTION").eq($(this).prevAll("LI").length).attr("selected","selected")
		})
	
	
	// cart
	$(".b-cart").each(function(){
		t = $(this)
		docart(t)
		t.find(".reorder A").click(function(){
			docart(t)
			return false
			})
		$(this).find(".b-cart-item .text INPUT").bind("blur", function(){
			docart(t)
			})
		$(this).find(".b-cart-item .ci__del").click(function(){
			$(this).parents(".b-cart-item:eq(0)").fadeOut(600,function(){
				$(this).remove()
				docart(t)
				})
			return false
			})
		})
	
	
	// item pics
	$(".b-picnav").each(function(){
		var t = $(this)
		var s = t.parent().find(".b-slides")

		
/*
		$(window).bind("load", function(){
			s.addClass("bla")
			s.css("width","9999px")
				.find(".b-frame").show().end()
				.height(s.height()).css("width","333px")
				.find(".b-frame").hide()
			s.find(".b-frame:eq(0)").show()
			})

*/
		t.find("LI A").click(function(){
			if ($(this).parent().hasClass("cur")) {
				}
			else {
				$(this).parent().addClass("cur").siblings().removeClass("cur")
				var pos = $(this).parent().prevAll("LI").length
				s.find(".b-frame:visible").fadeOut("fast", function(){
					$(this).parent().find(".b-frame").eq(pos).fadeIn("fast")
					})
				}
			return false
			})

		})

		
	$(".b-slides .b-frame_l:has(I)").click(function(){
		curpos = $(this).parents(".b-slides:eq(0)").parent().find(".b-picnav LI.cur").prevAll("LI").length
		$(".b-pop_bigphoto").find(".b-picnav LI").eq(curpos).find("A").click()
		$(".b-pop_bigphoto").find(".b-frame").eq(curpos).show().siblings().hide()
		popShow($(".b-pop_bigphoto"))
		return false
		})
		
	$(".b-picnav UL LI A").hover(
		function(){$(this).addClass("hover").find("SPAN").show()},
		function(){$(this).removeClass("hover").find("SPAN").hide()})
		
		
	// pop
	$("body").delegate(".b-pop__close", "click", function(){
		$(".l-tint").hide()
		$(this).parents(".b-pop").hide()
		return false
		})
	$(".l-tint").click(function(){
		$(".l-tint").hide()
		$(".b-pop").hide()
		return false
		})
		
	// link-pop
	$(".link-pop").click(function(){
		url = this.href
		$(".b-pop_html .b-pop__i").empty().load(url+" .l-pop-body", function(){popShow($(".b-pop_html"))})
		return false
		})
		
	// b-pop_gal
	$(".b-bigchoise").each(function(){
		$(this).find("A").click(function(){
			curpos = $(this).parents("LI:eq(0)").prevAll("LI").length
			$(".b-pop_gal").find(".b-picnav LI").eq(curpos).find("A").click()
			$(".b-pop_gal").find(".b-frame").eq(curpos).show().siblings().hide()
			popShow($(".b-pop_gal"))
			return false
			})
		})
			
			
	// pop config
	var curconfig = null
	$(".b-cart-item").each(function(){
		ppp = $(".b-pop_config")
		
		t.find(".b-isel").click(function(){
			curconfig = t = $(this).parents(".b-cart-item")
			ppp.find(".b-isel_color LI").each(function(){
				if ($(this).html() == t.find(".b-isel_color LI").html()) {cur = $(this)}
				})	
			cur.click()
			ppp.find(".b-isel_size LI").each(function(){
				if ($(this).html() == t.find(".b-isel_size LI").html()) {cur = $(this)}
				})	
			cur.click()
			
			popShow(ppp)
			return false
			})
		})
	$("body").delegate(".b-pop_grey .b-isel LI:not(.cur)", "click", function(){
		t = $(this)
		if (t.parents(".b-isel").hasClass("b-isel_color")) {
			curconfig.find(".b-isel_color LI").html(t.html())
			}
		else if (t.parents(".b-isel").hasClass("b-isel_size")) {
			curconfig.find(".b-isel_size LI").html(t.html())
			}
		
		})
			
	// b-bigchoise
/*
	$(".b-bigchoise LI A").click(function(){
		p = $(this).parent()
		if (!p.hasClass("cur")) {
			p.addClass("cur").siblings(".cur").removeClass("cur")
			}
		return false
		})
*/

	// ie frames
	if ($.browser.msie) {
		$(window).bind("load", function(){
			$(":not(.b-pop_bigphoto) .b-frame IMG").each(function(){
				a = ($(this).parent().height() - this.height) / 2
				$(this).css("margin-top", a)
			})
			$(".b-picnav ul li span IMG").each(function(){
				$(this).parents("SPAN:not(:visible),.b-pop").addClass("tempvis").show()
				a = (68 - this.height)/2 + 5
				$(this).css("margin-top", a)
				$(this).parents(".tempvis").removeClass(".tempvis").hide()
			})
		})
	}

	if ($.browser.msie) {
		$(".b-pop__close").prependTo($(".b-pop__close").parent())
	}
	
	
		
})

function anim(el, param, time) {
	el.stop().clearQueue().animate(param, time)
	}
	
function docart(cart){
	var cartsum = 0
	$(cart).find(".b-cart-item").each(function(){
		p = parseInt($(this).find(".text INPUT").attr("value"))
		if (!isNaN(p)) {
			cartsum += p * parseInt($(this).find(".price STRONG").html().split(" ")[0])
			$(this).find(".text_err").removeClass("text_err")
			}
		else {
			$(this).find(".text").addClass("text_err")
			}
		})
	$(cart).find(".b-cart-submit .title EM").html(cartsum)
	}
	
function isNumeric(input) {
	return (input - 0) == input && input.length > 0;
	}
	
function popShow(el){
	$(".l-tint").show()
	el.css({"top":$(window).scrollTop()+100}).show()
	}
