﻿$(document).ready(function () {

    $('#WidGetsLink').click(function () {
        $('#divCotacao').hide();

        var winH = $(window).height();
        var winW = $(window).width();
        var top = winH / 2 - $('#WidGets').height() / 2;
        var left = winW / 2 - $('#WidGets').width() / 2;

        if (top < 0)
            top = 0;

        if (left < 0)
            left = 0;

        //Get the screen height and width
        var maskHeight = $(document).height();
        var maskWidth = $(window).width();

        //Set height and width to mask to fill up the whole screen
        $('#Mascara').css({ 'width': maskWidth, 'height': maskHeight });
        $('#Mascara').css({ 'top': 0, 'left': 0 });

        //transition effect    
        $('#Mascara').fadeIn(1000);
        $('#Mascara').fadeTo("slow", 0.8);

        $('#WidGets').css('position', 'absolute');
        $('#WidGets').css('z-index', '9999999999');
        $('#WidGets').css('top', top);
        $('#WidGets').css('left', left);
        $('#WidGets').show();

    });

    $(function () {
        RefreshWidgets = function () {

            $('#Mascara').hide();
            $('#WidGets').hide();
            $('#divCotacao').show();

            var c1 = 'widex1';
            var c2 = 'widex2';
            var c3 = 'widex3';

            if (window.location.href.toLowerCase().indexOf('/home.aspx', 0) != -1) {
                c1 = 'widin1';
                c2 = 'widin2';
                c3 = '';
            }

            $('#WidPergunte').hide();
            $('#WidTradutor').hide();
            $('#WidSimulador').hide();
            $('#WidEventos').hide();
            $('#WidCockpit').hide();
            $('#WidSuperacao').hide();

            if (!$.cookie(c1) && !$.cookie(c2) && !$.cookie(c3)) {
                if (window.location.href.toLowerCase().indexOf('/home.aspx', 0) != -1) {
                    $('#WidPergunte').show();
                    $('#WidTradutor').show();
                }
                else {
                    $('#WidPergunte').show();
                    $('#WidTradutor').show();
                    //$('#WidSimulador').show();
                }
            }
            else {

                if (c1 != '' && $.cookie(c1) == 'PE')
                    $('#WidPergunte').show();
                if (c1 != '' && $.cookie(c1) == 'TR')
                    $('#WidTradutor').show();
                if (c1 != '' && $.cookie(c1) == 'SI')
                    $('#WidSimulador').show();
                if (c1 != '' && $.cookie(c1) == 'EV')
                    $('#WidEventos').show();
                if (c1 != '' && $.cookie(c1) == 'CO')
                    $('#WidCockpit').show();
                if (c1 != '' && $.cookie(c1) == 'SU')
                    $('#WidSuperacao').show();

                if (c2 != '' && $.cookie(c2) == 'PE')
                    $('#WidPergunte').show();
                if (c2 != '' && $.cookie(c2) == 'TR')
                    $('#WidTradutor').show();
                if (c2 != '' && $.cookie(c2) == 'SI')
                    $('#WidSimulador').show();
                if (c2 != '' && $.cookie(c2) == 'EV')
                    $('#WidEventos').show();
                if (c2 != '' && $.cookie(c2) == 'CO')
                    $('#WidCockpit').show();
                if (c2 != '' && $.cookie(c2) == 'SU')
                    $('#WidSuperacao').show();

                if (c3 != '' && $.cookie(c3) == 'PE')
                    $('#WidPergunte').show();
                if (c3 != '' && $.cookie(c3) == 'TR')
                    $('#WidTradutor').show();
                if (c3 != '' && $.cookie(c3) == 'SI')
                    $('#WidSimulador').show();
                if (c3 != '' && $.cookie(c3) == 'EV')
                    $('#WidEventos').show();
                if (c3 != '' && $.cookie(c3) == 'CO')
                    $('#WidCockpit').show();
                if (c3 != '' && $.cookie(c3) == 'SU')
                    $('#WidSuperacao').show();
            }
        };
    });

    RefreshWidgets();

});
