jQuery(function() {
				
jQuery(window).load(function() {
        jQuery('#slider').nivoSlider();
    }); 
	
  
jQuery("[placeholder]").textPlaceholder();
	
  jQuery('#mycarousel').jcarousel();
	  

    jQuery('#mycarousel').jcarousel({
        auto: 2,
        wrap: 'last',
        initCallback: mycarousel_initCallback
    });

	jQuery("#scroll-agenda, #scroll-listagem").scrollable({circular: true}).navigator(".navi");	

	if(jQuery(".scrollable .itens div").length == 3) jQuery(".scroll-paginacao").hide();

	var numItem = 4;
	if(jQuery(".scroll-wrap .scrollable .items div").length > numItem){			
		jQuery(".scroll-wrap .scrollable").scrollable({
			onSeek: function() { 
				if(this.getSize()-numItem <= this.getIndex()) jQuery(".scrollable").siblings(".right").addClass("disabled"); /*jQuery(".scroll-wrap .next").addClass("disabled");*/
				else jQuery(".scrollable").siblings(".right").removeClass("disabled");
			}		
		});
	}
	else{
		jQuery(".scroll-wrap .left").addClass("disabled");
		jQuery(".scroll-wrap .right").addClass("disabled");
	}

	
	if(!jQuery(".simple_overlay").length){
		jQuery('body').append("<div class=\"simple_overlay\" id=\"gallery\"><a class=\"prev\">Anterior</a><a class=\"next\">Pr&oacute;ximo</a><div class=\"info\"></div><img class=\"progress\" src=\"/js/jquery.tools/img/_loading.gif\" /></div>");
	}

	if(jQuery("a[rel='prettyPhoto']").length){
		jQuery("a[rel='prettyPhoto']").overlay({
			target: '#gallery',
			expose: '#000'
		}).gallery({
			speed: '600'
		});
	}
	
	

	
	jQuery.tools.validator.localize("br", {
		'*'				: 'Preecha corretamente este campo',
		':email'  		: 'E-mail inv&aacute;lido',
		':number' 		: 'Somente n&uacute;meros',
		':url' 			: 'Url inv&aacute;lida',
		'[max]'	 		: 'O valor m&aacute;ximo deve ser $1',
		'[min]'			: 'O valor m&iacute;nimo deve ser $1',
		'[required]'	: 'Preenchimento obrigat&oacute;rio'
	});
	
	jQuery.tools.validator.addEffect("twitter", function(errors, event) {
			/*var twitter = jQuery(this.getConf().container).fadeIn();*/
			var twitter = jQuery(this.getConf().container);
			twitter.find("p").remove();
			var justone = true;
			jQuery.each(errors, function(index, error) {
				if(justone){
					justone = false;
					twitter.append(
						"<p><img src=\"/js/jquery.tools/img/warning.png\"> Preencha o campo <strong>" +error.input.attr("label")+ "</strong> corretamente.</p>"
						/*"<p>Preencha o campo <strong>" +error.input.attr("label")+ "</strong> corretamente: " +error.messages[0]+ "</p>"*/
					);	
					var input = error.input;
					input.addClass("input-error").focus(function()  {
						input.removeClass("input-error");
					});
				}
			});
			var alerttimer = window.setTimeout(function(){
				jQuery('#form-alert').slideUp('normal');
			}, 3000);
			jQuery('#form-alert').slideDown('normal');
		}, 
		function(inputs)  {
	});		
	
	if(!jQuery("#form-alert").length){
		jQuery('body').append("<div id=\"form-alert\"></div>");
	}
	
	jQuery("form.validar").validator({ 
		lang: 'br', 
		effect: 'twitter', 
		container: '#form-alert',
		errorInputEvent: null		
	});

	jQuery(".mask-telefone").maska("(99) 9999-9999");
	jQuery(".mask-data").maska("99/99/9999");
	jQuery(".mask-CEP").maska("99999-999");
	jQuery(".mask-hora").maska("99:99");

	jQuery.tools.dateinput.localize("br",  {
	   months:        'Janeiro,Fevereiro,Mar&ccedil;o,Abril,Maio,Junho,Julho,Agosto,' +
						'Setembro,Outubro,Novembro,Dezembro',
	   shortMonths:   'Jan,Fev,Mar,Abr,Mai,Jun,Jul,Ago,Set,Out,Nov,Dez',
	   days:          'Domingo,Segunda,Ter&ccedil;a,Quarta,Quinta,Sexta,Sábado',
	   shortDays:     'Dom,Seg,Ter,Qua,Qui,Sex,Sáb'
	});
	jQuery(":date").dateinput({ 
		lang: 'br', 
		format: 'dd/mm/yyyy',
		offset: [30, 0]
	});
	
	jQuery("ul.tabs").tabs("div.panes > div");
	
	jQuery(".rounded-img, .rounded-img-small").load(function() {
		jQuery(this).wrap(function(){
			return '<span class="' + jQuery(this).attr('class') + '" style="background:url(' + jQuery(this).attr('src') + ') no-repeat center center; width: ' + jQuery(this).width() + 'px; height: ' + jQuery(this).height() + 'px;" />';
		});
		jQuery(this).css("opacity","0");
	});

	jQuery(".items img.zoom").click(function() {	
    	var imgZoom = jQuery(this).attr("rel");
		var wrap = jQuery("#imgP .img");
		wrap.fadeTo("medium", 0.5);
		wrap.attr("src", imgZoom);
		wrap.fadeTo("fast", 1);
	});
	
});

function msnBox(title, text){
	jQuery("#facebox div h2#msnTitle").html(title);
	jQuery("#facebox div p#msnText").html(text);
	jQuery("#facebox").overlay({
		top: 100,
		mask: {
			color: '#fff',
			loadSpeed: 200,
			opacity: 0.5
		},
		closeOnClick: true,
		load: true
	});
}

/*adaptado para o modo antigo*/
function jSuccess(title, text){
	msnBox(text, title);
}

/*adaptado para o modo antigo*/
function jError(title, text){
	msnBox(text, title);
}

/*adaptado para o modo antigo*/
function jWarning(title, text){
	msnBox(text, title);
}



	  function mycarousel_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};
