woogle.query(document).ready(function($){
	$img = $('div.woogle_result >  img');	
	// var width = 200;
	var height = 200;	
	var containerClass = "imghover";
	var offsetY = 70;
	var offsetX = 70;
	var fadeOutTime = 200;
	var fadeInTime = 400;
   
   	function findPos(obj) {
		var curleft = obj.offsetLeft || 0;
		var curtop = obj.offsetTop || 0;
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		}
		return {x:curleft,y:curtop};
	}	
	
	$img.mouseover(function(e) {
		
		var src = $(this).attr('src');
		
		// create Container
		var $imgContainer = $( document.createElement("div") );		
		
		var pos = findPos( this );
		
		var origHeight = $(this).attr('height');
		
		// Problem that no width is set
//		var origWidth = $(this).attr('width');
//		
//		var relWidthHeight = origWidth / origHeight ;
//		var width = height * relWidthHeight;		
		
		var windowWidth = window.innerWidth;
		var windowHeight = window.innerHeight;
		
		if( (pos.y + height + offsetY) > windowHeight ) {
			offsetY_a = pos.y - offsetY - origHeight;
		} else {
			offsetY_a = pos.y + offsetY;
		}
				
		if( (pos.x + height + offsetX) > windowWidth ) {
			offsetX_a = pos.x - offsetX - origWidth;
		} else {
			offsetX_a = pos.x + offsetX;
		}
		
		$imgContainer
				.hide()
				.addClass( containerClass )
				.css({
					position: "absolute",
					top: offsetY_a + "px",
					left: offsetX_a + "px",
					zIndex: 101
				})				
				.append('<img src="'+src+'" height="'+height+'" />');
				
		// Add to body element
		$("body").append($imgContainer.fadeIn(500) );
	});
   
	$img.mouseout( function(e) {
		$('div.'+containerClass).fadeOut(200 , function(e) {
			$(this).remove() ;
		});
	});
   
 });
