var mousex = 0;
var mousey = 0;
var grabx = 0;
var graby = 0;
var orix = 0;
var oriy = 0;
var elex = 0;
var eley = 0;
var algor = 0;


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

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


function remove_loading() { 
document.getElementById("loader_container").style.display= "none"; 
}



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


function show(e,imagename,title,width,height)
{
init();

//document.getElementById("preview_div").style.zIndex= 110;
//document.getElementById("form_cechaa").style.zIndex= 0; 
//document.getElementById("form_cechaa").style.display= "none"; 

//if(ea.x>0 || ea.y>0 ) 
//{ 
//MouseX =ea.x; MouseY =ea.y;  
//}else{
  //    MouseX =event.x; MouseY =event.y; 
    // }
     

	//gettrailobj().left=mousex+"px"
	//gettrailobj().top=mousex+"px"

	
	//document.onmousemove = followmouse;
	 //document.onmousedown=followmouse ;
//document.onmouseup = drop;


	//<div id="loader_container"><div id="loader"></div></div><div align="center">Loading template preview...</div>
		newHTML = '<div style=" z-index:110;" style="background-color=red;" onmousedown=hidetrail() align=right><a href=onmousedown=hidetrail()><b>zamknij</b></a>&nbsp; </div>';
		//newHTML = newHTML + '<h1 >' + ' '+title + '</h1>'
		
    	newHTML = newHTML + '<div style=" z-index:110;"><img   src="' + imagename + '" border="1"></div>';
		//newHTML = newHTML + '</div>'; 
		
		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";
		
	    xy(e);
		gettrailobj().left=MouseX+"px"
		gettrailobj().top=MouseY+"px"
	
}






















function xy(e)
{
if(e.x>0 || e.y>0 ) 
{ 
MouseX =e.x; MouseY =e.y;  
}else{
      MouseX =event.x; MouseY =event.y; 
     }

}



var dragobj = null;

function falsefunc() { return false; } // used to block cascading events

function init()
{
  document.onmousemove = update; // update(event) implied on NS, update(null) implied on IE
  update();
}

function getMouseXY(e) // works on IE6,FF,Moz,Opera7
{ 
  if (!e) e = window.event; // works on IE, but not NS (we rely on NS passing us the event)

  if (e)
  { 
    if (e.pageX || e.pageY)
    { // this doesn't work on IE6!! (works on FF,Moz,Opera7)
      mousex = e.pageX;
      mousey = e.pageY;
     }
    else if (e.clientX || e.clientY)
    { // works on IE6,FF,Moz,Opera7
      mousex = e.clientX + document.body.scrollLeft;
      mousey = e.clientY + document.body.scrollTop;
    }  
  }
}

function update(e) { getMouseXY(e); }

function grab(context)
{
  document.onmousedown = falsefunc; // in NS this prevents cascading of events, thus disabling text selection
  dragobj = context;
  dragobj.style.zIndex = 10; // move it to the top
  document.onmousemove = drag;
  document.onmouseup = drop;
  grabx = mousex;
  graby = mousey;
  elex = orix = dragobj.offsetLeft;
  eley = oriy = dragobj.offsetTop;
  update();
}

function drag(e) // parameter passing is important for NS family 
{
  if (dragobj)
  {
    elex = orix + (mousex-grabx);
    eley = oriy + (mousey-graby);
    dragobj.style.position = "absolute";
    dragobj.style.left = (elex).toString(10) + 'px';
    dragobj.style.top  = (eley).toString(10) + 'px';
  }
  update(e);
  return false; // in IE this prevents cascading of events, thus text selection is disabled
}

function drop()
{
  if (dragobj)
  {
    dragobj.style.zIndex = 0;
    dragobj = null;
  }
  update();
  document.onmousemove = update;
  document.onmouseup = null;
  document.onmousedown = null;   // re-enables text selection on NS
}



