﻿var browserVersion;
var direction;
var scrolltimer;

function scrollStart()
{
    if (document.layers) {	// netscape 4.0 and up
		browserVersion = eval(document.divASContainer.document.contentLayer);
	}
	else {
		if (document.getElementById) { // internet explorer 6.0 and netscape 6.0
			browserVersion= eval("document.getElementById('contentLayer').style");
		}
		else {	
			if (document.all) { // internet explorer 4.0 and up
				browserVersion = eval(document.all.contentLayer.style);
	      }
	   }
	}
	verScroll('right','1');
}


function verScroll(dir, spd) {
	minx = (document.getElementById('slideshow').offsetWidth - document.getElementById('divASContainer').offsetWidth) * -1;
	scrolltimer = null;
	direction = dir;
	speed = parseInt(spd);
	var x_pos;
	x_pos = parseInt(browserVersion.left);
	
	if (direction == "right" && x_pos > minx)
	    browserVersion.left = (x_pos - (speed)) + 'px';
	else if (direction == "right")
	    browserVersion.left = '0px';	
	
	if (direction == "left" && x_pos < 0)
	    browserVersion.left = (x_pos + (speed)) + 'px';
	else if (direction == "left")
	    browserVersion.left = minx + 'px';
	
	if (navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.indexOf("Mac") != -1)
	{
	    scrolltimer = setTimeout("verScroll(direction,speed)", 1);
	    speed=24;
	}
	else
	{
	    scrolltimer = setTimeout("verScroll(direction,speed)", 24);
	}
}

function stopScroll() {
	clearTimeout(scrolltimer);
}

function startAndStop(dir, spd) {
	clearTimeout(scrolltimer);
	verScroll(dir, spd);
}

AddOnLoadFunction('OnLoadHome','OnLoadHome()');


function OnLoadHome()
{
    document.getElementById('scrollLeft').onmouseover = function()
    {
        startAndStop('right','15'); 
        this.src='images/scroll_arrows_left_on.gif';
    };
    
    document.getElementById('scrollLeft').onmouseout = function()
    {
        startAndStop('right','1');
        this.src='images/scroll_arrows_left_off.gif';
    };
    
    document.getElementById('scrollRight').onmouseover = function()
    {
        startAndStop('left','15');
        this.src='images/scroll_arrows_right_on.gif';
    }
    
    document.getElementById('scrollRight').onmouseout = function()
    {
        startAndStop('left','1');
        this.src='images/scroll_arrows_right_off.gif';
    }
    
    
    var imgs = document.getElementsBySelector("#slideshow img");
    if (imgs && imgs.length > 0)
    {
        var pimgs = $A(imgs);
        pimgs.each( 
            function(img)
            {
                img.style.cursor = "pointer";
            
                img.onmouseover = function()
                {
                    stopScroll();
                };
                
                img.onmouseout = function()
                {
                    startAndStop(direction,'1');
                };
            }
        );
    }
    
    scrollStart();
}