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

jQuery(document).ready(function() {
	jQuery("a#1").click(function() { show(3); return false; });
	jQuery("a#2").click(function() { show(2); return false; });
	jQuery("a#3").click(function() { show(1); return false; });
	jQuery("a#4").click(function() { show(0); return false; });
	
	
	/*$("a#5").click(function() { show(4); return false; });
	$("a#6").click(function() { show(5); return false; });*/
	var images = jQuery("#gallery img");
	var thumbs = jQuery("#thumbs img");
	var thumblinks = jQuery("#thumbs a");
	var index = thumbs.length-1;
	var thumbsHeight = 150;
	var i = 0;
	thumblinks.slice(thumblinks.length-3,thumblinks.length).clone().attr('id', function() { var id = jQuery(this).id; return 'b' + this.id}).prependTo("#thumbs");
	jQuery("a#b1").click(function() { show(3); return false; });
	jQuery("a#b2").click(function() { show(2); return false; });
	jQuery("a#b3").click(function() { show(1); return false; });
	jQuery("a#b4").click(function() { show(0); return false; });
	
	/*$("a#b6").click(function() { show(5); return false; });8*/
	for (i=0; i<thumbs.length; i++) {
		jQuery(thumbs[i]).addClass("thumb-"+i);
		jQuery(images[i]).addClass("image-"+i);
	}
	
	show(index);
	setInterval(sift, 8000);
	function sift() {
		if ( index < thumbs.length && index > 0) {index -= 1 ; }
		else { index = thumbs.length-1 }
		show ( index );
	}
	function show(num) {
		images.fadeOut(400);
		jQuery(".image-"+num).stop().fadeIn(400);
		var scrollPos = ( (num-1) * thumbsHeight ) + 150;
		jQuery("#thumbs").stop().animate({scrollTop: scrollPos}, 400);
	}
});
