/* ------------------------------------
*
*	Since : 2008-07-09
*	Editor : BBmedia Inc. D_sasaki
*
-------------------------------------*/

var SlideClass = function(obj){
		
		this.nextIndex = obj.nextIndex || 0;
		this.maxPos = obj.maxPos;	
		this.width = obj.width;
		this.speed = obj.speed || 800;
		this.easing = obj.easing || "easeOutExpo";
		this.prev = obj.prev;
		this.next = obj.next;
		this.slideBox = obj.slideBox;
};

SlideClass.prototype = {
	slideContent : function(){
		this.slideBox
		.animate({left:-this.nextPos() + "px"},
		this.speed,
		this.easing)		
	},
	nextPos: function(){
		return (this.nextIndex * this.width) 		
	},			 
	defaultAction : function(){
		this.prev.addClass("off");
	},
	showPrev : function(){
		this.prev.removeClass("off")
	},
	hidePrev : function(){		
		this.prev.addClass("off");
	},
	showNext : function(){
		this.next.removeClass("off")
	},
	hideNext : function(){			
		this.next.addClass("off");
	},
	prevAction : function(event){
		
		var self = event.data;

		if(self.nextIndex == 0) return false;
		
		//if slideBox is animated now, stop animation.
		var now = Math.abs(self.slideBox.css("left").split("px")[0])
		var flag = (now % self.width)
		if(flag) self.slideBox.stop();
			
		self.nextIndex--	
		
		//hide "nextBtn" or "prevBtn".
		if(self.nextIndex == 0){
			self.hidePrev();	
		}else {
			self.showPrev();	
			self.showNext();			
		}
		
		//slide slideBox.				
		self.slideContent();	
		
		return false;
	},
	nextAction : function(event){
		
		var self = event.data;
		
		if(self.nextIndex == self.maxPos) return false;
		
		//if slideBox is animated now, stop animation.
		var now = Math.abs(self.slideBox.css("left").split("px")[0])
		var flag = (now % self.width)
		if(flag) self.slideBox.stop();	
		
		self.nextIndex++	
		
		//hide "nextBtn" or "prevBtn".
		if(self.nextIndex == self.maxPos){
			self.hideNext();	
		}else {
			self.showPrev();	
			self.showNext();	
		}
		
		//slide slideBox.				
		self.slideContent();	
		
		return false;		
	}	
};

jQuery(function(){
	jQuery("#ranking #rankingMore").hide();

	jQuery("#ranking ul li")
	.toggle(function() {		
		var self = jQuery(this);

		jQuery("#rankingMore")
		.slideDown("slow", function(){	
			self
			.addClass("open");
		});
	},
	function() {
		var self = jQuery(this);	
		
		jQuery("#rankingMore")
		.removeClass("open")
		.slideUp("slow",function(){
			self
			.removeClass("open");				 
		});
	})
	.find("a")
	.focus(function(){
		this.blur();				
	})

	
	//--------------------------------
	
	var waiwaiSlide = new SlideClass(
		{
			nextIndex : 0,
			maxPos :2,
			width : 497,
			speed : 800,
			easing : "easeOutExpo",
			prev : jQuery(".prev a"),
			next : jQuery(".next a"),
			slideBox : jQuery("#carouselList")
		}
	);
	
	waiwaiSlide.defaultAction()
	
	waiwaiSlide.prev.bind("click",waiwaiSlide,waiwaiSlide.prevAction);
	waiwaiSlide.prev.bind("focus",function(){
		this.blur();
	});
	waiwaiSlide.next.bind("click",waiwaiSlide,waiwaiSlide.nextAction);
	waiwaiSlide.next.bind("focus",function(){
		this.blur();
	});
	
	
	
});




