// slider script for home page
var timer=null;
// time between slide changes in milliseconds
var offset=6000;
// begins at slide INDEX+1, so -1 means start at first slide (zero)
var index=-1;

function slideImage(A){
	var B="image_"+target[A];
	$("#"+B).animate({opacity:1},800,function(){
         $(this).find(".word").animate({
			height:"show"},"slow")}).show()
		    .siblings(":visible")
		    .find(".word").animate({
			height:"hide"},"fast",function(){
			 $(this).parent().animate({opacity:0},800).hide()})}

function hookThumb(){
	$("#thumbs li a").bind("click",function(){
		if(timer){clearTimeout(timer)}
		var A=this.id;
		index=getIndex(A.substr(6));																																																								            rechange(index);																																																													            slideImage(index);																																																													            timer=window.setTimeout(auto,offset);
		    this.blur();
			return false
			})}

function hookBtn(){
	$("#thumbs li img")
		.filter("#play_prev,#play_next")
		.bind("click",function(){
			if(timer){clearTimeout(timer)}
		    var A=this.id;
			if(A=="play_prev"){
			index--;if(index<0){index=3}
			}
			else{index++;
			if(index>3){index=0}}rechange(index);																																											            slideImage(index);
			timer=window.setTimeout(auto,offset)})
			}

function getIndex(A){
	for(var B=0;B<target.length;B++){
	if(target[B]==A){return B}}}

function rechange(A){
	var B="thumb_"+target[A];
	 $("#thumbs li a.current").removeClass("current");
	 $("#"+B).addClass("current")}

function auto(){
	index++;
	if(index>3){index=0}
	rechange(index);
	slideImage(index);
    timer=window.setTimeout(auto,offset)};