//**************************************************************
// LozaAndriy Zoom
// Released on Apr 10 2009
// i'm searching for a job,pick me up!!!
// mail: landrij@gmail.com
//**************************************************************

(function($){

		$.fn.LAjqueryzoom = function(options){

		var settings = {
				xzoom: 300,		//zoomed width default width
				yzoom: 300,		//zoomed div default width
				offset: 10,		//zoomed div default offset
				position: "right"  //zoomed div default position,offset position is to the right of the image
			};

			if(options) {
				$.extend(settings, options);
			}

            var noalt ='';

		  $(this).click(function(){
			if($("#bigImage").css("display") == 'none'){
		   		$("#text_zoom_in").hide(0);
		   		$("#text_zoom_out").show(0);
		   		$("#smallImage").hide(0);
		   		$("#bigImage").show(0);}
		   	else{
		   		$("#text_zoom_in").show(0);
		   		$("#text_zoom_out").hide(0);
		   		$("#bigImage").hide(0);
		   		$("#smallImage").show(0);}
		   }); 

		
		$(this).hover(function(){

           
		    var imageLeft = $(this).get(0).offsetLeft;
		    var imageRight = $(this).get(0).offsetRight;
		    var imageTop =  $(this).get(0).offsetTop;
		    var imageWidth = $(this).get(0).offsetWidth;
		    var imageHeight = $(this).get(0).offsetHeight;

		   // var bigimage = settings.image;
             
		    //if($("div.LAzoomdiv").get().length == 0){

		    //$(this).after("<div class='LAzoomdiv'><img class='bigimg' src='"+bigimage+"'/></div>");

		    //}

		   // if(settings.position == "right"){

		   // leftpos = imageLeft + imageWidth + settings.offset;

		  //  }else{

		  //  leftpos = imageLeft - settings.xzoom - settings.offset;

		   // }

		  //  $("div.LAzoomdiv").css({ top: imageTop,left: leftpos });

		  //  $("div.LAzoomdiv").width(settings.xzoom);

		  //  $("div.LAzoomdiv").height(settings.yzoom);

		  //  $("div.LAzoomdiv").show();


			$(document.body).mousemove(function(e){
		    var bigwidth = $(".bigimg").get(0).offsetWidth;
		    var bigheight = $(".bigimg").get(0).offsetHeight;
		    var scaley ='x';
		    var scalex= 'y';

		    if(isNaN(scalex)|isNaN(scaley)){
			    var scalex = Math.round(bigwidth/imageWidth) ;
			    var scaley = Math.round(bigheight/imageHeight);
		    }

			mouse = new MouseEvent(e);

			scrolly = mouse.y - imageTop - ($("div.LAzoomdiv").height()*1/scaley)/2 ;

			$("div.LAzoomdiv").get(0).scrollTop = scrolly * scaley  ;

		    scrollx =    mouse.x - imageLeft - ($("div.LAzoomdiv").width()*1/scalex)/2 ;

			$("div.LAzoomdiv").get(0).scrollLeft = (scrollx) * scalex ;


				    });
		    },function(){
               // $(this).attr("alt",noalt);
		       //	$("div.LAzoomdiv").hide();
		       	$(document.body).unbind("mousemove");
		       //	$(".lenszoom").remove();
		       //	$("div.LAzoomdiv").remove();
		    });

		}

})(jQuery);

function MouseEvent(e) {
this.x = e.pageX
this.y = e.pageY
}


