/**
* 	Synergema for Heritage Prep
*
*	Created: 08/10/2011
*	Updated: 08/22/2011
*
*	Required:
*	jQuery Tools tabs
* 	$.url() plugin
*
**/
;(function($){
   
   // Current URL, for segment parsing 
	var url = $.url();
	
	// Only do this on the homepage
	if ( url.segment(1) == '' )
	{
		// Slideshow
		$( '#hero .content' ).orbit({
     animation: 'fade',                  // fade, horizontal-slide, vertical-slide, horizontal-push
     animationSpeed: 800,                // how fast animtions are
     timer: true, 			 // true or false to have the timer
     advanceSpeed: 4000, 		 // if timer is enabled, time between transitions 
     pauseOnHover: true, 		 // if you hover pauses the slider
     startClockOnMouseOut: false, 	 // if clock should start on MouseOut
     startClockOnMouseOutAfter: 1000, 	 // how long after MouseOut should the timer start again
     directionalNav: true, 		 // manual advancing directional navs
     captions: false, 			 // do you want captions?
     captionAnimation: 'fade', 		 // fade, slideOpen, none
     captionAnimationSpeed: 800, 	 // if so how quickly should they animate in
     bullets: true,			 // true or false to activate the bullet navigation
     bulletThumbs: false,		 // thumbnails for the bullets
     bulletThumbLocation: '',		 // location from this file where thumbs will be
     afterSlideChange: function(){} 	 // empty function
		});
		
		// Homepage tabs
		$('ul#tabs-nav').tabs('div#tabs-panes > div.pane', {
			// Tabs config
		});
		
		// Homepage tabs API reference
		var homepage_tabs_api = $('ul#tabs-nav').data('tabs');
		
		// Swap out story on tab clicks
		homepage_tabs_api.onClick(function(index) {
			get_story();
		});

		// Stories From Our Famlies - AJAX
		function get_story() {
			// This is the entry ID
			var entry_id = $('div.quote').attr('title');
			// AJAX request page
			var page = 'http://' + document.domain + '/home/story/' + entry_id;
			// Load the story from the AJAX request
			$('div.story').load(page);
		}
	}
	
	// Check for .subnav element
	if ( $( '.subnav > ul' ).length > 0 )
	{
		// Hide all .level-3 navs
		$( '.subnav ul li.level-2 ul' ).hide();
		// Show only the active .level-3 nav
		var slug = url.segment( 2 );
		$( '.subnav ul li[rel|="' + slug + '"].active.level-2 ul' ).show();
	}
	
	// Facebox modal windows
	$( 'a[rel*="facebox"]' ).facebox( {
		opacity: 0.75
	} );


})(jQuery);
