$(function() {

    $('.click-box').click(function() {
        window.location.href = $(this).find("a").attr('href');
    })
    preencher_campo("busca", "Pesquisar...");

    $('#form-busca').submit(function() {
        var $this = $(this);
        var busca = $this.find('#busca');
        var attr =busca.attr('title');
        
        if(busca.val()==attr){
            busca.focus();
            return false;
        }
    });
    
    //-----------------------------------------------------------------------------

    $('#menu .sub-menu').hover(function(){
        $(this).find('ul').show();
    },function(){
        
        $(this).find('ul').hide();
    });

    //$('.fancybox').fancybox();
    $(".fancybox").fancybox({
        'transitionIn' : 'elastic',
        'transitionOut' : 'elastic',
        'speedIn' : 600,
        'speedOut' : 200,
        'overlayShow' : true,
        'titleShow' : false

    });
    $(".i-fancybox").fancybox({
        //'transitionIn'	: 'elastic'
        //,'transitionOut': 'elastic'
        'speedIn' : 500,
        'speedOut' : 200,
        'overlayShow' : true,
        'titleShow' : false,
        'width' : '50%'
        //, 'height'	: '90%'
        ,
        'autoScale' : true,
        'type' : 'iframe'
    });
    $(".i-fancybox-autosize").fancybox({
        'type' : 'iframe',
        'autoDimensions' : true,
        'overlayShow' : true,
        'hideOnOverlayClick' : true,
        'showCloseButton' : true,
        'modal' : false

    });

    //tooltip
    $(".tooltip[title]").tooltip({
        position : "top center",
        //opacity : 0.7,
        effect : 'fade',
        tipClass: 'view-tooltip'
    });
});
/*--------------------- BUSCA TOPO SITE END -------------------------*/

$(function() {

    //var offTopTexto = $(".texto").offset().top;
    var winH = $(window).height();
    $(window).scroll(function() {

        if($(window).scrollTop() > 0) {

            $("#bar-float-bottom").fadeIn();
            $('#bar-float-bottom').css({
                top : (winH - 30) + $(window).scrollTop(),
                right : '0px'
            });

        } else {

            $("#bar-float-bottom").hide();

        }
        $("#msg-popup").css({
            top : $(window).scrollTop()
        });
    });
    $(".set-top").click(function() {
        $("html,body").stop().animate({
            scrollTop : 0
        }, 1000);
    });
    $(".set-back").click(function() {
        window.history.go(-1)
    });
});
function openFancyBox(url) {
    $.fancybox({
        href : url,
        overlayShow : false,
        hideOnOverlayClick : true,
        showCloseButton : true,
        modal : false,
        padding : 0,
        margin : 0,
        titleFormat : 'html'
    });
}

function openIFancyBox(url, width, height) {
    $.fancybox({
        href : url + "/ssId/" + Math.random(),
        type : 'iframe',
        width : width,
        height : height,
        overlayShow : true,
        hideOnOverlayClick : true,
        showCloseButton : true,
        modal : false,
        padding : 0,
        margin : 0

    });
}

function openIFancyBoxAutoSize(url) {
    $.fancybox({
        href : url + "/ssId/" + Math.random(),
        type : 'iframe',
        autoDimensions : true,
        overlayShow : true,
        hideOnOverlayClick : true,
        showCloseButton : true,
        modal : false,
        padding : 0,
        margin : 0

    });
}

function modalWait(text) {
    txt = '<div class="a-center"><img src="images/ajax-loader1.gif" alt="Aguarde..." /></div>';
    if(text != '')
        txt += text;

    $.modal(txt, {
        overlayClose : false,
        escClose : false
    });
}

/**
 *  Fecha o modal
 */
function modalWaitClose() {
    $.modal.close();
}

/**
 * Open ajax
 */
idOpenAjaxMenuPainel = '';
lastPageHash = window.location.hash;

function openAjax(url, target) {

    if(idOpenAjaxMenuPainel == url)
        return false;
    idOpenAjaxMenuPainel = url;

    $.ajax({
        url : url,
        type : 'post',
        beforeSend : function() {
            //modalWait();
            $(target).html(loading());
        },
        success : function(result) {
            $(target).html(result);
        //modalWaitClose();
        },
        error : function(error) {
        }
    });

}

function loading() {
    var html = '<div class="a-center" style="padding: 20px 0;"><img src="images/loader_light_blue.gif" alt="Aguarde..." /></div>';
    return html;
}

$(function() {
    /*----------------------------------------------------------------------*/
    /*
	 * qualquer link pode ser aberto com o script abaixo, basta seguir as instruções
	 *
	 */

    var clickLinkOpen = $(".link-ajax-painel .open a").bind({
        click : function(e) {
            e.preventDefault();
            ele = $(this);

            $('.link-ajax-painel .open').removeClass('active');
            ele.parent().addClass('active');

            if(idOpenAjaxMenuPainel == ele.attr('href'))
                return false;
            url = ele.attr('href').replace(/^(#|!)/, '');
            target = ele.parents('.link-ajax-painel').find("#contents");
            self.location.hash = url;
            idOpenAjaxMenuPainel = ele.attr('href');

            $.ajax({
                url : url,
                type : 'post',
                beforeSend : function() {
                    ele.addClass('loading');
                //target.html(loading());
                },
                success : function(result) {
                    target.html(result);
                },
                complete : function() {
                    ele.removeClass('loading');
                },
                error : function(error) {
                    target.html(result);
                }
            });
        //return false;
        }
    });

    if(lastPageHash != '' || lastPageHash != 'undefined') {

        openAjax(lastPageHash.replace(/^(#|!)/, ''), ".link-ajax-painel #contents");
    }
});

