// DropDownMenu
function rmAdClass(div){
    $('#'+div).removeClass(div+'_a');
    $('#'+div).addClass(div);
}

jQuery(document).ready(function(){
    var current_create = null;

     $('#navMenu li').click(function(){
        $('.nav').each(function() {
            rmAdClass($(this).attr('id'));
        });
        $(this).children('a').addClass($(this).children('a').attr('id')+'_a');
    });
    $('.nav').each(function() {
        rmAdClass($(this).attr('id'));
    });
    $('#'+currentPage).addClass(currentPage+'_a');
    
    //Set position for all links
    //  jQuery('#header ul ul').children('li:first-child').addClass('first-child');
  
    jQuery('#header li a').each(function(){
        var toLeft = 0;
        var toRight;
        if(jQuery(this).parents('ul').css('position') == 'absolute'){
            toLeft = jQuery(this).position().left  ;
            var widthU = $('#header ul ul').width();

            var toHeight = jQuery(this).parents('ul').children('li').index(jQuery(this).parent()) * 18 +5 ;
            jQuery(this).parent().children('ul').css('top',toHeight+'px');
            jQuery(this).parent().children('ul').css('left',-widthU+'px');
            jQuery(this).parents('ul:first').css('display','none');
        }
        else{
            var width = jQuery(this).parent().children('ul').width();
            var widthPar = jQuery(this).width();
            toLeft =  jQuery(this).position().left ;
             toRight= widthPar -(width - toLeft);
        }
        jQuery(this).parent().children('ul').css('left',toRight+'px');


    });
    //Event on all a in li
    jQuery('#header li a').mouseenter(function(){
        //Show all children a
        jQuery(this).addClass('active');
        jQuery(this).parent().children('ul').slideDown('fast');
    });

    jQuery('#header li').mouseleave(function(){
        if(typeof current_page == 'undefined' || jQuery(this).html() != current_create.html()){
            jQuery(this).children('a').removeClass('active');
        }
        jQuery(this).children('ul').slideUp('fast');
    });
});

jQuery(window).load(function(){

    var toHeightRight;
    var toHeight;

    if(407 < jQuery('.center-left').innerHeight())
        toHeightRight = jQuery('.center-left').innerHeight();
    else
        toHeightRight = jQuery('.center-separator').innerHeight();

    jQuery('.left, .right').each(function(index){
        toHeight = jQuery(this).siblings('.center').eq(0).innerHeight();
        jQuery(this).css('height', toHeight+8+'px');
    });

    jQuery('.center-right').css('height',toHeightRight +'px');
    jQuery('.center-separator').css('height',toHeight + 1 +'px');
});

