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 = 500;	// maximum image size.

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

function gettrailobj(){
	return $("trailimageid").style;
}


function gettrailobjnostyle(){
	return $('trailimageid');
}


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


function showtrail(imagename,title,description,showthumb,height,newP,frontPrice, backPrice,discount){

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

	document.onmousemove=followmouse;

	var newHTML = '<div style="padding: 0px; background-color: #FFF; border: 1px solid #CCCCCC;">';
	newHTML = newHTML + '<span class="largetitle">';
	
	
	if (newP=='true'){
		newHTML = newHTML + '<font color=#ff0000> New!</font> ';
	}
	newHTML = newHTML + title + '</span><div class="borderbot"></div>';
	newHTML = newHTML + '<span class="zoomDescription">' + description + '</span><br/>';
	
	if (showthumb > 0 ){
		newHTML = newHTML + '<div align="center" style="padding: 8px 2px 2px 2px;"><img src="' + imagename + '" border="0"/></div>';
	}
	
	if (frontPrice == backPrice){
		newHTML = newHTML + '<div class="pricetitle" align="center"><span class="bold"> AUD $'+ frontPrice + '</span></div></div>';
	} else {
		if (discount==null || discount==0){
			newHTML = newHTML + '<div class="pricetitle" align="center"><span class="bold">1 SIDED PRINT $'+ frontPrice +'&nbsp;&nbsp;&nbsp;2 SIDED PRINT $'+ backPrice + '</span></div></div>';
		} else {
			newHTML = newHTML + '<div class="pricetitle2" align="center"><span class="bold">1 SIDED PRINT $'+ formatAsMoney(frontPrice*(100-discount)/100) + '&nbsp;&nbsp;SAVE ' + formatAsMoney(discount) + '% (VALUE $'+ frontPrice + ')</span></div></div>';
			//newHTML = newHTML + '2 Sided Print &nbsp;($' + backPrice + ' - <font color=\'#FF000\'> ' + discount +'%OFF</font>) = <font color=\'#FF000\'>$'+ formatAsMoney(backPrice*(100-discount)/100) +' </font>' + '</div></div>';
		}
	}
	

	gettrailobjnostyle().innerHTML = newHTML;

	gettrailobj().visibility="visible";

}




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

}

function followmouse(e){
	var xcoord = 15;
	var ycoord = 15;
	
	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 (typeof e != "undefined"){
		if (docwidth - e.pageX < 300){
			xcoord = e.pageX - xcoord - 350; // Move to the left side of the cursor
		} else {
			xcoord += e.pageX;
		}
		if (docheight - e.pageY < (currentimageheight + 110)){
			ycoord += e.pageY;
			//ycoord += e.pageY - Math.max(0,(110 + currentimageheight + e.pageY - docheight - truebody().scrollTop));
		} else {
			ycoord += e.pageY;
		}

	} else if (typeof window.event != "undefined"){
		//alert ("2");
		if (docwidth - event.clientX < 300){
			xcoord = event.clientX + truebody().scrollLeft - xcoord - 350; // 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;
		}
	}

	 docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15;
	 docheight=document.all? Math.max(truebody().scrollHeight, truebody().clientHeight) : Math.max(document.body.offsetHeight, window.innerHeight);	
	
	
	if (xcoord < 0){xcoord = 0;}
  	if (ycoord < 0){ycoord = 0;}  
  	
	gettrailobj().left=xcoord+"px";
	gettrailobj().top=ycoord+"px";

}



function gettrailobjParent(){
	return window.parent.document.getElementById('trailimageid2').style;
}

function gettrailobjnostyleParent(){
	return window.parent.document.getElementById('trailimageid2');
}


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

function showtrailArtWork(image,title,description){
	
	document.onmousemove=followmouseArtWork;

	var newHTML = '<div style="padding: 0px; background-color: #FFF; ">';
	newHTML = newHTML + '<span class="largetitle">';
	
	
	newHTML = newHTML + title + '</span><div class="borderbot"></div>';
	newHTML = newHTML + description + '<br/>';

	newHTML = newHTML + '<div align="center" style="padding: 8px 2px 2px 2px;"><img src="' + image + '" border="0" width="300"/></div>';


	gettrailobjnostyleParent().innerHTML = newHTML;

	gettrailobjParent().visibility="visible";

}

function hidetrailArtWork(){
	gettrailobjParent().visibility="hidden";
	document.onmousemove="";
	gettrailobjParent().left="-500px";

}


function followmouseArtWork(e){
	
	if (navigator.appName.indexOf("Microsoft")!=-1) {
		toppos = 500;
		leftpos = window.screen.width/2 -400;
	}else{
		toppos = 530;
		leftpos = window.screen.width/2 -400;
	}
	
	
	//toppos2 = window.screen.width;
	//leftpos2 = window.screen.height;
	
	
	//alert (toppos + " " + leftpos);
	gettrailobjParent().left=leftpos;
	gettrailobjParent().top=toppos;

}


function formatAsMoney(mnt) {
    mnt -= 0;
    mnt = (Math.round(mnt*100))/100;
    return (mnt == Math.floor(mnt)) ? mnt + '.00' 
              : ( (mnt*10 == Math.floor(mnt*10)) ? 
                       mnt + '0' : mnt);
}

