﻿/// <reference path="../jquery-1.4.2/jquery-1.4.1-vsdoc.js" />

var Agentum = window["Agentum"] || {};

Agentum.Site = function($) {

    function initSite() {

        setInlinedForms();
        setLavaLamp();
    };

    function setInlinedForms() {

        $("label.inlined + .input-text").each(function(type) {

            $(this).focus(function() {
                $(this).prev("label.inlined").addClass("focus");
            });
            $(this).keypress(function() {
                $(this).prev("label.inlined").addClass("has-text").removeClass("focus");
            });
            $(this).blur(function() {
                if ($(this).val() == "") {
                    $(this).prev("label.inlined").removeClass("has-text").removeClass("focus");
                }
            });
        });
    };

    function setLavaLamp() {

        if (!$("#nav") && $("#nav li").length == 0) {
            return;
        }

        var style = 'easeOutExpo';

        // If nothing is selected, use the first item
        if ($("#nav li.selected").length == 0) {
            $("#nav li:first").addClass("selected");
        }

        //Retrieve the selected item position and width
        var default_left = Math.round($('#nav li.selected').offset().left - $('#nav').offset().left);
        var default_width = $('#nav li.selected').width();

        //Set the floating bar position and width  
        $('#box').css({ left: default_left });
        $('#box .head').css({ width: default_width });

        //if mouseover the menu item
        $('#nav li').hover(function() {

            //Get the position and width of the menu item
            left = Math.round($(this).offset().left - $('#nav').offset().left);
            width = $(this).width();

            //Set the floating bar position, width and transition  
            $('#box').stop(false, true).animate({ left: left }, { duration: 1000, easing: style });
            $('#box .head').stop(false, true).animate({ width: width }, { duration: 1000, easing: style });

            //if user click on the menu  
        }).click(function() {

            //reset the selected item
            $('#nav li').removeClass('selected');

            //select the current item  
            $(this).addClass('selected');

        });

        //If the mouse leave the menu, reset the floating bar to the selected item
        $('#nav').mouseleave(function() {

            //Retrieve the selected item position and width
            default_left = Math.round($('#nav li.selected').offset().left - $('#nav').offset().left);
            default_width = $('#nav li.selected').width();

            //Set the floating bar position, width and transition  
            $('#box').stop(false, true).animate({ left: default_left }, { duration: 1500, easing: style });
            $('#box .head').stop(false, true).animate({ width: default_width }, { duration: 1500, easing: style });

        });
    };

    return {
        init: initSite
    }

} (jQuery);

$(function() {

    $(".input-text").attr("autocomplete", "off");
    $(".input-text").attr("value", "");

    Agentum.Site.init();
});


