function loadCalendar(month,year) {
	$(".calendar").load("calendar.php?m="+month+"&y="+year+"", function() {
		$('a.event_day').parent('td').addClass('event');
		
	});
}

function startLoader() {
	$('div.slideshow').find('img').batchImageLoad({
			loadingCompleteCallback: myCallback
	});
}

function myCallback() {
	$("#loading").hide();
	$("div.slideshow").show().cycle({random: 1});
}

function qtip_error(e,context,custom_error) {
		
		if (custom_error) {
			var error = custom_error;
		} else {
			var error = $(e).next('a').attr('title');
		}
		
		//espera o elemento e o contexto deste mesmo
	    $(e,context).qtip({
               content: error,
               position: {
                  corner: {
                     tooltip: 'bottomLeft',
                     target: 'rightTop'
                  },
				  adjust: {screen: false}
               },
               show: {
                  when: false,
                  ready: true
               },
               hide: { when: { target: $(e) } },
               style: {
                  border: {
                     width: 3,
                     radius: 4,
					 color: '#e7c566'
                  },
				  fontSize: 11,
				  background: '#e7c566',
                  padding: 1,
				  color: '#473c1e',
                  textAlign: 'left',
                  tip: true
               }
            });
}

/*-----------------------------document ready -------------------------------------------------------------------------------*/
$(document).ready(function(){
	
	
	$("#menu_tree").treeview({
			animated: "fast",
			unique: true,
			persist: "location",
			collapsed: true
	});

	$('.slideshow').hide();
	
		//carrega o calendar.php no div
	$(".calendar").load("calendar.php", function() { 	
		$('a.event_day').parent('td').addClass('event');
	});


//header slideshow ------------------------------------------------------------

	$.getJSON('read_folder_json.php', function(data) {
												  
    $('div.slideshow').empty();
	
		var total = data.images.length - 1;
	
		$.each(data.images, function(i, item) {
			 
			$("div.slideshow").append('<img src="images/header/' + item + '" />');
			
			if (i == total) {
				
				startLoader();
			}
		});
	});
//header slideshow ------------------------------------------------------------

	$('#toogle_newsletter').click(function() {
		$('ul.newsletter').hide();
  		$('#newsletter').show();
	});
	
		
	//fancybox 
	$("a.thumb").fancybox({titlePosition  : 'inside'});


	$("dl.gallery div.photo a").fancybox({
		titlePosition  : 'inside',
		padding: 1,
		margin: 0,
		scrolling: 'no'
	});
	


//header slideshow ------------------------------------------------------------
/*	
	$.getJSON('destaques.php', function(data) {
	
												  		
		$.each(data.id, function(i, item) {
			 
			//console.log(data.title+data.location+data.id);
			
			$('div.destaque').html('<img src="images/graphics/teste_destaque.jpg" /><fieldset><h1>'+data.title+'</h1><h2>De '+data.begin+' a '+data.end+'</h2>'+'<h2>'+data.location+'</h2></fieldset>')
		});
		
	});
*/	

$('.destaque').cycle({ 
    fx:    'fade', 
    timeout:  7000 
});

//header slideshow ------------------------------------------------------------

 	
//------------toggles the index dl's menus
	$("h3.toogle").toggle(function(){
	  $(this).next('div.desc').show("fast");
	  $('span',this).text('[-]');
		},function(){
	  $(this).next('div.desc').hide("fast");
	  $('span',this).text('[+]');
	});

 

 if (/Safari[\/\s](\d+\.\d+)/.test(navigator.userAgent)){ 
 	$('.content').css('display','inline-block');
 }
 
 if ( $('.destaque span').children().size() > 0 ) {
     $('.destaque span').css('background-image','url(images/graphics/destaque_opacity.png)')
}
 
});

