/*
Simple Image Trail script- By JavaScriptKit.com
Visit http://www.javascriptkit.com for this script and more
This notice must stay intact
*/

//var t_id = setInterval(animate,20);
var pos=0;
var len=0;

var offsetfrommouse=[15,-300]; //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 defaultimageheight = 40;	// maximum image size.
var defaultimagewidth = 40;	// maximum image size.

var timer;

function animate()
{
	var elem = document.getElementById('progress');
	
	if(elem != null) 
	{
		if (len > 200) len = 0;
		
		len = len + 1;
			
		elem.style.width = len;
	}
}

function remove_loading() 
{
	var targelem = document.getElementById('loader_container');
	var targelem2 = document.getElementById('preloader_frame');
	
	targelem.style.display='none';
	targelem.style.visibility='hidden';
	
	targelem2.style.display='none';
	targelem2.style.visibility='hidden';
	
	var QuickBuyIFrm = document.getElementById('ifQBArticlePreview').contentWindow.document;
	var innerDocHeight = QuickBuyIFrm.body.scrollHeight;
	var innerDocWidth = QuickBuyIFrm.body.scrollWidth;
	
	if (shopTYPE == "B2B")
	{
		if (innerDocHeight > 700) innerDocHeight = 700;
		document.getElementById('ifQBArticlePreview').height = innerDocHeight - 20;
		
		if (innerDocHeight > 480) innerDocHeight = 480;
		document.getElementById('ifQBArticlePreview').width = innerDocWidth;
	}
	else
	{
		if (innerDocHeight > 900) innerDocHeight = 900;
		document.getElementById('ifQBArticlePreview').height = innerDocHeight - 20;
		
		if (innerDocHeight > 530) innerDocHeight = 530;
		document.getElementById('ifQBArticlePreview').width = innerDocWidth;
	}
}

function gettrailobj()
{
	if (document.getElementById)
	return document.getElementById("preview_div").style
}

function gettrailobjnostyle()
{
	if (document.getElementById)
	return document.getElementById("preview_div")
}

function truebody()
{
	return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function hidetrail()
{	
	gettrailobj().display= "none";
	document.onmousemove=""
	gettrailobj().left="-1000px"
	clearTimeout(timer);
}

function showtrail(articleid,width,height)
{
	timer = setTimeout("show('"+articleid+"',"+width+","+height+");",300);
	//show(articleid,width,height);
}

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 (typeof e != "undefined")
	{
		if (docwidth - e.pageX < defaultimagewidth + 2*offsetfrommouse[0]){
			xcoord = e.pageX - xcoord - defaultimagewidth; // Move to the left side of the cursor
		} else {
			xcoord += e.pageX;
		}
		if (docheight - e.pageY < defaultimageheight + 2*offsetfrommouse[1]){
			ycoord += e.pageY - Math.max(0,(2*offsetfrommouse[1] + defaultimageheight + e.pageY - docheight - truebody().scrollTop));
		} else {
			ycoord += e.pageY;
		}

	} 
	else if (typeof window.event != "undefined")
	{
		if (docwidth - event.clientX < defaultimagewidth + 2*offsetfrommouse[0]){
			xcoord = event.clientX + truebody().scrollLeft - xcoord - defaultimagewidth; // Move to the left side of the cursor
		} else {
			xcoord += truebody().scrollLeft+event.clientX
		}
		if (docheight - event.clientY < (defaultimageheight + 2*offsetfrommouse[1])){
			ycoord += event.clientY + truebody().scrollTop - Math.max(0,(2*offsetfrommouse[1] + defaultimageheight + event.clientY - docheight));
		} else {
			ycoord += truebody().scrollTop + event.clientY;
		}
	}
	
	gettrailobj().left=xcoord+"px"
	gettrailobj().top=ycoord+"px"
}

function show(articleid, width, height){
	
	if (shopTYPE == "B2B")
	{
		width = 480;
		height = 200;
	}
	else
	{
		width = 530;
		height = 200;
	}
	
	
	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth - offsetfrommouse[0]
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)

	if( (navigator.userAgent.indexOf("Konqueror")==-1  || navigator.userAgent.indexOf("Firefox")!=-1 || (navigator.userAgent.indexOf("Opera")==-1 && navigator.appVersion.indexOf("MSIE")!=-1)) && (docwidth>650 && docheight>500)) {
		( width == 0 ) ? width = defaultimagewidth: '';
		( height == 0 ) ? height = defaultimageheight: '';
	
		width += 30;
		height += 55;
		defaultimageheight = height;
		defaultimagewidth = width;
	
		document.onmousemove = followmouse; 
		
		newHTML = "";
		preloadHTML = "";

		newHTML = newHTML + '<div id="preloader_frame" style="z-index:111; position:absolute; background: #FFFFFF; border: 0px solid #444; width:'+  width +'px;height:'+ height +'px"><div id="loader_container"><div id="loader"><br><br><br><br><br><br><br><br><div align="center">Nalagam predogled artikla...</div><br><div id="loader_bg" stlye="background:#000000;"><div id="progress" stlye="background:#000000; height:20px; width:200px;"></div></div></div></div>';
		newHTML = newHTML + '</div>';

		newHTML = newHTML + '<iframe id="ifQBArticlePreview"'
		newHTML = newHTML + 'onload="javascript:remove_loading();"'
		newHTML = newHTML + 'src ="' + shopURL + '/include/QuickBuy_ArticlePreview.asp?ArticleID=' + articleid + '&QuickBuy_ArticlePreview=1"'
		newHTML = newHTML + 'width="' + width + '"'
		newHTML = newHTML + 'height="' + height + '"'
		newHTML = newHTML + 'frameborder="1"'
		newHTML = newHTML + 'marginheight="0"'
		newHTML = newHTML + 'marginwidth="0"'
		newHTML = newHTML + 'scrolling="no">'
		newHTML = newHTML + '</iframe>'


		gettrailobjnostyle().innerHTML = newHTML;		
		gettrailobj().display="block";
	}
}