
/* - - - - - - - - - - - - - - - - - - */
/* - Versione 1.6.4                - - */
/* - - - - - - - - - - - - - - - - - - */
// Var Globali
var flvPlay = "true";
var player  = null;
var endLink = "";
var IDplayerFLV ;

/* - - - - - - - - - - - - - - - - - - */


/* - - - - - - - - - - - - - - - - - - */
// DA MODIFICARE
/* - - - - - - - - - - - - - - - - - - */
// Posizionamento filmato 
// LEFT       : angolo inferiore Sinistro
// RIGHT      : angolo inferiore Destro
// BOX        : resta all'interno della pagina
var FlvPosition = 'LEFT'; 
var FlvIDPosition; 
/* - - - - - - - - - - - - - - - - - - */
// Dimensione Filmato
var FlvBoxWidth      = 400 ;
var FlvBoxHeight     = 350 ;
// offset Filmato
var BrowserStartClientWidth  = 0 ;
var BrowserStartClientHeight = 0 ;
var FlvBoxOffsetOrizOriginal = 0 ;
var FlvBoxOffsetVertOriginal = 0 ;
var FlvBoxOffsetOriz = 0 ;
var FlvBoxOffsetVert = 0 ;
/* - - - - - - - - - - - - - - - - - - */
// Directory
var flvPath = "/FLV/"; // percorso File FLV
var swfPath = "/FLV/"; // percorso player SWF
/* - - - - - - - - - - - - - - - - - - */
// Caricamento del filmato
// FIRST  : Filmato visualizzato SOLO alla prima visita della sessione
// ALWAYS : Filmato SEMPRE visualizzato 
var flv_onLoad      = "FIRST"; // FIRST , ALWAYS
/* - - - - - - - - - - - - - - - - - - */
// Azioni del Filmato a caricamneto pagina
// PLAY  : Autoplay del Filmato
// PAUSE : NON Autoplay del Filmato
// HIDE  : Rimuove il filmato
var flv_FirstVisit = "PLAY" ; // PLAY , PAUSE , HIDE
var flv_OtherVisit = "PAUSE" ; // PLAY , PAUSE , HIDE
/* - - - - - - - - - - - - - - - - - - */
// Azioni da eseguire
// NONE        : Nessuna
// LINK        : apre la pagina indicata nell'inizializzazione del player
// CLOSE       : chiude il player
// CUSTOM      : esegue lo script specificato
// CUSTOMCLOSE : esegue lo script specificato e chiude il player
// FRAME       : ripristina il DIV Originale
// CUSTOMFRAME : esegue lo script specificato e ripristina il DIV Originale
var flv_onCompleted = "NONE"; // NONE , LINK , CLOSE , CUSTOM , CUSTOMCLOSE , FRAME , CUSTOMFRAME
var flv_onPaused    = "NONE"; // NONE , LINK , CLOSE , CUSTOM , CUSTOMCLOSE , FRAME , CUSTOMFRAME
var flv_onPlaying   = "NONE"; // NONE , CUSTOM 

/* - - - - - - - - - - - - - - - - - - */
var ClientWidth = 0, ClientHeight = 0;
// recupero delle dimensioni effettive della finestra del brower
function ClientSize() {
	ClientWidth = 0;
	ClientHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    ClientWidth = window.innerWidth;
    ClientHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    ClientWidth = document.documentElement.clientWidth;
    ClientHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    ClientWidth = document.body.clientWidth;
    ClientHeight = document.body.clientHeight;
  }
//  window.alert( 'Width = '  + ClientWidth +'    '+ 'Height = ' + ClientHeight );
}
/* - - - - - - - - - - - - - - - - - - */
// Spostamento box SWF
/*
ID_          : Nome del player SWF
FlvPosition_ : posizione del player
	RIGHT = in basso a destra
	LEFT  = in basso a sinistra
	BOX   = resta nel punto definito
*/
	window.onresize =	FlvBoxWindowResize;
function FlvBoxReposition(ID_ , FlvPosition_) {
	FlvIDPosition = ID_ ; 
  FlvPosition = FlvPosition_ ;
  
	ClientSize();
  BrowserStartClientWidth  = ClientWidth;
  BrowserStartClientHeight = ClientHeight;
  
	var FlvDivobj       = document.getElementById(FlvIDPosition);
	if ( FlvDivobj ){
		if(FlvBoxOffsetVertOriginal ==0) FlvBoxOffsetVertOriginal = findPosY(FlvDivobj) ;
		if(FlvBoxOffsetOrizOriginal ==0) FlvBoxOffsetOrizOriginal = findPosX(FlvDivobj) ;
	}
	FlvBoxWindowResize();
}

function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }

function FlvBoxWindowResize() {
var FlvDivobj       = document.getElementById(FlvIDPosition);
if ( !(FlvDivobj) ) return;
	ClientSize();
var FlvDivobjLeft = (ClientWidth - FlvBoxWidth );
var FlvDivobjTop  = (ClientHeight - FlvBoxHeight);

	if (FlvDivobjLeft<0) { FlvDivobjLeft = 0 ; }
	if (FlvDivobjTop <0) { FlvDivobjTop  = 0 ; }



	switch (FlvPosition) {

	  

	  //personalizzato da Alessandro Bertolini
		case 'BACK_GRATIS2':
			var table  = document.getElementsByTagName("table");
			var xPos = findPosX(table[1])+792 ;
			if (document.all) { // Explorer
	            FlvDivobj.style.position = 'absolute';
	           FlvDivobj.style.top = '563px';
	           FlvDivobj.style.left = (xPos+3)+ 'px';
	        }

	        else {
				
	            FlvDivobj.style.position = 'absolute';
	            
	            FlvDivobj.style.left = xPos+ 'px';
				if (BrowserDetect.browser=="Safari" ||BrowserDetect.browser=="Chrome") {
					FlvDivobj.style.top = '564px';
					FlvDivobj.style.left = (xPos+3)+ 'px';
				}
				else {
					FlvDivobj.style.top = '587px';
					FlvDivobj.style.left = xPos+ 'px';
				}
	        }

	        break;

		break;
	    
		
		case 'BACK_GRATIS':
			var table  = document.getElementsByTagName("table");

			var xPos = findPosX(table[1])+794 ;
	        if (document.all) { // Explorer
				
	            FlvDivobj.style.position = 'absolute';
				
	             FlvDivobj.style.top = '215px';

	             FlvDivobj.style.left = xPos+ 'px';

	        }

	        else {
				
	            FlvDivobj.style.position = 'absolute';
				if (BrowserDetect.browser=="Safari" ||BrowserDetect.browser=="Chrome") {
					FlvDivobj.style.top = '214px';
				}
				else {
	           	 FlvDivobj.style.top = '215px';
				}

	            FlvDivobj.style.left = xPos+ 'px';

	        }

	        break;
	        
	  case 'RIGHT':
			if (document.all){ // Explorer
				FlvDivobj.style.position='absolute'; }
			else {
				FlvDivobj.style.position='fixed'; }
			FlvDivobj.style.top  = (FlvDivobjTop  +FlvBoxOffsetVert) +'px';
			FlvDivobj.style.left = (FlvDivobjLeft +FlvBoxOffsetOriz) +'px';
	  break;
	  case 'LEFT':
			if (document.all){ // Explorer
				FlvDivobj.style.position='absolute'; }
			else {
				FlvDivobj.style.position='fixed'; }
			FlvDivobj.style.top  = (FlvDivobjTop +FlvBoxOffsetVert) +'px';
	    FlvDivobj.style.left = (              FlvBoxOffsetOriz) +'px';
	  break;
	  case 'BOX':
			FlvDivobj.style.position='absolute';
//			if (document.all){
				FlvDivobj.style.top  = (FlvBoxOffsetVertOriginal +FlvBoxOffsetVert) +'px';
				FlvDivobj.style.left = (FlvBoxOffsetOrizOriginal +FlvBoxOffsetOriz) +'px';
//			}
	  default:
	}
}
/* - - - - - - - - - - - - - - - - - - */
var Box_ID ="";
var Box_Class;
var Box_innerHTML ="";
/* - - - - - - - - - - - - - - - - - - */
var flashvarsWithLink;
var flashvarsNoLink;
var VisitPageAction;
var FlvBoxparams;
var flvMinimized = false;
/* - - - - - - - - - - - - - - - - - - */
function FlvPlayer(Box_,ID_,Flv_,FlvW_,FlvH_,Img_,Lnk_) {
/*
Box_  : Nome del div contenente il filmato
ID_   : Nome del player SWF
Flv_  : Nome del filmato FILE.FLV
FlvW_ : Larghezza del filmato 
FlvH_ : Altezza del filmato 
Img_  : Immagine di Inzio/Fine
Lnk_  : Link a cui reindirizzare la pagina a fine filmato 
*/    
endLink = Lnk_;

var VisitedPage = checkVisit(ID_);
VisitPageAction = 'PLAY';

if(VisitedPage == false) { VisitPageAction = flv_FirstVisit; }
else { VisitPageAction = flv_OtherVisit; }

		switch (VisitPageAction) {
		  case 'PLAY':
			  flvPlay = "true";
		  break;
		  case 'PAUSE':
			  flvPlay = "false";
		  break;
		  case 'HIDE':
			  flvPlay = "false";
		  break;
		  case 'MINIMIZE':
				flvMinimized = true;
			  flvPlay = "true";
		  break;
		  default:
		} 

FlvBoxWidth      = FlvW_ ;
FlvBoxHeight     = FlvH_ ;

FlvBoxflashvarsWithLink = {
  'file'         : flvPath + Flv_
, 'link'         : Lnk_
, 'image'        : flvPath + Img_
, 'shuffle'      : 'false'
, 'repeat'       : 'none'
, 'stretching'   : 'none'
, 'autostart'    : flvPlay
, 'volume'       : '100'
, 'frontcolor'   : '86C29D'
, 'backcolor'    : '849BC1'
, 'lightcolor'   : 'C286BA'
, 'screencolor'  : 'FFFFFF'
, 'screenalpha'  : '0'
, 'type'         : 'video'
, 'controlbar'   : 'none'
, 'quality'      : 'true'
, 'state'        : 'BUFFERING'
, 'displayclick' : 'link'
, 'linktarget'   : '_self'
}
FlvBoxflashvarsNoLink = {
  'file'         : flvPath + Flv_
, 'Image'        : flvPath + Img_
, 'shuffle'      : 'false'
, 'repeat'       : 'non8e'
, 'stretching'   : 'none'
, 'autostart'    : flvPlay
, 'volume'       : '100'
, 'frontcolor'   : '86C29D'
, 'backcolor'    : '849BC1'
, 'lightcolor'   : 'C286BA'
, 'screencolor'  : 'FFFFFF'
, 'screenalpha'  : '0'
, 'type'         : 'video'
, 'controlbar'   : 'none'
, 'quality'      : 'true'
, 'state'        : 'BUFFERING'
, 'linktarget'   : '_self'
}
FlvBoxparams = {
  'allowfullscreen'   : 'false'
, 'allowscriptaccess' : 'always'
, 'wmode'             : 'transparent'
, 'menu'              : 'false'
, 'bgColor'           : '#000000'
}
//, wmode             : 'transparent'

FlvPlayerCreate(Box_,ID_);
}

function FlvPlayerCreate(Box_,ID_) {
var attributes = {
  'id'   : ID_
, 'name' : ID_
}
var flashvars;

if ( (endLink != null) && (endLink != '') ) {
	flashvars = FlvBoxflashvarsWithLink;
}else{
	flashvars = FlvBoxflashvarsNoLink;
}

	fnc_checkFrame(Box_);

switch (VisitPageAction) {
	case 'HIDE':
		removeElementById(Box_); 
	break;
	default:
	if (flvMinimized){
		removeElementById(Box_);
		fnc_Minimize();
		flvMinimized=false;
	}else{
		Box_ID = Box_ + "1";
		Box_Class = document.getElementById(Box_).className;
		Box_innerHTML = document.getElementById(Box_).innerHTML;
		swfobject.embedSWF( '/FLV/player.swf' , Box_ , FlvBoxWidth, FlvBoxHeight, '10', false, flashvars, FlvBoxparams, attributes); 
	}}
}

function playerReady(obj) {
 player = gid(obj.id);
  FlvBoxReposition(obj.id,FlvPosition);
 addListeners();
};

function addListeners() {
 playlist = player.getPlaylist();
 if(playlist.length > 0) {
  player.addModelListener('STATE', 'stateMonitor');
//  player.addModelListener('TIME',  'timeMonitor');
  }else{
  setTimeout("addListeners();", 100); }
};

function stateMonitor(obj){
	if(obj.newstate == 'PLAYING') {
	//istruzioni da eseguire durante il filmato
		switch (flv_onPlaying) {
		  case 'CUSTOM':
				fnc__onPlaying();
		  break;
		  case 'NONE':
		  default:
		} 
	}
	if(obj.newstate == 'COMPLETED') {
	//istruzioni da eseguire a fine filmato
		switch (flv_onCompleted) {
		  case 'LINK':
			  if ( (endLink != null) && (endLink != '') ) { document.location = endLink; }
		  break;
		  case 'CLOSE':
				removeElementById(obj.id);
		  break;
		  case 'CUSTOM':
				fnc__onCompleted();
		  break;

		case 'CUSTOMCLOSE2':

    
				fnc__onCompleted();
				removeElementById(obj.id);
				replay_back_gratis2();
		  break;
		
		case 'CUSTOMCLOSE':

    
				fnc__onCompleted();
				removeElementById(obj.id);
				replay_back_gratis();
		  break;
		  case 'FRAME':
			  removeElementById(obj.id);
				fnc_redrawFrame();
		  break;
		  case 'CUSTOMFRAME':
		  	removeElementById(obj.id);
				fnc__showFrame();
				fnc_redrawFrame();
		  break;
		  case 'MINIMIZE':		  	
		  	removeElementById(obj.id);
		  	fnc_Minimize();
		  break;
		  case 'NONE':
		  default:
		} 
	}
	if(obj.newstate == 'PAUSED') {
	//istruzioni da eseguire a pausa filmato
		switch (flv_onPaused) {
		  case 'LINK':
			  if ( (endLink != null) && (endLink != '') ) { document.location = endLink; }
		  break;
		  case 'CLOSE':
		  	removeElementById(obj.id);
		  break;
		  case 'CUSTOM':
				fnc__onPaused();
		  break;

case 'CUSTOMCLOSE':

    fnc__onPaused();

    removeElementById(obj.id);

    replay_back_gratis();

    break;
		  case 'FRAME':
		  	removeElementById(obj.id);
				fnc_redrawFrame();
		  break;
		  case 'CUSTOMFRAME':
		  	removeElementById(obj.id);
				fnc__showFrame();
				fnc_redrawFrame();
		  break;
		  case 'MINIMIZE':
		  	removeElementById(obj.id);
		  	fnc_Minimize();
		  break;
		  case 'NONE':
		  default:
		} 
	}

};

function timeMonitor(obj) {
 if( (obj.position > 20.0)) {
 //istruzioni da eseguire dopo 20.0 secondi di filmato
 }
};

function gid(name) { return document.getElementById(name); };

function removeElementById(ID_) { 
	var Remove_id = document.getElementById(ID_);
if ( !(Remove_id) ) return;	
	Remove_id.parentNode.removeChild(Remove_id);	
};
/* - - - - - - - - - - - - - - - - - - - - - - - */
function fnc_checkFrame(Box_ID_){
var divTag = document.getElementById(Box_ID_);
	if ( !(divTag) ) {
		fnc_drawFrame(Box_ID_);
	}
}
function fnc_drawFrame(Box_ID_){
var divTag = document.createElement("div");
try {
		divTag.setAttribute('id', Box_ID_ );
//    divTag.className = Box_Class;
//    divTag.innerHTML = Box_innerHTML;
    divTag.style.height  = FlvBoxHeight +'px';
		divTag.style.width = FlvBoxWidth +'px';
		divTag.style.top  = '0px';
		divTag.style.left = '0px';
		divTag.style.display = 'block';

    document.body.appendChild(divTag);
    FlvBoxReposition(Box_ID,FlvPosition);
			} catch(err) {
			  alert("ERROR "+ err );
			}
}
function fnc_redrawFrame(){
var divTag = document.createElement("div");
try {
		divTag.setAttribute('id', Box_ID );
    divTag.className = Box_Class;
    divTag.innerHTML = Box_innerHTML;
    
    divTag.style.height  = FlvBoxHeight +'px';
		divTag.style.width = FlvBoxWidth +'px';
		divTag.style.top  = '0px';
		divTag.style.left = '0px';
		divTag.style.display = 'block';

    document.body.appendChild(divTag);
    FlvBoxReposition(Box_ID,FlvPosition);
			} catch(err) {
			  alert("ERROR "+ err );
			}
}
function CloseFrame() { 
	removeElementById(Box_ID);
};
/* - - - - - - - - - - - - - - - - - - - - - - - */
function fnc_Minimize(flvObj_) { 
var divTag = document.createElement("div");
var divPlayID = 'flvPlayButton';
var divPlayObj = document.getElementById(divPlayID);
while (divPlayObj != null){
	divPlayID += '2';
 divPlayObj = document.getElementById(divPlayID);
}
try {
		divTag.setAttribute('id', divPlayID );
//    divTag.className = Box_Class;
    divTag.innerHTML = "<a href=\"javascript:FlvPlayerCreate('"+ divPlayID +"','"+ divPlayID +"_')\"><img border='0' src=\""+ flvPath +"play.png\"/></a>";
    
    divTag.style.height  = '80px';
		divTag.style.width = '80px';
		divTag.style.top  = '0px';
		divTag.style.left = '0px';
		divTag.style.display = 'block';

    document.body.appendChild(divTag);

var FlvDivobjLeft = FlvBoxWidth ;
var FlvDivobjTop  = FlvBoxHeight ;    

FlvBoxWidth  = 80 ;
FlvBoxHeight = 80 ;

    FlvBoxReposition(divPlayID,FlvPosition);
    
FlvBoxWidth  = FlvDivobjLeft ;
FlvBoxHeight = FlvDivobjTop  ;
			} catch(err) {
			  alert("ERROR "+ err );
			}
};
/* - - - - - - - - - - - - - - - - - - - - - - - */
/* Funzione di controllo prima pagina con Cookie */

function getCookie(c_name_) {
var search = c_name_ + "="
var returnvalue = "";
	if (document.cookie.length > 0) {
		offset = document.cookie.indexOf(search)
		// if cookie exists
		if (offset != -1) {
			offset += search.length
			// set index of beginning of value
			end = document.cookie.indexOf(";", offset);
			// set index of end of cookie value
			if (end == -1) end = document.cookie.length;
			returnvalue=unescape(document.cookie.substring(offset, end))
		}
	}
return returnvalue;
}

function setCookie(c_name_,value_){
	document.cookie=c_name_ +'='+ value_ ;
}

function checkVisit(c_name_) {
var c_Return =getCookie(c_name_);
var returnvalue = true;
	if (c_Return==null || c_Return=="") {
  	setCookie(c_name_,'Visited');
  	returnvalue = true; }
	else { 
  	returnvalue = false; }
if ( flv_onLoad == "ALWAYS" ){
	 returnvalue = true;
	 }
return !returnvalue;
}
/* - - - - - - - - - - - - - - - - - - - - - - - */
/* Funzione di controllo prima pagina con Cookie */

/* - - - - - - - - - - - - - - - - - - */
function findPosX(obj) {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent) break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }

function findPosY(obj) {
    var curtop = 0;
    if(obj.offsetParent)
        while(1) {
          curtop += obj.offsetTop;
          if(!obj.offsetParent) break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;

}

