// JavaScript Document
var currE = 0;
var docLinks = new Array(3);
//Link 1 from wellness stories Banner on Gateway page
var wsLink = "content/products/product-detail.aspx?id=722&tab=4";
//Link 1 from wellness center banner (if one is used in a particular month, otherwise it will stay '#')
var mbLink = "#";
// Links 1, 2 and 3 from 'banner1.swf' file
docLinks[0] = "content/products/product-detail.aspx?id=3918&tab=4";
docLinks[1] = "content/products/view-products.aspx?id=4000";
docLinks[2] = "content/affiliate/why-join.aspx";
//docLinks[2] = "content/products/product-detail.aspx?id=4150&tab=4";
var img1 = new Image(950, 405);
img1.src = 'images/FLASHALT/slide1.jpg';
var img2 = new Image(950, 405);
img2.src = 'images/FLASHALT/slide2.jpg';
var img3 = new Image(950, 405);
img3.src = 'images/FLASHALT/slide3.jpg';
var jqTimer = false;

function writeFlash(path, flaPath, theScript, w, h) {
    flaPath = path + "/" + flaPath;
    var hasFlash = false;
    try {
        var fo = new ActiveXObject('ShockwaveFlash.ShockwaveFlash');
        if (fo) hasFlash = true;
    }
    catch (e) {
        if (navigator.mimeTypes["application/x-shockwave-flash"] != undefined) hasFlash = true;
    }
    if (hasFlash) {
        document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="' + w + '" height="' + h + '" id="' + theScript + '" align viewastext>');
        document.write('<param name="movie" value="' + flaPath + "/" + theScript + '.swf">');
        document.write('<param name="quality" value="high">');
        document.write('<param name="wmode" value="transparent">');
        document.write('<param name="allowScriptAccess" value="always">');
        document.write('<embed src="' + flaPath + "/" + theScript + '.swf" quality="high" swliveconnect="true" allowScriptAccess="always" name="' + theScript + '" align width="' + w + '" height="' + h + '" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer" wmode="transparent">');
        document.write('</object>');
    }
    if (!hasFlash && (theScript == 'banner1')) {
        document.write('<div id="jsDiv" style="background:url(' + path + '/images/FLASHALT/slide1.jpg) top left no-repeat; position:relative; height:' + h + 'px; width=' + w + 'px;">');
        document.write('<a href="#" style="width:40px; height:' + h + 'px; cursor:pointer;" onclick="javascript:changeBG(\'p\'); jqTimer=false;"><div title="Previous" style="float:left; width:40px; height:' + h + 'px;">&nbsp;</div></a>');
        document.write('<a id="divLink" style="width:' + (w - 86) + 'px; height:' + h + 'px; cursor:pointer;" href="');
        document.write(docLinks[0]);
        document.write('"><div id="noFlashLink" style="float:left; width:' + (w - 86) + 'px; height:' + h + 'px;">&nbsp;</div></a>');
        document.write('<a href="#" style="width:40px; height:' + h + 'px; cursor:pointer;" onclick="javascript:changeBG(\'n\'); jqTimer=false;"><div title="Next" style="float:left; width:40px; height:' + h + 'px;">&nbsp;</div></a>');
        document.write('</div>');
        startTIMER();
    }
    if (!hasFlash && (theScript == 'WellnessStories')) {
        document.write("<a href=\"" + path + "/" + wsLink + "\"><img src=\"" + path + "/images/FLASHALT/gateway-Replace.jpg\" width=\"" + w + "\" height=\"" + h + "\" alt=\"\" /></a>");
    }
    if (!hasFlash && (theScript == 'Main-Banner')) {
        document.write("<a href=\"" + path + "/" + mbLink + "\"><img src=\"" + path + "/images/FLASHALT/WellnessCenter-banner.jpg\" width=\"" + w + "\" height=\"" + h + "\" alt=\"\" /></a>");
    }
}
function startTIMER() {
    if (jqTimer) {
        var myTimer = setTimeout("startTIMER();", 6000);
        changeBG('n');
    }
    else {
        var myTimer = setTimeout("startTIMER();", 6000);
        jqTimer = true;
    }
}
function changeBG(NP) {
    //alert(currE);
    var myArr = new Array(3);
    var myDiv = document.getElementById('jsDiv');
    var myLink = document.getElementById('noFlashLink');
    // we will need to determine if the site is US or Canada... set an appropriate variable to replace "US" / "CA" below...
    myArr[0] = 'images/FLASHALT/slide1.jpg';
    myArr[1] = 'images/FLASHALT/slide2.jpg';
    myArr[2] = 'images/FLASHALT/slide3.jpg';
    //Canada...
    //myArr[0] = 'images/FLASHALT/CA-slide1.jpg';
    //myArr[1] = 'images/FLASHALT/CA-slide2.jpg';
    //myArr[2] = 'images/FLASHALT/CA-slide3.jpg';
    if (NP == "n" && currE <= 2) {
        if (currE != 2) {
            currE++;
            $('#jsDiv').hide();
            myDiv.style.backgroundImage = "url(" + myArr[currE] + ")";
            $('#jsDiv').fadeIn('slow');
            checkCurrE();
        }
        else {
            currE = -1;
            currE++;
            $('#jsDiv').hide();
            myDiv.style.backgroundImage = "url(" + myArr[currE] + ")";
            $('#jsDiv').fadeIn('slow');
            checkCurrE();
        }
    }
    if (NP == "p" && currE >= 0) {
        if (currE != 0) {
            currE--;
            $('#jsDiv').hide();
            myDiv.style.backgroundImage = "url(" + myArr[currE] + ")";
            $('#jsDiv').fadeIn('slow');
            checkCurrE();
        }
        else {
            currE = 3;
            currE--;
            $('#jsDiv').hide();
            myDiv.style.backgroundImage = "url(" + myArr[currE] + ")";
            $('#jsDiv').fadeIn('slow');
            checkCurrE();
        }
    }
}
function checkCurrE() {
    var myDivLink = document.getElementById('divLink');
    if (currE) {
        myDivLink.href = docLinks[currE];
    }
    else {
        myDivLink.href = docLinks[0];
    }
}
