$(document).ready(function(){

	// Hide elements which we dont want to show initially
	$('.dontshow').hide();
	
	// Fancybox popups	
	$('.fancybox').fancybox();
	
	// Create ajax document folders
	$('.library_folder').each(function () {
		var thingy = $(this).attr('data-rel');
		$(this).load('ajax/library.asp?'+ thingy);
	});
	
	// Initially hide listed subfolders, then toggle in-out 
	$('.folder:has(> ul.folder_open_close)').each(function () {
		$(this).children('div.folder_opener').css('cursor','pointer');
		$(this).children('.folder ul').hide();
	});
	$('div.folder_opener').live('click', function() {
		$(this).toggleClass('open')
		$(this).next('.folder_open_close').slideToggle();
	});

	// Create ajax gallery
	$('.gallery_folder').each(function () {
		var thingy = $(this).attr('data-rel');
		$(this).load('ajax/gallery.asp?'+ thingy);
	});
	
	// Toggle calendar type
	$('.togglecalview').live('click', function() {
		$('#calendar').fadeToggle();
		$('#eventlist').fadeToggle();
		return false;
	});	


	
	if($().validate) {
	    // Validation plugin exists
	    $(".vform").validate();
	} else {
	    // Validation plugin DOES NOT exist
	}
});


$(window).load(function(){
});
