// JavaScript Document


jQuery(document).ready(function(){
   //mouseEnter
   $(".img-nahled").mouseenter(function(e){
      var clientWidth = window.innerWidth || document.body.clientWidth || document.documentElement.clientWidth;
      var clientHeight = window.innerHeight || document.body.clientHeight || document.documentElement.clientHeight;
      var pos = getAbsolutePosition(this);
      pos.x = e.pageX  - pos.x;
      pos.y = e.pageY - pos.y;
      
      if((clientWidth - e.clientX) < 350){
        var x = ((e.clientX-300) - (pos.x));
      }        
   	  else{
        var x = ((e.clientX+160) - (pos.x));
      }       
        
      if(e.clientY < 400){
        var y =  50;
      }      
      else{
        var y = (e.clientY - 400);        
      }
      $("#dynNahled").css({'left' : x + 'px', 'top' : y + 'px'});
   }); 
   
   //mouseLeave
   $(".img-nahled").mouseleave(function(){
     $("#dynNahled").hide();   
   });   
   
    $("#dynNahled").click(function(){
      $("#dynNahled").hide();    
    });
});


function getAbsolutePosition(element) {
 var r = { x: element.offsetLeft, y: element.offsetTop };
 if (element.offsetParent) {
   var tmp = getAbsolutePosition(element.offsetParent);
   r.x += tmp.x;
   r.y += tmp.y;
 }
 return r;
}; 



function nahled_okno(url, w, h){
   var x = screen.width;
   var y = screen.height - 95;
   if (w >= x) 
   { 
     w = x;
     x = 0;                
   }
   else
   { x = (x - w)/2; }
   if (h >= y)
   {
     h = y;         
     y = 0;
   }     
   else
   { y = (y - h)/2; }        
   return popupWin = window.open(url, '_blank', 'toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=' + w + ',height=' + h + ',left=' + x + ',top=' + y);
   popupWin.focus();
};  


function dyn_nahled(id_zbozi){
   $.ajax({  
       type: "GET",  
       url: "http://www.vseprozenu.cz/dyn_nahled.php",  
       cache: true,   
       data: "id=" + id_zbozi,  
       dataType: "html",   
       success: function(data){  
         $("#dynNahled").html(data).show();  
       }  
     });
};

