﻿$(document).ready( SetupEffects );

var timerId;
var currentLeft = 0;
var direction = -1;
var moveAmount = 226;
var imagesToScroll = 8;
var imageWidth = 226;
var clickOffSoundFlag = 0;
var canScrollFlag = true;
		
		
function SetupEffects(){
    
    $("#imagecontainer div.picture")
    .hover
    (
         function() { Hilite(this); }
        ,function() { DeHilite(this); }
    );
    
      
    $("#ctlMoveRightArrow")
    .click
    ( 
        function(){ MoveImages(0); } 
    );
    
    
    $("#ctlMoveLeftArrow")
    .click
    ( 
        function(){ MoveImages(1); } 
    );
        
    SetupImages();   
    
}//SetupEffects





//*****************************************************************************************************
//
// Setup and Animate Image Functions
//
//*****************************************************************************************************
function SetupImages(){
    
    $("#imagecontainer div.picture").each( function(index, obj) {         
        var left = 226 * index;
        left = left + "px";
        $(obj).css( "left", left );        
     });
     
     $("#imagecontainer div.picture").each( function(index, obj) {         
        $(obj).css( "display", "block" );        
     });
     
}//SetupImages



function MoveImages( newDirection ){
    direction = newDirection;
    if( canScrollFlag ){
        canScrollFlag = false;
        Animate();
        setTimeout( "ResetScrollFlag()", 700 );
    }//if
}//MOveIMages



function ResetScrollFlag(){
    canScrollFlag = true;    
}//ResetScrollFlag



function Animate(){
        $("#imagecontainer div.picture").each( function(index, obj) { AnimateImage( index, obj ); } );  
}//Animate



function AnimateImage( index, obj){

    var animageFlag = true;
    var tempLeft = $(obj).css("left");
    tempLeft = parseInt( tempLeft );
    
    if( tempLeft < -226 ){
        tempLeft = tempLeft + ( imageWidth * (imagesToScroll - 1) ) ;        
        $(obj).css( "left", tempLeft + "px" );           
    }else if( tempLeft >= (imageWidth * (imagesToScroll - 2 ) ) ){
        tempLeft = -226;     
        $(obj).css( "left", tempLeft + "px" );           
    }//if
    
    if( direction == 0 ){
        tempLeft = tempLeft - moveAmount;
    } else {
        tempLeft = tempLeft + moveAmount;
    }//if
    
    tempLeft = tempLeft + "px";
    $(obj).animate( { "left":tempLeft }, 500  );    
    
}//AnimateImage





//*****************************************************************************************************
//
// Rollover Functions
//
//*****************************************************************************************************
function Hilite( obj ){
    
    clickOffSoundFlag = 0;
    //fix for some items staying highlited
    $("#imagecontainer div.title").css( { "display":"none", cursor:"default" } )          
    $(obj).find("div.title").fadeIn("slow");
}//Hilite



function DeHilite(obj){
   $(obj).find("div.title").css( { "display":"none", cursor:"default" } );
   //PlayClickOffSound();  
}//DeHilite



function PlayClickOffSound(){    
    if( clickOffSoundFlag == 0 ){
        //clickOffSound
	    $.sound.play(clickOffSound, {timeout:2000});	
	    clickOffSoundFlag = 1;
	}//if
}//PLayClickOffSound



