/*
jQuery(
	   function( $ ) {
 
			$( ".screenshot" ).bind(
				"mouseenter",
				function( event ) {
				  mover( this );
				  //console.log( event.type, " :: ", this.id );
				} 
			);
			
			$( ".screenshot" ).bind(
				"mouseleave",
				function( event ) {
				  mout();
				  //console.log( event.type, " :: ", this.id );
				} 
			);
	 
	   }
);
*/

var previewLeftMax = "200";
var mouseX=0, mouseY=0;
$(document).ready( function(){
						   
    $( ".prevscreen" ).hover ( 
							  
							  function () {
										     var bShowAbove = false;
/*										 
										     if( this.classList.contains('lowerprevrow') )
												bShowAbove = true;
*/												
											 mover(this, bShowAbove);
						      }, 
   
   							  function () {
											 mout();
							  }
	);
   
   
    $( ".prevscreen" ).mousemove ( function (e) {
									 mouseX = e.pageX;
									 mouseY = e.pageY;
									 //console.log(mouseX);
									 var previewdiv = document.getElementById("grow");

									 if( previewdiv ) {
										 var yOffset = 15;
/*									 
										 if( previewdiv.classList.contains('lowerprevrow') )
											 yOffset = -previewdiv.children[0].naturalHeight-10;
*/											 
										 previewdiv.style.top = (mouseY+yOffset)+"px";
										 if(mouseX <= previewLeftMax)
										   previewdiv.style.left = (mouseX+10)+"px";
										 else
										   previewdiv.style.left = previewLeftMax +"px"
									 }									 
									 
    });

 
    $(document).bind( 'mousemove', function(e) {    
									mouseX = e.pageX;
									mouseY = e.pageY;
    });
   
});


function mover( previmage, showabove ) {
    var destimg = previmage.src;
	destimg = destimg.replace('_small', '');

    var div = document.createElement('div');
	img = document.createElement("img");	
	img.src = destimg;
	div.appendChild(img);	

	if( showabove )
	  div.classList.add('lowerprevrow');
	div.setAttribute("id","grow")
	div.style.position = "absolute";
	div.style.border = "1px solid black";
    div.style.top = "100px";
    div.style.left = "260px";
	
	var yOffset = 15;
/*
	if( div.classList.contains('lowerprevrow') )
	   yOffset = -div.children[0].naturalHeight-10;
*/	   
	div.style.top = (mouseY+yOffset)+"px";

    if(mouseX <= previewLeftMax)
	  div.style.left = (mouseX+10)+"px";
	else
	  div.style.left = previewLeftMax +"px";

	document.getElementById('previewscreens').appendChild(div);
}


function mout() {
	document.getElementById('previewscreens').removeChild(document.getElementById("grow"));
}


function preview(imgurl, width, height){ 	
  var newwindow = null;
  newwindow = ( window.open ("newwindow", "ArgusMonitor","toolbar=no,width="+width+",height="+height+",ScreenX="+((window.innerWidth-width)/2)+",screenY="+((screen.height-height)/2)+",directories=no,status=no,scrollbars=no,resizable=yes,menubar=no,titlebar=no,location=no,toolbar=no") );
  newwindow.location.href = imgurl;
  newwindow.focus();
  return false;
}            


