/*
 * --------------------------------------------------------------------
 * 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 = $("#carousel-gallery .featured");
	var thumbs = $("#carousel-thumbs img");
	$(thumbs).slice(0,3).clone().appendTo("#carousel-thumbs");
	for (i=0; i<thumbs.length; i++)
	{
		$(thumbs[i]).addClass("thumb-"+i);
		$(images[i]).addClass("image-"+i);
	}
	
	show(index, 0);
	setInterval(sift, 5000);
	
	function sift()
	{
		if (index<(thumbs.length-1)){index+=1 ; }
		else {index=0}
		show (index, 400);
	}
	
	function show(num, speed)
	{
		$(images).fadeOut(speed);
		$(".image-"+num).stop().fadeIn(speed);
		var scrollPos = (num+1)*($(thumbs[0]).attr("height"));
		$("#carousel-thumbs").stop().animate({scrollTop: scrollPos}, speed);		
	}
});
