// the fade out/in stuff when clicking on a page link

// this is a stupid hack because the better method borks the page layout
// hide all the body content - do this before the document is ready, otherwise it won't work
document.write('<style type="text/css">body{display:none}</style>');

//document is ready – begin fade in
jQuery(function($) {
$(document).ready(function() {
    $("body").css("display", "none");
	$('#wrapper').css("display", "none");
    $("body").fadeIn(500);
	$('#wrapper').fadeIn(2000);
    $("body").css("display", "block");
	});
});

// fade out the page once a link is clicked - this needs to be separate from the fade-in, otherwise it doesn't work.
jQuery(function($) {
	$(document).ready(function() {
		$("a.fadeout").click(function(event){
			event.preventDefault();
			linkLocation = this.href;
			$("#wrapper").fadeOut(500);
			$("body").fadeOut(1000, redirectPage);
		});
		function redirectPage() {
			window.location = linkLocation;
		}
	});
});

// for the sidebar menu – add classes for control + styling
jQuery(function($) {
	$(document).ready(function appendClasses() {
		//level 0
		$('#access #menu-danieljaber').addClass('accordion-menu');
		var menuTitle0 = jQuery('#access #menu-danieljaber').attr('id');
		$('#access #menu-danieljaber').attr('class', 'accordion-menu-' + menuTitle0 + '-level0');
		//level 1
		$('#access #menu-danieljaber ul').addClass('accordion-menu');
		var menuTitle1 = jQuery('#access #menu-danieljaber').attr('id');
		$('#access #menu-danieljaber ul').attr('class', 'accordion-menu-' + menuTitle1 + '-level1');
		//level 2
		$('#access #menu-danieljaber ul ul').addClass('accordion-menu');
		var menuTitle2 = jQuery('#access #menu-danieljaber').attr('id');
		$('#access #menu-danieljaber ul ul').attr('class', 'accordion-menu-' + menuTitle2 + '-level2');

		$('#access #news-menu').addClass('accordion-menu');
		var menuTitle0 = jQuery('#access #news-menu').attr('id');
		$('#access #news-menu').attr('class', 'accordion-menu-' + menuTitle0 + '-level0');
	});
});

// for the sidebar menu – show/hide sub-menus and animate
jQuery(function($) {
	$(document).ready(function initMenus() {
		$('#menu-danieljaber ul').hide();
		$('#news-menu ul').hide();
		$(".current_page_item ul:first").slideDown('normal');

		$(".current_page_item").parents("ul, li").map(function () { 
			$(this).slideDown('normal');
		});
	
		$('#menu-danieljaber li a').click(function() {
			var checkElement = jQuery(this).next();
			var parent = this.parentNode.parentNode.id;
			if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
				if($('#' + parent).hasClass('collapsible')) {
					$('#' + parent + ' ul:visible').slideUp(600);
					}
				return false;
				}
			if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
				$('#' + parent + ' ul:visible').slideUp(600);
				checkElement.slideDown(1200);
				return false;
			}
		});
	
		$('#news-menu li a').click(function() {
			var checkElement = jQuery(this).next();
			var parent = this.parentNode.parentNode.id;
			if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
				if($('#' + parent).hasClass('collapsible')) {
					$('#' + parent + ' ul:visible').slideUp(600);
				}
				return false;
			}
			if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
				$('#' + parent + ' ul:visible').slideUp(600);
				checkElement.slideDown(1200);
				return false;
			}
		});
	});
});

// this adds a class to the menu, so parent links do not send the site off to another page, caused by redirectPage in the next function
jQuery(function($) {
	$('#primary .menu-item-861 a').addClass('fadeout'); // home
	$('#primary .menu-item-882 a').addClass('fadeout'); // design > adt – g
	$('#primary .menu-item-884 a').addClass('fadeout'); // training > ballet
	$('#primary .menu-item-885 a').addClass('fadeout'); // training > contemporary
	$('#primary .menu-item-887 a').addClass('fadeout'); // who > daniel jaber
	$('#primary .menu-item-897 a').addClass('fadeout'); // press
	$('#primary .menu-item-898 a').addClass('fadeout'); // contact
	$('#primary .menu-item-899 a').addClass('fadeout'); // news
	$('#menu-danieljaber li ul li a').addClass('fadeout'); // everything else
	$('#primary .menu-item-902 a').addClass('fadeout'); // news page home
	$('#primary .menu-item-903 a').addClass('fadeout'); // news page contact
	$('#primary .menu-item-904 a').addClass('fadeout'); // news page news
	$('#primary .all-archives a').addClass('fadeout'); // news page all archives
	$('#news-menu li ul li a').addClass('fadeout'); // everything else on news
});

// some basic layout stuff for the small square images
jQuery(function($) {
$("#content a.images").parent().css({"padding":"0px 0px 0px 199px"});
});

