function tools_anim_subtools(tool){
    var subtool = $(tool).next()
    while (subtool.hasClass('menu_main') && subtool.hasClass('sub')){
        if (subtool.css('display') == 'none'){
            subtool.show('fast');
        } else {
            subtool.hide('fast');
        }
        subtool = subtool.next();
    }
}

function tools_hide_others(tool){
    $('div#col245').children().each(function(){
        if ($(this).hasClass('menu_main') && $(this).hasClass('sub')){
            if ($(this).css('display') != 'none'){
                $(this).hide('fast');
            }
        }
    });
}
function tools_anim(){
    $('div#col245').children().each(function(i){
        if ($(this).hasClass('menu_main') && $(this).hasClass('sub')){
            $(this).hide();
        }else{
           var children
           if(!$(this).hasClass('spacer10')){
        	children = $(this).children();
           }
           if (!children || children.attr('href') == '#' )
           {
	           $(this).click(function(){
	                tools_hide_others(this);
	                tools_anim_subtools(this);
	                return false;
                          
	           });
           }
        }
    });
}

//jQuery.preloadImages = function() {
//    for(var i = 0; i<arguments.length; i++) {
//       jQuery("<img>").attr("src", arguments[i]);
//    }
//}

function menu_anim() {
    $('.menu_main img').each(function(i){
        jQuery("<img>").attr("src", this.src.replace('.gif', '_on.gif'));
        if (!$(this).parents().hasClass('on')) {
            $(this).hover(function() {
                this.src = this.src.replace('.gif', '_on.gif');
            },
            function() {
                this.src = this.src.replace('_on.gif', '.gif');
            });
        }
    });
    $('.menu_main.on img').each(function() {
        this.src = this.src.replace('.gif', '_on.gif');
    });

}

$(document).ready(function(){
        tools_anim();
        menu_anim();
        $('.menu_main.active').each(function() { 
            tools_hide_others(this);
            tools_anim_subtools(this);
        });
})
