var pic_real_width = 0, pic_real_height = 100, leftP = 0, topP = 0, bigIMG, mp;
window.onload=function(){
	$('#page').append('<div id="zoom"></div>');

	    $("a[lang=lightbox]").hover(function(e){
	    	$('#zoom').html("<img src=" + $(this).attr('href') + " alt='Large Image' />");
	    	topP = $("img", this).position().top;
	    	leftP = $("img", this).position().left;
	    	mp = e.pageY;
		    $('#zoom img').bind('load', function(){
		    	fire_loading(mp);
		    });

	    	$("#zoom").css('display','block');
		    	
	    	//fire_loading(e.pageY);

			$(document).mousemove(function(e){
		    	fire_loading(e.pageY);
			});

			if( pic_real_height > 100 ) {
				$('#zoom img').css('visibility','visible');

			}

	    }, function(){
	        $("#zoom").css('display','none');
	        $('#zoom img').css('visibility','hidden');
	        $('#zoom').css({
			'height':'100px',
			'width':'100px'
		});
	    });

}

function fire_loading(pageY) {
	if( $("#zoom img").height() > 100) {
		pic_real_height = $("#zoom img").height();
		$('#zoom img').css('visibility','visible');
    	$('#zoom').css({
    		'height':$("#zoom img").height(),
    		'width':$("#zoom img").width()
    	});
	}
	$("#zoom").css("top",(topP + 160 - pic_real_height )).css("left", (leftP - ($("#zoom img").width()/2) + 70 ));
}
