$(document).ready(function () {	
	var intervaloMenu;
	$("#Menu .auto li:has(a)")
	.mouseenter(function(){
		//$(this).children("div").css("display","block");
		var subMenu = $(this).children("div");
		$(subMenu).fadeIn("fast");
	})
	.mouseleave(function(){
		var subMenu = $(this).children("div");
		$(subMenu).mouseenter(function(){
			if(intervaloMenu)clearInterval(intervaloMenu);
		});
		intervaloMenu = setTimeout(function(){
			$(subMenu).css("display","none");
		},100)
	});
		
	if(temCalendario)calendario();
	$("a[rel^='prettyPhoto']").prettyPhoto({
		animationSpeed: 'normal', /* fast/slow/normal */
		padding: 40, /* padding for each side of the picture */
		opacity: 0.35, /* Value betwee 0 and 1 */
		showTitle: true, /* true/false */
		allowresize: true, /* true/false */
		counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
		theme: 'dark_square', /* light_rounded / dark_rounded / light_square / dark_square */
		callback: function(){}
	});
});

function enqueteVotada(id){
	id = "e_"+id;
	var nomeCookie = "enquete";
	var valorAtual = getCookie(nomeCookie);
	var novoValor = valorAtual;
	if(valorAtual == null)novoValor = id+":";
	else if(valorAtual.indexOf(id) == -1)novoValor += id+":";
	setCookie(nomeCookie, novoValor, 365);
}

function setCookie(name, value, days){
	var expireDate = new Date();
	var expstring=expireDate.setDate(expireDate.getDate()+parseInt(days));
	document.cookie = name+"="+value+"; expires="+expireDate.toGMTString()+"; path=/";
}

function getCookie(Name){
	var re=new RegExp(Name+"=[^;]+", "i");
	if (document.cookie.match(re))return document.cookie.match(re)[0].split("=")[1];
	return "";
}

function verifica(id){
	var id = "e_"+id;
	var cookies = getCookie("enquete");
	if(cookies.indexOf(id) != -1)return true;
	else return false;
}

function calendario(){
	var cal = new YAHOO.widget.Calendar("cal1Container",{LOCALE_WEEKDAYS:"1char",MULTI_SELECT:false});
	cal.cfg.setProperty("MONTHS_LONG",["Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro"]);
	cal.cfg.setProperty("WEEKDAYS_1CHAR",["S", "T", "Q", "Q", "S", "S", "D"]);
	cal.cfg.setProperty("DATE_FIELD_DELIMITER", ".");
	//DEFINE A POSIÇÃO MÊS/DIA/ANO PARA DIA/MÊS/ANO
	cal.cfg.setProperty("MDY_DAY_POSITION", 1);
	cal.cfg.setProperty("MDY_MONTH_POSITION", 2);
	cal.cfg.setProperty("MDY_YEAR_POSITION", 3);
	//DIA/MÊS
	cal.cfg.setProperty("MD_DAY_POSITION", 1);
	cal.cfg.setProperty("MD_MONTH_POSITION", 2);
	cal.renderEvent.subscribe(function(){
		jQuery.each($("td.calcell"),function(index,objeto){
			var data = cal.cellDates[index];
			var dataFinal = eventos(data[0],data[1],data[2]);
			if(dataFinal!=undefined){
				var a = $(this).children("a");
				$(a)
				.css({color:"#CC0000"})
				.bind("mouseenter",function(){
					if(dataFinal!=undefined){
						$(this).parent("td")
						.css({position:"relative"})
						.append(
							$("<div></div>")
							.html("<b style='color:#CC0000'>"+dataFinal["titulo"]+"</b><br /><span style='color:#666;font-size:10px'>Clique para mais detalhes</span>")
							.css({position:"absolute",zIndex:100,backgroundColor:"white",border:"2px solid #CC0000",padding:"2px",textAlign:"left",marginTop:-55,marginLeft:-150,width:150})
						)
						.bind("mouseleave",function(){
							$(this).children("div").remove();
						})
						.bind("click",function(){
							window.open("http://www.crecimg.com.br/Eventos/id-"+dataFinal["id"]+"/","_self");
						});
					}
				});
			}
		});
	});
	cal.render();
}

function videoManager(video, texto){
	var enderecoPlayer = "http://e-mobili.net/manager/exec/index.php?acao=player&aplicacao=site&video=";
	var player = window.open("","videoManager","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=260,height=300");
	player.document.write("<html><head><title>Vídeo - "+texto+"</title></head><body style='background:#c0c0c0'><div align='center'><iframe src='"+enderecoPlayer+video+"' width='240' height='235' frameborder='0' scrolling='no' allowtransparency='yes'></iframe><br /><span style='font:normal 13px arial;margin-top:4px'>"+texto+"</span></div></body></html>");
}
