function rand( min, max ) {
	return Math.floor( Math.random() * ( max - min + 1 ) ) + min;
}

$(document).ready(function() {  	
	
	/*
	$('#imgs').nivoSlider({
		effect:'random',
		animSpeed:500,
		pauseTime:3000,
		directionNav: false, //Next & Prev
		directionNavHide: false, //Only show on hover
		pauseOnHover: true, //Stop animation while hovering
		beforeChange: function(){},
		afterChange: function(){
			
		}
	});*/

    $("#destaques").jCarouselLite({
        btnNext: "#next",
        btnPrev: "#prev",	        
		speed: 1000,
		auto: 5000,
		start: rand( 0, $("#destaques li").size()-1 ),
		easing: "easeInOutQuad",
		beforeStart: function() {
    		$($("#destaques nav")[0]).fadeOut(500);
    	},
    	afterEnd: function() {
    		$($("#destaques nav")[0]).fadeIn(500);
    	}
    });
    
    $("#nm_contato").bind('focus click', function() { $(this).select(); });
    $("#ds_email").bind('focus click', function() { $(this).select(); });
    
    $("#btnCadastrar").bind('click', function() {
    	var nome = $("#nm_contato").val();
    	var email = $("#ds_email").val();
    	
    	if( nome == "Nome" || email == "Email" ) {
    		alert('Digite os dados corretamente');
    		$("#nm_contato").focus();
    	} else {
	    	if( !validarEmail(email) ) {
	    		alert('E-mail inválido');
	    		$("#ds_email").focus();
	    	} else {
		    	$.ajax({ 
					type: "GET",
					url: "newsletter/xml?nome="+nome+"&email="+email,
					dataType: "text",
					success: function( txt ){
						$('#frmNewsletter').html('');
						$('#msg_news').html( txt );
				    }}
				);
	    	}
    	}
    	
    });

});