﻿var interval;
var timerdivinterval;

function showPreRoll(fcexp)
{
    var Pre_Roll_Ad = document.getElementById('PreRollAd_div').innerHTML;
    document.getElementById('div_video_ads').style.visibility = "visible";
    document.getElementById('div_video_ads').style.display = "block";
    document.getElementById('div_video_ads').style.background = "#333333";
    document.getElementById('div_video_ads').innerHTML = "";
    //fcexp = 1 for freedocast,0 = express
    if(fcexp == 1) 
    {
        document.getElementById('div_video_ads').style.height='370px';
        document.getElementById('div_video_ads').style.width='614px';
        document.getElementById('div_video_ads').style.top=parseInt(-400)  +'px';
    }
    else
    {
        document.getElementById('div_video_ads').style.height='350px';
        document.getElementById('div_video_ads').style.width='470px';
        document.getElementById('div_video_ads').style.top=parseInt(-350)  +'px';
    }

    var scriptElement = '<div style="margin:0px auto; width:250px;text-align:center;">';
        scriptElement +='<div id="timerdiv" style="text-align:center; font-size:11px;font-weight:bold;';
        scriptElement +='font-family:Verdana, Arial, Helvetica, sans-serif; color:White;height:19px;border:none; z-index:10000000003;">';
        scriptElement +='This ad will close in <span id="timer_div"></span> seconds.</div></div>';
        scriptElement +='<div style="margin:0px auto; width:100px;text-align:center;">';
        scriptElement +='<input type="button" id="btnSkip" onclick="closeAd(0,'+fcexp+')"';
        scriptElement +='style="background: url(http://adshare3.freedocast.com/skipad.png) no-repeat;width:77px;';
        scriptElement +='height:19px;display:none;border:none; position:absolute; z-index:100000005;top:300px;padding:0px 3px 0px 3px;'; 
        scriptElement +='font-weight:bold;filter:alpha(opacity=80);opacity:0.8;" / ></div>';
        
    document.getElementById('div_video_ads').innerHTML = scriptElement + Pre_Roll_Ad;

     StartTheTimer(fcexp);
  	  
}

var secs=30;

function StartTheTimer(fcexp)
{
    if (secs==0)
    {
        closeAd(0,fcexp);
    }
    else
    {
        if(secs==10)
        {
            document.getElementById('btnSkip').style.visibility = "visible";
            document.getElementById('btnSkip').style.display = "block";
        }
	    
	    document.getElementById('timer_div').innerHTML= secs;
        secs = secs - 1
        timerdivinterval = self.setTimeout("StartTheTimer("+fcexp+")",1000)
    }
}


function showMidRoll(fcexp)
{
    var Mid_Roll_Ad = document.getElementById('MidRollAd_div').innerHTML;
    document.getElementById('div_video_ads').style.visibility = "visible";
    document.getElementById('div_video_ads').style.display = "block";
    document.getElementById('div_video_ads').style.background = "none";
    document.getElementById('div_video_ads').innerHTML = "";
    
    //fcexp = 1 for freedocast,0 = express
    if(fcexp == 1) 
    {
        document.getElementById('div_video_ads').style.height='80px';
         document.getElementById('div_video_ads').style.width='614px';
        document.getElementById('div_video_ads').style.top=parseInt(-110)  +'px';
     }
    else
    {
        document.getElementById('div_video_ads').style.height='80px';
         document.getElementById('div_video_ads').style.width='480px';
        document.getElementById('div_video_ads').style.top=parseInt(-110)  +'px';
    }

    var scriptElement ='<div style="height:15px; display:block; text-align:right; margin: 0px auto; width:468px"><input type="button" id="btnSkip" onclick="closeAd(1,'+fcexp+')" style="background: url(http://adshare3.freedocast.com/closebutton1.gif); display:block; cursor:pointer; border:none; float:right; width:70px; height:15px; filter:alpha(opacity=90);opacity:0.9;"/ ></div>';
  	document.getElementById('div_video_ads').innerHTML=scriptElement + Mid_Roll_Ad;
	interval = setTimeout("showMidRoll("+fcexp+")",120000);
  
}

function showSkipButton()
{
 document.getElementById('btnSkip').style.display = "block";  
}

function showPre_MidRoll(fcexp)
{
    setTimeout("showPreRoll("+fcexp+")",180000);
    setTimeout("showMidRoll("+fcexp+")",220000);
}

function closeAd(midorPre,fcexp)
{
     document.getElementById('div_video_ads').style.display = "none";
     document.getElementById('div_video_ads').style.visibility = "hidden";
     document.getElementById('div_video_ads').innerHTML = "";	
     
     if(timerdivinterval!=""){clearInterval(timerdivinterval);}
     
     if(midorPre == 1)
     {
        if(interval!=""){clearInterval(interval);}      
	    setTimeout("showMidRoll("+fcexp+")",120000);
     }
}

function selectChange(control)
{
  var currenturl = window.location.href;
  var index1 = currenturl.indexOf("="); 
  
  currenturl = currenturl.substring(0,index1 + 1) + control.value;

  window.location.href = currenturl;
}

