function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function showstats(str) {
  divobj = document.getElementById("fileinfo");
  td = divobj.getElementsByTagName("td");
  try {
    s = eval(str);
  }
  catch(e) {
    s = null;
  }
  if (s=="null") s = null;
  if (s!=null) {
    td[1].innerHTML = s.split("#")[0];
    td[3].innerHTML = s.split("#")[1];
    td[5].innerHTML = s.split("#")[2];
  }
  else 
    td[1].innerHTML = "";
}

function clearstats() {
  divobj = document.getElementById("fileinfo");
  td = divobj.getElementsByTagName("td");
  td[1].innerHTML = "";
  td[3].innerHTML = "";
  td[5].innerHTML = "";
}

function setQualityTabs() {
  qtabs = document.getElementById("qualities");
  a = qtabs.getElementsByTagName("a");
  for (i=0;i<5;i++) {
    try {
      s = eval(a[i].val);
    }
    catch(e) {
      s = null;
    }
    if (s=="null") s = null;
    if (s) {    
      a[i].style.cursor = "pointer";
      // change the anchor for filedownloads
      if ( a[i].val.indexOf("_d_") > 0 ) {
        dfile = s.split("#")[3].substring(1);
        // if no filename is defined, make this option unavailable
        if (typeof(dfile)=="undefined") s = null;
        else a[i].href += "&file="+dfile;
        //else a[i].href = "vod_download.asp?file="+dfile;
      }
    }
    if (s==null) { // this clip is unavailable (or not defined)
      a[i].style.cursor = "default";
      imgs = a[i].getElementsByTagName("img");
      pos = (imgs[0].src.indexOf(".jpg"));
      imgs[0].src = imgs[0].src.substr(0,pos) + "NA.jpg";
      a[i].href = "#";
      a[i].onmouseover = null;
      a[i].onmouseout = null;
    }
  }
}


function fixPNGs() {
  //isStd = (navigator.appName == "Netscape") ? true : false;
  isMS  = (navigator.appName.indexOf("Microsoft") != -1) ? true : false;
  isMac = (navigator.platform.indexOf("Mac") != -1) ? true : false;
  isPNG = (isMS && !isMac) ? false : true;

  if (!isPNG) {
    // Opera sometimes identifies itself as IE, but it cannot use 
    // PNGs as filters (however transparent PNGs work natively in Opera), 
    // so fix this situation
    if ( navigator.userAgent.indexOf("Opera")>0 ) isPNG = true;
  }

  if (!isPNG) {
    var imgs = document.getElementsByTagName("IMG");
    var i;
    for (i=0;i<imgs.length;i++)  {
        if ( imgs[i].src.indexOf(".png")>0 ) 	{
	      imgs[i].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+imgs[i].src+"')";
	      imgs[i].src = "images/empty.gif";
	    }
    }
  }
}

alpha = 100;
function pulsate(divid,delta,limit) {
  divob1 = document.getElementById(divid);
  alpha += delta;
  if (delta>0 && alpha>limit) delta=-delta, alpha=limit, limit=30;
  if (delta<0 && alpha<limit) delta=-delta, alpha=limit, limit=100;
  divob1.style.filter = "Alpha(opacity="+alpha+")"
  setTimeout("pulsate('"+divid+"',"+delta+","+limit+")",30);
}

marqleft = 50;
marqwid  = 0;
marqobj  = null;
function startMarquee() {
  marqobj = document.getElementById("marquee");
  if (marqobj) {
    marqwid = marqobj.style.width;
    spanobj = marqobj.getElementsByTagName("span")[0];
    spanobj.innerHTML += " &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "; 
    spanobj.innerHTML += " &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "; 
    marqwid = parseInt(spanobj.offsetWidth);
    spanobj.innerHTML += spanobj.innerHTML;
    scrollMarquee();
  }
}
function scrollMarquee() {
  marqleft-=2;
  if (marqleft<-marqwid) marqleft+=marqwid;
  marqobj.style.left = marqleft+"px";
  setTimeout("scrollMarquee()",30);
}

msecs0 = 0;
msecs1 = 0;
nfiles = 0;
function signal() {
  dNow = new Date();
  msecs1 = dNow.getTime();
  diff = msecs1-msecs0;
  rate = Math.floor((256*1024*8)/diff); // 
  speedo_rate.innerHTML = (rate)+" kbps";    
  // reset so user can check again
  msecs0 = 0;
  msecs1 = 0;
}
function speedo_check() {
  speedo_rate.innerHTML = "checking";
  dNow = new Date();
  msecs0 = dNow.getTime();
  document.getElementById("speedo_frame").src = "speedo.html?"+msecs0;
}

function fileReady(fname) {
  ihtml  = "<a href='download.asp?file="+fname+"'><font color='#4189a8'>&gt;&gt; <b>DOWNLOAD THE VIDEO</b> &lt;&lt;</font></a><br><br>";
  ihtml += "<div style='text-align:left'><br>";
  ihtml += "Your file is ready for download<br><br>";
  ihtml += "1. Click the link<br>";
  ihtml += "2. Select 'Save'<br><br>";
  ihtml += "or<br><br>";
  ihtml += "1. Right-click the link<br>";
  ihtml += "2. Select 'Save Target As' or 'Save Link As'</div>";
  
  downloadfile.innerHTML = ihtml;
}

function showDownloadDetails() {
  res = eval(vidid).split("#")[1];
  notice_html  = "<br><div class='style7'>You're downloading:<br>"
  notice_html += "<div id='prev_title'><div>" + eval(vidname+"_title") + "</div></div>";
  notice_html += "at a resolution of:<br>";
  notice_html += "<div id='prev_res'><div>" + res + "</div></div>";
  notice_html += "</div>";
  document.getElementById("notice").innerHTML = notice_html;
}

function isIE() {
  if (navigator.userAgent.indexOf("MSIE") > -1) return true;
  else return false;
}

function isWIN() {
  if (navigator.userAgent.indexOf("Windows") > -1) return true;
  else return false;
}

function init() {
  MM_preloadImages('images/front.jpg','images/modem.jpg','images/pda.jpg','images/tv.jpg','images/streaming.jpg','images/dvd.jpg','images/modem.jpg','images/pda.jpg','images/tv.jpg','images/streaming.jpg','images/dvd.jpg','images/vhs.jpg','images/downloadable.jpg','images/broadcast.jpg')
  fixPNGs();
  
  fiobj = document.getElementById("pulser");
  if (fiobj) {
    html =  "<div style='margin:3px;text-align:center'>";
    
    dopulse = 0;
    if (typeof(CanvidPack)!="undefined") {
      e = CanvidPack.Error;
      /*  
      e = 0 - successfully installed;
      e = 1 - canvid3.ax is missing.
      e = 2 - canvid3.dll is missing.
      e = 3 - canvidaudio.ax is missing.
      e = 4 - unidownload2.dll is missing.
      e = 5 - canvidplayer43.dll is missing.
      e = "undefined" - unidownloadpack3.dll is not installed. 
      */
      if ( typeof(e)=="undefined" ) {
        if ( isIE() && isWIN() ) {
          html += "<div style='margin:6px'>";
          html += "<a href='InstallUniDownloadPack3.exe' style='font-size:13px;color:#ffffff;font-weight:800'>click here</a><br>"; 
          html += " to install the player.<br>";
          html += "(1.89MB)";
          html += "</div>";
          
          spanobj = document.getElementById("marquee").getElementsByTagName("span")[0];
          spanobj.innerHTML = "<b>Please install the player to view Truenet Media content...</b>";
          
          // set the main image to make it really, really, really obvious (this is for the airheads)
          mainimg = document.getElementById("main");
          if (mainimg) {
            mainimg.src = "images/dmoInstall.jpg";
            mainmap.innerHTML = "<area shape='rect' coords='161,130,286,200' href='InstallUniDownloadPack3.exe'>";
          }
          
          dopulse = 1;
        }
        else {
          html += "<div style='margin:6px'>Please use MS Windows and Internet Explorer.</div>";
        }
      }
      else if (e>0) {
        html += "<div style='margin:6px'>The Canvid component encountered error #" + e + ", ";
        html += "during installation.  Please restart your browser and try again.</div>";
      }
      else {
        html += "<div style='margin:6px'>We present 8 categories above for your viewing pleasure.</div>";
      }
      
      html += "</div>";
      fiobj.innerHTML = html;
      if (dopulse) pulsate("pulser",-2,30);
    }  
  }
  
  if ( document.getElementById("qualities") != null ) {
    setQualityTabs();
  }
  
  if ( typeof(canvid) != "undefined" ) {
    StartCanvid();
  }
  if ( typeof(unidownload)=="object" ) { // authorize
    if ( typeof(unidownload.GetKey)!="undefined" ) {
      document.cookie = "userid=100";
      document.cookie = "ccode="+unidownload.GetKey();
    }
  }
  startMarquee();
}