$(document).ready(function(){
 
  if ($('#hintGallery').length > 0)
  hintGallery("hintGallery");
 
  });
 

 function hintGallery(container) {
  
  jQuery.fn.isChildOfElement = function(b){
   return (this.parents(b).length > 0);
  };
 
  $('#' + container + ' .hintDiv').each(function(index){
   $(this).attr("id", container+"Div_" + (index+1));
   $("#" + container + "Div_" + (index+1) + " *").attr("rel", container+"Div_" + (index+1));
  });
  
  $('#' + container + ' img.hintImg').each(function(index){
                 
   $(this).attr("rel", container+"Div_" + (index+1));
   //$(this).addClass("hintImg");
   $("#"+container+"Div_" + (index+1) + " div.image").html("<img width=\"160\" height=\"95\" alt=\"" + $(this).attr("alt") + "\" src=\"" + $(this).attr("src") + "\" />");
  });
  
 
  $(document).mouseover(function(event){
 
    if ($(event.target).isChildOfElement('#'+container) == false) {
     $('.hintDiv').fadeOut("4000");
    } 
    
    else if ($(event.target).hasClass('hintImg')) {
 
     var imgOffset = $(event.target).offset();
 
     $("#" + $(event.target).attr("rel")).css("top", (imgOffset.top - 11) + "px");
 
     if ($("#" + $(event.target).attr("rel")).hasClass("alignLeft")) {
      $("#" + $(event.target).attr("rel")).css("left", (imgOffset.left - ($("#" + $(event.target).attr("rel")).outerWidth() / 2) - 5) + "px");
      
     } else {
      $("#" + $(event.target).attr("rel")).css("left", (imgOffset.left - 11) + "px");
     }
 
     if ($("#" + $(event.target).attr("rel")).css("display") != "block") {
 
      $('.hintDiv[id!="' + $(event.target).attr("rel") + '"]').fadeOut("4000");
      $("#" + $(event.target).attr("rel")).fadeIn("2000");
 
     }
     
    }
 
  });
  
 }

