function imagePreview(tag){	
	/* 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 */
	$(tag).hover(function(e){
		this.t = this.title;
		this.title = "";	
		var c = (this.t != "") ? "<br/>" + this.t : "";
		$("body").append("<p id='ipreview'><img src='"+ this.href +"' alt='Image preview' />"+ c +"</p>");								 
		$("#ipreview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");						
    },
	function(){
		this.title = this.t;	
		$("#ipreview").remove();
    });	
	$("tag").mousemove(function(e){
		$("#ipreview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};

$(document).ready(function(){

    $(".cat_item").mouseover(
      function () {
        $(this).addClass('cat_item_hover');
      });
	 $(".cat_item").mouseout( 
      function () {
       $(this).removeClass('cat_item_hover');
      }
    );
	
	if ($(".prod_item_image").length > 0 || $(".pii_main").length > 0 || $(".productinfo_image").length > 0) {
		$("body").prepend('<div id="imgpreview" class="prod_item_image_preview"></div>');
	}
	
	
	$(".prod_item_image").hover(
      function (){
        //$(this).find('.prod_item_image_preview').stop().show();
		$("#imgpreview").stop().show();
      },
      function () {
       //$(this).find('.prod_item_image_preview').stop().hide();
	   $("#imgpreview").stop().hide();
      }
    );

	$(".prod_item_image").mousemove(function(e){
	  //$(this).find('.prod_item_image_preview').css('left',(24+e.pageX)+'px').css('top',(24+e.pageY)+'px');    
	  $("#imgpreview").html($(this).find('.prod_item_image_preview').html());
	  $("#imgpreview").css('left',(24+e.pageX)+'px').css('top',(24+e.pageY)+'px');  	  
    });
	
	
	$(".pii_main").mouseover(
      function (){
        	$(this).find('.pii_main_zoom').show();//fadeIn('fast');
      });
	$(".pii_main").mouseout(
      function () {
       $(this).find('.pii_main_zoom').hide();//fadeOut('fast');
      }
    );
	
	$(".pii_other_item").hover(
      function (){
        	$(this).find('.pii_main_zoom').fadeIn('fast');
      }, 
      function () {
			$(this).find('.pii_main_zoom').fadeOut('fast');
      }
    );
	
	$(".pii_main .pii_main_zoom").click(
      function (e){
			$("#imgpreview").html($('.pii_main_zoomprev:first').html());
			$("#imgpreview").css('left',(24+e.pageX)+'px').css('top',(24+e.pageY)+'px').css("display", "block");  	
			$("#imgpreview a.close").click(
				function() {$("#imgpreview").hide();return false;}
			);
			
		  	// $(".pii_main_zoomprev").hide();
		  	// $(this).hide();
			// $(".pii_main_zoomprev:first").show();
      }
    );
	
	$("#imgpreview").click(
		function() {$("#imgpreview").hide();return false;}
	);	
	
	$(".pii_other_item").hover(
      function (){
		  	// $(".pii_main_zoomprev").hide();
        	// $(this).find('.pii_main_zoomprev').show();
			$("#imgpreview").stop().show();
      }, 
      function () {
			$("#imgpreview").stop().hide();
       		// $(".pii_main_zoomprev").hide();
      }
    );

	$(".pii_other_item").mousemove(function(e){
	  $("#imgpreview").html($(this).find('.pii_main_zoomprev').html());
	  $("#imgpreview").css('left',(24+e.pageX)+'px').css('top',(e.pageY-64)+'px');  	  
	  //$(this).find('.pii_main_zoomprev').css('left',(24+e.pageX)+'px').css('top',(e.pageY-64)+'px');      
    });
	
	$(".pii_main_zoomprev .close").click(
      // function (){
		  	// $(".pii_main_zoomprev").hide();
      // }
 function() {alert("asdasd"); return false;}
 );

	$(".pii_main_zoomprev").hover(
      function (){}, 
      function () {
       $(this).hide();
      }
    );
	
  });


