$(document).ready(function(){

	//----------- Home Page Slideshow
	$('#homeSlideshow').cycle({ 
		fx:     'fade', 
		speed:   3000, 
		timeout: 5000,
		before:  onBefore, 
		after:   onAfterHome
	 });
	
	//----------- Main Slideshow
	$('#slideshow').cycle({ 
		fx:     'fade', 
		speed:   1500, 
		timeout: 5000, 
		next:   '#next',
        prev:   '#prev',
		before:  onBefore, 
		after:   onAfter
	 });
	
	function onBefore() { 
		//if (this.alt != '') {
			$('#output').animate({  
				height: "0",
				opacity: 0
			}, 500 );
			$('#output').html("");
		//}
		//else $('#output').hide();  
	} 
	
	function onAfter(curr,next,opts) { 
		$('#output').animate({ 
			height: "16px",
			opacity: 0.7
      	}, 500 );
		//console.log(opts.slideCount);
		$('#output').append('<h2>' + this.alt + '</h2>'); 
		if (opts.slideCount==1) {
			$('#slideshow').cycle('stop');
			return false;
		}
	}
	function onAfterHome() { 
		if (this.alt != '') {
			$('#output').animate({ 
				height: "16px",
				opacity: 0.7
			}, 500 );
			$('#output').append('<h2 class="homeSlideCaption">' + this.alt + '</h2>'); 
		}
		else $('#output').hide();
	}
	
	$('#pause').click(function() { $('#slideshow').cycle('pause'); return false; });
    $('#play').click(function() { $('#slideshow').cycle('resume'); return false; });

	//----------- Fancybox
	//$("a.fancy").fancybox();

	$("a.fancy").fancybox({
		'imageScale': true,
		'padding': 5,
		'overlayShow': true,
		'overlayOpacity': 0.7,
		'hideOnContentClick': true,
		'centerOnScroll': true,
		'easingIn': "easeOutBack",
		'easingOut': "easeOutSine",
		'easingChange': "easeInOutQuad"    
	  });

	//-----------  Table styling
	$('table#project_details tr:odd, form table tr:odd').addClass('odd');
	$('table#project_details tr:even, form table tr:even').addClass('even');
	
	//----------- Simple accordion for sub menu
	// Figure out the location based on the browser URL
	var path = location.pathname;
	var targetPath = path.split('/');
	if (targetPath[3]!=null) {
		//alert('null');
		var targetPath = '/'+targetPath[1] +'/'+targetPath[2] +'.htm';	
	} else {
		var targetPath = path;
	}
	// Set your homepage here, eg. /index.php or /
	var home = "/index.htm";
	// Check the home link against the path and set the navigation accordingly. 
	if (path == home || path == "/") {
		// Note that the jQuery selector matches *only* the home link
		var $nav = $('#rightSidebar ul li a[href="' + home + '"]');
	} else {
		var $nav = $('#rightSidebar ul li a[href^="' + targetPath +'"]');
	}
	// Hide all subnavigation
	$('#rightSidebar ul li ul').hide();
	// Add the active class to the current path and activate it's subnavigation
	$nav.siblings("ul").slideDown();
	// If the active class has subnavigation, show it
	$nav.parents("ul").fadeIn();


	
}); //Close document.ready

$(window).bind("load", function() {
    //-----------  Preload images for slideshows
	$('#loading').hide();
	$('#slideshowWrapper').fadeIn('slow');
});
