/*
 * ------------------------------------------------------------
 * Simple Scroller
 * by Siddharth S, www.ssiddharth.com, hello@ssiddharth.com
 * Version: 1.0, 05.10.2009
 * ------------------------------------------------------------
 */
/*$.noConflict();*/
$(document).ready(function() 
{	 
	var index = 0;
	var images = $("#gallery img");
	var thumbs = $("#thumbs img");
	var imgHeight = $(thumbs).attr("height");
	//$(thumbs).slice(0,3).clone().appendTo("#thumbs");
	for (i=0; i<thumbs.length; i++)
	{
		$(thumbs[i]).addClass("thumb-"+i);
		$(images[i]).addClass("image-"+i);
	}

	$("#next").click(sift);
	show(index);
	setInterval(sift, 6000);

	function sift()
	{
	    if(index < (Math.floor(thumbs.length)/2)-1){ index+=1;}
		else {index=0; }

		if((index+1) >(thumbs.length)-2){scrollPos = 0;}
		else {scrollPos = index+1};
		show (index);
	}

	function show(num)
	{
		$(images).fadeOut(400);
		$(".image-"+num).stop().fadeIn(400);
		var scrollPos = (num+1)*imgHeight;
		$("#thumbs").stop().animate({scrollTop: scrollPos}, 400);
		//console.log(scrollPos, "img.image-"+num);
	}
});
