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

var offsetfrommouse=[5,5]; //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;

var eObj;

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
}

var d_x = 0;
var d_y = 0;

function DragDrop(dstart)
{
  if(dstart == 1)
  {
	document.onmousemove=followmouse
        d_x = event.clientX - parseInt(gettrailobj().left);
        d_y = event.clientY - parseInt(gettrailobj().top);
  }
  else
  {
         document.onmousemove=""
  }
}


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

function showtrail(imagename,title,width,height){
	i = imagename
	t = title
	w = width
	h = height
	
	show('"+i+"',t,w,h)
	timer = setTimeout("show('"+i+"',t,w,h);",200);
}
function show(imagename,title,width,height){

    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: '';

		defaultimageheight = height
		defaultimagewidth = width

                func1 = "MM_swapImage('btn_close','','../images/buttons/btn_close_on.gif',1)"

		newHTML = '<div class="border_preview" style="width:'+  width +'px;height:'+ height +'px">'
		newHTML = newHTML + '<table width="100%"  border="0" cellpadding="0" cellspacing="0"><tr><td bgcolor="#c8db1f">'
                newHTML = newHTML + '<table width="100%" height="19" border="0" cellpadding="0" cellspacing="0"><tr>';
                newHTML = newHTML + '<td onmouseup="DragDrop(0)" onmousedown="DragDrop(1)" background="../images/stationary/bg_top_imgshow.gif">&nbsp;</td>';
                newHTML = newHTML + '<td width="15" align="right" background="../images/stationary/bg_top_imgshow.gif">';
                newHTML = newHTML + '<a href="javascript:hidetrail()" onMouseOut="MM_swapImgRestore()" onMouseOver="'+func1+'"><img src="../images/buttons/btn_close.gif" alt="Close" name="btn_close" width="13" height="19" border="0" hspace="3"></a>';
                newHTML = newHTML + '</td></tr>'
                newHTML = newHTML + '</table>'
		newHTML = newHTML + '</td></tr>'
		newHTML = newHTML + '<tr><td align="center" bgcolor="#c8db1f" valign="middle">'
		newHTML = newHTML + '<div id="loader_container"><div id="loader"><div align="center">Завантаження зображення...</div><div id="loader_bg"><div id="progress"> </div></div></div></div>';
    	        newHTML = newHTML + '<div class="preview_temp_load"><img onload="javascript:remove_loading();" src="' + imagename + '" border="0"></div>';
		newHTML = newHTML + '</div>';

		newHTML = newHTML + '</td></tr></table>'

		//newHTML = newHTML + '<font class="title_h2">' + ' '+title + '</font>'



		/*if(navigator.userAgent.indexOf("MSIE")!=-1 && navigator.userAgent.indexOf("Opera")==-1 ){
			newHTML = newHTML+'<iframe src="about:blank" scrolling="no" frameborder="0" width="'+width+'" height="'+height+'"></iframe>';
		}*/

		gettrailobjnostyle().innerHTML = newHTML;
		gettrailobj().display="block";

		gettrailobj().left=(docwidth/2 - defaultimagewidth/2) +"px"
	        gettrailobj().top=(docheight/2 - defaultimageheight/2)+"px"
	}
}

function followmouse(e){
	var xcoord=0;//offsetfrommouse[0]
	var ycoord=0;//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"){
                      xcoord += e.pageX - d_x;
                      ycoord += e.pageY - d_y;

	} else if (typeof window.event != "undefined"){
                      xcoord += event.clientX - d_x;
                      ycoord += event.clientY - d_y;
	}

	gettrailobj().left=xcoord+"px"
	gettrailobj().top=ycoord+"px"

}

