// This flag is used by scripts.js to load the correct video.html file.

var previewPlayer = true;  // put in later when Huda is ready!
var cnnSlateID;
var cnnSlateTeaseID;
var cnnSlateSliderID;
var cnnDomainArray = location.hostname.split( '.' );
var EditionDomain = ( cnnDomainArray.length > 1 ) ? '.' + cnnDomainArray[cnnDomainArray.length-2] + '.' + cnnDomainArray[cnnDomainArray.length-1] : '';


function cnnDynScriptInclude(queryString) {
    var incFile = getParameter(queryString,'fwst');
    if ((incFile == "null") || (incFile == "undefined")) {
        incFile = "defaultDPT";
    }
    //alert("incFile " + incFile);
    var str='<script type="text/javascript" src="http://i.a.cnn.net/cnn/video/portable/scripts/' + incFile + '.js"><\/script>';
    //alert(str);
    document.write(str);
}


function cnnLoadPromoInterface() {
        if(videoActiveX) {
                document.getElementById('cnnPromoInterface').className = "PC";
                document.getElementById('cnnVideoWindow').className = "cnnVideoWindowPC";
                document.getElementById('cnnVideoScreen').className = "cnnVideoScreenPC";
                document.getElementById('cnnWhatsOn').className = "cnnWhatsOnOn";
        } else {
                if (cnnFlip4Mac) {
                    document.getElementById('cnnPromoInterface').className = "cnnFlip4Mac";
                    document.getElementById('cnnVideoWindow').className = "cnnVideoWindowFlip4Mac";
                    document.getElementById('cnnVideoScreen').className = "cnnVideoScreenFlip4Mac ";
                } else {
                    document.getElementById('cnnPromoInterface').className = "MAC";
                    document.getElementById('cnnVideoWindow').className = "cnnVideoWindowMAC";
                    document.getElementById('cnnVideoScreen').className = "cnnVideoScreenMAC";
                }
        }
}

function cnnHideSlateAndGo() {
    cnnSlateID.style.visibility = 'hidden';
    cnnSlateTeaseID.style.visibility = 'hidden';
    cnnSlateSliderID.style.visibility = 'hidden';
    cnnLoadMode(); 
    var t = cnnGetDPT();
    setTimeout("cnnDP()", cnnGetDPT());
}

function cnnDP() {
    if (msie) {
        document.getElementById("cnnBlockPC1UI").style.visibility = 'visible';
        document.getElementById("cnnBlockPC2UI").style.visibility = 'visible';
        document.getElementById("cnnBlockPC3UI").style.visibility = 'visible';
        document.getElementById("cnnBlockPC4UI").style.visibility = 'visible';
    } else {
        var block = document.getElementById("cnnBlockMACUI");
        block.style.visibility = 'visible';
    }

    cnnSlateID.style.visibility = 'hidden';
    cnnSlateTeaseID.style.visibility = 'hidden';
    cnnSlateSliderID.style.visibility = 'hidden';

    cnnLoadVideo("video/marketing");
    cnnSalesVideoPlaying = true; 
    setTimeout("cnnDPFlag = true");
}

function cnnStartPromo() {
    if (msie) {
        cnnSlateID = document.getElementById('cnnSlatePC') || null;
    } else if (cnnFlip4Mac) {
        cnnSlateID = document.getElementById('cnnSlateFlip4Mac') || null;
    } else {
        cnnSlateID = document.getElementById('cnnSlateMAC') || null;
    }

    cnnSlateTeaseID = document.getElementById('cnnSlateTease') || null;
    cnnSlateSliderID = document.getElementById('cnnSlateSlider') || null;

    //alert("cnnSlateID " + cnnSlateID);
    //alert("cnnSlateTeaseID " + cnnSlateTeaseID);
    //alert("cnnSlateSliderID " + cnnSlateSliderID);

    var t = cnnGetDPT();
    var theHtml = "<center><h3>"+ ((t / 1000) / 60) + " Minute Preview</h3><h4>Starts Now</h4></center>";
    if (!msie) {
        theHtml = "<br>" + theHtml;
    }

    cnnSlateTeaseID.innerHTML = theHtml;

    cnnSlateID.style.display = "block";
    cnnSlateID.style.visibility = 'visible';
    cnnSlateTeaseID.style.visibility = 'visible';
    cnnSlateSliderID.style.visibility = 'visible';

    setTimeout("cnnHideSlateAndGo()",3000);
}


function cnnGetPromoPlayerCookie() {
    var theCookie = WM_readCookie("oneaday");
    return theCookie;
}

function cnnSetPromoPlayerCookie() {
    var curDate = new Date();

    // firefox getYear() returns current year - 1900; IE and others return current year
    var curYear = curDate.getYear();
    if (curYear < 1900) {
        curYear += 1900;
    }

    var expDate = new Date(curYear, curDate.getMonth(), curDate.getDate(), 23,59,59);
    var expDateGMT = expDate.toGMTString();

    WM_setCookie("oneaday", "7F08377AD40A3F", expDateGMT, "/", EditionDomain);
}

function cookieCheck() {
    if (cnnGetPromoPlayerCookie()) {
        alert("The Preview can only be viewed once a day.");

        // redirect to landing page
        top.location.href="http://www.cnn.com/pipeline/index.preview.html";
    } else {
        cnnSetPromoPlayerCookie();
        if (!cnnGetPromoPlayerCookie()) {
            alert("Please enable cookies before launching the Pipeline Web Player.");

            // redirect to blank page
            top.location.href="blank.html";
        }
    }
}

function cnnLoadPromoPlayer() {
    setBrowser();
    cnnLoadPromoInterface();
    cnnRefreshRelated();
    cnnRefreshJustIn();
    cnnRefreshSchedule();
    cnnRefreshNowInTheNews();
    cnnRefreshTopStories();
    cnnRefreshLiveFeeds();
    cnnRefreshLiveFeedImages();
    cnnPlayTopStories();
    cnnRefreshOnDemand();
    cnnLoadBrowse('time');
    cnnRefreshWhatsOn();
    pollForContentUpdates();

    // Wait a few seconds before showing slate, so that more interface 
    // images can be loaded many of them are coming in asynch (because 
    // of IFRAME's / AJAX)
    setTimeout("cnnStartPromo()", 4000);
}
