﻿
$(function() {
    var hoverHelper = {
        orgWidth: '',
        orgLeft: '',
        hasNodeSelected: false,
        showHelper: function(helperWidth, helperPosL) {
            $("#hover-helper").stop().animate({
                width: helperWidth,
                left: helperPosL
            }, 200);
        },
        hideHelper: function() {
            $("#hover-helper").hide();
        }
    }

    var selectedNode = $("#nav ul li.sel");

    //If no selected then check for a child selected
    if (selectedNode.position() == null)
        selectedNode = $("#nav ul li.child-sel");

    if (selectedNode.position() != null) {
        hoverHelper.hasNodeSelected = true;

        var outerWidth = selectedNode.outerWidth(false);
        var pl = $("#hover-helper").css("padding-left").replace("px", "");

        hoverHelper.orgWidth = outerWidth - pl;
        hoverHelper.orgLeft = selectedNode.position().left;

        $("#hover-helper").css("left", hoverHelper.orgLeft + "px");

        $("#hover-helper").stop().animate({
            width: hoverHelper.orgWidth
        }, 200);
    }

    $("#nav ul li").hover(
        function() {
            var outerWidth = $(this).outerWidth(false);
            var pl = $("#hover-helper").css("padding-left").replace("px", "");
            var helperWidth = outerWidth - pl;

            hoverHelper.showHelper(helperWidth, $(this).position().left);
        },
        function() { }
    );

    $("#nav ul").hover(
    function() { },
    function() {
        if (hoverHelper.hasNodeSelected) {
            hoverHelper.showHelper(hoverHelper.orgWidth, hoverHelper.orgLeft);
        }
        else {
            hoverHelper.hideHelper();
        }
    }
    );

    /* Eignalisti hover */

    $("#property-list div.property").hover(
        function() {
            $("div.property-hover", $(this).parent()).removeClass("property-hover");
            $(this).addClass("property-hover");
        },
        function() {
            $(this).removeClass("property-hover");
        }
    );
    
    $("#property-list div.property").click(function() {
        var url = $(this).find("a.more").attr("href");
        
        if(url != "")
            window.location = url;

    });
});


