gDropDownMaxLines = 10;

function addHighlight(imgsrc) {
   if (imgsrc.indexOf("-over.gif") == -1) {
        return imgsrc.replace(".gif","-over.gif");
   }
   return imgsrc;
}

function closeAllMenuDropDowns() {
    gHoverTimer = -1;
    jQuery(".dropDown").each(function (i) {
        jQuery(this).trigger("mouseenter");
        jQuery(this).trigger("mouseleave");
    });
}



jQuery.fn.outerHTML = function() {
    var doc = this[0] ? this[0].ownerDocument : document;
    return $('<div>', doc).append(this.eq(0).clone()).html();
};

var gHoverTimer = -1;

jQuery(document).ready(function($){    
    if (jQuery.browser.msie && (jQuery.browser.version < 8)) {
        ISIE = true;
    } else {
        ISIE = false;   
    }
    $('.menuKill').mouseover(
        function() { 
            closeAllMenuDropDowns();
        }
    );
    
    $('.singlecolumn a').each(function (i) {
           if ($(this).next().hasClass('menuLink')) {
           $(this).after("<div class='betweenLinks'></div>");
           }
    });

    var ddch;
    $('.dropDownContainer').each(function (j) {
        ddch = $(this).parent().height() - 40;
       $('.multicolumn',this).each(function (i) {
           if ($(this).next().hasClass('multicolumn')) {
            $(this).after("<div class='betweenColumns' style='height: "+ddch+"px;'></div>");
           } else {
            $(this).after("<div class='clear'></div>");
           }        
       }) 
    });

    $('.hasThumbnail').mouseover(function() {
        var thumbnailURI = $(this).next('img').attr('src');
        $('.ddThumbHolder').css('background-image','url(' + thumbnailURI + ')');
    });
    $('.hasThumbnail').mouseout(function() {
        var thumbnailURI = $(this).next('img').attr('src');
        $('.ddThumbHolder').css('background-image','none');
    });

	$('#language_select').mouseover(function() {
		var theDropDown = $('#languages');
	    theDropDown.css('top', $(this).outerHeight() + 4);
		theDropDown.css('right', 0);
	    theDropDown.slideDown("fast").bind("mouseenter", function (e) {
	       $(this).bind("mouseleave", function (e) {  
	            if (ISIE) {
	                $(this).hide();
	            } else {
	                $(this).fadeOut("fast")
	            }
	            $(this).unbind("mouseenter mouseleave");
	       }); 
       
	    }); 
	});
    $('.tab').mouseover(
        function() {
            var pnt = $(this).parent(); //tab
            var position = $(this).position();
            var tabBarPosition = pnt.position();
            var outerpos = pnt.position();
            var outerheight = pnt.height();
			var outerwidth = pnt.width();
            
            var theDropDown = $(this).next();
			var columns = $('.multicolumn', theDropDown).size();
            
            $(".dropDown").stop(true,true);
            $(".dropDown").not(theDropDown).each(function (i) {
                $(this).hide();
            });

            if (!$(theDropDown).hasClass("dropDown")) return;
            $('.tab').removeClass('on');
            $(this).addClass('on');

            if ($(theDropDown).hasClass("wide")) {
                theDropDown.css('left', tabBarPosition.left + 200);
            } else {
                theDropDown.css('left', position.left - 2);    
            }

			$('.ddThumb:first', theDropDown).each(function() {
				var thumburi = $(this).attr('src');
				$('.ddThumbHolder', theDropDown).css('background-image', 'url(' + thumburi + ')');
			});

            theDropDown.css('top', outerpos.top + outerheight);
            theDropDown.slideDown("fast").bind("mouseenter", function (e) {
               $(this).bind("mouseleave", function (e) {  
                    if (ISIE) {
                        $(this).hide();
                    } else {
                        $(this).fadeOut("fast")
                    }
                    $(this).unbind("mouseenter mouseleave");
                    $('.tab').removeClass('on');
               }); 
               
            }); 
        }
    );
    
    //DEBUG
    //$('.tab').eq(0).trigger("mouseover");
   //keep rollover ON while menu is ON
   ///* background-image:url(images/gel-button.gif); */
    
});