function rollover2(a, c, b) {
    str = a.src;
    if (!a.src) str = a.firstChild.src;
    str = c ? str.indexOf(".jpg") > 0 ? str.substring(0, str.length - 4) + "b.jpg" : str.substring(0, str.length - 4) + "b.gif" : str.indexOf(".jpg") > 0 ? str.substring(0, str.length - 5) + ".jpg" : str.substring(0, str.length - 5) + ".gif";
    a.firstChild.src = str;
    if (b) {
        a.onmouseover = function () {};
        a.onmouseout = function () {}
    }
}


var HidingTimers = {};

function mega_drop(par, ns, open, rover) {
    if (open) {
        clearTimeout(HidingTimers[ns]);

        $('.megaMenu_dropdown').each(function (index) {
            if ((this.id !== ns)) {
                $(this).stop(true, true);
                mega_hide(this.id);
            }
        })
        
        mega_show(ns, par);
    } else {
        HidingTimers[ns] = setTimeout(function () {
            mega_hide(ns);
        }, 1000)
    }
}

$(function () {

    $('.megaMenu_dropdown')
        .bind("mouseenter", function () {
            clearTimeout(HidingTimers[this.id]);
        })
        .bind("mouseleave", function () {
            var dd = this;
            HidingTimers[this.id] = setTimeout(function () {
                mega_hide(dd.id);
            }, 1000);
        })
        .find("a")
            .bind("focus", function(){ $(this).parents(".megaMenu_dropdown").prev().children().trigger("mouseover"); })
            .bind("blur", function(){ $(this).parents(".megaMenu_dropdown").trigger("mouseout"); })
        .end()
        .each(function(){           
            $(this).show();
            mega_hide(this.id);
            $(this)
                .prev() 
                    .find("a")
                        .bind("focus", function(){
                            $(this).trigger("mouseover");
                        })
                        .bind("blur", function(){
                            $(this).trigger("mouseout");
                        });
        });
})

function mega_show(ns, par){
        var pheight = $(par).height();
        var coords_md = $('#mainDiv').offset()
        var coords_par = $(par).offset()
        var $drop = $('#' + ns);
        var oldHeight = $drop.height();
        
        $drop.css({
            position: 'absolute',
            zIndex: 5000,
            left: coords_par.left + 'px',
            top: (coords_par.top + pheight) + 'px'
        });
}
function mega_hide(ns, par) {
    $('#' + ns)
        .stop(true, true)
        .css({position:"absolute", left:"-9999px"});
}
