// JavaScript Document


function preferiti(){
	var title='BikeTV';
	var lnk='http:\/\/www.biketv.it';
	var testo='&raquo; Aggiungi ai Preferiti';
	var data='';
	if( window.sidebar && window.sidebar.addPanel ) {
		if (navigator.userAgent.lastIndexOf("Netscape") != -1) {
			data='<a href="#." onclick="window.sidebar.addPanel( \''+title+'\', \''+lnk+'\', \'\' ); return false;" title="Aggiungi ai Preferiti">'+testo+'<\/a>';}
		else{data='<a href="#." onclick="window.sidebar.addPanel( \''+title+'\', \''+lnk+'\', \'\' ); return false;" title="Aggiungi ai Preferiti">'+testo+'<\/a>';}
												}
	else if( window.opera && window.print ) {data='<a title="'+title+'" rel="sidebar" href="'+lnk+'" title="Aggiungi ai Preferiti">'+testo+'<\/a>';}
	else if( window.external && ( navigator.platform == 'Win32' || ( window.ScriptEngine && ScriptEngine().indexOf('InScript') + 1 ) ) ) {
					data='<a href="#." onclick="window.external.AddFavorite( location.href.replace( \/#.*\/, \'\' ), document.title ); return false;" title="Aggiungi ai Preferiti">'+testo+'<\/a>';}
	document.write(data);
}



function get_random(number)
{
    var ranNum= Math.floor(Math.random()*number);
    return ranNum;
}




		function setContent(id) {
			if (document.getElementById) {
				var windowHeight = getSizeWindow("h");
				if (windowHeight > 0) {
					var contentElement = document.getElementById(id);
 
					var contentHeight = contentElement.offsetHeight;

					if (windowHeight - contentHeight > 0) {
						contentElement.style.position = 'relative';
						contentElement.style.marginTop = "0";
						contentElement.style.top = ((windowHeight / 2) - (contentHeight / 2)) + 'px';

						
					}
					else {
						contentElement.style.position = 'static';
						if(BrowserDetect.browser=="Firefox"){
						contentElement.style.marginTop = "40px";
						}else{
						contentElement.style.marginTop = "40";
						}
					}
				}
			}
		}




function getSizeWindow(dimension) {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  
  if(dimension=="w"){
	  return myWidth;
  }else if(dimension=="h"){
	  return myHeight;
  }

}



/////////////////////////////////// CORRECT PNG 


function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
{
   var arVersion = navigator.appVersion.split("MSIE")
   var version = parseFloat(arVersion[1])

   if ((version >= 5.5) && (version <= 7) && (document.body.filters))
   {

      for(var i=0; i<document.images.length; i++)
      {
         var img = document.images[i]
         var imgName = img.src.toUpperCase()
         if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
         {
            var imgID = (img.id) ? "id='" + img.id + "' " : ""
            var imgClass = (img.className) ? "class='" + img.className + "' " : ""
            var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
            var imgStyle = "display:inline-block;" + img.style.cssText
            if (img.align == "left") imgStyle = "float:left;" + imgStyle
            if (img.align == "right") imgStyle = "float:right;" + imgStyle
            if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
            var strNewHTML = "<div " + imgID + imgClass + imgTitle
            + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
            + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
            + "(src=\'" + img.src + "\', sizingMethod='scale');\"></div>"
            img.outerHTML = strNewHTML
            i = i-1
         }
      }
   }   
}



/////////////////////////////// ADD LOAD EVENT 


function addLoadEvent(func) {
	
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}




///////////////////////// DIMENSIONI DELLO SCHERMO

function getSizeScreen(dimension){

	if (self.screen) {     // for NN4 and IE4
			width = screen.width
			height = screen.height
	// Testing this first prevents firing the slow Java of NN4
	} else if (self.java) {   // for NN3 with enabled Java
		   var jkit = java.awt.Toolkit.getDefaultToolkit();
		   var scrsize = jkit.getScreenSize();       
		   width = scrsize.width; 
		   height = scrsize.height; 
	} else{
	 width = height = '?' // N2, E3, N3 w/Java off, probably Opera and WebTV
	}


	  if(dimension=="w"){
		  return width;
	  }else if(dimension=="h"){
		  return height;
	  }
	  
	  

}




/////////////////////////////////// FUNZIONE DI CODIFICA STRINGA URL //////

function URLEncode(plaintext)
{
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert( "Unicode Character '" 
                        + ch 
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for

	return encoded;
};


/////////////////////////////////// FUNZIONE DI DECODIFICA STRINGA URL


function URLDecode(encoded)
{
   // Replace + with ' '
   // Replace %xx with equivalent character
   // Put [ERROR] in output if %xx is invalid.
   if(encoded!=""){

   var HEXCHARS = "0123456789ABCDEFabcdef"; 
   var plaintext = "";
   var i = 0;
   while (i < encoded.length) {
       var ch = encoded.charAt(i);
	   if (ch == "+") {
	       plaintext += " ";
		   i++;
	   } else if (ch == "%") {
			if (i < (encoded.length-2) 
					&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1 
					&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
				plaintext += unescape( encoded.substr(i,3) );
				i += 3;
			} else {
				alert( 'Bad escape combination near ...' + encoded.substr(i) );
				plaintext += "%[ERROR]";
				i++;
			}
		} else {
		   plaintext += ch;
		   i++;
		}
	} // while

   return plaintext;
   }
}


//////////////////////////////// APRI POPUP CENTRATA ///////////////////////////

var win = null;

function ApriPopUp(file, w, h){
	
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings =
	'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars=yes,resizable'
	win = window.open(file,"",settings);
}



/////////////////// APRO VIDEO IN FULLSCREEN


/*

var newwindow=null;


function OpenVideoFullscreen(autoreVideo, titoloVideo, fileVideo, timesVideo, positionsVideo, positionVideo, durationVideo, rand) {
	
	var html="";
	var ws = getSizeScreen("w") ;
	var hs = getSizeScreen("h") ;
	var h= hs;
	var w = Math.floor((550*h)/440);
	
	var pw = Math.floor((screen.width-ws)/2);
	var ph = Math.floor((screen.height-hs)/2);
	//window.open("fullscreen.html?rand="+rand,"","width=" + w + ",height=" + h + ",top=" + ph + ",left=" + pw);

		if (newwindow && !newwindow.closed){
			
		   newwindow.focus(); 
		   newwindow.document.clear();
		 
		} else {
		
			newwindow=window.open('','','width='+w+',height='+h+',top='+ph+',left='+pw+',resizable=1') 
		}
		
		
		    html += '<script type="text\/javascript"> ';
		    
			html += 'var noflashcontent2 = ""; ';
			html += 'var flashvars2 = "&w='+w+'&h='+h+'&rand='+get_random(10000)+'&fullscreen=yes&newwindow=yes&home=no&autoreVideo='+autoreVideo+'&titoloVideo='+titoloVideo+'&fileVideo='+fileVideo+'&timesVideo='+timesVideo+'&positionsVideo='+positionsVideo+'&positionVideo='+positionVideo+'&durationVideo='+durationVideo+'&widthVideo='+w+'&heightVideo='+h+'&end=1";  ';
		
		    html += 'generatorflash("swf/scrubber.swf",'+w+','+h+',"FFFFFF","8,0,0,0","8",flashvars2,noflashcontent2); ';
		
		
	        html += '<\/script>';
		
		//alert(html);
		
			newwindow.document.writeln('<head><title>FULLSCREEN<\/title>');
			newwindow.document.writeln('<script language="javascript" type="text\/javascript" src="js\/detect_browser.js"><\/script> \n');
newwindow.document.writeln('<script language="javascript" type="text\/javascript" src="js\/detect_flash.js"><\/script> \n');
newwindow.document.writeln('<script language="javascript" type="text\/javascript" src="js\/function.js"><\/script> \n');
            newwindow.document.writeln('<style media="all" type="text\/css"> \n');
	        newwindow.document.writeln('body{ margin:0px; padding:0px; background-color:#000000; } \n');
            newwindow.document.writeln('</style>');
			newwindow.document.writeln('<link href="css\/biketv-2007.css" rel="stylesheet" type="text\/css" \/>');
			newwindow.document.writeln('<\/head><body>');
			newwindow.document.writeln(html);
			newwindow.document.writeln('<\/body><\/html>');
			newwindow.document.close();
		
       
		
} 


*/

function OpenVideoFullscreen(autoreVideo, titoloVideo, fileVideo, timesVideo, positionsVideo, positionVideo, durationVideo, rand) {
	
	var widthVideo = 550;
	var heightVideo = 440;
	
	var html="";
	var ws = getSizeScreen("w") ;
	var hs = getSizeScreen("h") ;
	var h= hs;
	var w = Math.floor((widthVideo*h)/heightVideo);
	
	var pw = Math.floor((screen.width-ws)/2);
	var ph = Math.floor((screen.height-hs)/2);
	
	var newheight;
	var newwidth;

	window.open('fullscreen.php?autoreVideo='+autoreVideo+'&titoloVideo='+titoloVideo+'&fileVideo='+fileVideo+'&timesVideo='+timesVideo+'&positionsVideo='+positionsVideo+'&positionVideo='+positionVideo+'&durationVideo='+durationVideo+'&rand='+rand+'&widthVideo='+w+'&heightVideo='+h+'&end=1','fullscreen','width='+w+',height='+h+',top='+ph+',left='+pw+',resizable=0, scrolling=no,toolbar=no,status=no,menubar=no');
		
} 


///////////////////////// nuova funzione apri fullscreen ...

function OpenFullScreen(id_cat, id_vid, countVideo, timesVideo, positionsVideo, positionVideo, durationVideo, rand) {
	
	var widthVideo = 550;
	var heightVideo = 440;
	
	var html="";
	var ws = getSizeScreen("w") ;
	var hs = getSizeScreen("h") ;
	var h= hs;
	var w = Math.floor((widthVideo*h)/heightVideo);
	
	var pw = Math.floor((screen.width-ws)/2);
	var ph = Math.floor((screen.height-hs)/2);
	
	var newheight;
	var newwidth;
	
	if(document.getElementById("VideoPlayer")){
	var VideoPlayer = document.getElementById("VideoPlayer");
	VideoPlayer.innerHTML = "";
	var style='margin-left:200px; margin-top:200px;';
	VideoPlayer.innerHTML += '<img src="img/p_replay.gif" border="0" alt="Replay Video" style="'+style+'">';
	}

	window.open('fullscreen.php?id_cat='+id_cat+'&id_vid='+id_vid+'&countVideo='+countVideo+'&timesVideo='+timesVideo+'&positionsVideo='+positionsVideo+'&positionVideo='+positionVideo+'&durationVideo='+durationVideo+'&rand='+rand+'&widthVideo='+w+'&heightVideo='+h+'&end=1','fullscreen','width='+w+',height='+h+',top='+ph+',left='+pw+',resizable=0, scrolling=yes,toolbar=no,status=no,menubar=no');
		
} 


///////////////////////// DIMENSIONI DELLO SCHERMO

function getSizeScreen(dimension){

	if (self.screen) {     // for NN4 and IE4
			width = screen.width
			height = screen.height
	// Testing this first prevents firing the slow Java of NN4
	} else if (self.java) {   // for NN3 with enabled Java
		   var jkit = java.awt.Toolkit.getDefaultToolkit();
		   var scrsize = jkit.getScreenSize();       
		   width = scrsize.width; 
		   height = scrsize.height; 
	} else{
	 width = height = '?' // N2, E3, N3 w/Java off, probably Opera and WebTV
	}


	  if(dimension=="w"){
		  return width;
	  }else if(dimension=="h"){
		  return height;
	  }
	  
	  

}