/*
 * Make a WordPress theme AJAXed
 *
 * Created by Rilwis (http://www.deluxeblogtips.com)
 *
 * Based on Chris Coyer's script (http://css-tricks.com/video-screencasts/81-ajaxing-a-wordpress-theme/)
 */

jQuery(document).ready(function($) {
	var $mainContent = $('#theVideo'),
		siteUrl = 'http://' + top.location.host.toString(),
		url = '';
	
	$(document).delegate('.vidNav .video a', 'click', function() {
		location.hash = this.pathname;
		return false;
	});
	
	$(window).bind('hashchange', function(){
		url = window.location.hash.substring(1);
		
		if (!url || url.charAt(0) != '/') {
			return;
		}
		
		url = url + ' #loadVid';

		$mainContent.animate({opacity: "0.1"}).addClass('vidHeight').html('<span class="spinner"></span>').load(url, function() {
			$mainContent.animate({opacity: "1"});
		if($mainContent.is(':hidden')) {
			$mainContent.show();
		}	
		});
	});
	
	$(window).trigger('hashchange');
	
	if ($('#featuredVideosLink').length != 0) {
		$('#featuredVideosLink').click(function(e) {
				e.preventDefault();
				$('.allVideos').slideUp('slow', function() {
				    $('.featuredVideos').slideDown('slow');
				  });
			});
		$('#allVideosLink').click(function(e) {
				e.preventDefault();
				$('.featuredVideos').slideUp('slow', function() {
				    $('.allVideos').slideDown('slow');
				  });
			});
	}
	$('.hideVid').live('click',function(){
		$('#theVideo').animate({opacity: "0.1"}).slideUp('slow');
		return false; 
	});
});
