/*
 * --------------------------------------------------------------------
 * Simple Scroller
 * by Siddharth S, www.ssiddharth.com, hello@ssiddharth.com
 * Version: 1.0, 05.10.2009 	
 * --------------------------------------------------------------------
 */

$(document).ready(function() 
{	 
	var index = 0;
	var images = $("#gallery li");
	var thumbs = $("#thumbs a");
	var imgHeight = '105';
	$(thumbs).slice(0,3).clone().appendTo("#thumbs");
	for (i=0; i<thumbs.length; i++)
	{
		$(thumbs[i]).addClass("thumb-"+i);
		$(images[i]).addClass("image-"+i);
	}
	
	
	
	function sift()
	{
		
		if (index<(thumbs.length-1)){index++ ; }
		else {index=0}
		show (index);
   if (index > 0) {$("#prev").show()};
   if (index == 0) {$("#prev").hide()};
	return false;
		
	}
	
	function sift2()
	{
		if (index<(thumbs.length+1)){index-- ; }
		show (index);
			if (index > 0) {$("#prev").show()};
			if (index == 0) {$("#prev").hide()};
			return false;

	}
			
	function sift3()
	{
		
		index=$(this).attr("rel");
		show (index);
		if (index > 0) {$("#prev").show()};
  		if (index == 0) {$("#prev").hide()};
		return false;
				
	}
	
	
	
	function show(num)
	{
		$(images).fadeOut(400);
		$(".image-"+num).stop().fadeIn(400);
		var scrollPos = (num)*imgHeight;
		var scrollPos2 = scrollPos + 105;
		$("#thumbs").stop().animate({scrollTop: scrollPos2}, 400);	
		
	}
	
	function pause()
	{
		clearInterval(refreshIntervalId);
	}
	

	
	
	$("#next").click(sift);
	$("#prev").click(sift2);
	$("#thumbs a").click(sift3);
	if (index == 0) {$("#prev").hide()};
	show(index);
	var refreshIntervalId = setInterval(sift, 8000);
	

	$(".pause").click(pause);
	$(".hoverPause").hover(pause);
	
	$("a.hide").click(function(){
		$("span.hide").remove();
		return false;
							   });

	

	
	
	
	
});
