/*
 * 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 = 10;
		yOffset = 30;
		var ScrollTop = document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft;
        if (ScrollTop == 0)
        {
            if (window.pageYOffset)
                ScrollTop = window.pageYOffset;
            else
                ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
        }
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
		
	/* END CONFIG */
	$("a.preview").hover(function(e){
		this.t = this.title;
		this.title = "";	
		var c = (this.t != "") ? "<br/>" + this.t : "";
		$("body").append("<p id='preview'><img src='"+ this.href +"' alt='Image preview' />"+ c +"</p>");
		if (gup("Body") == 2)
	    {								 
		    $("#preview")
			    //.css("top",(e.pageY - xOffset) + "px")
			    //.css("left",(e.pageX + yOffset) + "px")
			    .css("left",(document.body.clientWidth / 2 - 275) + "px")
			    .fadeIn("fast");
		}
		else
		{
		    $("#preview")
		        .css("left",(document.body.clientWidth / 2 - 490) + "px")
			    .fadeIn("fast");
		}					
    },
	function(){
		this.title = this.t;	
		$("#preview").remove();
    });	
	$("a.preview").mousemove(function(e){
	    if (gup("Body") == 2)
	    {
	        $("#preview").css("left",(document.body.clientWidth / 2 - 170) + "px");
	    }
	    else
	    {
	        $("#preview").css("left", (document.body.clientWidth / 2 - 490) + "px");
	    }
		$("#preview")
			//.css("top",(e.pageY - xOffset) + "px")
			//.css("left",(e.pageX + yOffset) + "px");
	});
	$("a.preview").click(function(e){

	    if (gup("Body") == 2)
	    {
	        window.location = "../Showcase/ShowcaseItem.aspx?i=" + this.rel + "&Body=2&Path=Body";
	    }
	    else
	    {  
	        window.location = "../Showcase/ShowcaseNeck.aspx?i=" + this.rel + "&Body=1&Path=Neck";
	    }
	    return false;
	});			
};


// starting the script on page load
$(document).ready(function(){
	imagePreview();
});

function gup( name )
{
    name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
    var regexS = "[\\?&]"+name+"=([^&#]*)";
    var regex = new RegExp( regexS );
    var results = regex.exec( window.location.href );
    if( results == null )
        return "";
    else
        return results[1];
}