$(document).ready(function() {

	// Cache the Slide Gallery Elements we are working on
	var $slide_gallery = $('#page_header .slideshow');
	var $slide_images = $('#page_header .slideshow li img');
	var $slide_caption = $('<div class="caption"></div>');
	var $slide_nav = $('<div class="navigation"></div>');
	
	// Cache the Newsletter Form Elements we are working on
	var $newsletter_txt = $('#newsletter input[type=text]');
	
	
	// SLIDESHOW GALLERY
	
	// If the slideshow element is present and it has more than one image
	if($slide_gallery && $slide_images.length > 1) {
		
		// 1. Add in the caption and navigation elements
		$slide_gallery.after($slide_caption);
		$slide_caption.after($slide_nav);
		
		// 2. Insert the cycle plugin on the slide show
		$slide_gallery.cycle({ 
			fx:			'fade',
			speed:   	600, 
			timeout:	5000,	
			pager:		'#page_header .navigation',
			after:		displayCaption,
			pause:   	1
		});
		
	}
	
	// Function to display caption in slide gallery (callback)
	function displayCaption() { 
	    var captionText = $(this).children('img').attr('alt');
	    $slide_caption.text(captionText); 
	}
	
	// HEADER NAVIGATION
	
	// Look for Sub-Lists in list elements and add the "multi" class
	$('#site_header .navigation li ul').parent().addClass('multi');
	
	// IMAGE GALLERY
	
	// If a thumbnail image gallery is present, use the lightbox plugin on it
	$('.gallery a').fancybox();
	
	// LOCAL TIME
	var options = { utc: true, utc_offset: 1};
	
	$('#secondary .time p').jclock(options);
	
	
	// NEWSLETTER FORM
	
	$newsletter_txt.example(function() {
		return $(this).attr('title');
	}, {className: 'example'});

});
