﻿var intIntervalTimeout = 0;
var blnAllowInterval = false;

function SetupFeaturedEmployers() {
    Event.observe(window, 'load', function() {
        var objDiv = $('divFeaturedEmployers');
        Event.observe(objDiv, 'mouseover', function() {
            StopFeaturedEmployers();
        });
        Event.observe(objDiv, 'mouseout', function() {
            StartFeaturedEmployers();
        });
        ShowFeaturedEmployers();
    });
}

function StopFeaturedEmployers() {
    if (intIntervalTimeout != 0) {
        window.clearTimeout(intIntervalTimeout);
        intIntervalTimeout = 0;
    }
}

function StartFeaturedEmployers() {
    StopFeaturedEmployers();
    if (blnAllowInterval) {
        intIntervalTimeout = window.setTimeout("ShowFeaturedEmployers()", 5000);
    }
}


function ShowFeaturedEmployers() {
    var objFeaturedJob = null;
    
    var strHTML = "<table 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 < 2; 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 < 2; i++) {
            intCurrentPositionID++;
            if (intCurrentPositionID == FeaturedEmployers.length) {
                intCurrentPositionID = 0;
            }
            objFeaturedJob = FeaturedEmployers[intCurrentPositionID];
            strHTML += "<td valign=\"middle\" align=\"center\">" + GetFullURL(objFeaturedJob.Link,objFeaturedJob.Title) + "<img border=\"0\" alt=\"\" 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 > 4) {
        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;
}