var offsetfrommouse=[15,15]; //image x,y offsets from cursor position in pixels. Enter 0,0 for no offset
var displayduration=1; //duration in seconds image should remain visible. 0 for always.
var currentimageheight = 369;	// maximum image size.
var t_id = 0;
var currentimagewidth = 429;	// maximum image size.
var timer;

var pos=0;
var dir=2;
var len=0;

function getSize() {
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		myWidth = window.innerWidth; myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth ||document.documentElement.clientHeight ) ) {
		myWidth = document.documentElement.clientWidth; myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		myWidth = document.body.clientWidth; myHeight = document.body.clientHeight;
	}
	return [myWidth,myHeight];
}
function getScrollXY() {
	var scrOfX = 0, scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
		scrOfY = window.pageYOffset; scrOfX = window.pageXOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		scrOfY = document.body.scrollTop; scrOfX = document.body.scrollLeft;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		scrOfY = document.documentElement.scrollTop; scrOfX = document.documentElement.scrollLeft;
	}
	return[scrOfX,scrOfY];
}

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

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


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


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

function showtrail(imagename,title,showthumb){
	i = imagename
	t = title
	s = showthumb
	timer = setTimeout("show('"+i+"',t,s);",200);
}
function show(imagename,title,showthumb){
	
	document.onmousemove=followmouse;
	t_id = setInterval(animate,20);
	
	newHTML = '<div class="border_preview"><div id="loader_container"><div id="loader" style="position:relative;"><div align="center">Loading template preview...</div><div id="loader_bg"><div id="progress"> </div></div></div></div>';
	newHTML = newHTML + '<h2 class="Heading2" align="center">' + title + '</h2>'
	if (showthumb > 0){
    newHTML = newHTML + '<div align="center" style="padding: 8px 10px 17px 10px;"><img onload="javascript:remove_loading();" src="' + imagename + '" border="0"></div>';

	newHTML = newHTML + '</div>';
	framewidth = currentimagewidth+33;
	if ((navigator.userAgent.indexOf("Firefox")==-1) && (navigator.userAgent.indexOf("Opera")==-1) ) {	newHTML = newHTML+'<iframe src="about:blank" scrolling="no" frameborder="0" width="'+framewidth+'" height="'+currentimageheight+'"></iframe>';}

	var obj_id = gettrailobjnostyle()
	obj_id.innerHTML = newHTML;

	gettrailobj().display="block";

}
}
function showtip(id){
	
	document.onmousemove=followmouse;
	t_id = setInterval(animate,20);

	/*if(text.length > 10)
	{
			
		newHTML = '<div class="border_preview" >';
	}else
	{
		newHTML = '<div class="border_preview" style="display:none" >';
	}
	

    newHTML = newHTML + '<div align="center" style="padding: 5px 15px 15px 15px;border: #ffc040 1px solid;background-color: #CCCC99;">' + text + '</div>';

	newHTML = newHTML + '</div>';	*/
	var obj_id = gettrailobjnostyle()
	//obj_id.innerHTML = newHTML;
	if(String(document.getElementById(id).innerHTML).length>5) // chi khi co noi dung moi hien thi
	{
		obj_id.innerHTML = document.getElementById(id).innerHTML;
		gettrailobj().display="block";
	}

	

}
var IE = document.all?true:false
function followmouse(e){

	if (IE) { // grab the x-y pos.s if browser is IE
	    tempX = event.clientX + document.body.scrollLeft
	    tempY = event.clientY + document.body.scrollTop
	  } else {  // grab the x-y pos.s if browser is NS
	    tempX = e.pageX
	    tempY = e.pageY
	  }  
	// catch possible negative values in NS4
	if (tempX < 0){tempX = 0}
	if (tempY < 0){tempY = 0} 
	tempX=tempX+20;
	tempY=tempY-10;
	gettrailobj().left = tempX+"px";
	gettrailobj().top = tempY+"px";
}

function animate()
{
	var elem = document.getElementById('progress');
	if(elem != null) {
		if (pos==0) len += dir;
		if (len>32 || pos>79) pos += dir;
		if (pos>79) len -= dir;
		if (pos>79 && len==0) pos=0;
		elem.style.left = pos;
		elem.style.width = len;
	}
	
}

function remove_loading() {
	this.clearInterval(t_id);
	var targelem = document.getElementById('loader_container');
	targelem.style.display='none';
	targelem.style.visibility='hidden';
	//var t_id = setInterval(animate,60);
}


	    