﻿/// <reference path="~/js/jquery-1.4.2.js" />
/// <reference path="~/js/jquery.idfix.js" />
/// <reference path="~/js/BodyFix.js" />

$(document).ready(function() {

    if ($('div.login').length > 0) {
        // Fix position of login div
        var LoginHeight = $('.menu').position().top + $('.menu').height() + 20;
        $('div.login').css('top', LoginHeight.toString() + 'px');
    }

    // $('#slideshow').cycle();

    /*
    if (typeof (initMap) == "function") {
    initMap();
    }
    else {
    alert('nope');
    }
    */
});

function InitMenu() {

    CheckMenuItems($('.menu'));

    $(document).bind('click', function() {
        HideAllSubMenus();
    });
}

function CheckMenuItems(Parent) {
    var ID = 0;
    var Element, SubMenu;
    var OpenSubMenuFunction;
    Parent.children().each(function() {
        // alert('tag for ' + Element.attr('id') + ' is ' + Element[0].tagName);

        Element = jQuery(this);

        // Each <a> element is a menu item which may have a submenu
        // if (Element.is("a")) {
        if (Element[0].tagName.toLowerCase() == 'a') {

            // Detect submenu (if present)
            ID = parseInt(Element.attr('id'));
            // alert('id = ' + ID.toString());
            SubMenu = jQuery('#submenu' + ID.toString());
            if (SubMenu.length) {
                // Yes, set onclick/hover
                // OpenSubMenuFunction = new Function("OpenSubMenu(" + ID.toString() + ");");
                // Element.hover(function() { OpenSubMenuFunction() }, null);
            }
        }
    });
}

function OpenSubMenu(ID) {

    HideAllSubMenus();


    // Show submenu
    // Get position of the link (parent)
    var LinkID  = GetRealID('item' + ID.toString());
    
    var Left    = $(LinkID).position().left;
    var Top     = $(LinkID).position().top;
    var Width   = $(LinkID).width();
    var X       = Left + Width + 21 + 20;

    // Set position and show
    $('#submenu' + ID.toString()).css('left', X.toString() + 'px');
    $('#submenu' + ID.toString()).css('top', Top.toString() + 'px');
    $('#submenu' + ID.toString()).show('fast');

}
function HideAllSubMenus() {
    $('.submenu').hide('normal');
}
function HideSubMenu(ID) {
    $('#submenu' + ID.toString()).hide('normal');
}

