/*
 * --------------------------------------------------------------------
 * Simple Scroller
 * by Siddharth S, www.ssiddharth.com, hello@ssiddharth.com
 * Version: 1.0, 05.10.2009 	
 * --------------------------------------------------------------------
 */
	var automatic = true;
jQuery(document).ready(function() 
{	 
	var index = 0;
	var images = jQuery("#gallery img");
	var thumbs = jQuery("#thumbs img");
	var imgHeight = jQuery(thumbs).attr("height");

	//jQuery(thumbs).slice(0,3).clone().appendTo("#thumbs");
	for (i=0; i<thumbs.length; i++)
	{
		jQuery(thumbs[i]).addClass("thumb-"+i);
		jQuery(images[i]).addClass("image-"+i);
	}
	
	jQuery("#next").click(nextfn);
	jQuery(".thumb-0").addClass('active');
	show(index);
	setInterval(sift, 6000);
	
	jQuery("#thumbs a").click(function loadimage(){
		automatic		=	false;
	    var new_index	=	jQuery(this).attr('rel');
		jQuery("img").removeClass('active');
		jQuery(".thumb-"+new_index).addClass('active');
		index	=	new_index;
		show (new_index);
	});
	
	function sift()
	{
		if(automatic) {
			if (index<(thumbs.length-1)){index+=1 ; }
			else {index=0}
			jQuery("img").removeClass('active');
			jQuery(".thumb-"+index).addClass('active');
			show (index);
		}
	}
	
	function nextfn()
	{
			if (index<(thumbs.length-1)){index=parseInt(index)+parseInt(1) ; }
			else {index=0}
			jQuery("img").removeClass('active');
			jQuery(".thumb-"+index).addClass('active');
			show (index);
	}
	
	function show(num)
	{
		//jQuery(images).fadeOut(400);
		jQuery(images).hide();
		jQuery(".image-"+num).stop().fadeIn(400);
		var scrollPos = (num+1)*imgHeight;
		jQuery("#thumbs").stop().animate({scrollTop: scrollPos}, 400);		
		console.log(scrollPos, "img.image-"+num);
	}
});
jQuery.noConflict();
