
var promob = 1 // current promo block
function promoChange() {
	promob = $(".b-slider-ctrls .cur").prevAll().length
	$(".b-promo").fadeOut()
	$("#b-promo" + promob).fadeIn()
	}

var promoAnimTO = false
var promoAnimTime = 4000
function promoAnim() {
	$(".b-slider-ctrls .next").click()
	promoAnimTO = setTimeout("promoAnim()", promoAnimTime)
	}

$(document).ready(function(){

	jQuery.extend(jQuery.easing, {
		swap1: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t + b;
		return c/2*((t-=2)*t*t + 2) + b;
			}
		});
		
	// 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")}})
		.bind("blur",function(){if(this.value==""){	$(this).attr("value",this.hint).addClass("text_hint")}})
	
	//promo
	$(".b-slider-ctrls")
		.find(".next").click(function(){
			if ($(this).siblings(".cur").next().hasClass("s")) {
				$(this).siblings(".cur").removeClass("cur").next().addClass("cur")
				promoChange()
				}
			else {
				$(this).siblings(".cur").removeClass("cur")
				$(this).siblings(".s").first().addClass("cur")
				promoChange()
				}
			})
		.end()
		.find(".prev").click(function(){
			if ($(this).siblings(".cur").prev().hasClass("s")) {
				$(this).siblings(".cur").removeClass("cur").prev().addClass("cur")
				promoChange()
				}
			else {
				$(this).siblings(".cur").removeClass("cur")
				$(this).siblings(".s").last().addClass("cur")
				promoChange()
				}
			})
		.end()
		.find("LI").not(".prev,.next").click(function(){
			if (!$(this).hasClass("cur")) {
				$(this).addClass("cur").siblings(".cur").removeClass("cur")	
				promoChange()
				}
			})
	$(".l-promo").hover(
		function(){if (promoAnimTO) clearTimeout(promoAnimTO)},
		function(){promoAnimTO = setTimeout("promoAnim()", promoAnimTime)})
	promoAnimTO = setTimeout("promoAnim()", promoAnimTime)
	
	
	// pop
	$(".b-pop").draggable({cancel:'A', cursor:'move', handle:'.b-pop__head,.b-pop__txt' })
	$(".b-pop__nav A").click(function(){
		$(this).parents(".b-pop__nav").find(".cur").removeClass("cur")
		$(this).parent().addClass("cur")
		$(this).parents(".b-pop__nav").find(".open").removeClass("open")
		$(this).parents("LI").addClass("open")
		})
	
});
