﻿$().ready(function() {
    LoadMenu();
    LoadH2();
    $("#Facebook, #Twitter").hover(function() {
        $(this).prev().show();
    }, function() {
        $(this).prev().hide();
    });

    $('#ecommerce-button').click(function() {
        $.blockUI({
            message: $('#ecommerce-version-box'),
            css: {
                top: ($(window).height() - 523) / 2 + 'px',
                left: ($(window).width() - 534) / 2 + 'px',
                height: '523px',
                width: '534px',
                border: 'none',
                '-webkit-border-radius': '10px',
                '-moz-border-radius': '10px',
                '-o-border-radius': '10px',
                'border-radius': '10px',
                'background-color': 'transparent'
            }
        });
        $('.blockOverlay').click($.unblockUI);
    });

});

$.ajaxSetup({
  cache: false
});


function CloseExchangeRatesMenu() {
    RebuildExchangeRatesMenu();
    ShowExchangeRatesMenu();
}

function CloseWindow() {
    $.unblockUI();
}

function LoadH2() {
    $.each($("h2"), function() {
        titleArray = $(this).text().split("");
        charsImg = "";

        for (i = 0; i <= titleArray.length - 1; i++) {
            charsImg += "<img src='Images/Default/Chars/" + titleArray[i].charCodeAt() + ".png'>";
        }

        $(this).html(charsImg);
        $(this).show();
    });
}

function LoadMenu() {
    $.each($("#menuContainer a"), function(i) {
        $(this).mouseover(function() {
            $(this).attr("style", "padding-left:4px");
            $(this).parents("div:first").attr("style", "background-color:#F5F5F5");
        })
        .mouseout(function() {
            $(this).attr("style", "font-weight:normal");
            $(this).parents("div:first").attr("style", "background-color:#FFF");
        });
    });
}


function LogOut() {
    $.post("servicios/iniciar-sesion", { action: 'Logout' }, function() {
        window.location.href = "/home";
    });
}

function RebuildExchangeRatesMenu() {
    $("#exchangeRateLoading").show();
    $("#exchangeRateData").fadeOut("slow");
    $("#exchangeRateInfo").fadeOut("slow");
    $("#backButton").fadeOut("slow");
    $(".footerMenuItem").css("width", "130px");
    $(".footerMenuItem").find("span").hide();
    $(".footerMenuItem").removeClass("footerMenuItemSelected").addClass("footerMenuItem").fadeIn();
    $(".footerMenuItem").find("td:eq(1)").removeClass("footerMenuItemTD");
    $("#footerMenu").animate({ width: "130px" }, 500);

}

function ShowExchangeRate(country) {
    $("#footerMenu table[country!='" + country + "']").parent().animate({ opacity: "hide" }, 500);
    var selectedItem = $("#footerMenu table[country='" + country + "']").parent();
    selectedItem.animate({
        width: "250px"
    }, {
        duration: 500,
        complete: function() {
            selectedItem.find("td:eq(1)").addClass("footerMenuItemTD");
            selectedItem.find("span").show();
            $("#exchangeRateInfo").fadeIn();
            selectedItem.addClass("footerMenuItemSelected");
            $.get("servicios/master", { action: 'GetExchangeRate', country: country }, function(data) {
                $("#exchangeRateInfo").animate({
                    height: "165px"
                }, {
                    duration: 500,
                    complete: function() {
                        data = eval('(' + data + ')');
                        $("#exchangeRateAmount").text(data.ExchangeRate);
                        $("#currency").text(data.Currency);
                        $("#exchangeRateDescription").text(data.Description);
                        $("#exchangeRateLoading").hide();
                        $("#exchangeRateData").fadeIn("slow");
                        $("#backButton").fadeIn("slow");
                    }
                });

            });
        }
    });

    $("#footerMenu").animate({ width: "250px" }, 500);
}


function ShowExchangeRatesMenu() {
    $("#ExchangeRates").toggle();
}

function ShowForgotPassword() {
    $("#forgotPasswordContainer").slideToggle("fast");
}

function HideForgotPassword() {
    $("#forgotPasswordContainer").slideUp("fast");
}




