/*
 * 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;
		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
		
	/* END CONFIG */
	$(".preview2").hover(function(e){
		if (!$(this).find("ul").size() > 0)
		{
			$(this).css("background-color", "#F0F0FF")
		}
/*
		this.t = this.title;
		this.title = "";	
		var c = (this.t != "") ? "<br/>" + this.t : "";
	*/	
		//http://test.vodyanoy.com.ua/ru/gr_img/2000111252_110
		var lnk = "/ru/imgres/" +  $(this).find("a").attr("href").slice(-11, -1) + "_220";
		$("body").append("<p id='preview'><img src='" + lnk + "' alt='' /></p>");								 
		var pos = $(this).offset();  
		var docViewTop = $(window).scrollTop();
		var docViewBottom = docViewTop + $(window).height();
/*
		if (pos.top + 100 > docViewBottom)
		{
			pos.top = docViewBottom - 100;
		}

	*/	
			$("#preview").css("left",$(".left").width() - 5 + "px");
			if (pos.top + 200 > docViewBottom)
			{
				$("#preview").css("position","fixed");				
				$("#preview").css("bottom","0px");
			} else {
				$("#preview").css("top",pos.top + "px");
			}
			$("#preview").fadeIn("fast");						
	//}

/*	$("a.preview").hover(function(e){
		this.t = this.title;
		this.title = "";	
		var c = (this.t != "") ? "<br/>" + this.t : "";
		
		//http://test.vodyanoy.com.ua/ru/gr_img/2000111252_110
		var lnk = "/ru/imgres/" + this.href.slice(-11, -1) + "_220";
		$("body").append("<p id='preview'><img src='" + lnk + "' alt='' /></p>");								 
		//$("body").append("<p id='preview'><img src='"+ this.id +"' alt='Image preview' />"+ c +"</p>");								 
		//$(this).parents(".preview1").animate({ opacity: "hide" }, "slow");
		var pos = $(this).parents(".preview1").offset();  
		var width = $(this).parents(".preview1").width();

		$("#preview")
			.css("left",$(".left").width() - 5 + "px")
			.css("top",pos.top + "px")
			.fadeIn("fast");						
			
		/*	.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");						
			*/
    },
	function(){
		//this.title = this.t;	
		$("#preview").remove();
		$(this).css("background-color", "transparent")
    });	
	/*
	$("a.preview").mousemove(function(e){
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});
	*/			
};

this.imagePreview_tables = function(){	
		
		xOffset = 10;
		yOffset = 30;

	$(".preview_tables_el").hover(function(e){
		$(this).css("background-color", "#F0F0FF")
		var lnk = "/ru/imgp_small/" +  $(this).find("a").attr("href").slice(-11, -1) + "_300";
		$("#preview_tables").attr("src", lnk);
		$("#preview_tables").fadeIn("fast");						
    },
	function(){
		$(this).css("background-color", "transparent")
    });	
};


// starting the script on page load
$(document).ready(function(){
	imagePreview();
//	imagePreview_tables();
	setupZoom();
	$(".preview1").click(function(){
        window.location=$(this).find("a").attr("href"); return false;
    });
	
	$(function() {
			$("#browser").treeview();
		})

	$("ul.sf-menu").supersubs({ 
            minWidth:    12,   // minimum width of sub-menus in em units 
            maxWidth:    45,   // maximum width of sub-menus in em units 
            extraWidth:  1     // extra width can ensure lines don't sometimes turn over 
                               // due to slight rounding differences and font-family 
        }).superfish();  // call supersubs first, then superfish, so that subs are 
                         // not display:none when measuring. Call before initialising 
                         // containing tabs for same reason. 
//	$(".products").quickPager();
});



