// JavaScript Document

this.imagePreview = function(imgPath){	

	var total_width=$(document).width();
	var total_height=$(document).height();
	 $("a.mypreviewbox").hover(function(e) 
		 {
			 
			
		
			xOffset = $(this).width();
			
			yOffset = $(this).height();
			 
			var Pos = $(this).position();
			
			
			//alert(BrowserDetect.version);
			
			if(BrowserDetect.version==7 || BrowserDetect.version==6)
			{
				var xPos  = Pos.left+$("#preview_relative_div").position().left; 
				var yPos  = Pos.top+$("#preview_relative_div").position().top; 
			}
			else
			{
				var xPos  = Pos.left;
				var yPos  = Pos.top;
			}
		
			var imgPath=$(this).find("img:first").attr("imgPath");
			
			
			
			
			var image=new Image();
			
			var show_width="";

			var show_height="";
			
			
			$(image).load(function(){
								   
								   
				show_width=this.width/2;

				show_height=this.height/2;
				
				$(this).attr("width",show_width);
				$(this).attr("height",show_height);
				
				
				
				var total_needed_x=xPos+show_width;
				
				var total_needed_y=yPos+show_height;
				
			
				if(total_needed_x>total_width)
				move_value_x=(Pos.left-(total_needed_x-total_width))-50;
				else
				move_value_x=Pos.left;
				
			
				if(total_needed_y>total_height)
				{
					move_value_y=(Pos.top-(total_needed_y-total_height))-100;
					move_value_x=move_value_x+xOffset;
					
					
				}
				else
				{
					move_value_y=yPos+yOffset;
					
				}
				
				
		
			
				$("div.gallery_viewer").css({"top":(move_value_y) +  "px","left":(move_value_x)+ "px"})
				.html(this).show();					   
								   
			}).attr("src",imgPath);
			
			
		 
	}, function() {
	
			$('div.gallery_viewer').html("").hide();
			
		});


};