


/*
* ------------------------------------------------------------------------------------------------
* @namespace structure
* ------------------------------------------------------------------------------------------------
*/
var structure = {


    /*
    * ------------------------------------------------------------------------------------------------
    * @alias init
    * ------------------------------------------------------------------------------------------------
    */
    init: function()
    {
        structure.mainNav();
        structure.contactNav.init();
        //structure.selectFooter();
        structure.sitemap();
        structure.tracking.init();

        $('#footer #social-medias li a').neoHover();
    },

    neighborhoodSelect: {
        setCurrent : function(){
            var foo = $('body').attr('class').split(' ');
            var item = foo[foo.length - 1];
            var curr = $('.neighborhood-select .' + item);
            curr.addClass('current');
        }
    },
    /*
    * ------------------------------------------------------------------------------------------------
    * @alias Tracking
    *
    * TRACKING
    * See too: 
    * Veja tambem: 
    * 
    * /App_Code/Tracking.cs
    * Line: 37
    * Method "Call"
    *
    * /App_code/MasteBase.cs
    * Line: 31
    * HiddenField TrackControlHidden
    * 
    * /Principal.master
    * Line: 42
    * <asp:hiddenfield id="hdnTrackControl" runat="server" />
    * 
    * All sections of code have the tag "here is tracking"
    * Todos os trechos de codigo possuem a tag "here is tracking"
    * 
    * ------------------------------------------------------------------------------------------------
    */
    tracking: {

        init: function()
        {
            var trackControl = $('span#track-control input');

            if (trackControl.val() != undefined && trackControl.val() != "")
            {
                this.call(trackControl.val())
            }
            else
            {
                //trace('nao chama...');
            }
        },

        call: function(key)
        {
            trace('chama ' + key);
            dpc_pageview(key);
        },
        /*
        * Use the method 'hrefCall' in hyperlinks, so that 
        * tracking occurs before the page is unloaded
        */
        hrefCall: function(key, handler)
        {
            this.call(key);

            if ($(handler).attr('href') != undefined)
            {
                setTimeout(function()
                {
                    if ($(handler).attr('target') == '_blank')
                    {
                        window.open($(handler).attr('href'));
                        void (0);
                    }
                    else
                    {
                        location.href = $(handler).attr('href');
                    }
                }, 500);
            }
            return false;
        }
    },
    /*
    * ------------------------------------------------------------------------------------------------
    * @alias eyeCandies
    * ------------------------------------------------------------------------------------------------
    */
    sitemap: function()
    {
        var el = 'div#footer ul#sitemap li';

        $(':last-child', 'div#footer ul#sitemap').addClass('last-child');

        $(el).hover(function()
        {
            $('dl dt a', this).addClass('hover');
        }, function()
        {
            $('dl dt a', this).removeClass('hover');
        });
    },


    /*
    * ------------------------------------------------------------------------------------------------
    * @alias selectFooter
    * ------------------------------------------------------------------------------------------------
    */
    selectFooter: function()
    {
        var easing = 'easeOutQuad';
        var fakeSelect = '<dl>';
        var el = 'div#footer fieldset';
        var fakeSelectHeight;


        $(el + ' select option').each(function(i)
        {
            fakeSelect += (i === 0) ? '<dt>' : '<dd>';
            fakeSelect += '<a href="' + $(this).attr('value') + '" title="">';
            fakeSelect += $(this).text();
            fakeSelect += '</a>';
            fakeSelect += (i === 0) ? '</dt>' : '</dd>';
        });

        fakeSelect += '</dl>';

        $(el + ' select').hide();

        $(el).append(fakeSelect);

        fakeSelectHeight = $('div#footer fieldset dl dt a').height();
        fakeSelectHeight += ($('div#footer fieldset dl dd a').eq(0).height() + 11) * $('div#footer fieldset dl dd a').length;

        //$(el).height(fakeSelectHeight);

        $(el).hover(function()
        {
            $('dl', this).animate({ height: fakeSelectHeight }, { queue: false, duration: 300 }, easing);
            $('dl dt a', this).css('background-position', '0 -35px');
        }, function()
        {
            $('dl', this).animate({ height: 35 }, { queue: false, duration: 300 }, easing);
            $('dl dt a', this).css('background-position', '0 0');
        });

        $(el + ' dl dd').hover(function()
        {
            $(this).children().animate({ paddingLeft: 20, opacity: 1 }, { queue: false, duration: 200 }, easing);
        }, function()
        {
            $(this).children().animate({ paddingLeft: 10, opacity: 0.9 }, { queue: false, duration: 200 }, easing);
        });
    },


    /*
    * ------------------------------------------------------------------------------------------------
    * @alias contactNav
    * ------------------------------------------------------------------------------------------------
    */
    contactNav:
	{
	    init: function()
	    {
	        structure.contactNav.forms();

	        var easing = 'easeOutQuad';
	        var holder = $('div#header ul#contact-nav');

	        $('li:last-child', holder).addClass('last-child');

	        //$('.contact-nav-online a', holder).neoHover();
	        $('.contact-nav-call-us a', holder).neoHover();
	        $('.contact-nav-sms a', holder).neoHover({ initWidth: 110, maxWidth: 110 });
	        $('.contact-nav-schedule a', holder).neoHover({ initWidth: 82, maxWidth: 82 });
	        $('.contact-nav-call-you a', holder).neoHover({ initWidth: 99, maxWidth: 99 });
	        $('.contact-nav-online a', holder).neoHover({ initWidth: 93, maxWidth: 93 });
	        $('.contact-nav-client-maxhaus a', holder).neoHover({ initWidth: 100, maxWidth: 100 });


	        $('.contact-nav-online a').click(function()
	        {
	            /* here is tracking */
	            tracking.call('menu_superior/atendimento-online/clique');
	            mxh.openCall();
	        });


	        $('#call-you').fadeTo(0, 0);
	        $('.contact-nav-call-you a', holder).click(function()
	        {
	            $(this).parent().addClass('active');
	            $('h3.call-you-title').show();
	            $('h3.schedule-title').hide();
	            $('#call-you').animate({ height: 215, opacity: 1 }, { queue: false, duration: 300 }, 'easeOutQuad');
	            $('#call-you .close-contact').bind('click', structure.contactNav.closeAll);

	            $('.contact-nav-schedule a').parent().removeClass('active');
	            $('#schedule').animate({ height: 0, opacity: 0 }, { queue: false, duration: 300 }, 'easeOutQuad');

	            $(holder).unbind('mouseout');
	            return false;
	        });


	        $('#schedule').fadeTo(0, 0);
	        $('.contact-nav-schedule a', holder).click(function()
	        {
	            $(this).parent().addClass('active');
	            $('h3.call-you-title').hide();
	            $('h3.schedule-title').show();
	            $('#schedule').animate({ height: 304, opacity: 1 }, { queue: false, duration: 300 }, 'easeOutQuad');
	            $('#schedule .close-schedule').bind('click', structure.contactNav.closeAll);

	            $('.contact-nav-call-you a').parent().removeClass('active');
	            $('#call-you').animate({ height: 0, opacity: 0 }, { queue: false, duration: 300 }, 'easeOutQuad');

	            $(holder).unbind('mouseout');
	            return false;
	        });


	        $(holder).bind('mouseover', structure.contactNav.over);
	        $(holder).bind('mouseout', structure.contactNav.out);




	        $("#schedule .calendar").datepicker({
	            dayNamesMin: ['D', 'S', 'T', 'Q', 'Q', 'S', 'S'],
	            monthNames: ['Janeiro', 'Fevereiro', 'Mar&ccedil;o', 'Abril', 'Maio', 'Junho', 'Julho', 'Agosto', 'Setembro', 'Outubro', 'Novembro', 'Dezembro'],
	            altField: '#schedule .schedule-day',
	            altFormat: 'dd/mm/yy'
	        });



	    },

	    over: function()
	    {
	        $('.contact-nav-schedule a').animate({ width: 82 }, { queue: false, duration: 400 }, 'easeOutQuad');
	        $('.contact-nav-call-you a').animate({ width: 99 }, { queue: false, duration: 200 }, 'easeOutQuad');
	        $('.contact-nav-online a').animate({ width: 93 }, { queue: false, duration: 200 }, 'easeOutQuad');
	    },

	    out: function()
	    {
	        $('.contact-nav-schedule a').animate({ width: 20 }, { queue: false, duration: 400 }, 'easeOutQuad');
	        $('.contact-nav-call-you a').animate({ width: 20 }, { queue: false, duration: 200 }, 'easeOutQuad');
	        $('.contact-nav-online a').animate({ width: 23 }, { queue: false, duration: 200 }, 'easeOutQuad');
	    },

	    closeAll: function()
	    {
	        $('.contact-nav-schedule a').parent().removeClass('active');
	        $('.contact-nav-call-you a').parent().removeClass('active');
	        $('.contact-nav-online a').parent().removeClass('active');
	        $('h3.call-you-title').hide();
	        $('h3.schedule-title').hide();
	        $('#schedule').animate({ height: 0, opacity: 0 }, { queue: false, duration: 300 }, 'easeOutQuad');
	        $('#call-you').animate({ height: 0, opacity: 0 }, { queue: false, duration: 300 }, 'easeOutQuad');
	        $('.contact-nav-schedule a').animate({ width: 20 }, { queue: false, duration: 400 }, 'easeOutQuad');
	        $('.contact-nav-call-you a').animate({ width: 20 }, { queue: false, duration: 200 }, 'easeOutQuad');
	        $('.contact-nav-online a').animate({ width: 23 }, { queue: false, duration: 200 }, 'easeOutQuad');
	    },

	    forms: function()
	    {

	        $('#schedule .msg, #call-you .msg').click(function()
	        {
	            $(this).removeClass('success');
	            $(this).removeClass('error');
	            $(this).text('enviando dados...');
	            $(this).hide();
	        });


	        $('#schedule .submit').click(function()
	        {
	            $.ajax({
	                type: "post",
	                dataType: "json",
	                url: "resources/json/shared/schedule-visit.aspx",
	                data: {
	                    'intHouseId': $('#schedule #strMaxhaus :selected').val(),
	                    'strName': $('#schedule #ctl00_strName').val(),
	                    'strEmail': $('#schedule #ctl00_strEmail').val(),
	                    'strPhone': $('#schedule #ctl00_strPhone').val(),
	                    'strDate': $('#schedule #ctl00_strDate').val(),
	                    'strHour': $('#schedule #ctl00_strHour1').val() + ":" + $('#schedule #ctl00_strHour2').val()
	                },
	                beforeSend: function()
	                {
	                    $('#schedule .msg').show();
	                },
	                success: function(json)
	                {
	                    switch (json.success)
	                    {
	                        case true:
	                            $('#schedule .msg').text(json.message[0]);
	                            $('#schedule .msg').addClass('error');
	                            tracking.call('menu_superior/agende-uma-visita/enviou-sucesso');

	                            break;

	                        case false:
	                            $('#schedule .msg').text(json.message[0]);
	                            $('#schedule .msg').addClass('error');
	                            break;
	                    }
	                }
	            });
	        });

	        $('#call-you .submit').click(function()
	        {
	            $.ajax({
	                type: "post",
	                dataType: "json",
	                url: "resources/json/shared/maxhaus-call-you.aspx",
	                data: {
	                    'strName': $('#call-you #ctl00_strName2').val(),
	                    'strDDD': $('#call-you #ctl00_strDDD').val(),
	                    'strPhone': $('#call-you #ctl00_strPhone2').val()
	                },
	                beforeSend: function()
	                {
	                    $('#call-you .msg').show();
	                },
	                success: function(json)
	                {
	                    switch (json.success)
	                    {
	                        case true:
	                            $('#call-you .msg').text(json.message[0]);
	                            $('#call-you .msg').addClass('error');
	                            tracking.call('menu_superior/maxhaus-te-liga/enviou-sucesso');
	                            break;

	                        case false:
	                            $('#call-you .msg').text(json.message[0]);
	                            $('#call-you .msg').addClass('error');
	                            break;
	                    }
	                }
	            });
	        });






	    }




	},


    /*
    * ------------------------------------------------------------------------------------------------
    * @alias mainNav
    * ------------------------------------------------------------------------------------------------
    */
    mainNav: function()
    {
        $('div#header ul#nav li a').neoHover();
    }


};


var trace = function(value){
	try
	{
		console.log(value);			
	}
	catch(err)
	{
	}
};

/*
* ------------------------------------------------------------------------------------------------
* @Shortcuts
* ------------------------------------------------------------------------------------------------
*/
var tracking = structure.tracking;












