//função para fade in / out de divs
function fadeOut(target,from) {
			$(target).animate({opacity: 'hide'}, 'fast', function() {
				if (jQuery.browser.msie)  
				this.style.removeAttribute('filter');			
				$(from).animate({opacity: 'show'}, 'fast', function() {
					//alert("done");
				})
			})	
};

//muda o mês no calendário
function loadCalendar(month,year) {
	$("#calendar").load("calendar.php?m="+month+"&y="+year+"");
}


$(document).ready(function() {
						   
						   
		//Jquery datepicker
	/*$('#datepicker').datepicker({
			changeMonth: true,
			changeYear: true,
			dateFormat: 'yy-mm-dd',
	});*/
	
	$('#datepicker').datepicker({
					changeMonth: true,
					changeYear: true,
					dateFormat: 'yy-mm-dd',
					dayNames: ['Domingo', 'Segunda', 'Terça-Feira', 'Quarta-Feira', 'Quinta-Feira', 'Sexta-Feira', 'Sábado'],
					dayNamesMin: ['Dom', 'Seg', 'Ter', 'Qua', 'Qui', 'Sex', 'Sáb'],
					monthNamesShort: ['Jan','Fev','Mar','Abr','Mai','Jun','Jul','Ago','Set','Out','Nov','Dez']				
	});

	//chama o fadeout
	$('.fadein').click(function() {
		fadeOut("#photo","#sendform");
		return false;
	 });
	$('.fadeout').click(function() {
		fadeOut("#sendform","#photo");
		return false;
	});

	//carrega o calendar.php no página inicial e eventos
	$("#calendar").load("calendar.php?m="+ $(document).getUrlParam("m") + ";y="+ $(document).getUrlParam("y") );
	
	
	//Menu lateral e do horizontal
	$('.nav').superfish({speed:0,delay:0});
	$('.navhor').superfish({speed:0,delay:0});
	
	//Jquery treeview
	$("#tree1").treeview({
			collapsed: true,
			animated: "medium",
			control:"#sidetreecontrol1",
			persist: "location"
	});
	$("#tree2").treeview({
			collapsed: true,
			animated: "medium",
			control:"#sidetreecontrol2",
			persist: "location"
	});
	$("#tree3").treeview({
			collapsed: true,
			animated: "medium",
			control:"#sidetreecontrol3",
			persist: "location"
	});
	
	
	//mapa das juntas de freguesia
	$(".mapBt").click(function () {
		var pos = $(this).attr('alt');
		var prev = $.cookie('last');
		
		if (prev) {
		  $('.info').hide("slow");
	
		}
		
		$("#"+pos).show("slow");
		$.cookie('last', pos);
			
		  
	});
	
	
	//chama os filmes de flash - slideshow de imagens
	//tamanho das imagens do flash: 860x153
	var so = new SWFObject("../flash/banner.swf", "sotester", "860", "165", "8", "#333");
	so.write("slideshow");
	
	//chama os filmes de flash - newsticker
	var so = new SWFObject("../flash/news_ticker.swf", "sotester", "860", "27", "8", "#333");
	so.write("news");
	
	//Abre a pesquisa
	$("#openSearch").click(function () {
		  $("#searchbox").toggle();
	 });
	 
	// zebra tables
	$('tr:odd').addClass('odd');
	
	//modals da acção social
	$('#ex1c')
		.jqm({
		  trigger:'#ex1cTrigger',
		  overlay: 0,
		  onShow: function(h) {
			/* callback executed when a trigger click. Show notice */
			h.w.css('opacity',0.92).slideDown(); 
			},
		  onHide: function(h) {
			/* callback executed on window hide. Hide notice, overlay. */
			h.w.slideUp("slow",function() { if(h.o) h.o.remove(); }); } 
		  });
	
	$('#ex2c')
		.jqm({
		  trigger:'#ex2cTrigger',
		  overlay: 0,
		  onShow: function(h) {
			/* callback executed when a trigger click. Show notice */
			h.w.css('opacity',0.92).slideDown(); 
			},
		  onHide: function(h) {
			/* callback executed on window hide. Hide notice, overlay. */
			h.w.slideUp("slow",function() { if(h.o) h.o.remove(); }); } 
		  });
	$('#ex3c')
		.jqm({
		  trigger:'#ex3cTrigger',
		  overlay: 0,
		  onShow: function(h) {
			/* callback executed when a trigger click. Show notice */
			h.w.css('opacity',0.92).slideDown(); 
			},
		  onHide: function(h) {
			/* callback executed on window hide. Hide notice, overlay. */
			h.w.slideUp("slow",function() { if(h.o) h.o.remove(); }); } 
		  });
		
	/*	
	var items = $('.projectos li').get();
	
	items.sort(function(a,b){ 
		  var keyA = $(a).text();
		  var keyB = $(b).text();
	
			if (keyA < keyB) return -1;
			 if (keyA > keyB) return 1;
			  return 0;
	});
	
	var ul = $('.projectos');
	$.each(items, function(i, li){
		  ul.append(li);
	});
	*/


});