/* Modify These Settings */

adDiv       = 'mediaspace';
isPreLoaded  = false;
newState     = 'NOT STARTED';
lastStatus   = 'NOT STARTED';
Footer       = "<div class='adclose' style='margin:3px auto 3px auto;width:100px;clear:both;'><a href='JavaScript:void( 0 )' onClick=\roverlayclose('content'); return false;\r class='adbutton'>Close Ad</a></div></center>";
Header       = "<style type='text/css'>.adbutton:link {background: url(/gfx/adbutton.png) no-repeat;text-decoration: none;text-align: center;border: none;display: block;width: 94px;height: 22px;line-height:20px;cursor: pointer; clear:both;color:#333333;font-size:12px;} .adbutton:hover {background: url(/gfx/adbutton.png) no-repeat 0 -22px;clear:both;color:#AAAAAA;}</style><center>";
PreIframe    = "<br><br><br><br><br><center><iframe src='/ads_pre.php?url=" + window.location + "' width='320' height='270' frameborder='0'></iframe></center>";
PauseIframe  = "<br><br><br><br><br><center><iframe src='/ads_pause.php?url=" + window.location + "' width='320' height='270' frameborder='0'></iframe></center>";
PostIframe   = "<br><br><br><br><br><center><iframe src='/ads_post.php?url=" + window.location + "' width='320' height='270' frameborder='0'></iframe></center>";
showPre      = true;
showPause    = true;
showPost     = true;
playerWidth  = 640;
playerHeight = 519;

/* DON'T TOUCH BELOW THIS LINE */

if (showPre) {showPreroll();} else {startPlaying();};

function playerReady(obj) {
    pid = obj['id'];
    pobj = thisMovie(pid);
    pobj.addModelListener("STATE", "playerStateChange");
}

function getPlayer(gid) {
    if(navigator.appName.indexOf("Microsoft") != - 1) {
        return window[gid]; 
    }
    else {return document[gid]; }
}

function startPlaying() {
    pid = GetPlayerId();
    getPlayer(pid).sendEvent("PLAY", "true");
}

function overlaycloseandplay(subobj) {
    document.getElementById("content_" + adDiv).style.display = "none"; 
    startPlaying();
}

function sendEvent(swf, typ, prm) {
    if (thisMovie(swf) != null) {
        thisMovie(swf).sendEvent(typ, prm); }
}

function thisMovie(swf) {
    if(navigator.appName.indexOf("Microsoft") != - 1) {return window[swf]; }
    else {return document[swf]; }
}; 

function GetPlayerId() {
    var imager, flash, looper, nChildCount, x, item, y; 
    looper = 0; 
    imager = document.getElementById(adDiv); 
    nChildCount = imager.childNodes.length; 
    for (looper = 0; looper < nChildCount; looper++) {
        flash = imager.childNodes[looper]; 
        x = flash.childNodes.length; 
        if (x > 0) {
            for (y = 0; y < x; y++) {
                item = flash.childNodes[y]; 
                if (item.width > 200) {return item.id; }
            }
        }
        if (flash.width > 200) {return flash.id; }
    }
    return 0; 
}

function overlayclose(subobj) {
    document.getElementById("content_" + adDiv).style.display = "none"; 
    document.getElementById("content_" + adDiv).innerHTML = ""; 
}

function showPreroll() {
    if (!isPreLoaded) {
        isPreLoaded = true;
        setTimeout("showAd()", 1000);
    }
}

function playerStateChange(stateobj) {
    lastStatus = stateobj.oldstate;
    if ((stateobj.newstate == "COMPLETE") || (stateobj.newstate == "COMPLETED")) {lastStatus = "COMPLETE"; showAd();};
    if (stateobj.newstate == "PAUSED" && stateobj.oldstate == "PLAYING") {showAd();};
    if (stateobj.newstate == "PLAYING") {overlayclose();};    
}

function showAd() {
    objDiv = document.getElementById(adDiv); 
    objDiv.style["width"] = playerWidth + "px";

    objP = document.getElementById(adDiv); 
    objP = objP.firstChild; 

    var subs = document.createElement('DIV'); 
    subs.setAttribute('id', 'content_' + adDiv); 
    subs.setAttribute('name', 'content_' + adDiv); 
    subs.setAttribute('border', '0'); 
    subs.style["position"] = "absolute"; 
    subs.style["float"] = "left"; 
    subs.style["z-index"] = "100"; 
    subs.style["width"] = playerWidth + "px"; 
    subs.style["height"] = playerHeight + "px"; 
    subs.style["display"] = "none"; 
    var parNode = objP.parentNode; 
    parNode.insertBefore(subs, objP); 

    sDiv = document.getElementById("content_" + adDiv); 
    sDiv.style["display"] = "block"; 
    sDiv.style["z-index"] = "100"; 
    sDiv.style["width"] = playerWidth + "px"; 
    sDiv.style["height"] = playerHeight + "px"; 
    sDiv.style["text-align"] = "left"; 
    sDiv.style["float"] = "left"; 

    if (lastStatus == "NOT STARTED") {
        lastStatus = "PREROLL"; 
        sDiv.innerHTML = Header + PreIframe + Footer.replace("overlayclose(", "overlaycloseandplay(");
    }

    if (lastStatus == "PLAYING" && showPause) {
        lastStatus = "PAUSED"; 
        sDiv.innerHTML = Header + PauseIframe + Footer.replace("overlayclose(", "overlaycloseandplay(");
    }

    if (lastStatus == "COMPLETE" && showPost) {
        lastStatus = "POSTROLL"; 
        sDiv.innerHTML = Header + PostIframe + Footer;
    }
}


