/*!
#######################################################################
# 
# RockNess Music Festival
# JavaScript setup routines
#
# Hand-crafted by Phenotype (phenotype.net)
#
#######################################################################
*/

	////////////////////////////////////////////////////////////////////
	//	Initialise setup routines
	////////////////////////////////////////////////////////////////////
	
	// Called when DOM is ready
	$(document).ready(domSetup);
	
	// Called when entire page is loaded
	$(window).load(pageSetup);
	
	// Called when DOM is unloaded
	$(window).unload(domUnload);
	
	////////////////////////////////////////////////////////////////////
	//	Define setup routines
	////////////////////////////////////////////////////////////////////
	
	/* 
	domSetup()
	
	All JavaScript requiring initialisation on DOM LOAD should be called
	from this routine.
	-----------------------------------------------------------------------
	*/
	
	function domSetup() {

		////////////////////////////////////////////////////////////////////
		//	Navigation
		////////////////////////////////////////////////////////////////////
			
			// Superfish menu
			$('ul.dropdown-menu').superfish({
				delay: 1000,
				dropShadows: false,
				autoArrows: false,
				animation: {'height' : 'show'},
				speed: 200	
			});	
			
			// Shrink news list if looking at one of the first two news articles
		/*if (document.getElementById('news'))
			{
			lis = $('#page-list li:gt(1)');
			if (!(lis.hasClass('current')))
				{
				lis.css('display', 'none').eq(0).before(
					'<div><a href="#" onclick="$(this.parentNode).nextAll().slideDown(1000, function(){equalCols();}); $(this).remove(); return false;">See more news articles&hellip;</a></div>'
					);
				}
			}*/

		if ( $('contribute-to-gallery')[0] ) {
			// Incrementally revealing fieldsets
			$('fieldset:gt(1):not(:has(:submit))').css('display', 'none');
			$('fieldset:has(:submit)').before('<div><p class="button-link"><a href="#" onclick="$(\'fieldset:hidden:first\').slideDown(600); if($(\'fieldset:hidden\').length == 0) this.parentNode.style.display=\'none\'; return false;"><span>Add another image</span></a></p></div>');
		}

			equalCols(); // first run as early as possibly to minimise blocks jumping around
			
			/*
			Setup external links (target attribute not allowed by XHTML 1.1)
			(see http://www.sitepoint.com/article/standards-compliant-world/)
			*/
			$('a[rel="external"]').attr('target','blank');
		
		////////////////////////////////////////////////////////////////////
		//	/Navigation
		////////////////////////////////////////////////////////////////////
		
		////////////////////////////////////////////////////////////////////
		//	Slideshow
		////////////////////////////////////////////////////////////////////
		
			$('#lineup ul').smaugSlide({
				baseClassName: 'lineup',
				activeClassName: 'selected',
				slideHeight: 230,
				duration: 300,
				pause: 5000,
				easing: 'swing',
				autoScroll: true
			});
		
		////////////////////////////////////////////////////////////////////
		//	/Slideshow
		////////////////////////////////////////////////////////////////////
		
		////////////////////////////////////////////////////////////////////
		//	Flash embedding
		////////////////////////////////////////////////////////////////////

			if ( $('#muzu-content')[0] ) {
			
				var flashvars = {};
				var params = {};
				params.wmode = "transparent";
				params.allowfullscreen = "true";
				params.allowscriptaccess = "always";
				var attributes = {};
				swfobject.embedSWF("http://www.muzu.tv/player/getPlayer/a/vaoE3K2V5j/autostart=n&includeAll=n&soundoff=n", "muzu-content", "350", "300", "9.0.0", false, flashvars, params, attributes);
			}
			
		////////////////////////////////////////////////////////////////////
		//	/Flash embedding
		////////////////////////////////////////////////////////////////////
		
		////////////////////////////////////////////////////////////////////
		//	IE6 PNG fix
		////////////////////////////////////////////////////////////////////

			if($.browser.msie && $.browser.version == '6.0') {
				DD_belatedPNG.fix('#header h1 a, #header h2, #header h3#lineup-promo a, #header h3#tickets-promo a, #navigation, #loch #scenery #hills-1, #loch #scenery #hills-2, img, .slideshow h3');
			}
		
		////////////////////////////////////////////////////////////////////
		//	IE6 PNG fix
		////////////////////////////////////////////////////////////////////

	} // End domSetup()
	
	/* 
	pageSetup()
	
	All JavaScript requiring initialisation on PAGE LOAD should be called
	from this routine (all images and elements should be loaded and ready to
	manipulate by this point)
	-----------------------------------------------------------------------
	*/
	
	function pageSetup() {
	
		//setupScenery();

		equalCols(); // second run just in case any images have loaded and changed the layout again.

	} // End pageSetup()
	
	/* 
	domUnload()
	
	Called when page/DOM is unloaded
	-----------------------------------------------------------------------
	*/
	
	function domUnload() {

	} // End domUnload()
	
	
	/* 
	equalCols()
	
	Function to equalise height of module columns
	-----------------------------------------------------------------------
	*/
	function equalCols() {
	$('.row').each(function() {
		var maxModuleHeight = 0;
		var maxModules = 0;
		var columns = $(this).children('div.column');
	
		columns.each(function() {
			var modules = $(this).children('div.module');
			if (modules.length)
				{
				maxModules = Math.max(maxModules, modules.length);
				maxModuleHeight = Math.max(maxModuleHeight, modules.height());
				}
			});
		if (maxModules == 1) columns.children('div.module').each(function() {
			if ($(this).height() < maxModuleHeight) this.style.height = maxModuleHeight.toString().concat('px');
			});
		});	
	}; // End equalCols()