/**
 * @name jQuery Image Magnifrier
 * @license GPL
 * @version 0.0.1
 * @date Oktober 14, 2010
 * @category jQuery script
 * @author Andre Thomas (andre@xlr8.at)
 * @copyright (c) 2010 Andre Thomas (http://xlr8.at)
 * @example Visit http://xlr8.at/ for more informations about this jQuery plugin
 * 
 * 
 * Please keep the credits when using this script. Please send improvments and suggestions on improving this tiny script to me.
 * 
 */




$(document).ready(function(){
	
	var xxximg = new Image(); 
	$(".xmag").mouseover(function(){
		//alert("here");
		    if(! $(this).hasClass("active")) {
		    	$(this).addClass("active");	  
		    	c = $(this).children(".thumbnail").attr("rel");
		       	xxximg.src = c; 
		    	xxx = "<div id=xframe class=active style=\"border:1px solid f00; position:absolute;\"><img style=\"display:none; position:absolute; \" id=grossesBild src=\"" + c +"\"></div>";	
		    	$(this).prepend(xxx);
		    	$("#xframe img").fadeIn(1000);
		  	}
		  
    });

    $(".xmag").mouseleave(function(event){
  	  if($(this).hasClass("active")) {
  		 $(this).removeClass("active");
    		 //$("#xframe img").fadeOut(500,function(){
    			 $("#xframe").remove();
    		// });
    	 
  	  }
    });
    
    
	$(".xmag").mousemove(function(event){

	      a = parseInt(event.pageX); 
		  b = parseInt(event.pageY);
		  if ( $(this).hasClass("active") ) {
				 g=parseInt ( xxximg.width );
			  	 h=parseInt($(this).css("width"));
				 i=parseInt(xxximg.height);
				 j=parseInt($(this).css("height"));
			     f=g/h -1;
				 k=i/j -1;
			     var position = $(this).offset();
	             x=parseInt(position.left);
	             y=parseInt(position.top);
	             
	             
	            // alert(x + " "+y);
	             z =  parseInt((a - x ) * f * -1 );
	             zz =  parseInt( (b - y ) * k * -1);
				 $("#xframe").children("#grossesBild").css("left", z + "px" );
				 $("#xframe").children("#grossesBild").css("top", zz + "px");
		  }	
 
    });

}); 
