/*
    navigation js for Visionect Electronics site
    requires jquery-1.3.2.min.js, jquery.timers-1.1.2.js
    Luka Birsa, 2009, (C) Visionect
*/

$(document).ready(function(){
    var speed = 0;
    var delay = 20;
    var hide_delay = 250;
    
    var visible_elements;
    
    function display_current_navi(){
        $(".current_page_ancestor, .current_page_item").add($(".current_page_ancestor, .current_page_item").parent()).add($(".current_page_ancestor, .current_page_item").siblings()).add($(".current_page_item").children("ul")).show();
        fix_navi_height();
    }
    
    function fix_navi_height(){
		//proper positioning of elements in menu:
        $("#top>li>ul>li ul").each(function(){$(this).parents('ul:first').width();$(this).css('left',$(this).parents('ul:first').outerWidth()-10)});
		$("#top>li>ul>li ul").each(function(i){$(this).css("top",$(this).parent().position().top-5);});

        //$("#top>li ul").filter(":visible").css("-moz-border-radius-bottomleft","0px").css("-webkit-border-bottom-left-radius","0px").css("-moz-border-radius-bottomright","0px").css("-webkit-border-bottom-right-radius","0px").css("border-right","none");
/*        visible_elements_new = $("#top>li ul").filter(":visible");
        var cmp = 1;
        if(visible_elements!=null){
            var element_counter = 0;
            visible_elements_new.each(function(){
                element_counter+=1;
                element = $(this);
                if($.inArray(element,$(visible_elements))==-1){
                    cmp = 0;
                }
            });
        }
        else{
            cmp = 0;
        }
        if(cmp != 1){
            var max_height = 0;
            $("#top>li ul").filter(":visible").each(function(){
                curr_height=$(this).children("li").length*$(this).children("li").height();
                if(curr_height>max_height){
                    max_height=curr_height;
                }
            }).height(max_height);

            visible_elements=visible_elements_new;
        }
*/

       // $("#top>li ul").filter(":visible").filter(":first").css("-moz-border-radius-bottomleft","10px").css("-webkit-border-bottom-left-radius","10px");
       // $("#top>li ul").filter(":visible").filter(":last").css("-moz-border-radius-bottomright","10px").css("-webkit-border-bottom-right-radius","10px").css("border-right","1px solid #FAFAFF");
    }
    
    $("#top li").live("mouseover", function(){
        if($(this).parents("#top>li").length==0){
            $(".selected").removeClass("selected");
            $(this).addClass("selected");
            $("#navi ul").not("#top").hide(0);
        }
        $($(this).siblings()).children("ul").hide(speed);
        $(document).stopTime("menu_mouseout");
        $(this).children().not("a").show(speed);
        fix_navi_height();
    });
    
    $("#top li").live("mouseout", function(){
       // console.log("MO: ", $(this), " DEP: ", depth);
        $(document).oneTime(hide_delay,"menu_mouseout", function(){
            $("#navi ul").not("#top").hide(speed);
            display_current_navi();
            $(".selected").removeClass("selected");
        });
    });
    
    display_current_navi();
});

