﻿function HomepageScroller(sContainerDiv, sContentDiv, sArrowLeft, sArrowRight, iSpeed, iScrollDist) {
    var thisScrollObj = new Object();
        
    thisScrollObj.speed = (iSpeed) ? iSpeed : 20;
    thisScrollObj.scrollDist = (iScrollDist) ? iScrollDist : 3;
    thisScrollObj.scrollDistOrig = thisScrollObj.scrollDist;
    
    thisScrollObj.dir = 0;
    thisScrollObj.timerid = 0;
    thisScrollObj.contentXMin = 0;
    
    
    thisScrollObj.oContainerDiv = document.getElementById(sContainerDiv);
    thisScrollObj.oContentDiv = document.getElementById(sContentDiv);
    thisScrollObj.oArrowLeft = document.getElementById(sArrowLeft);
    thisScrollObj.oArrowRight = document.getElementById(sArrowRight);            
        
    thisScrollObj.init = function() {
        thisScrollObj.oContentDiv.style.left = "0px";    
        thisScrollObj.contentXMin = thisScrollObj.oContainerDiv.offsetWidth - thisScrollObj.oContentDiv.offsetWidth;
        
        //thisScrollObj.oArrowLeft.style.visibility = (thisScrollObj.contentXMin >= 0) ? "hidden" : "visible";
        //thisScrollObj.oArrowRight.style.visibility = (thisScrollObj.contentXMin >= 0) ? "hidden" : "visible";
    }        
    
    thisScrollObj.scroll = function() {
        thisScrollObj.contentXMin = thisScrollObj.oContainerDiv.offsetWidth - thisScrollObj.oContentDiv.offsetWidth;
    
        iLeft = parseInt(thisScrollObj.oContentDiv.style.left)        
        iLeft += (thisScrollObj.scrollDist * thisScrollObj.dir)
                
        iLeft = (iLeft < thisScrollObj.contentXMin) ? thisScrollObj.contentXMin : iLeft;
        iLeft = (iLeft > 0) ? 0 : iLeft;
        
        thisScrollObj.oContentDiv.style.left = iLeft + "px";
    }
    thisScrollObj.start = function(dir) {
        thisScrollObj.dir = (dir == "left") ? 1 : -1
        thisScrollObj.timerId = setInterval(thisScrollObj.scroll, thisScrollObj.speed);         
    }
    thisScrollObj.stop = function() {
        if (thisScrollObj.timerId) clearInterval(thisScrollObj.timerId);
        thisScrollObj.timerId = 0;  
        thisScrollObj.dir = "";  
    }
    thisScrollObj.doublespeed = function() {
        thisScrollObj.scrollDist = thisScrollObj.scrollDistOrig * 2;
    }
    thisScrollObj.resetspeed = function() {
        thisScrollObj.scrollDist = thisScrollObj.scrollDistOrig;
    }
    
    thisScrollObj.init();
    return thisScrollObj;
}


function setThumb(e, aLink, sImageURL) {    
    oRolloverDIV = document.getElementById("rollOver"); 
    oRolloverImage = document.getElementById("rollOverImage");    
    oRolloverDIV.aLink = aLink;
    aLink.style.visibility = "hidden";
    
    oRolloverImage.src = sImageURL;
    oRolloverDIV.style.cursor = "pointer";
    
    SiteX = (document.body.clientWidth - 828) / 2;    // 828 is the width of the wrapper DIV
   
    oRolloverDIV.style.left = e.clientX - SiteX - 50 - 14 + "px"; // 50 = 1/2 of the width of the popup, 14 is the padding on wrapper DIV
    showThumb();  
}

function showThumb() {
    oRollover = document.getElementById("rollOver");
    oRollover.style.display = "block";
}
function hideThumb(aLink) {
    oRollover = document.getElementById("rollOver");
    oRollover.style.display = "none";
    aLink.style.visibility = "visible";
}
function getLink(oRollOver) {
    location.href = oRollOver.aLink.href;
}
