(function() {
	
	// define Us namespace if it doesn't already exist
	window.Us = window.Us || {};
	
	// Videos of the Day Module (Using the Module pattern here)
	Us.VideosOfTheDay = (function() {
		
		// private properties
		
		// main selectors used by module
		var MODULE_ID = '#videos-of-the-day';
		var VIDEO_THUMBS = MODULE_ID + ' #video-thumbs li';
		var VIDEO_THUMBS_IMG = VIDEO_THUMBS + ' img';
		var TITLE = MODULE_ID + ' #video-details h4 a';
		var POSTED_DATE = MODULE_ID + ' #video-details .posted';
		var EXCERPT = MODULE_ID + ' #video-details p';
		
		var currentSelectedThumb = null;
				
		// private methods
		
		function setVideoDetails(/*Object*/ args) {
			var $title = $(TITLE);
			var $posted = $(POSTED_DATE);
			var $excerpt = $(EXCERPT);
			
			// set title and title link value
			$title.html(args.title);
			$title.attr('href', args.link);
						
			// set the posted date
			$posted.html(args.date);
		
			// set the excerpt
			$excerpt.html(args.excerpt);
		};
		
		function setActiveVideoImage(link, image) {
			$('#active a').attr('href', link);
			$('#active a img').attr('src', image);
		};
 		
		function changeVideoData($element) {
			
			$(VIDEO_THUMBS).removeClass('current');
			$($element).addClass('current');
			
			var $theImg = $('.thumb', $element);
			
			var theDate = $('.meta .posted', $element).html();
			var theTitle = $('.meta h4', $element).html();
			var theExcerpt = $('.meta p', $element).html();		
			var theImage = $('.meta span.img-lrg', $element).html();

			var theLink = $('.meta span.img-link', $element).html();
			
			setVideoDetails({
				title: theTitle,
				link: theLink,
				date: theDate,
				excerpt: theExcerpt
			});
			
			setActiveVideoImage(theLink, theImage);
		};
		
		// public methods
		function init() {
			$(VIDEO_THUMBS).click(function() {		
				// swap out the gallery data
				changeVideoData(this);
				
				// store the newly selected thumb
				currentSelectedThumb = this; // this is the li element
					
			})
			.eq(0).trigger('click'); // and now trigger the click on the first thumb to kick it off
		}
		
		// public api
		return {
			
			init: init
				
		}
		
	})();
	
})();

// Document is ready!! Go!!!
jQuery(document).ready(function($){
	
	// init Videos of the Day module
	Us.VideosOfTheDay.init();
	
});
