﻿
mainmenu ={
    init: function() {
        this.preload();
        
        $('img', '.menu').hover(
            function(){
                this.src = this.src.replace('.png', '_hover.png');
                
                var index = $('img', '.menu').index($(this));
                if(index !=-1) mainmenu.showsubmenu('.seq'+index, index);
                   
            },
            function(){
                this.src = this.src.replace('_hover.png', '.png');
            }
        );
        //$('.subnavgation').css('display','none');
    },
    
    preload: function() {
        var images = new Array();
        $('img', '.menu').each(function(i, e){
            var s = this.src.toLowerCase();
            s = s.replace('.png', '_hover.png');
            images[i] = new Image();
            images[i].src = s;
        });
    },
    
    showsubmenu: function(selector, i) {
        
        $('.action', '#subnav>div')
            .fadeOut("fast", function() {
                $(this).css('display', 'none');
            });
            
        $(selector).find('.pointer').css({'margin-left': (i*90)+'px'});
        $(selector).css({display:'block'})
            .addClass('action')
            .fadeIn('fast');
    }
    
};

$(document).ready(function(){
    mainmenu.init();
});
