jQuery.noConflict();

jQuery(function() {

	// Write screen resolution to cookies
	jQuery.cookie('screen_x',screen.width,{path:'/',expires:'-1'});
	jQuery.cookie('screen_y',screen.height,{path:'/',expires:'-1'});
	
	// Lightbox effect
	jQuery('a[rel=lightbox]').lightBox();
	
	// Supersize images
	var container_width = jQuery('.container').width();
	jQuery.fn.supersized.options = {  
		startwidth: container_width,  
		startheight: container_width * 0.75,
		slideshow: 0,
		width_reduction: 230
	};
	jQuery('#supersize').supersized();
	jQuery('#supersize .activeslide').fadeIn();
	
	// Initial state
	jQuery('#toggle_element:hidden').parent().hide();
	
	// Hide subnavigation for animation
	jQuery('ul.nav li.current>ul').hide(); // Old
	jQuery('div.nav>ul li.ancestor>*').hide(); // New
	jQuery('div.nav>ul li.current>*').hide(); // New

	// Show all appropriate navigation immediately (comment out if animating)
	//jQuery('ul.nav li.current').parent().show(); // Old
	//jQuery('ul.nav li.current>ul').show(); // Old
	//jQuery('div.nav>ul li.ancestor').parent().show(); // New
	//jQuery('div.nav>ul li.current').parent().show(); // New
	//jQuery('div.nav>ul li.current>*').show(); // New
	
	// Toggle element
	jQuery('.toggle_link').click(
		function() {
			if (jQuery('#toggle_element').css('display') == 'none') {
				// Slide other content aside if necessary
				jQuery('#toggle_element:hidden').parent().parent().children('.slideable').animate({
					marginLeft: "280px"
				},1000);
				// Fade in element
				jQuery('#toggle_element:hidden').parent().fadeIn('1000');
				jQuery('#toggle_element:hidden').fadeIn('1000');
			}
			else {
				// Fade out element
				jQuery('#toggle_element:visible').fadeOut('1000');
				jQuery('#toggle_element:visible').parent().fadeOut('1000');
				// Slide other content aside if necessary
				jQuery('#toggle_element:visible').parent().parent().children('.slideable').animate({
					marginLeft: "0"
				},1000);
			}
			return false;
		}
	);
	jQuery('#toggle_close').click(
		function() {
			// Fade out element
			jQuery('#toggle_element').fadeOut('1000');
			jQuery('#toggle_element').parent().fadeOut('1000');
			// Slide other content aside if necessary
			jQuery('#toggle_element:visible').parent().parent().children('.slideable').animate({
				marginLeft: "0"
			},1000);
		}
	);
	
	// Preload images (must come after all other jQuery functionality)
	jQuery.preloadCssImages();
	
});

// Run on full content load
jQuery(window).load(function() {

	// Animate subnavigation
	jQuery('ul.nav li.current').parent().show(); // Old
	jQuery('ul.nav li.current>ul').slideDown(); // Old
	jQuery('div.nav>ul li.ancestor').parent().show(); // New
	jQuery('div.nav>ul li.ancestor').show(); // New
	jQuery('div.nav>ul li.ancestor>*').show(); // New
	jQuery('div.nav>ul li.current').parent().show(); // New
	jQuery('div.nav>ul li.current>*').slideDown(); // New
	
	// Scroll to content (mobile devices only)
	if (jQuery('.container').width() <= 480 && jQuery('#supersize').length > 0) {
		setTimeout("jQuery('body').scrollTo('#supersize',1000);",1000);
	}

});
