// Javascript.

	function initMenus() {
		$('ul.menu ul').hide();
		$.each($('ul.menu'), function(){
			$('#' + this.id + '.expandfirst ul:first').show();
			$('.expanded').show();
		});
			
		$('ul.menu li a').click(	
			function() {
				var checkElement = $(this).next();
				var parent = this.parentNode.parentNode.id;

				if($('#' + parent).hasClass('noaccordion')) {
				
					// Check for a single link with no children - i.e. no accordion necessary.
					if(!(checkElement.is('ul'))){
						// Let the link execute with no further interruptions!
						return true;
					}
				
					if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
						$(this).next().children().fadeOut("fast");
					}else{
						$(this).next().children().fadeIn("normal");
					}
					$(this).next().slideToggle('normal');

					return false;
				}
				if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
					if($('#' + parent).hasClass('collapsible')) {
						$('#' + parent + ' ul:visible').slideUp('normal');
					}
					return false;
				}
				if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
					$('#' + parent + ' ul:visible').slideUp('normal');
					checkElement.slideDown('normal');
					return false;
				}
			}
		);
	}
	
	jQuery(function($) {
		
		$('.gallery_holder').addClass('gallery_holder'); // adds new class name to maintain degradability
		$('.nav').css('display','none'); // hides the nav initially
		
		$('ul.gallery').galleria({
			history   : false, // deactivates the history object for bookmarking, back-button etc.
			clickNext : false, // helper for making the image clickable. Let's not have that in this example.
			insert    : undefined, // the containing selector for our main image. 
								   // If not found or undefined (like here), galleria will create a container 
								   // before the ul with the class .galleria_container (see CSS)
			onImage   : function() { $('.nav').css('display','block'); } // shows the nav when the image is showing
		});
		var firstItem = $('ul.galleria li:first').addClass('active').find('img').addClass('selected'); 
		$.galleria.activate(firstItem.attr('src'));

	});
	

	// Initialise observers etc.
	$(document).ready(function(){
		initMenus();
		//$('ul.gallery').galleria();
		
		$('#close_sizeguide').live('click', function(){ 
			$('#dialog').dialog('close');
            return false; 
        }); 
	
		$('.ui-widget-overlay').live('click', function(){
			$('#dialog').dialog('close');
			return false;
		});
		
		$('#lnksizeguide').click(function(event){
			event.preventDefault();

			$("#dialog").dialog({
				modal: true,
				position: 'center',
				width: 500,
				height: 550,
				draggable: false,
				maxHeight: 600,
				resizable: false
			});
				
			$('#dialog').dialog('open');			

		});
	});
