$(function() {
	
	var numItem = 5;
	if($(".scroll-wrap .scrollable .items div").length > numItem){			
		$(".scroll-wrap .scrollable").scrollable({
			onSeek: function() { 
				if(this.getSize()-numItem <= this.getIndex()) $(".scrollable").siblings(".next").addClass("disabled"); /*jQuery(".scroll-wrap .next").addClass("disabled");*/
				else $(".scrollable").siblings(".next").removeClass("disabled");
				
			}
		});
	}
	else{
		$(".scroll-wrap .left").addClass("disabled");
		$(".scroll-wrap .right").addClass("disabled");
	}
	
	if(!$(".simple_overlay").length){
		$('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($("a[rel='prettyPhoto']").length){
		$("a[rel='prettyPhoto']").overlay({
			target: '#gallery',
			expose: '#000'
		}).gallery({
			speed: '600'
		});
	}

	$.tools.validator.addEffect("twitter", function(errors, event) {
		var twitter = $(this.getConf().container);
		twitter.find("p").remove();
		var justone = true;
		$.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("title")+ "</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(){
			$('#form-alert').slideUp('normal');
		}, 3000);
		$('#form-alert').slideDown('normal');
	}, 
	function(inputs)  {
	});		

	if(!$("#form-alert").length){
		$('body').append("<div id=\"form-alert\"></div>");
	}

	$("form.validar").validator({ 
		effect: 'twitter', 
		container: '#form-alert',
		errorInputEvent: null		
	});
	$("form.validar").attr("novalidate", "novalidate"); 
	
	/*banner slider*/
	$('.nivoSlider').nivoSlider({
		effect:'fade',		
		slices:10,
		animSpeed:700,						
		pauseTime:3500,
		startSlide:0,
		pauseOnHover:true,
		directionNav:false,
		controlNav:false
	});

	$(".mask-telefone").maska("(99) 9999-9999");
	$(".mask-data").maska("99/99/9999");
	$(".mask-CEP").maska("99999-999");
	$(".mask-CPF").maska("999.999.999-99");
	$(".mask-hora").maska("99:99");
	$("input, textarea").placeholder();
	
});

function msnBox(title, text){
	$("#facebox div h2#msnTitle").html(title);
	$("#facebox div p#msnText").html(text);
	$("#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);
}

