// JavaScript Document

var index = {};
index.timer = false;
index.flag = true;
index.second = 3000;
index.val = 216;
index.easing = "easeOutCubic";

index.init = function(){

	$(".bnList .prev a").click(function(){
					  
		index.prevnext("prev");
		return false;
					  
	});
	$(".bnList .next a").click(function(){
					  
		index.prevnext("next");
		return false;
	});
//	$(".bnList ul li:last").insertBefore(".bnList ul li:first");
	
	
	
	$(".bnList").hover(function(){
		clearTimeout(index.timer);
	},function(){
		index.timer = setTimeout(function(){
			index.prevnext("next");
		},index.second);
	}).find("ul").fadeIn(600,function(){
		index.timer = setTimeout(function(){
			index.prevnext("next");
		},index.second);
	});
	
	
	
	
};

index.prevnext = function(flag){
	clearTimeout(index.timer);
	if(index.flag){		
		index.flag = false;
		var cssParam = {};
		cssParam.marginLeft = (0 - index.val) + "px";
		if(flag == "prev"){
			$(".bnList ul li:last").insertBefore(".bnList ul li:first");
			$(".bnList ul").stop().css(cssParam).animate({"marginLeft":"0px"}, 1000 ,index.easing,function(){
				Reset();										     
			});
			
		}else{
			$(".bnList ul").stop().animate(cssParam, 1000 ,index.easing,function(){
				Reset();
			$(".bnList ul").append($(".bnList ul li:first"));
			});
		}
	}
	
	
	function Reset(){
		var cssParam = {};
		cssParam.marginLeft = "0px";
		$(".bnList ul").stop().css(cssParam);
		index.flag = true;
		index.timer = setTimeout(function(){
			index.prevnext("next");
		},index.second);
	}
	
	
};



$(function(){
	if($("#portalTop #main .bnList li").length > 3) {
		$(".bnList .prev,.bnList .next").show();
		index.init();
		
	}else{
		$(".bnList ul").fadeIn(600);
	}
	if($('.favorite dd').length > 0){
    	$('.favorite dd').flatHeights();
	}
});

jQuery.extend( jQuery.easing,
{
	def: 'easeOutCubic',
	easeOutCubic: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t + 1) + b;
	}
});



