$(function () {
    
    // cross browser css
    $('html').browsercss();
           
    // fading for mounseover on fade boxes
    $('.box-grey, body.level-sub #page-body').mouseenter(function() {
        $(this).fadeTo('300',0.95,'easeOutQuad')    
    }).mouseleave(function() {
        $(this).fadeTo('300',0.75,'easeOutQuad')
    
    });   

    // menu rollups
//    $('#page-menu li.hasub a').mouseover(function() {
//        console.log($(this));
//        $(this).parent().find('ul.l2').slideDown(100);
//    }).mouseout(function() {
//        $(this).parent().find('ul.l2').slideUp('fast');
//    });
//    $('#page-menu .submenu').each()
    
    $('.submenu').each(function () {
        $(this).parent().eq(0).hoverIntent({
            timeout: 100,
            over: function () {
                var current = $('.submenu:eq(0)', this);
                current.slideDown(100);
            },
            out: function () {
                var current = $('.submenu:eq(0)', this);
                current.fadeOut(200);
            }
        });
        
        $(this).find('li').each(function() {
//            console.log($(this));
            $(this).hover( function() {
//                $(this).fadeTo('100',0.95,'easeOutQuad');
            }, function() {
//                $(this).fadeTo('100',0.85,'easeOutQuad');
            });
        });
    });

    
    // menu color animation
    $('#page-menu a, .lang-menu a,').hover(function(){
        $(this).animate({color: '#bd4650'},200,'easeOutQuad');
    },function() {
        $(this).animate({color: '#ffffff'},200,'easeOutQuad');        
    });
    // init function
    load = function () {
        $('body.level-sub #page-body').fadeTo('2000',0.85,'easeOutQuad');
        $('body.level-main #page-body').fadeTo('2000',1.0,'easeOutQuad');
//        this.alignFooter();
        $('.lang-menu').animate({
            top: '0px'
        },1000, 'easeOutQuad');

        // automatic footer align
        var top = parseInt($('#page-head').height()) + parseInt($('#page-body').height());
//        var bottom = parseInt($('#page-foot').height());
        var offset = top;        
        if($('body').hasClass('level-sub')) {offset = top + 24;}       
        var height = offset + 'px';
        $('#bg-body').animate({
           height: height
        }, 1000, 'easeOutQuad');
    }
    
    unload = function () {
        $('#page-body').fadeOut('850','easeOutQuad');
        $('#bg-body').animate({
           height: '3000px'
        }, 1000, 'easeOutQuad');       
    }
            
    
    // events
//    $(document).ready();
    
//    opera fixes
    if( typeof(opera) !== 'undefined') {
        opera.setOverrideHistoryNavigationMode('compatible');
        history.navigationMode = 'compatible';
    }
    
    $(window).load(load);
    $(window).bind('beforeunload',unload);
});

