var hplayer  = null;
var vidpath = "/media/useruploads/video/";
var thumbpath = vidpath+"thumbs/";
var swfpath = "/swf/";

function playhomevideo(filename,thumb,divname,bool,level,obj)
{
          //alert(obj.id);
          var swffile = swfpath + "player-licensed.swf";
          var vidthumb = thumbpath + thumb;
          var vidfile =   vidpath+ filename;
          var so = new SWFObject(swffile,'ply','534','300','9');    //It was 385     721 425     438
          so.addParam('allowfullscreen','true');
          so.addParam('allowscriptaccess','always');
          so.addParam('wmode','opaque');
          so.addParam('frontcolor','86C29D');
          so.addParam('backcolor','FAFAFA');
          so.addVariable('screencolor','D1D1D1'); //D1D1D1 DBD9D9    D7D4D4   D4D2D2   CAC9C9    C7C7C7    CECECE   D2D2D2
          so.addVariable('file',vidfile);
          so.addVariable('image',vidthumb);
          //so.addVariable('skin', '/swf/snel.zip'); 
          so.addVariable('autostart',bool); 
          so.addVariable('stretching', 'exactfit');
          //so.addVariable('plugins','gapro-1');
          //so.addVariable('gapro.accountid', 'UA-5990399-4');
          //alert("HI");
          if(document.getElementById(divname))
          {
              if(document.getElementById('videowrapper'))document.getElementById('videowrapper').style.display = 'block';
              if(document.getElementById('closebtn'))document.getElementById('closebtn').style.display = 'inline';
              if(level !=null && level == 'home')
              {
                  if(document.getElementById('courses'))document.getElementById('courses').style.display = 'none';
                  if(document.getElementById('freeshortcourse'))document.getElementById('freeshortcourse').style.display = 'none';
              }
              so.write(divname);
          }
}

function playcasevideo(filename,thumb,divname,bool,vlabel,vintro,vpdf)
{
    var swffile = swfpath + "player-licensed.swf";
    var vidthumb = thumbpath + thumb;
    var vidfile =   vidpath+ filename;
    var so = new SWFObject(swffile,'ply','605','375','9');    //It was 385     721 425     438
    so.addParam('allowfullscreen','true');
    so.addParam('allowscriptaccess','always');
    so.addParam('wmode','opaque');
    so.addParam('frontcolor','86C29D');
    so.addParam('backcolor','FAFAFA');
    so.addVariable('screencolor','D1D1D1'); //D1D1D1 DBD9D9    D7D4D4   D4D2D2   CAC9C9    C7C7C7    CECECE   D2D2D2
    so.addVariable('file',vidfile);
    so.addVariable('image',vidthumb);
    //so.addVariable('skin', '/swf/snel.zip'); 
    so.addVariable('autostart',bool); 
    so.addVariable('stretching', 'exactfit');
    so.write(divname);
    if(document.getElementById('vtitle') && vlabel !=null)
    {
          document.getElementById('vtitle').innerHTML = vlabel;
    }
    else if(document.getElementById('vtitle') )
    {
       document.getElementById('vtitle').innerHTML = ""; 
    }
    if(document.getElementById('vdesc') && vintro !=null)
    {
          document.getElementById('vdesc').innerHTML = vintro;
    }
    else if(document.getElementById('vdesc') )
    {
       document.getElementById('vdesc').innerHTML = ""; 
    }
    if(document.getElementById('vtrans') && vpdf !=null && vpdf !="")
    {
          var pdflink = "<div class='pdficon'><a href='"+vpdf+"' target=_>";  
          pdflink +=  "<img src='/img/pdficon.jpg' alt='Click me' height='50px' width='40px' class='pdficon'/></a></div>";
          pdflink += "<div class='pdfdesc'><b>&nbsp;<a href='"+vpdf+"' target=_>Download Transcript</a></b></div>";
          document.getElementById('vtrans').innerHTML = pdflink;
          
    }
    else if(document.getElementById('vtrans') )
    {
       document.getElementById('vtrans').innerHTML = ""; 
    } 

}

function playIntrovideo(filename,thumb,bool)
{
          var swffile = swfpath + "player-licensed.swf";
          var vidthumb = thumbpath + thumb;
          var vidfile =   vidpath+ filename;
          var so = new SWFObject(swffile,'ply','325','225','9');    //It was 385     721 425     438
          so.addParam('allowfullscreen','true');
          so.addParam('allowscriptaccess','always');
          so.addParam('wmode','opaque');
          so.addParam('frontcolor','86C29D');
          so.addParam('backcolor','FAFAFA');
          so.addVariable('screencolor','D1D1D1'); //D1D1D1 DBD9D9    D7D4D4   D4D2D2   CAC9C9    C7C7C7    CECECE   D2D2D2
          so.addVariable('file',vidfile);
          so.addVariable('image',vidthumb);
          //so.addVariable('skin', '/swf/snel.zip'); 
          so.addVariable('autostart',bool); 
          so.addVariable('stretching', 'exactfit');
          so.write('videoplayer');
}

function playerReady(thePlayer) {
    hplayer = window.document[thePlayer.id];
}


function playtest()
{
    var so = new SWFObject('/swf/player-licensed.swf','ply4','320','240','9');
    so.addParam('allowfullscreen','true');
    so.addParam('allowscriptaccess','always');
    so.addVariable('file','/media/useruploads/video/hv_BBB_Intro_video.flv');  
    so.addVariable('image','/media/useruploads/video/thumbs/hv_BBB_Intro_video.jpg');  
    so.write('player4');
}

function playSWF()
{
    
}

function removeElement(divname,objectid,videowrapper,level) 
{
  if(document.getElementById(divname))
  {
      var d = document.getElementById(divname);
      if(document.getElementById(objectid))
      {
        var olddiv = document.getElementById(objectid);
        d.removeChild(olddiv);  
      } 
  }
  if(document.getElementById(videowrapper))
  {
      document.getElementById(videowrapper).style.display = 'none';
  }
  if(level !=null && level == 'home')
  {
      if(document.getElementById('courses'))document.getElementById('courses').style.display = 'block';
      if(document.getElementById('freeshortcourse'))document.getElementById('freeshortcourse').style.display = 'block';
  }
              
}

function playnovideo(divname,obj)
{
    if(document.getElementById(divname))
    {
        document.getElementById(divname).style.display = 'block';
        if(document.getElementById('courses'))document.getElementById('courses').style.display = 'none';
        if(document.getElementById('freeshortcourse'))document.getElementById('freeshortcourse').style.display = 'none';
        setTimeout("disablediv('"+divname+"')",3000);
    }
}

function disablediv(div)
{
    if(document.getElementById(div))
    {
        document.getElementById(div).style.display = "none";
        if(document.getElementById('courses'))document.getElementById('courses').style.display = 'block';
        if(document.getElementById('freeshortcourse'))document.getElementById('freeshortcourse').style.display = 'block';
    }
}


function setRedBorder(obj,id)
{
    if(obj == 'null')
    {
        obj = document.getElementById(id);
    }
    obj.style.borderStyle = 'solid';
    obj.style.borderWidth = '6px';
    obj.style.borderColor = '#FF9A9A';
}

function removeRedBorder(obj,id)
{
    if(obj == 'null')
    {
        obj = document.getElementById(id);
    }
    obj.style.border = 'none';
}

function setRedBorderPlayicon(playiconid,cnt,id)
{
    var objs = id+cnt;
     if(objs != 'null')
    {
        obj = document.getElementById(objs);
        obj.style.borderStyle = 'solid';
        obj.style.borderWidth = '6px';
        obj.style.borderColor = '#FF9A9A';
        playiconid = playiconid+cnt;
        var x =document.getElementById(playiconid);
        var styleProp = 'top';
        if (x.currentStyle)
        var y = x.currentStyle[styleProp];
        else if (window.getComputedStyle)
            var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
        if(y)
        {
            fixPosition('top',y,'-48px',x)
                    fixPosition('left',y,'34px',x)
        }
    }
}

function fixPosition(attribute,y,offset,x)
{
   var len = y.length;
   var attr = y.substr(-(len),(len-2));
   //alert(attr+ attribute);
   attr = parseInt(attr)+ offset;
   if(attribute == 'top')
   {
       x.style.top = offset;
   }
   else if(attribute == 'left')
   {
       x.style.left =offset;
   }
}

function removeRedBorderPlayicon(playiconid,cnt,id)
{
    var objs = id+cnt;
     if(objs != 'null')
    {
        obj = document.getElementById(objs);
        obj.style.border = 'none';
        playiconid = playiconid+cnt;
        var x =document.getElementById(playiconid);
        var styleProp = 'top';
        if (x.currentStyle)
            var y = x.currentStyle[styleProp];
        else if (window.getComputedStyle)
            var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
        if(y)
        {
            fixPosition('top',y,'-40px',x);
            fixPosition('left',y,'30px',x);
        }
    }

}
