function testCSS(){
    if ($('body').css('clear') != 'right') 
        return false;
    return true;
}

var currentSubmenu = 0
var currentHover = 0

$(document).ready(function(){
    $.fn.wait = function(time, type){
        time = time || 0;
        type = type || "fx";
        return this.queue(type, function(){
            var self = this;
            setTimeout(function(){
                $(self).dequeue();
            }, time);
        });
    };
    $('.pagecontent>*>a:not(.nospecial)').linkControl({
        overlay: true,
        padding: 5,
        bgColor: '#000',
        borderColor: '#333'
    });
    
    //alert($('.hidden.submenu.menu').css('display', 'inline'));

    $('.errors').hide();
    $('.collapseable').hide();
    $('.errorstitle').click(function(){
        $(this).next('.errors').slideToggle(600);
    });
    $('.collapseabletitle').click(function(){
        $(this).next('.collapseable').slideToggle(600);
    });
    
    cacheSubmenu = $('.submenu').html();
    if ($('.sel').length > 0) {
        currentSubmenu = $('.sel').attr('id').charAt(4) * 1;
    }
    else {
        currentSubmenu = 0;
    }
    $('#main1,#main2,#main3').mouseenter(function(){
        if (testCSS()) {
            currentHover = ($(this).attr('id').charAt(4)) * 1;
            if (currentHover != currentSubmenu) {
                $(this).fadeTo('normal', 0.50, function(){
                    $(this).fadeTo('normal', 1);
                });
            }
        };
            });
    
    $('ul.hidden').hide();
    
    $('#main1,#main2,#main3').hover(function(){
        if (testCSS()) {
            currentHover = ($(this).attr('id').charAt(4)) * 1;
            if (currentHover != currentSubmenu) {
                $('.submenu').filter(':animated').wait().stop(true, false).end().filter(':visible').fadeOut('normal', function(){
                    $('#submenu' + currentHover).fadeIn('normal');
                    $('#submenu' + currentHover).fadeTo('fast', 1.00)
                });
            }
        }
        return false;
    }, function(){
        if (testCSS()) {
            if (currentHover != currentSubmenu) {
                $('.submenu').filter(':animated').wait().stop(true, false).end().filter(':visible').fadeOut('normal', function(){
                    if (currentSubmenu > 0) {
                        $('#submenu' + currentSubmenu).fadeIn('normal');
                        $('#submenu' + currentSubmenu).fadeTo('fast', 1.00)
                    }
                });
            }
        }
        return false;
    });
});
