/* Vwp_launcher.js - Vieweb.it 3.0.1 12-jul-08 21.00 e.g. */
var VwpPath = "http://www.vieweb.it/Vwp/";
// definizione dei flag che regolano il modo di lavorare del player (devono essere uguali in Vwp.js
Vwp_Auto = 0;     // (default auto speed detection)
Vwp_L = 1;        // modo 184
Vwp_M = 2;        // modo 334
Vwp_H = 3;        // modo 644
Vwp_U = 4;        // modo 1024
Vwp_H1 = 5;       // modo 1104 
Vwp_H2 = 6;       // modo 1504
Vwp_H3 = 7;       // modo 2404
Vwp_Popup = 16;   // modalità popup
Vwp_Iframe = 0;   // (default IFRAME)
Vwp_inWindow = 32; // modalità in finestra
Vwp_Full = 0;     // (default full-screen)
Vwp_Exit = 64;    // esci dal full screen all'ESC (default passa a modalità finestra)
Vwp_Cap = 128;    // includi gestione capitoli                    //VW-EG   080119
var VwpURL;
var VwpFrame;
var VwpKey = "";  // drm key                                      //VW-EG   080128
var VwpStartFrame = 0;                                            //VW-EG   080201
var VwpEndFrame = 0;                                              //VW-EG   080201
var VwpWindowTop = -1;                                            //VW-EG   080712
var VwpWindowLeft = -1;                                           //VW-EG   080712
var VwpPosition = "fixed";                                        //VW-EG   080712
var VwpRunning = false;
var VwpPerc;
var VwpWindow;
var VwpClientPage;
var lastId;

function VwpPlayDrm(cliente,clip,lingua,flag){
var x,y,wx,wy;
var de = document.documentElement;
var w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
var h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;
  if (flag & Vwp_Cap) {
    wx = 932;
  } else {
    wx = 729;
  }
  wy = 550;
  if (flag & Vwp_Popup) {
    x = (screen.width - wx) / 2 - 5;
    y = (screen.height - wy) / 2 - 44;
  } else {
    x = (w - wx) / 2;
    y = (h - wy) / 2;
  }
  VwpPlay(cliente,"www.vieweb.it/viv",clip,y,x,wx,wy,flag);
}

function VwpSkin(cliente,clip,lingua,flag){
var x,y,wx,wy,wc;
var de = document.documentElement;
var w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
var h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;
if (flag & Vwp_Cap) wc = 231;
else wc = 0;  
var ediv=document.getElementById('DivPlayer');
//alert("Ediv->"+ediv);
if(ediv){
 //  alert("esiste");
  VwpPosition = "absolute";
   x=document.getElementById('DivPlayer').offsetLeft;
   y=document.getElementById('DivPlayer').offsetTop;
   wx=document.getElementById('DivPlayer').offsetWidth + wc;
   wy=document.getElementById('DivPlayer').offsetHeight + 45;
//   alert("x->"+x+"\ny->"+y+"\nwx->"+wx+"\nwy->"+wy);  
} else {
  wx = 578 + wc;
  wy = 558;
  if (flag & Vwp_Popup) {
    x = (screen.width - wx) / 2 - 5;
    y = (screen.height - wy) / 2 - 44;
  } else {
    x = (w - wx) / 2;
    y = (h - wy) / 2;
  }
}
  VwpPlay(cliente,"www.vieweb.it/viv",clip,y,x,wx,wy,flag);
}

function VwpPlay(Client_ID, Server, Clip, top, left, Wwidth, Wheight, flag) {
  d = new Date();     // prendi il tempo al click dell'utente
  var CT = d.getTime();
  var VwpStyle;
  var height;
  var width;
  VwpWindowTop=top;                                   //VW-EG   080708
  VwpWindowLeft=left;                                 //VW-EG   080708
  VwpRunning = true;
  lastId = location.hash;
  if (Wwidth == 1) {
    width = 1;       //VW-EG provvisorio
    height = 1;      //VW-EG provvisorio
    VwpPosition = "absolute";   //VW-EG   080715
  	if( typeof( window.pageYOffset ) == 'number' ) {
  		VwpWindowTop = window.pageYOffset; 
      VwpWindowLeft = window.pageXOffset;
  	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
  		VwpWindowTop = document.body.scrollTop; 
      VwpWindowLeft = document.body.scrollLeft;
  	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
  		VwpWindowTop = document.documentElement.scrollTop; 
      VwpWindowLeft = document.documentElement.scrollLeft;
  	}
  	//alert( 'VwpWindowTop = ' + VwpWindowTop + '\nVwpWindowLeft = ' + VwpWindowLeft );
  }
  else {
    width = "";      //VW-EG provvisorio
    height = "";
  }
  var CP = this.location.href.split("?")[0].split("#")[0];  // get ClientPath from ClientURL    //VW-EG   080530
  VwpURL = VwpPath+"Vwp.php?Cl="+Client_ID+"&cp="+Clip+"&sv="+Server+"&wd="+width+"&hd="+height+"&ss="+flag+"&ct="+CT+"&ck="+VwpKey+"&cs="+VwpStartFrame+"&ce="+VwpEndFrame+"&CP="+CP;  //VW-EG   080530
  if(flag & Vwp_Popup) {
    VwpStyle = "top="+top+",left="+left+",width="+Wwidth+",height="+Wheight+",status=no,menubar=no,toolbar=no,scrollbar=no,location=no,directories=no";
    VwpWindow = window.open(VwpURL, "", VwpStyle);
    if (window.focus) VwpWindow.focus();  
  }
  else {
/*
    VwpFrame=document.getElementById("VwpFrame");
    VwpFrame.width=Wwidth;
    VwpFrame.height=Wheight;
*/    
    VwpClientPage = location;                       //rimuovi l'hash dopo averlo ricevuto    //VW-EG 080217
    VwpFrame = document.createElement("IFRAME");
  	//VwpFrame.setAttribute("src", VwpURL);
	  VwpFrame.setAttribute("frameBorder", 0);
    VwpFrame.setAttribute("width", Wwidth);
	  VwpFrame.setAttribute("height", Wheight);
	  VwpFrame.setAttribute("scrolling", "no");
	  VwpFrame.setAttribute("allowTransparency", "true");
  	document.body.appendChild(VwpFrame);
    VwpFrame.style.position=VwpPosition;                //queste 3 righe funzionano in IE7 e non in FF  //VW-EG  080218+080709
    VwpFrame.style.top=VwpWindowTop;    //VW-EG   080709
    VwpFrame.style.left=VwpWindowLeft;  //VW-EG   080709
    VwpFrame.style.backgroundColor = 'transparent';     //VW-EG   080924 
    VwpFrame.setAttribute("style", "position:"+VwpPosition+"; top:"+VwpWindowTop+"px; left:"+VwpWindowLeft+"px;"); //questo funziona in FF e non in ie //VW-EG 080218+080709+080709
    VwpFrame.src=VwpURL;
    VwpFrame.style.visibility="visible";
    VwpWindow = false;
  }
	setTimeout('VwpCheck()', 200);
}
function VwpClose(perc) {         // funzione call back dal player
//alert("VwpClose="+perc);
//if (VwpWindow != null) {
//  VwpWindow.close();
//} else {
//  VwpFrame.style.visibility="hidden";  
//  //VwpFrame.src="";
//}
  VwpPerc = perc;
  VwpRunning = false;
}
function VwpCheck() {
var KeyGen;
var HostPath="";
  if (VwpPosition != "fixed") {                                        //VW-EG   080708 inizio
  var top;                 
  var left;
  var ediv=document.getElementById('DivPlayer');
    if(ediv){
       left=document.getElementById('DivPlayer').offsetLeft;
       top=document.getElementById('DivPlayer').offsetTop;
       if((VwpWindowTop != top) || (VwpWindowLeft != left)) {
         VwpWindowTop=top;
         VwpWindowLeft=left;
         VwpFrame.style.position="absolute";                      //queste 3 righe funzionano in IE7 e non in FF  //VW-EG  080218
         VwpFrame.style.top=top;
         VwpFrame.style.left=left;
         VwpFrame.setAttribute("style", "position:absolute; top: "+top+"px; left: "+left+"px;"); //questo funziona in FF e non in ie //VW-EG 080218
       }
    } 
  }                                                              //VW-EG   080708 fine   
/*    //VW-EG   080709
 	if(location.hash != lastId) {
    //alert("Response="+location.hash);
    VwpPerc = location.hash.substr(1,location.hash.length-1) * 1; //VwpPerc = numero che segue il #      //VW-EG 080217 
    location = VwpClientPage;                                     //rimuovi l'hash dopo averlo ricevuto  //VW-EG 080217
    VwpRunning = false;
  }
*/    //VW-EG   080709
  if (VwpRunning) {
  	setTimeout('VwpCheck()', 200);
  }
  else {
    if (VwpWindow) {
      try{
        VwpWindow.close();
      }
      catch(e){
        //alert();
      }
    } else {
      VwpFrame.style.visibility="hidden";  
      //VwpFrame.src="about:blank";
    }
    //alert ("customerclose="+VwpPerc);
    try {
      CustomerVwpClose(VwpPerc);
    }
    catch (e) {
      //VwpFrame.src="";
    }
    try {
     	document.body.removeChild(VwpFrame);
    }
    catch (e) {
    }
    try {
      KeyGen = document.getElementById("VwpKeyFrame").src;
      if (KeyGen.indexOf("://") == -1) {
        HostPath += VwpClientPage;
        if (HostPath.indexOf("?") != -1) HostPath = HostPath.substr(0,HostPath.indexOf("?"));
        if (HostPath.indexOf("#") != -1) HostPath = HostPath.substr(0,HostPath.indexOf("#"));
        KeyGen = HostPath.substr(0,HostPath.lastIndexOf("/")+1) + KeyGen;
      }
      //alert("ricaricamento Keygen="+KeyGen);
      document.getElementById("VwpKeyFrame").src = KeyGen;
    }
    catch (e) {
    }
  }
}
