// avoid conflict
jQuery.noConflict();
var $j = jQuery;

/*
	onload call
**************************************/

	$j(document).ready(function(){
		hozSlider.init();
	});

/*
	hozSlider by Takazudo
	http://gyauza.egoism.jp/clip/
**************************************/

	var hozSlider=
	{
		speed: 100, // set speed here
		isWhileAnimation: false,
		itemW: null,
		itemsNum: null,
		
		init:function()
		{
			hozSlider.setup();
			hozSlider.bindEvents();
		},
		
		setup: function()
		{
			// get width and height
			var $item=$j("#sliderItemList div.item").eq(0);
			var num=$j("#sliderItemList div.item").length;
			var w = $item.width();
			var h = $item.height();
			var totalW = w*num;
			$j("#sliderItemList")
				.width(totalW)
				.height(h)
				.css("margin-left",-w);
			$item.css("width",0);
			
			// set global vars
			hozSlider.itemW = w;
			hozSlider.itemsNum = num;
		},
		
		bindEvents: function()
		{
			// bind events to the buttons
			$j("#toLeft").click(function(){ hozSlider.toLeft(); });
			$j("#toRight").click(function(){ hozSlider.toRight(); });
		},
		
		toLeft: function()
		{
			// die if while animation
			if(hozSlider.isWhileAnimation) return;
			
			// set animation status
			hozSlider.isWhileAnimation = true;
			
			// the first item goes to the last
			$j("#sliderItemList div.item").eq(0)
				.appendTo("#sliderItemList")
				.width(hozSlider.itemW);
				
			// the first item shrink to width 0
			$j("#sliderItemList div.item").eq(0).animate({
				width: 0
			}, hozSlider.speed, function(){
				hozSlider.isWhileAnimation = false; // end animation
			});
		},
		toRight: function()
		{
			// die if while animation
			if(hozSlider.isWhileAnimation) return;
			
			// set animation status
			hozSlider.isWhileAnimation = true;
			
			// the last item goes to the first
			$j("#sliderItemList div.item").eq(hozSlider.itemsNum-1)
				.css("width",0)
				.prependTo("#sliderItemList");
				
			// the 2nd item expand to the item's width
			$j("#sliderItemList div.item").eq(1).animate({
				width: hozSlider.itemW
			}, hozSlider.speed, function(){
				hozSlider.isWhileAnimation = false; // end animation
			});
		}
	}
