var lb=new edWidget();

function edWidget(){ // edWidget class
    
        
    edWidget.prototype.filteron=function(){
        //code to turn on the filter layer
    }
    
    edWidget.prototype.filteroff=function(){
        //code to turn off the filter layer
        var filter=document.getElementById('filter');
        filter.style.display='none';
    }
    
    edWidget.prototype.displaybox=function(){
        //code to dispaly the lightbox
        var b=document.getElementById('box');
        b.style.display="inline";
        var lightbox='<div id="lb_wrapper">';
            lightbox+='<div id="iframe_holder">';
            lightbox+='<iframe id="ed_iframe" name="ed_iframe" src="http://ictthatworks.net/ED3/index.html"></iframe></div>';
            lightbox+='<div id="close"><span id="ed_closeBox">Close<input type="image" src="http://ictthatworks.net/ED/client/closeImg.jpg" value="close" name="close_btn" id="closeBtn" onclick="closeLightbox()" width="10px" height="10px"/></span><div>';
            lightbox+='</div>';
            b.innerHTML=lightbox;
              

    }
    
    edWidget.prototype.hidebox=function(){
     //code to hide the lightbox
     var lbox=document.getElementById('box');
     lbox.style.display='none';
    }
}

function init(videoId,postCode){
   // alert('hello');
//Parms
//     videoId - Identifies the video uniquly
//     postCode - the locations postcode
if(getCookie(videoId)=='set'){
  //do nothing just play video (Widget alread viewed)
}
else{
    //if cookie not set display and update url.
    
 //Function to display widget and pass host info to widget   
lb.displaybox();
lb.filteron();
//Calls Javascript on host page to edit iframe URL
updateurl(videoId,postCode);
  setCookie(videoId,"set",365);
}
}
function closeLightbox(){
    //Close widget
    lb.hidebox();
    lb.filteroff();
}

function updateurl(_videoId, _postCode){
        var host=window.location.host;
        var userid='0';
        var videoid=_videoId;
        var postcode=_postCode;
        
        
        var dataStr='?uid='+userid+'&vid='+videoid+'&pcode='+postcode+'&host='+host;
        var iframedoc=document.getElementById('ed_iframe');
        var iframUrl=iframedoc.getAttribute('src');
        var newurl=iframUrl+dataStr;
        iframedoc.setAttribute('src',newurl);
    }
    
//Cookies to set and check if video has been clicked.
function setCookie(c_name,c_value,expiredays)
//c_name should be video ID
//c_value should = "Set"

{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(c_value)+
((expiredays==null) ? "" : ";expires="+exdate.toUTCString());
}

function getCookie(c_name)
{
   //c_name should be video ID 
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}
