
var cellHeight = 36;
var cellWidth  = 185;

var mainCellShift = 3;

$(document).ready(function(){

    prepareMenu();

});

function prepareMenu() {

    $( '#Menu .sub'    ).hide();
    $( '#Menu .subsub' ).hide();

    //alert( $( '#Menu li a' ).html() );

    $( '#Menu li a' ).click(function() {
        //alert( $(this).html() );
    });

    $( '#Menu ul.sub').mouseover(function() {
        $(this).show();
    });
    $( '#Menu ul.sub').mouseout(function() {
        $(this).hide();
    });

    $( '#Menu ul.subsub').mouseover(function() {
        $(this).show();
    });
    $( '#Menu ul.subsub').mouseout(function() {
        $(this).hide();
    });

    $('#Menu').find('a').mouseover(function() {

        $(this).parent().find('ul').hide();

        var element = $(this).parent().children('ul');

        var horizontalShift = cellWidth;
        var verticalShift   = -cellHeight;

        element.css("margin-top",  verticalShift );

        if( lang == "ar" ) {
            element.css("margin-right", horizontalShift);
        }else{
            element.css("margin-left",  horizontalShift);
        }

        element.show();
    });

    $('#Menu').find('a').mouseout(function() {
        $(this).parent().children('ul').hide();
    });

    fixMenuHeight();

}

function fixMenuHeight() {

    // fix down position :0
    //alert( $('ul.main>li' ).html() );

    var itemsCount = $( 'ul.main>li' ).length;

    //alert(itemsCount);

    $( '#Menu' ).css("height", itemsCount*cellHeight);

    //alert( '$( #Menu ul ).length: '+$( '#Menu ul' ).length );

}
