// JavaScript Document
/*
Simple Image Trail script- By JavaScriptKit.com
Visit http://www.javascriptkit.com for this script and more
This notice must stay intact
*/

var offsetfrommouse=[-180,-350]; //image x,y offsets from cursor position in pixels. Enter 0,0 for no offset
var displayduration=0; //duration in seconds image should remain visible. 0 for always.
var currentimageheight = 370;	// maximum image size.
var fileBottomNavCloseImage = "images/closelabel.gif";

if (document.getElementById || document.all){
	document.write('<div id="trailimageid">');
	document.write('</div>');
	
}

function gettrailobj(){
 if (document.getElementById)
 return document.getElementById("trailimageid").style
 else if (document.all)
 return document.all.trailimagid.style
}

function gettrailobjnostyle(){
if (document.getElementById)
return document.getElementById("trailimageid")
else if (document.all)
return document.all.trailimagid
}

function truebody(){
return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function ocultar(){
 var arrayPageSize = getPageSize();	
}

function Start(URL, WIDTH, HEIGHT) {
 windowprops = "left=50,top=50,width=" + WIDTH + ",height=" + HEIGHT;
 preview = window.open(URL, "preview", windowprops);
} 

function mostrartrailer(titulo,ancho,altura){
 hidetrail();
 ventana = "trailers/"+titulo;
 Start(ventana,ancho,altura);
}

function showtrail(imagename,title,description,ratingaverage,ratingnumber,showthumb,height,tipo){

	if (height > 0){
		currentimageheight = height;
	}

    document.onmousemove=followmouse;

	cameraHTML = '';
/*
	if (ratingnumber == 0){
		ratingaverage = 0;
	}

	for(x = 1; x <= 5; x++){

		if (ratingaverage >= 1){
			cameraHTML = cameraHTML + '<img src="img/estrella1.gif">';
		} else if (ratingaverage >= 0.5){
			cameraHTML = cameraHTML + '<img src="img/estrella2.gif">';
		} else {
			cameraHTML = cameraHTML + '<img src="img/estrella3.gif">';
		}
	
		ratingaverage = ratingaverage - 1;

	}
	cameraHTML+='<br/>';
	if ( ratingnumber == 1 ) {cameraHTML = cameraHTML + ratingnumber + ' vez ha sido vista.'} else
	{cameraHTML = cameraHTML + ratingnumber + ' veces ha sido vista.';}*/
	
 if (tipo==7){
	document.getElementById('trailimageid').style.width = 367;
	offsetfrommouse=[-180,-350];
	newHTML = '<div style="padding: 5px; background-color: #FFF; font-size: 9pt; border: 1px solid #888;">';
	newHTML = newHTML + '<span class="cabezera_e">' + title + '</span>';
	newHTML = newHTML + '<div class="subt_e">' + description + '</div>';
    newHTML = newHTML + '<div align="center" style="padding: 8px 2px 2px 2px;"><img src="' + imagename + '?ran=' + aleatorio(100,1000) + '" border="0"></div>';	
 }
 
 if (tipo==8){
   newHTML = '<table align="left" width="'+ ratingaverage +'px" border="0" cellspacing="0" cellpadding="0"><tr><td><img style=" top:-13px; position:absolute; margin-left:15px" src="images/arrow2.gif"></td></tr>';
   newHTML = newHTML + '<tr><td><div style="z-index:100; padding:1px; border:1px solid black; background-color:lightyellow ">';
   

   newHTML = newHTML + '<div>';
   newHTML = newHTML + '<table><tr>';
   if (imagename) {newHTML = newHTML + '<td><img border="1" src="'+imagename+'?ran=' + aleatorio(100,1000) + '"></td><td><div  style="font-size:10px; font-family:verdana;">';} else {newHTML = newHTML + '<td><div  style="font-size:10px; font-family:verdana;">';}
   newHTML = newHTML + description;
   newHTML = newHTML + '</div></td></tr>';
   newHTML = newHTML + '</div>';   
   newHTML = newHTML + '</div></td></tr>';
   newHTML = newHTML + '</table>';
  offsetfrommouse=[0,20];	 
 }
 
 if (tipo == 9) { // Video
            document.getElementById('trailimageid').style.width = 300;
            offsetfrommouse=[-180,-300];   
            newHTML = '<div style="padding: 5px; background-color: #FFF; font-size: 9pt; border: 1px solid #888;">';
			newHTML = newHTML + '<span class="cabezera_e">' + title + '</span>';
			newHTML = newHTML + '<div class="subt_e">' + description + '</div>';
			newHTML = newHTML + '<div class="flash">';
			newHTML = newHTML +	'<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="300" height="200">';
			newHTML = newHTML + '<param name="movie" value="../js/playFLV2.swf">';
			newHTML = newHTML + '<param name="quality" value="best">';
			newHTML = newHTML + '<param name="loop" value="true">';
			newHTML = newHTML + '<param name="FlashVars" value="video=' + imagename + '&bufferPercent=25">';
			newHTML = newHTML + '<embed src="../js/playFLV2.swf" loop="true" FlashVars="video=' + imagename + '&bufferPercent=25" width="300" height="200" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash">';
			newHTML = newHTML + '</object></div>';
	}
	newHTML = newHTML + '</div>';

	 gettrailobjnostyle().innerHTML = newHTML;
	 gettrailobj().visibility="visible";
}


function hidetrail(){
	gettrailobjnostyle().innerHTML = ""; 
	gettrailobj().visibility="hidden"
	document.onmousemove=""
	gettrailobj().left="-500px"

}

function aleatorio(inferior,superior){ 
    numPosibilidades = superior - inferior 
    aleat = Math.random() * numPosibilidades 
    aleat = Math.round(aleat) 
    return parseInt(inferior) + aleat 
}

function followmouse(e){

	var xcoord=offsetfrommouse[0]
	var ycoord=offsetfrommouse[1]

	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(document.body.offsetHeight, window.innerHeight)

	//if (document.all){
	//	gettrailobjnostyle().innerHTML = 'A = ' + truebody().scrollHeight + '<br>B = ' + truebody().clientHeight;
	//} else {
	//	gettrailobjnostyle().innerHTML = 'C = ' + document.body.offsetHeight + '<br>D = ' + window.innerHeight;
	//}

	if (typeof e != "undefined"){
		if (docwidth - e.pageX < 300){
			xcoord = e.pageX - xcoord - 286; // Move to the left side of the cursor
		} else {
			xcoord += e.pageX;
		}
		if (docheight - e.pageY < (currentimageheight + 110)){
			ycoord += e.pageY - Math.max(0,(110 + currentimageheight + e.pageY - docheight - truebody().scrollTop));
		} else {
			ycoord += e.pageY;
		}

	} else if (typeof window.event != "undefined"){
		if (docwidth - event.clientX < 300){
			xcoord = event.clientX + truebody().scrollLeft - xcoord - 286; // Move to the left side of the cursor
		} else {
			xcoord += truebody().scrollLeft+event.clientX
		}
		if (docheight - event.clientY < (currentimageheight + 110)){
			ycoord += event.clientY + truebody().scrollTop - Math.max(0,(110 + currentimageheight + event.clientY - docheight));
		} else {
			ycoord += truebody().scrollTop + event.clientY;
		}
	}

	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
	var docheight=document.all? Math.max(truebody().scrollHeight, truebody().clientHeight) : Math.max(document.body.offsetHeight, window.innerHeight)

	gettrailobj().left=xcoord+"px"
	gettrailobj().top=ycoord+"px"

}