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

var offsetfrommouse=[-100,+120]; 
var timer;

function gettrailobj(){
if (parent.parent.document.getElementById) return parent.parent.document.getElementById("preview_div").style
}

function gettrailobjnostyle(){
if (parent.parent.document.getElementById) return parent.parent.document.getElementById("preview_div")
}

function hidetrail(){	
	gettrailobj().display= "none";
	document.onmousemove="";
	gettrailobj().left="-500px";
	clearTimeout(timer);
}

function showtrail(imagename,_title,_width,_height,template_type){

	i = imagename;
	t = _title;
	w = _width;
	h = _height;
	timer = setTimeout("show('"+i+"',t,w,h,'"+template_type+"');",100);
}
function show(imagename,_title,_width,_height,template_type){

 	document.onmousemove=followmouse; 
	newHTML = '<div class="border_preview" id="bp" style="width:'+  (_width+30) +'px;height:'+ (_height+66) +'px"><div id="loader_container"><div id="loader"><div align="center">Loading template preview...</div><div id="loader_bg"><div id="progress"> </div></div></div></div>';
	newHTML = newHTML + '<div class="preview_h2">' + ' '+_title + '</div>';
	newHTML = newHTML + '<div style="text-align: center;width: 100%;">' + ' '+template_type + '</div>';
	newHTML = newHTML + '<div class="preview_temp_load"><img id="trail" onload="javascript:remove_loading();" src="' + imagename + '" border="1" width="'+_width+'" height="'+_height+'"></div>';
	newHTML = newHTML + '</div>'; 
		
	gettrailobjnostyle().innerHTML = newHTML;
	gettrailobj().display="block";
	
}

function followmouse(e){
	hh = parent.parent.document.getElementById("bp").style.height;
	hh = parseInt(hh.replace("px",""));
	if (parent.parent.document.width > 936){
		var xcoord=offsetfrommouse[0]+parent.parent.document.width/2-document.width-430+468;
	} else {
		var xcoord=offsetfrommouse[0]+936-document.width-430;
	}
	
	var ycoord=offsetfrommouse[1];
	
	if (typeof e != "undefined"){
		xcoord+=e.pageX;
		ycoord+=e.pageY;
	} 

	gettrailobj().left=xcoord+"px";
	
	if (parent.parent.window.innerHeight > 20 +hh){
		if ((ycoord - parent.parent.window.pageYOffset  < 0) && (ycoord + hh + 10 > parent.parent.window.innerHeight + parent.parent.window.pageYOffset)){
	 		hidetrail();
		} else if (ycoord + hh + 10 > parent.parent.window.innerHeight + parent.parent.window.pageYOffset){
			gettrailobj().top=parent.parent.window.innerHeight + parent.parent.window.pageYOffset-hh-10 +"px";
		} else if (ycoord - parent.parent.window.pageYOffset -10 < 0){
			gettrailobj().top=parent.parent.window.pageYOffset+10+"px";
		} else {
			gettrailobj().top=ycoord+"px";
		}
	} else{
		hidetrail();
	}
}
