﻿/*
Esconde um determinado objeto com efeito de fadeout.
o = objeto
f = tempo de fadeout
t = tempo do timeout
*/
function appEsconder(o, f, t) {
    if (f == null) f = 500;
    if (t == null) t = 3000;
    
    window.setTimeout(function() { $(o).fadeOut(f) }, t);
}

/*
Framework para hint em campo text
*/
(function($) {
    $.fn.hint = function(blurClass) {
        if (!blurClass) blurClass = 'blur';

        return this.each(function() {
            var $input = $(this),
                title = $input.attr('title'),
                $form = $(this.form),
                $win = $(window);

            function remove() {
                if ($input.attr('value') === title && $input.hasClass(blurClass)) {
                    $input.val('').removeClass(blurClass);
                }
            }

            // only apply logic if the element has the attribute
            if (title) {
                // on blur, set value to title attr if text is blank
                $input.blur(function() {
                    if (this.value === '') {
                        $input.val(title).addClass(blurClass);
                    }
                }).focus(remove).blur(); // now change all inputs to title

                // clear the pre-defined text when form is submitted
                $form.submit(remove);
                $win.unload(remove); // handles Firefox's autocomplete
            }
        });
    };
})(jQuery);

//Carrega o destaque da home
function fnDestaque(c, i) {

    fnNav(1);
    $('#id_home').show();

    $.ajax({
        type: "POST",
        url: appUrl_ + "includes/Ajax.aspx/Destaques", // URL da página/nome do WebMethod
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        data: "{codhome: '" + c + "', idioma: '" + i + "'}", // Parâmetros da função
        beforeSend: function(json) {
            //intervalo
            $('#id_home').fadeIn();
        },
        success: function(json) {
            //sucesso
            $("#id_home").html(json.d);
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            //erro
        }
    });
}

//Carrega o destaque da home
function fnHide() {
    $('#id_home').hide();
    fnNav(0);
}

//Troca imagem da navegacao
function fnNav(v)
{
    if (v == 1)
    {
        document.getElementById("id_hideoff").style.display = 'none';
        document.getElementById("id_hideon").style.display = '';
    }
    else 
    {
        document.getElementById("id_hideon").style.display = 'none';
        document.getElementById("id_hideoff").style.display = '';
    }
}

//Troca imagem do fundo (Seções)
function fnBg(url) {
    if (url != null) {
        $(function() {
            var img = new Image();

            $(img)
            .load(function() {
                $(this).hide();

                $('#fundo').html("")
                $('#fundo').append(this);

                $(this).fadeIn();
            })

            .attr('src', url);
        });
    }
}
