﻿$(function() {
    $('#menuSendRequest>textarea').focus(function() {

        if ($(this).val() == 'Tutaj wpisz treść swojej prośby...') {
            $(this).val('');
        }
    });

    $('#menuSendRequest>textarea').blur(function() {
        if ($(this).val().length > 0) {
        } else {
            $(this).val('Tutaj wpisz treść swojej prośby...');
        }

    });
    //fix for chrome
    var MenuIdActElem;
    $('#newRequestContent').mouseover(function() {
        clearTimeout(Menu.time);
        Menu.$navContent.find(Menu.translation(MenuIdActElem, 'button')).addClass('act');
    });

    var Menu =
    {
        hideBox: 1,
        time: null,
        $navContent: $('#nav-content'),
        fadeSpeed: 150,
        translation: function(from, type) {
            switch (type) {
                case 'box':
                    return ['#', from.substring(0, from.length - 1), 'area'].join('');
                    break;

                case 'button':
                    return ['#', from.substring(0, from.length - 4), 'b'].join('');
                    break;
            }
        },
        init: function() {
            Menu.$navContent.find('>div').css({ 'opacity': '0' });
            Menu.$navContent.bind('mouseover mouseout', function(e) {
                var This = e.target,
		$this = $(This),
		boxId = Menu.translation(This.id, 'box');

                switch (e.type) {
                    case 'mouseover':
                        if ($this.is('a.menu-button')) {
                            if (Menu.hideBox == '#' + This.id && Menu.$navContent.find(boxId).css('display')=='block') {
                                clearTimeout(Menu.time);
                                Menu.$navContent.find('>div:not(#' + boxId + ')').hide();
                                $this.addClass('act');
                                return;
                            }
                            Menu.$navContent.find('>div:not(#' + boxId + ')').hide();
                            $this.addClass('act');
                            Menu.$navContent.find(boxId).css({ 'display': 'block', 'opacity': '0' }).animate({ 'opacity': '1' }, { duration: Menu.fadeSpeed, queue: false });
                        }

                        if ($this.is('div.top')) {
                            clearTimeout(Menu.time);
                            Menu.$navContent.find(Menu.translation($this.parent('div.menuBox').attr('id'), 'button')).addClass('act');
                        }
                        break;

                    case 'mouseout':
                        if ($this.is('a')) {
                            $this.removeClass('act');
                            Menu.time = setTimeout(function() {
                                Menu.$navContent.find(boxId).fadeOut(Menu.fadeSpeed);
                            }, 50);
                        }
                        break;
                }
            });

            Menu.$navContent.find('div.menuBox').bind('mouseleave', function() {
                var $this = $(this),
                thisId = this.id;
                MenuIdActElem = thisId;
                Menu.$navContent.find(Menu.translation(thisId, 'button')).removeClass('act');
                Menu.hideBox = Menu.translation(thisId, 'button'); //this.id;
                Menu.time = setTimeout(function() {
                    $this.fadeOut(Menu.fadeSpeed);

                }, 100);
                Menu.hideBox = Menu.translation(thisId, 'button');
            });
        }
    };
    Menu.init();
});
