$(document).ready(function () {
    $('body *:first-child').addClass('first-child');
    $('body *:last-child').addClass('last-child');
    $('.msgBusca').example(function () {
        return $(this).attr('title')
    });
    DD_roundies.addRule('.curv01', '3px 3px 3px 3px', true);
    DD_roundies.addRule('.curv02', '5px 5px 0 0', true);
    DD_roundies.addRule('.curv03', '5px 5px 5px 5px', true);
    DD_roundies.addRule('.curv04', '0 0 5px 5px', true);
    DD_roundies.addRule('.curv05', '0 5px 5px 0', true);
    $('#areas').easySelectBox({
        speed: 400
    });
    $('.ddlEscopo').easySelectBox({
        speed: 400
    });

    if($(".resetFont").length > 0) {
        $.getScript("/Util/home/js/jquery.fontSize.js", function () {});
    }

    function megaHoverOver() {
        $(this).find(".boxSubmenu").stop().fadeTo('fast', 1).show();
        (function ($) {
            jQuery.fn.calcSubWidth = function () {
                rowWidth = 0;
                $(this).find("ul").each(function () {
                    rowWidth += $(this).width()
                })
            }
        })(jQuery);
        if ($(this).find(".row").length > 0) {
            var biggestRow = 0;
            $(this).find(".row").each(function () {
                $(this).calcSubWidth();
                if (rowWidth > biggestRow) {
                    biggestRow = rowWidth
                }
            })
        } else {
            $(this).calcSubWidth();
            $(this).find(".boxSubmenu").css({
                'width': rowWidth
            })
        }
    }
    function megaHoverOut() {
        $(this).find(".boxSubmenu").stop().fadeTo('fast', 0, function () {
            $(this).hide()
        })
    }
    var config = {
        sensitivity: 1,
        interval: 100,
        over: megaHoverOver,
        timeout: 500,
        out: megaHoverOut
    };
    $("ul li .boxSubmenu").css({
        'opacity': '0'
    });
    $("ul li").hoverIntent(config);
    $('.equalize').equalHeights();
    $("#tabs").tabs();
    $('.destGrande').each(function (i) {
        if ($(this).data('events') == null) {
            $(this).hover(function () {
                $(this).find('div.descricao').stop(true, true).animate({
                    'bottom': 0
                }, {
                    duration: 200,
                    easing: 'easeInOutCirc'
                })
            }, function () {
                $(this).find('div.descricao').stop(true, true).animate({
                    'bottom': -32
                }, {
                    duration: 200,
                    easing: 'easeInOutCirc'
                })
            })
        }
    });

    function carousel_initCallback(carousel) {
        jQuery('.jcarousel-control a').bind('click', function () {
            carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
            return false
        })
    };

    function carousel_highlight(carousel, obejctli, liindex, listate) {
        jQuery('.jcarousel-control a:nth-child(' + liindex + ')').attr("class", "active")
    };

    function carousel_removehighlight(carousel, obejctli, liindex, listate) {
        jQuery('.jcarousel-control a:nth-child(' + liindex + ')').removeAttr("class", "active")
    };
    $("#mycarousel").jcarousel({
        scroll: 1,
        auto: 8,
        wrap: 'last',
        animation: 'slow',
        initCallback: carousel_initCallback,
        itemVisibleInCallback: carousel_highlight,
        itemVisibleOutCallback: carousel_removehighlight,
        buttonNextHTML: null,
        buttonPrevHTML: null
    })
    if($(".nyroModal").length > 0) {
        $.getScript("/Scripts/nyroModal/jquery.nyroModal.js", function () {
            $("#lnkMiniCad.nyroModal").nyroModal({
                bgColor: "#000",
                width: 580,
                height: 600
            });
            $("#lnkRegistro.nyroModal").nyroModal({
                bgColor: "#000",
                width: 580,
                height: 800
            });
            $("#lnkLembrarSenha.nyroModal").nyroModal({
                bgColor: "#000",
                width: 80,
                height: 80
            });
            $("#lnkOuvidoriaFrame.nyroModal").nyroModal({
                bgColor: "#000",
                width: 750,
                height: 610
            });
            $("#lnkContinueCadastro.nyroModal").nyroModal({
                bgColor: "#000",
                width: 600,
                height: 600,
                closeButton: '<a href="#" onclick="__doPostBack()" class="nyroModalClose" id="closeBut" title="close">Close</a>'
            });
            $("#lnkCompEmail.nyroModal").nyroModal({
                bgColor: "#000",
                width: 600,
                height: 600
            });
            $("#lnkCadPJ.nyroModal").nyroModal({
                bgColor: "#000",
                width: 600,
                height: 600
            });
            $("#lnkCadPF.nyroModal").nyroModal({
                bgColor: "#000",
                width: 600,
                height: 600
            });
            $("#lnkAvatar.nyroModal").nyroModal({
                bgColor: "#000",
                width: 850,
                height: 500
            });
            $("#lnkRelatarErros.nyroModal").nyroModal({
                bgColor: "#000",
                width: 300,
                height: 400
            });
            $("#lnkMeuSebraeMensagem.nyroModal").nyroModal({
                bgColor: "#000",
                width: 600,
                height: 300
            });
            $("#lnkMeuSebraeIndique.nyroModal").nyroModal({
                bgColor: "#000",
                width: 600,
                height: 600
            });
            $("#lnkTermoDeUso.nyroModal").nyroModal({
                bgColor: "#000",
                width: 600,
                height: 600
            });
            $("#lnkCentralDeAtedimento.nyroModal").nyroModal({
                bgColor: "#000",
                width: 100,
                height: 100
            });
            $("#lnkGaleriaFotos.nyroModal").nyroModal({
                bgColor: "#000",
                width: 835,
                height: 530
            });
            $("#ctl00_PlaceHolderMain_lnkAviseme.nyroModal").nyroModal({
                bgColor: "#000",
                width: 700,
                height: 700
            });
            $("#lnkTenhoInteresseAviseme.nyroModal").nyroModal({
                bgColor: "#000",
                width: 700,
                height: 700
            });

            $("#lnkProdutoParaEmpresarios.nyroModal").nyroModal({
                bgColor: "#000",
                width: 550,
                height: 400
            });

            $("#lnkVerDatas.nyroModal").nyroModal({
                bgColor: "#000",
                width: 650,
                height: 700
            });
            $("#lnkVerEnderecos.nyroModal").nyroModal({
                bgColor: "#000",
                width: 750,
                height: 700
            });
            $("#lnkPopUpLogin.nyroModal").nyroModal({
                bgColor: "#000",
                width: 500,
                height: 600
            });
            $("#lnkVejaMais.nyroModal").nyroModal({
                bgColor: "#000",
                width: 700,
                height: 900
            });
            $("#lnkMPEsNoBrasil.nyroModal").nyroModal({
                bgColor: "#000",
                width: 650,
                height: 900
            });
            $("#lnkMPEsEmSaoPaulo.nyroModal").nyroModal({
                bgColor: "#000",
                width: 650,
                height: 900
            });
            $("#lnkEstudosEPesquisas01.nyroModal").nyroModal({
                bgColor: "#000",
                width: 600,
                height: 900
            });
            $("#lnkEstudosEPesquisas02.nyroModal").nyroModal({
                bgColor: "#000",
                width: 600,
                height: 900
            });
            $("#lnkEstudosEPesquisas03.nyroModal").nyroModal({
                bgColor: "#000",
                width: 600,
                height: 900
            });
            $("#lnkEstudosEPesquisas04.nyroModal").nyroModal({
                bgColor: "#000",
                width: 600,
                height: 900
            });
            $("#lnkVideoTVSebrae.nyroModal").nyroModal({
                bgColor: "#000",
                width: 600,
                height: 500
            });
        });
    }

    $.getScript("/Scripts/nyroModal/jquery.nyroModal.js", function () {
        $(".EstPes ul li span a").attr("target", "_blank");
        $(".EstPes ul li span a").nyroModal({
            bgColor: "#000",
            width: 535,
            height: 900
        });
    });
});

function OpenModal(url, width, height) {
    if(!$.isFunction($.nyroModalManual)) {
        $.getScript("/Scripts/nyroModal/jquery.nyroModal.js", function () {
            $.nyroModalManual({
                forceType: 'iframe',
                url: url,
                width: width,
                height: height,
                closeButton: '<a href="#" onclick="__doPostBack(\'\');" class="nyroModalClose" id="closeBut" title="close">Close</a>'
            });
        });
    } else {
        $.nyroModalManual({
            forceType: 'iframe',
            url: url,
            width: width,
            height: height,
            closeButton: '<a href="#" onclick="__doPostBack(\'\');" class="nyroModalClose" id="closeBut" title="close">Close</a>'
        });
    }
}

function OpenLogin(url) {
    OpenModal(url, 500, 500);
}

function OpenCadastro(url) {
    OpenModal(url, 600, 700);
}

function OpenCentralAtendimento() {
    OpenModal('/Paginas/modal/CentralDeAtendimento.aspx', 100, 100);
}

function OpenOuvidoria() {
    OpenModal('/paginas/modal/ouvidoria.aspx', 750, 610);
}

function OpenLembrarSenha() {
    OpenModal('/paginas/modal/LembrarSenha.aspx', 80, 80);
}
