/*
Versioning @ 1.03

*/

$(document).ready(function() {
	$.ga.load('UA-584220-18'); 
	
//## Ajaxifying links
    $('.jax').bind('click', function() {
    
// Track Ajax pageview
    	var trackUrl = $(this).attr('href');
    	trackUrl = trackUrl[0]!='/' ? '/' + trackUrl : trackUrl;
		$.ga.trackPageview(trackUrl);
		
// Post to link href
	  	$.post(this.href,"format=core", function(data){
	// Add response to container	  	
	  		$('.jax_container').html(data);
	// Check for existence of form and ajaxify submit	  		
	  		$('.jax_form').submit(function() {
				$.post( "contact",$(this).serialize()+'&format=core', function(formResponse) {
					$('.jax_container').html(formResponse);
				});
				return false;
			});
	  	});
	  	
// Update active link styling
		$('a.current').toggleClass('current'); 				// Remove active style where it exists
		var curClass = this.className.replace(/jax/gi,'');	// Find class of clicked and addclass current globally
		$("."+curClass).addClass('current');
	  	return false;
	});
	
// Initialize slideshow
	$("div.tabs").tabs("ul.images > li", { 
        fadeOutSpeed: "slow",
        rotate: true 
    }).slideshow();
    
	api = $("div.tabs").tabs(); 
	api.getConf().effect = "fade"; // config fade effect after init slideshow to avoid initial image fadein
	
	// Auto-rotate function
	var loopCount = 0;
	var autoRotate = setInterval(tcoRotate,5500);
	
	function tcoRotate() {
		if(loopCount++ == 6) { clearInterval(autoRotate); } 
		else { api.next(); }
	}
	
	$('div.image_control > a').bind('click', function() { // Detect user control and stop auto play
		if ( typeof autoRotate != 'undefined' ){ clearInterval(autoRotate); delete autoRotate;}
	});
	
	flashembed("audio", "/audio/birdsong.swf");
		
});
