// always remove outlines
$("a").each(function(){
	this.onmouseup = this.blur();
});
// document ready

function IncludeJavaScript(jsFile)
{
    document.write('<script type="text/javascript" src="' + jsFile + '"></script>'); 
}

//	Function to include stylesheet through javascript
function IncludeCSS(CSS_File_Path) 
{
	var v_css  = document.createElement('link');
	v_css.rel = 'stylesheet'
	v_css.type = 'text/css';
	v_css.href = CSS_File_Path;
	document.getElementsByTagName('head')[0].appendChild(v_css);
}


$(document).ready(function() {
	$("a#1").click(function() { show(0); return false; });
	$("a#2").click(function() { show(1); return false; });
	$("a#3").click(function() { show(2); return false; });
	$("a#4").click(function() { show(3); return false; });
	$("a#5").click(function() { show(4); return false; });
	$("a#6").click(function() { show(5); return false; });
	var images = $("#gallery img");
	var thumbs = $("#thumbs img");
	var thumblinks = $("#thumbs a");
	var index = thumbs.length-1;
	var thumbsHeight = 120;
	thumblinks.slice(thumblinks.length-3,thumblinks.length).clone().attr('id', function() { var id = $(this).id; return 'b' + this.id}).prependTo("#thumbs");
	$("a#b4").click(function() { show(3); return false; });
	$("a#b5").click(function() { show(4); return false; });
	$("a#b6").click(function() { show(5); return false; });
	for (i=0; i<thumbs.length; i++) {
		$(thumbs[i]).addClass("thumb-"+i);
		$(images[i]).addClass("image-"+i);
	}
	show(index);
	setInterval(sift, 9000);
	function sift() {
		if ( index < thumbs.length && index > 0) {index -= 1 ; }
		else { index = thumbs.length-1 }
		show ( index );
	}
	function show(num) {
		images.fadeOut(400);
		$(".image-"+num).stop().fadeIn(400);
		var scrollPos = ( (num-1) * thumbsHeight ) + 120;
		$("#thumbs").stop().animate({scrollTop: scrollPos}, 400);
	}
});
