// Homepage functions

// functions preload 
/*
Event.observe(window, 'load', function() {
	var slideshow1 = $('slideshow1');
	var slideshow2 = $('slideshow2');
	var slideshow3 = $('slideshow3');
	
	slideshow1.onmouseover  = function() {holdSlide()};
	slideshow1.onmouseout  = function() {rotateSlide(1)};
	
	slideshow2.onmouseover  = function() {holdSlide()};
	slideshow2.onmouseout  = function() {rotateSlide(2)};
	
	slideshow3.onmouseover  = function() {holdSlide()};
	slideshow3.onmouseout  = function() {rotateSlide(3)};

});
*/


//scroller functions
scrollerImages=new Array() //preload images
for (p=0; p<theScrollerImages.length; p++){
		scrollerImages[p] = document.createElement('img');
		scrollerImages[p] = document.createElement('img');
		//button_on.setAttribute('src','redButtonOn.gif');
		//button_go.setAttribute('src','redButtonGo.gif');
		scrollerImages[p].setAttribute('src',theScrollerImages[p]);
		//scrollerImages[p]=new Image()
		//scrollerImages[p].src=theScrollerImages[p]
}

// change the mouseover btns
// id of the object sending and number in the array to change the image to
function changeBtn(btnId, btnNewSrc){

	$(btnId).src = scrollerImages[btnNewSrc].src;

}

//width in pixels for the bottom images for the scroller function
stopat1 = 161;
stopat2 = 336;

//set up image scroller
$('images1').innerHTML = $('images2').innerHTML;
$('images3').innerHTML = $('images2').innerHTML;

$('scrollContent').style.marginLeft = -(stopat1 * 6) + "px";

//scroll content on the bottom of the page
// uses scriptaculous library system 
defaultStep=10
step=defaultStep


// set default value for counter to keep from clicking too far one way or the other
numClicksRight = 0;

function MoveRight(id)
{
    //clear the mousedowns for stopping multiple clicks 
	$('moveLeftLink').onmousedown=null ;
  	$('moveRightLink').onmousedown=null ;
	
	// move function 
	if (numClicksRight > -5){
		new Effect.MoveBy(id, 0, stopat1 , 
			  {
				  duration: 1.5,  
				  transition: Effect.Transitions.sinoidal,
				  queue: 'end',
				  afterFinish: returnMouseDown
			  });
		
			numClicksRight--;
			//alert (numClicksRight);
			
	}
	// move function and reset div to appear to scroll forever
	else {
		
		new Effect.MoveBy(id, 0, stopat1 , 
			  {
				  duration: 1.5,  
				  transition: Effect.Transitions.sinoidal,
				  queue: 'end',
				  afterFinish: moveScroller1
			  });
		
		
	}
	
}

// reset scrolling div 
function moveScroller1() {
		
		$('scrollContent').style.left = "0px";
		numClicksRight = 0;
		//alert($('scrollContent').style.marginLeft);
		returnMouseDown();
		
}

function MoveLeft(id)
{
	//clear the mousedowns for stopping multiple clicks 
    $('moveLeftLink').onmousedown=null ;
    $('moveRightLink').onmousedown=null ;
	
	if (numClicksRight < 7){
		new Effect.MoveBy(id, 0, -stopat1 , 
			  {
				  duration: 1.5,  
				  transition: Effect.Transitions.sinoidal,
				  queue: 'end',
				  afterFinish: returnMouseDown
			  });
		numClicksRight++;
	}
	
	// move function and reset div to appear to scroll forever
	else {
	
		new Effect.MoveBy(id, 0, -stopat1 , 
			  {
				  duration: 1.5,  
				  transition: Effect.Transitions.sinoidal,
				  queue: 'end',
				  afterFinish: moveScroller2
			  });
		
			
	}
	
}

// reset scrolling div 
function moveScroller2() {

		$('scrollContent').style.left = (-1 *(stopat1 * 2)) + "px";
		numClicksRight = 2;
		returnMouseDown();
		
}

// return mousedown functionality 
function returnMouseDown()


{

	var click1 = $('moveLeftLink');
   	var click2 = $('moveRightLink');
	click1.onmousedown  = function() {MoveRight('scrollContent')};
	click2.onmousedown  = function() {MoveLeft('scrollContent')};

}

// slideshow functions 

 var fullDelay = 7000;
 var shortDelay = 2000;
 var firstSlide = 1;
 var lastSlide = 3; 

 try {
    	start_slideshow(firstSlide, lastSlide, fullDelay);
	}
	
	catch (e) {}
    var t1, t2, t3, t4;
    function start_slideshow(start_frame, end_frame, delay) {
       	t1 = setTimeout(switch_slides(start_frame,start_frame,end_frame, delay), delay);
    }
                            
    function switch_slides(frame, start_frame, end_frame, delay) {
        return (function() {
            Effect.Fade('slideshow' + frame);
			var currentSlideNumber = "slideClick" + frame;
		 	$(currentSlideNumber).style.backgroundColor= "#cccccc";
            if (frame == end_frame) { frame = start_frame; } else { frame = frame + 1; }
            t2 = setTimeout("Effect.Appear('slideshow" + frame + "');", 1);
			var currentSlideNumber = "slideClick" + frame;
		 	$(currentSlideNumber).style.backgroundColor= "#ffffff";
            t3 = setTimeout(switch_slides(frame, start_frame, end_frame, delay), delay + 1);
        })
    }
	
	
	function showSlide(thisSlide){
		
		
		$('slideClick1').onclick = "";
		$('slideClick2').onclick = "";
		$('slideClick3').onclick = "";
		
		clearTimeout(t1);
		clearTimeout(t2);
		clearTimeout(t3);
		clearTimeout(t4);
		
		var currentSlide = 0;
		
		if (($('slideshow1').style.display != "none") && thisSlide != 1){
		 	Effect.Fade('slideshow' + 1);
			$('slideClick1').style.backgroundColor= "#cccccc";
			currentSlide = 1;
		}
		if (($('slideshow2').style.display != "none") && thisSlide != 2){
		 	Effect.Fade('slideshow' + 2);
			$('slideClick2').style.backgroundColor= "#cccccc";
			currentSlide = 2;
		}
		if (($('slideshow3').style.display != "none") && thisSlide != 3){
		 	Effect.Fade('slideshow' + 3);
			$('slideClick3').style.backgroundColor= "#cccccc";
			currentSlide = 3;
		}
		 
		 if (currentSlide != thisSlide) {
		 	var currentSlideNumber = "slideClick" + thisSlide;
		 	Effect.Appear('slideshow' + thisSlide, {afterFinish: returnOnclick} );
			$(currentSlideNumber).style.backgroundColor= "#ffffff";
			t1 = setTimeout(switch_slides(thisSlide, firstSlide, lastSlide, fullDelay), fullDelay);
		 }
	}
	
	//mouseover function for slideshow
	function holdSlide() {
	
		clearTimeout(t1);
		clearTimeout(t2);
		clearTimeout(t3);
		clearTimeout(t4);
	
	
	}
	
	//mouseout function for slideshow
	function rotateSlide(thisSlide) {
		
		//use this if you want it to change right away
		//thisSlide += 1;
		
		if (thisSlide > lastSlide) {
		
			thisSlide = firstSlide;
		
		}
		
		//use this if you want it to change right away
		
		//t4 = setTimeout(showSlide(thisSlide), shortDelay);
		
		 
		 //use this to wait for timer
		 
		 
		 	var currentSlideNumber = "slideClick" + thisSlide;
		 	Effect.Appear('slideshow' + thisSlide, {afterFinish: returnOnclick} );
			$(currentSlideNumber).style.backgroundColor= "#ffffff";
			t1 = setTimeout(switch_slides(thisSlide, firstSlide, lastSlide, fullDelay), shortDelay);
		 
	
	}
	
		
	function returnOnclick(){
		var img1 = $('slideClick1');
		var img2 = $('slideClick2');
		var img3 = $('slideClick3');
		
		img1.onclick = function() {showSlide(1)};
		img2.onclick = function() {showSlide(2)};
		img3.onclick = function() {showSlide(3)};
	}
