$(document).ready(function() {
	$("body").addClass("js");
	$("#header .menu .submenu").hide();
	$("#header .wrapSubmenu").hide();
	$("#header .menu .mn01").hover(function(){
		hSmenu(this);
	},
	function(){ hZero(this); });
	$("#header .menu .mn02").hover(function(){
		hSmenu(this);
	},
	function(){ hZero(this); });
	function hSmenu(ele) {
		var MyH = $(ele).find('.submenu').height();
		//$("#header .menu .submenu").hide();
		$("#header .wrapSubmenu").css({'height': (MyH+10)+'px'});
		//$(ele).find('.submenu').slideDown('fast');
		//$("#header .wrapSubmenu").slideDown('fast');
		$("#header .wrapSubmenu").show();
		$(ele).find('.submenu').show();
	}
	function hZero(ele) {
		//setTimeout(function() {
		//$(ele).find('.submenu').slideUp('fast');
		//$("#header .wrapSubmenu").slideUp('fast');
		//$(ele).find('.submenu').hover(function(){
		//}, function(){
			$("#header .wrapSubmenu").hide();
			$(ele).find('.submenu').hide();
		//});
		//}, 200);
	}
	/*$(".auxMenu a.login").click(function(){
		var ele = $(this).parents('li').eq(0).find('form');
		if($(this).hasClass('active')) {
			$('.auxMenu form').hide();
			$(".auxMenu a.login").removeClass('active');
			$(ele).hide();
			$("#header .wrapSubmenu").hide();
		} else {
			$('.auxMenu form').hide();
			$(".auxMenu a.login").removeClass('active');
			$(this).addClass('active');
			$(ele).show();
			var MyH = $(ele).height();
			$("#header .wrapSubmenu").css({'height': (MyH+10)+'px'}).show();
		}
		return false;
	});
	$(".auxMenu3 a.login").click(function(){
		var myForm = "";
		if ($(this).hasClass('form1')) {
			myForm = ".form1";
		} else if($(this).hasClass('form2')) {
			myForm = ".form2";
		}
		var ele = $(this).parents('ul').eq(0).next('.formsLogins').find(myForm);
		if($(this).hasClass('active')) {
			$('.auxMenu3').next('.formsLogins').find('form').hide();
			$(".auxMenu3 a.login").removeClass('active');
			$(ele).hide();
			$("#header .wrapSubmenu").hide();
		} else {
			$('.auxMenu3').next('.formsLogins').find('form').hide();
			$(".auxMenu3 a.login").removeClass('active');
			$(this).addClass('active');
			$(ele).show();
			var MyH = $(ele).height();
			$("#header .wrapSubmenu").css({'height': (MyH+10)+'px'}).show();
		}
		return false;
	});*/
	$('.hcont').hide();
	$('.regulamento .mCont .tsc').css({'cursor': 'pointer'});
	$('.regulamento .mCont .tsc').click(function(){
		var node = $(this).next('div.hcont');
		node.slideToggle();
	});
	function carosel() {
		$(".cWrap ul.bList, .cWrap").height(cHeight);
		var wrapCont = $(".cWrap ul.bList").parents('.wrapCont').eq(0).height();//-10
		/*if(wrapCont < cHeight) {
			$(".cWrap ul.bList").parents('.wrapCont').eq(0).height(cHeight-10);
		} else {
			$(".cWrap ul.bList").parents('.wrapCont').eq(0).height(wrapCont);
		}*/
			$(".cWrap ul.bList").parents('.wrapCont').eq(0).height(wrapCont);
		//bListTotal.css({'position':'absolute', 'bottom': '0'});
		$(".cWrap ul.pag a").click(function(){
			var id = $(this).attr('rel')-1;
			bListTotal.fadeOut();
			bListTotal.removeClass('on');
			bListTotal.eq(id).fadeIn();
			bListTotal.eq(id).addClass('on');
			$(".cWrap ul.pag a").removeClass('active');
			$(this).addClass('active');
			//clearInterval(myInt);
			return false;
		});
		aIndex = 0;
		var myInt = setInterval(function(){
			if(aIndex >= bListTotal.length-1) {
				aIndex = -1;
			} else {
				aIndex = $(bListTotal).index($('.cWrap ul.bList li.on').eq(0));
			}
			$(".cWrap ul.pag a").eq(aIndex+1).click();
		}, 6000);
		
	clearTimeout(settime);
	}
	var bListTotal = $(".cWrap ul.bList li");
	if(bListTotal.length > 1) {
	var pag = '<ul class="pag">';
	var pagOn = ' class="active"';
	for(i=1;i<=bListTotal.length;i++) {
		if(i!=1){pagOn = '';}
		pag += '<li><a href="#'+i+'"'+pagOn+' rel="'+i+'">'+i+'</a></li>';
	}
	pag += '</ul>';
	$(".cWrap").prepend(pag);
	}
	var cHeight = 250;
	$(".cWrap ul.bList li").css({'position':'absolute', 'bottom': '0'}).hide();
	$('.cWrap ul.bList li.on').show();
	settime = setTimeout(function(){
	bListTotal.each(function(){
		$.get($(this).find('img').eq(0).attr('src'));
			if ($(this).height() > cHeight) {
				cHeight = $(this).height();
			}
	});
	carosel();
	}, 2000);
	
	startDatePicker();
	markOnCalendar();
	$('.tClean').click(function(){
		$('textarea').val('');
		$('textarea').focus();
	});
});

var changingDate = false;
var mm = ['Janeiro','Fevereiro','Mar&ccedil;o','Abril','Maio','Junho','Julho','Agosto','Setembro','Outubro','Novembro','Dezembro'];
function startDatePicker(){
	jQuery(function($){
		$.datepicker.regional['pt-BR'] = {
			closeText: 'Fechar',
			prevText: '&#x3c;Anterior',
			nextText: 'Pr&oacute;ximo&#x3e;',
			currentText: 'Hoje',
			monthNames: ['Janeiro','Fevereiro','Mar&ccedil;o','Abril','Maio','Junho','Julho','Agosto','Setembro','Outubro','Novembro','Dezembro'],
			monthNamesShort: ['Jan','Fev','Mar','Abr','Mai','Jun','Jul','Ago','Set','Out','Nov','Dez'],
			dayNames: ['Domingo','Segunda-feira','Ter&ccedil;a-feira','Quarta-feira','Quinta-feira','Sexta-feira','Sabado'],
			dayNamesShort: ['Dom','Seg','Ter','Qua','Qui','Sex','Sab'],
			dayNamesMin: ['D','S','T','Q','Q','S','S'],
			dateFormat: 'd/mm/yy', firstDay: 0,
			isRTL: false};
		$.datepicker.setDefaults($.datepicker.regional['pt-BR']);
	});
	$(".datePicker").datepicker({
		onSelect: function(dateText, inst) {
			var date = dateText.substring(0,dateText.indexOf("/"));
			var x = new Date(dateText.substring(3,5)+"/"+dateText.substring(0,2)+"/"+dateText.substring(6,10));
			$(".birthList h2").text(mm[x.getMonth()]+" - Dia "+date);
			$(".listNiver li").show();
			$(".listNiver li .date").each(function(){if($(this).text() != date){$(this).parent().hide();}});
			setTimeout("datePickerTitle()", 1);
			return false;
		}
	});
	setTimeout("datePickerTitle()", 1);
}
function datePickerTitle(){
	
	markOnCalendar();
	$(".seeAll, .ui-datepicker-title").css("cursor", "pointer").unbind("click").click(function(){
		$(".listNiver li").show();
		if($(".aniversariantes").length > 0){
			$(".birthList h2").text("Aniversariantes do mês de "+ $(".ui-datepicker-month").text());
		}else{
			$(".birthList h2").text("Eventos do mês de "+ $(".ui-datepicker-month").text());
		}
	});
}
function markOnCalendar(){
	$(".ui-datepicker-calendar td").removeClass("active").children().removeClass("ui-state-active");
	$(".listNiver li .date").each(function(){
		var text = $(this).text();
		$(".ui-datepicker-calendar td").each(function(){if(($(this).text() == text) || ("0"+$(this).text() == text)){$(this).addClass("active");}});
	});
}
