/*
 * Image preview script 
 * powered by jQuery (http://www.jquery.com)
 * 
 * written by Alen Grakalic (http://cssglobe.com)
 * 
 * for more info visit http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery
 *
 */
 
this.imagePreview = function(){	
	/* CONFIG */
		
		xOffset = 300;
		yOffset = 30;
		maxImgWidth = 420;
		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
		
	/* END CONFIG */
	$("a.preview")
		.livequery(function(){
			$(this).hover(function(e){
				$("#preview").remove();
				var imgId = $(this).attr("id");
				var albTitle = smImgLookup.images[imgId]['Album_Title'];
				var imgKeywords = smImgLookup.images[imgId]['Keywords'];
				var catName = smImgLookup.images[imgId]['Category_Name'];
				var subcatName = smImgLookup.images[imgId]['SubCategory_Name'];
				$("body").append("<div id='preview' align='center'><img src='"+ $(this).attr("href") +"' alt='Image preview' /><div id='preview-txt' align='left'><p>"+ $(this).attr("title") +"<br /><br /><strong>Album: </strong>"+ albTitle  +"<br /><strong>Category: </strong>"+ catName +"<br /><strong>Sub Category: </strong>"+ subcatName +"<br /><strong>Keywords: </strong>"+ imgKeywords +"</p></div></div>");
				if ( (e.pageX + yOffset + maxImgWidth) >= $(document).width() ) {
					left = (e.pageX - maxImgWidth - yOffset);
				} else {
					left = (e.pageX + yOffset);
				}
				$("#preview")
					.css("top",(e.pageY - xOffset) + "px")
					.css("left",left + "px")
					.fadeIn("fast");						
    			}, function(){
				$("#preview").remove();
    			});
		});
	$("a.preview")
		.livequery(function(){
			$(this).mousemove(function(e){
				if ( (e.pageX + yOffset + maxImgWidth) >= $(document).width() ) {
					left = (e.pageX - maxImgWidth - yOffset);
				} else {
					left = (e.pageX + yOffset);
				}
				$("#preview")
					.css("top",(e.pageY - xOffset) + "px")
					.css("left",left + "px");
				});
		});
};


// starting the script on page load
$(document).ready(function(){
	imagePreview();
});


