$.fn.delay = function(time, callback){
    $.fx.step.delay = function(){};
    return this.animate({delay:1}, time, callback);
}

$(function(){
    $('#flashMessage').prepend('<div id="close"><a href="javascript:void();" id="close_div"><img src="'+link+'img/icons/cancel.png" /></a></div>');
    $('#close_div').click(function() {
    	$('#flashMessage').fadeOut();
    }); 
    /*
    if ($('#flashMessage')){
    	$('#flashMessage').append('<img src="'+link+'/img/icons/cancel.png" />');
        $('#flashMessage').delay(3000).fadeTo('slow', 0.01, function(){
            $(this).slideUp('fast', function(){
                $(this).remove();
            });
        });
    }*/
    if ($('.flashError')){
        $('.flashError').delay(3000).fadeTo('slow', 0.01, function(){
            $(this).slideUp('fast', function(){
                $(this).remove();
            });
        });
    }    
	$('#contato').validationEngine();
	$('#OpnioIndexForm').validationEngine({scroll: true});
	$('#ClienteAlterarSenhaForm').validationEngine();
	$('#ChamadoOrcamentoForm').validationEngine({scroll: true});
	$('#ChamadoAbrirForm').validationEngine({scroll: true});
	$('#input_search').Watermark("Digite o que deseja buscar");
	$('a[rel=localizacao], a[rel=localizacao2]').fancybox({
		'width'				: 515,
		'height'			: 450,
        'autoScale'     	: false,
        'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe'
	});
	$('a[rel=contrato]').fancybox({
		'width'				: '50%',
		'height'			: '70%',
		'autoScale'     	: false,
		'type'				: 'iframe'
	});
	$('a[rel=como_comprar],, a[rel=formas_de_pagamento], a[rel=formas_de_pagamento2], a[rel=onde_entregam]').fancybox({
		'height': 419,
		'autoScale': false,
		'type': 'iframe'
	});
	$('a[rel=horario_de_atendimento]').fancybox({
		'height': 148,
		'autoScale': false,
		'type': 'iframe'		
	});
	$('a#recuperar-senha').fancybox();
	$('a[rel=recuperar-senha2]').fancybox();
	$('a[rel=recuperar-senha3]').fancybox();
	$('a[rel=duvida_arte]').fancybox();
	$('#alteracao_prova, #aprovar_prova').fancybox();
	$('#open_modal_entrega').fancybox();
	$('#ClienteTipoPessoaF').click(function() {
		$('.juridica').hide();
		$('.fisica').show();
	});
	$('#ClienteTipoPessoaJ').click(function() {
		$('.juridica').show();
		$('.fisica').hide();
	});	
	$('#ClienteTipoPessoaJ').click(function() {
		$('#cpf').hide();
		$('#rg').hide();
		$('#cnpj').show();
		$('#corporate_name').show();
		$('#state_registration').show();
		$('#corporate_contact').show();
	});
	$('.tooltip').tooltip({
		track: true,
		delay: 0,
		showURL: false,
		showBody: " - ",
		fade: 250
	});
	
	$('.tooltip-img').tooltip({
		track: true,
		delay: 0,
		showURL: false,
		showBody: " - ",
		fade: 250,		
	    bodyHandler: function() { 
        	return $("<img/>").attr("src", this.src); 
    	} 
	});
	$('#change_category').change(function() {
		window.location = $(this).val();
	});
	$('#content_tabs').tabs();
    $("#g").jCarouselLite({
        btnPrev : '.g_prev',
        btnNext : '.g_next',
        visible : 4
    });
    $('a[rel=gallery]').fancybox();
    $('#box_mais_contatos').fancybox();
    $('#comprovante_pagamento').fancybox();
    $('#comprovante_pagamento2').fancybox();
    $('#comprovante_pagamento3').fancybox();
    $('#promocoes').fancybox();
    $('a[rel=promocoes2]').fancybox();
    $('#promocoess ul').cycle({ 
        fx:     'fade', 
        speed:  'fast', 
        pager:  '#navs', 
         
        // callback fn that creates a thumbnail to use as pager anchor 
        pagerAnchorBuilder: function(idx, slide) { 
    		return '#navs li:eq(' + idx + ') a';
        } 
    });    
});
