

$(function(){
   
    $('.megaMenu_dropdown').each(function(i, me){
        var id = $(me).attr("id"),
            $img = $("#img_" + id),
            src = $img.attr("src");
            
            $img.data("original-src", src);
            
            new Image().src = rolloverSrc(src);
            //new Image().src = dropdownSrc(id);
    });

});

function rolloverSrc(src) {
    var lastDotIndex = src.lastIndexOf("."),
            filename = src.substring(0, lastDotIndex),
            fileext = src.substring(lastDotIndex);
            
    return filename + "b" + fileext;
}
function dropdownSrc(id) {            
    return "/images/dropdown_" + id + ".png";
}

  var HidingTimer_Mega
  function mega_drop(par, ns, open, rover) {
	  if (open) {
        clearTimeout(HidingTimer_Mega);
		
		  var pheight = $(par).height()
	  
		  $('.megaMenu_dropdown').each(function(index) {
                var $img = $("#img_" + this.id);
                $img.attr("src", $img.data("original-src"));
                
                  if ((this.id == ns)) {
                      $img.attr("src", rolloverSrc($img.data("original-src")));
                      $(this).show()
                  } else {
                      $(this).hide()
                  }
		  });
	  
		  var coords_md = $('#mainDiv').offset()
		  var coords_par = $(par).offset()
		  //$('.megaMenu_dropdown').css({background: 'url('+ dropdownSrc(ns) +') no-repeat' });
		  $('#' + ns).css({
			  position: 'absolute',
			  zIndex: 5000,
			  left: '-235px',
			  top: '36px'
		  });
	  } else {
		  HidingTimer_Mega = setTimeout('mega_hide("' + ns + '")', 200)
	  }
  }

  $(window).load(function() {
		$('.megaMenu_dropdown').each(function(index) {
			$(this).mouseenter(function() { clearTimeout(HidingTimer_Mega); $(this).show() })
			$(this).mouseleave(function() { HidingTimer_Mega = setTimeout('mega_hide("' + this.id + '")', 200) })
		})          
	})

	function mega_hide(ns, par) {
        $('#' + ns).hide()
		$('.megaMenu_dropdown').each(function(index) {
                var $img = $("#img_" + this.id);
                $img.attr("src", $img.data("original-src"));
		})               
	}
