/*
Simple Image Trail script- By JavaScriptKit.com
Visit http://www.javascriptkit.com for this script and more
This notice must stay intact
*/
/*
Modified original for Paxxion.com
by Matteo Borace 
matteo.borace@s4win.com 
*/



var offsetfrommouse=[15,15]; //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 = 150;	// maximum image size.

if (document.getElementById || document.all){
	document.write('<div id="trailimageid" style="z-index:100;position:absolute;visibility:visible;left:0px;top:0px;width:1px;height:1px">');
	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
}


//imagename >> url dell'immagine
//width >> larghezza dell'immagine
//height >> altezza dell'immagine
function showtrail(imagename,id,width,height){
//	var adv = false;
//	var edi = false;

//	var adv_print_img = "Pbl.gif"
//    if(adv_print) {
//    	adv_print_img = "Predbl.gif";
//    	adv = true;
//    }
//	var adv_print_plus_img = "P+bl.gif";
//	if(adv_print_plus){
//		adv_print_plus_img = "P+redbl.gif";
//		adv = true;
//	}
//	var adv_print_super_plus_img = "PSbl.gif";
//	if(adv_print_super_plus){
//		adv_print_super_plus_img = "PSredbl.gif";
//		adv = true;
//	}	
//	var adv_web_img = "Wbl.gif";
//	if(adv_web){
//		adv_web_img = "Wredbl.gif";
//		adv = true;
//	}		
//	var edi_print_img ="Pbl.gif";
//	if(edi_print){
//		edi_print_img = "Predbl.gif";
//		edi = true;
//	}	
//	var edi_print_plus_img="P+bl.gif";
//	if(edi_print_plus){
//		edi_print_plus_img = "P+redbl.gif";
//		edi = true;
//	}	
//	var edi_web_img = "Wbl.gif";
//	if(edi_web){
//		edi_web_img = "Wredbl.gif";
//		edi = true;
//	}
//	if (height > 0){
//		currentimageheight = height;
//	}
	
//	var ediImg ='EDIbl.gif';
//	if(edi)
//		ediImg ='EDIblred.gif';
//	var advImg ='ADVbl.gif';
//	if(adv)
//		advImg ='ADVredbl.gif';
		
	document.onmousemove=followmouse;
/*
	newHTML = '<div style="padding: 0px; z-index:100; border: 0px;">';
	newHTML = newHTML +	'<table border="0" cellspacing="0" cellpadding="10">';
  	newHTML = newHTML +	'<tr>';
    newHTML = newHTML +	'<td bgcolor="#000000" class="FourBorders"><table width="100%" border="0" cellspacing="0" cellpadding="0">';
    newHTML = newHTML +	'<tr>';	
	newHTML = newHTML +	'    <td><table width="100%" border="0" cellspacing="0" cellpadding="0">';
    newHTML = newHTML +	'<tr>';
    newHTML = newHTML +	'<td align="left" class="Stile4">'+id+'</td>';
    newHTML = newHTML +	'<td align="right" class="TopCenterSpaceBorder"><img src="Images/SearchImagesResponse/'+ediImg+'" hspace="10" /><img src="Images/SearchImagesResponse/'+edi_web_img+'" width="9" height="11" /><img src="Images/SearchImagesResponse/'+edi_print_img+'" width="6" height="11" hspace="5" /><img src="Images/SearchImagesResponse/'+edi_print_plus_img+'" /></td>';
    newHTML = newHTML +	'<td width="100" align="center"><img src="Images/SearchImagesResponse/'+advImg+'"  hspace="5" /><img src="Images/SearchImagesResponse/'+adv_web_img+'" width="9" height="11" hspace="5" /><img src="Images/SearchImagesResponse/'+adv_print_img+'" width="6" height="11" /><img src="Images/SearchImagesResponse/'+adv_print_plus_img+'" width="13" height="11" hspace="5" /><img src="Images/SearchImagesResponse/'+adv_print_super_plus_img+'" /></td>';
    newHTML = newHTML +	'</tr>';
    newHTML = newHTML +	'</table></td>';
    newHTML = newHTML +	'</tr>';
	newHTML = newHTML +	'      <tr>';
	newHTML = newHTML +	'        <td height="5"></td>';
	newHTML = newHTML +	'      </tr>';
	newHTML = newHTML +	'      <tr>';
	newHTML = newHTML +	'        <td align="center" valign="middle"><img src="'+imagename+'" width="'+width+'" height="'+height+'" class="FourBorders" /></td>';
	newHTML = newHTML +	'      </tr>';
	newHTML = newHTML +	'    </table></td>';
	newHTML = newHTML +	'  </tr>';
	newHTML = newHTML +	'</table>';
	newHTML = newHTML + '</div>';
*/
    //alert('0');
	newHTML = 			'<div style="padding: 0px; z-index:100; border: 0px;">';
	newHTML = newHTML +	' <table border="0" cellspacing="0" cellpadding="10">';
	newHTML = newHTML +	'	<tr>';
	//newHTML = newHTML +	'	  <td align="left" class="Stile4">'+id+'</td>';
	newHTML = newHTML +	'	  <td>';
	newHTML = newHTML + '		<img src="'+imagename+'" width="'+width+'" height="'+height+'" />'
	newHTML = newHTML +	'	  </td>';
	newHTML = newHTML +	'	</tr>';
	newHTML = newHTML +	' </table>';
	newHTML = newHTML + '</div>';
	
	gettrailobjnostyle().innerHTML = newHTML;
	gettrailobj().display="inline";
}


function hidetrail(){
	gettrailobj().innerHTML = " ";
	gettrailobj().display="none"
	document.onmousemove=""
	gettrailobj().left="-500px"

}

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(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 < 380){
			xcoord = e.pageX - xcoord - 400; // Move to the left side of the cursor
		} else {
			xcoord += e.pageX;
		}
		if (docheight - e.pageY < (currentimageheight + 110)){
			// truebody().scrollTop is always zero in Safari 3.1, so we us documnet.body.scrollTop instead
			if ( document.body ){
				scrollTop = Math.max(truebody().scrollTop, document.body.scrollTop);
			} else {
				scrollTop = truebody().scrollTop;
			}
			ycoord += e.pageY - Math.max(0,(110 + currentimageheight + e.pageY - docheight - scrollTop));
		} else {
			ycoord += e.pageY;
		}

	} else if (typeof window.event != "undefined"){
		if (docwidth - event.clientX < 380){
			xcoord = event.clientX + truebody().scrollLeft - xcoord - 400; // 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;
		}
	}

	if(ycoord < 0) { ycoord = ycoord*-1; }
	gettrailobj().left=xcoord+"px";
	gettrailobj().top=ycoord+"px";

}

function followmouseBatch(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(window.innerHeight)

	var trailInnerDiv = $('trailInnerDiv');
	var currentimageheight = trailInnerDiv.offsetHeight;
	var currentimagewidth = trailInnerDiv.offsetWidth;

	scrollPos = Position.realOffset(truebody());
	
	if (typeof e != "undefined"){
		if (docwidth - e.pageX < 380){
			xcoord = e.pageX - xcoord - 400; // Move to the left side of the cursor
		} else {
			xcoord += e.pageX;
		}
		if ((e.pageY - scrollPos[1]) + currentimageheight > docheight){
			ycoord = -ycoord + (e.pageY - currentimageheight);
		} else {
			ycoord += e.pageY;
		}
	} else if (typeof window.event != "undefined"){
		if (event.clientX + currentimagewidth > docwidth){
			xcoord = -xcoord + ((event.clientX + scrollPos[0]) - currentimagewidth); // Move to the left side of the cursor
		} else {
			xcoord += (event.clientX + scrollPos[0]);
		}
		if (event.clientY + currentimageheight > docheight){
			ycoord = -ycoord + ((event.clientY + scrollPos[1]) - currentimageheight);
		} else {
			ycoord += (event.clientY + scrollPos[1]);
		}
	}

	if(ycoord < 0) { ycoord = ycoord*-1; }

	gettrailobj().left=xcoord+"px"
	gettrailobj().top=ycoord+"px"

}

