﻿var intIntervalTimeout = 0;
var blnAllowInterval = false;
var intCols = 0;
var intRows = 0;

function SetupFeaturedEmployers() {
    Event.observe(window, 'load', function () {
        var objDiv = $('divFeaturedEmployers');
        Event.observe(objDiv, 'mouseover', function () {
            StopFeaturedEmployers();
        });
        Event.observe(objDiv, 'mouseout', function () {
            StartFeaturedEmployers();
        });


        //image sizes 100x70
        intCols = Math.floor(objDiv.getWidth() / 100);
        intRows = Math.floor(objDiv.getHeight() / 70);

        ShowFeaturedEmployers();
    });
}

function StopFeaturedEmployers() {
    if (intIntervalTimeout != 0) {
        window.clearTimeout(intIntervalTimeout);
        intIntervalTimeout = 0;
    }
}

function StartFeaturedEmployers() {
    StopFeaturedEmployers();
    if (blnAllowInterval) {
        intIntervalTimeout = window.setTimeout("ShowFeaturedEmployers()", 2000 + (500 * (intRows * intCols)));
    }
}


function ShowFeaturedEmployers() {
    var objFeaturedJob = null;

    var strHTML = "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">";
    //strHTML += "<tr>";
    //strHTML += "<td><img border=\"0\" width=\"1\" height=\"1\" src=\"/site/misc/sportspeople/sp2005/image/spacer.gif\"/></td>";
    //strHTML += "<td><img border=\"0\" width=\"133\" height=\"0\" src=\"/site/misc/sportspeople/sp2005/image/spacer.gif\"/></td>";
    //strHTML += "<td><img border=\"0\" width=\"133\" height=\"0\" src=\"/site/misc/sportspeople/sp2005/image/spacer.gif\"/></td>";
    //strHTML += "</tr>";
    for (var j = 0; j < intRows; j++) {
        strHTML += "<tr>";
        //strHTML += "<td><img border=\"0\" height=\"78\" width=\"5\" src=\"/site/misc/sportspeople/sp2005/image/spacer.gif\"/></td>";
        for (var i = 0; i < intCols; i++) {
            intCurrentPositionID++;
            if (intCurrentPositionID == FeaturedEmployers.length) {
                intCurrentPositionID = 0;
            }
            objFeaturedJob = FeaturedEmployers[intCurrentPositionID];
            strHTML += "<td valign=\"middle\" width=\"" + (100 / intCols) + "%\" align=\"center\">" + GetFullURL(objFeaturedJob.Link, objFeaturedJob.Title) + "<img alt=\"" + URLDecode(objFeaturedJob.Title) + "\" border=\"0\" src=\"/site/misc/sportspeople/uploads/logo_images/image_" + URLDecode(objFeaturedJob.Image) + "_0.jpg\"/></a></td>";
        }
        strHTML += "</tr>";
    }
    strHTML += "</table>";
    //alert(strHTML);
    $('divFeaturedEmployers').innerHTML = strHTML;

    if (FeaturedEmployers.length > (intRows*intCols)) {
        blnAllowInterval = true;
        StartFeaturedEmployers();
    }
}

function URLDecode(s) {
    return decodeURIComponent(s).replace(/\+/g, " ");
}

function GetFullURL(sLink, sTitle) {
    var strURL = "<a title=\"" + URLDecode(sTitle) + "\"";

    if (sLink.substring(32, 0) == "/sp/position/PositionDisplay.asp") {
        strURL += " target=\"positiondisplay\" href=\"" + sLink + "\" onclick=\"DoJSPopup(this.href,this.target,630,600); return false;\">";
    }
    else if (sLink.substring(1, 0) == "/") {
        strURL += " target=\"_top\" href=\"" + sLink + "\">";
    }
    else if (sLink.substring(4, 0) == "http") {
        strURL += " target=\"_blank\" href=\"" + sLink + "\">";
    }
    else {
        strURL += " target=\"_top\" href=\"/?ID=" + sLink + "\">";
    }

    return strURL;
}
