/* Tells jQuery to do all the following code once the body has loaded */
$(document).ready(function(){
						   
						   
	/* ***************************************
	MAIN NAVIGATION	
	*************************************** */
	// Use URL Parser plugin to get the current page's file name
	//var pageName = jQuery.url.segment(2); // Local server
	var pageName = jQuery.url.segment(1); // Remote server
	
	$('#nav-main .link-list .active-menu').find('\'a[href$="\/' + pageName + '"]\'').parent('li').addClass('selected').parents('li, ol, ul').addClass('selected-parent');
						   
						   
						   
	/* ***************************************
	FORMS
	*************************************** */
	// Make form headings behave like field labels (I know this is a stupid thing to do)
	$('#mailinglist h3').click(function() { 
		$('#email2').focus();
	});
	
	$('#search h3').click(function() { 
		$('#q').focus();
	});
	
	$('form input[type="text"], form input[type="password"]').focus(function() { 
		$(this).addClass('selected'); 
	 });
	$('form input[type="text"], form input[type="password"]').blur(function() { 
		$(this).removeClass('selected'); 
	 });
	
	
	
	/* ***************************************
	OPEN LINKS IN NEW WINDOW
	*************************************** */
	$('#content-related3 .logos a, #sada a, .video a').attr('title','External link - Opens in a new window').click( function() {
		window.open( $(this).attr('href') );
		return false;
	});
	

	
						   
	/* ***************************************
	IMAGE GALLERIES	
	*************************************** */
	// Add the HTML markup needed for the gallery
	$('#thumbs').before('<div id="gallery"><div id="loading" class="loader"></div><div id="slideshow"></div><div id="caption"></div></div>');
	// Remove default large image for JavaScript version
	$('#image-default').addClass('hidden');
	// Stops images from opening in new windows in JavaScript version
	$('#thumbs a').removeAttr("target");
	
	// Initially set opacity on thumbs and add additional styling for hover effect on thumbs
	var onMouseOutOpacity = 0.67;
	$('#thumbs ul.thumbs li').css('opacity', onMouseOutOpacity)
		.hover(
			function () {
				$(this).not('.selected').fadeTo('fast', 1.0);
			}, 
			function () {
				$(this).not('.selected').fadeTo('fast', onMouseOutOpacity);
			}
		);

	$(document).ready(function() {
		// Initialize Advanced Galleriffic Gallery
		var galleryAdv = $('#gallery').galleriffic('#thumbs', {
			delay:                  2000,
			numThumbs:              12,
			preloadAhead:           10,
			enableTopPager:         true,
			enableBottomPager:      true,
			imageContainerSel:      '#slideshow',
			controlsContainerSel:   '#controls',
			captionContainerSel:    '#caption',
			loadingContainerSel:    '#loading',
			renderSSControls:       false,
			renderNavControls:      false,
			playLinkText:           'Play Slideshow',
			pauseLinkText:          'Pause Slideshow',
			prevLinkText:           '&lsaquo; Previous Photo',
			nextLinkText:           'Next Photo &rsaquo;',
			nextPageLinkText:       'Next &rsaquo;',
			prevPageLinkText:       '&lsaquo; Prev',
			enableHistory:          true,
			autoStart:              false,
			onChange:               function(prevIndex, nextIndex) {
				$('#thumbs ul.thumbs').children()
					.eq(prevIndex).fadeTo('fast', onMouseOutOpacity).end()
					.eq(nextIndex).fadeTo('fast', 1.0);
			},
			onTransitionOut:        function(callback) {
				$('#caption').fadeOut('fast');
				$('#slideshow').fadeOut('fast', callback);
			},
			onTransitionIn:         function() {
				$('#slideshow, #caption').fadeIn('fast');
			},
			onPageTransitionOut:    function(callback) {
				$('#thumbs ul.thumbs').fadeOut('fast', callback);
			},
			onPageTransitionIn:     function() {
				$('#thumbs ul.thumbs').fadeIn('fast');
			}
		});
	});
	



		
/* ***************************************
DON'T DELETE - End of code run once body has loaded
*************************************** */
});
	
