$(document).ready(function() {
	app.cycle('videowall');
	app.cycleChamada('chamada_menu');
	$('#foto').addClass('foto_'+app.randNumber(1,3));	
	app.resize();
	
	app.chamadaHome();
	app.productList();
	
	$("#frmCadastroMedico").validate({
		rules: {
			txtEmail: {
				required: true,
				email: true
				
			},
			txtSenha: {
				required: true,
				equalTo: "#txtConfirmarSenha"
				
			}
		},
		errorContainer: "#errorCadastro",
		errorPlacement: function(label, element) {        
			$("#errorCadastro").append(label);
			$("#errorCadastro").show();
		},
	   errorClass: "error-input",
	   focusInvalid: false,
	   onfocusout: false,
	   onkeyup: false,
	   wrapper: "li"
	});
	
	var height = 0;
	$("#chamadas").each(function(){
		console.log($(this).height());
		if(height < $(this).height()){
			height = $(this).height();
		}
	});
	//console.log(height);
});

$(window).resize(function() {
	app.resize();
});

var app = {
	resize : function(){
		var windowWidth = $(window).width();
		var resize = (windowWidth - 970);
		resize = (65 - resize) + 16;
		if (resize > 0)
			$('#foto').animate({right:"-"+resize+"px"}, 'fast');
		else
			$('#foto').animate({right:0}, 1000);
	},
	cycle : function(id){
		
		if ($('#'+id).children(0).children().size() < 2){ 
			$('#nav').hide(); 
		}
		
		$('#'+id).children(0).cycle({ 
			fx:     'scrollHorz', 
			speed:  1000, 
			timeout: 8000,
			next:   '#next2', 
		    prev:   '#prev2'
		});
	},
	cycleChamada : function(id){
		$('#'+id).children(0).cycle({ 
			fx:     'fade', 
			speed:  1000, 
			pause: 1,
			timeout: 10000
		});
	},
	randNumber : function(i, f) {
		if (i > f) { 
			numInicial = f;numFinal = i+1;
		}else{
			numInicial = i;numFinal = f+1; 
		}
		numRandom = Math.floor((Math.random()*(numFinal-numInicial))+numInicial);
		return numRandom;
	},
	chamadaHome: function()	{
		var chamadas = $("#chamadas").children(0).find('.chamada');
		$.each(chamadas, function(index, data){ 
			if(index == 1){
				$(data).addClass('chamada');
				$(data).addClass('chamada_middle');
			}						  
		});
	},
	productList: function(){
		var list = $(".productList").children().find('tr');
		var cont = 0;
		$.each(list, function(index, data){
			if(cont > 0){
				if((cont % 2) == 0){
					$(data).addClass("corSim");
				}
			}
			cont++;
		});
	}
};
