$('#overlay').hide(); // hide the flyout
$('.content-nav li a em').each(function() { //get each content nav
	contentNavClass = $(this).text(); // read the link text
	$(this).parent().addClass(contentNavClass); // apply the class to the parent

});

function brightenTheLights() {
	$('#lights-out').fadeOut('slow', function() { 
		$('#lights-out').css({'opacity': 1});
		$('#lights-out').remove(); 
		
	});
};
	
			
function dimTheLights() {
	$('#wrap').prepend('<div id="lights-out"></div>');
	$('#lights-out').css({'visibility': 'visible'});
	$('#lights-out').css({'opacity': 0});
	$('#lights-out').animate({opacity : 0.6}, 700);
};

function getAnchor(){ // parse the url
	var url = window.location.hash; // get everything after the #
	
	if(url == '#trailer') {movieClick() }; // if its trailer, show the trailer
	if(url == '#book') {bookClick() }; // if its book, show the book
	
	
}; // end getAnchor

getAnchor(); // init the function
arrowIn();

function arrowOut(){
	$('h3.site-title').hide("slide", 
		{ direction: "left" },
		1000);
	$('#sponsortable').hide("slide", 
		{ direction: "left" },
		1000);	
	$('#store-inventory').hide("slide", 
		{ direction: "down" },
		650);	
	
	
	
	
};

function arrowIn(){
	$('h3.site-title').show("slide", 
		{ direction: "left" },
		1000);
	$('#sponsortable').show("slide", 
		{ direction: "left" },
		1000);		
	$('#store-inventory').show("slide", 
		{ direction: "down" },
		650);		
};


function closeOverlay(){

	$('.close').hide();	
	$('#overlay').hide("slide", { 
		direction: "down" 
	}, 650);
	
	$('.temp-loader').remove();
		return false;
};

function bookClick() {
	if ($('#overlay').is(':hidden')) {
		dimTheLights();
		arrowOut();
	}

	if ($('#overlay:visible').hasClass('movie-toggle')) {
		closeOverlay();
	}
	if ($('#overlay:visible').hasClass('book-toggle')) {
		$('#overlay').hide("slide", 
		{ direction: "down" },
		650);
		brightenTheLights();
		
		$('#tag-line').show("slide", 
		{ direction: "left" },
		650);
		
		return false;
	}
	
	
	
	$('.close').hide();
	
	
	$('#overlay').removeClass('movie-toggle');
	$('#overlay').addClass('book-toggle');
	$('a.switch-tabs').text('Das Rennen');

	
	$('#overlay').show("slide", 
	{ direction: "down" },
	650, function() { 
		$('.close').fadeIn('slow');
		$('#map-player').prepend('<div class="temp-loader"></div>');
		$('.temp-loader').load('http://www.snowkayak.com/map.php');
	 }
	);
	
	return false;
};

function movieClick() {
	$('.temp-loader').remove();
	if ($('#overlay').is(':hidden')) {
		dimTheLights();
		arrowOut();
	}
	
	if ($('#overlay:visible').hasClass('book-toggle')) {
		closeOverlay();
	}

	if ($('#overlay:visible').hasClass('movie-toggle')) {
		$('#overlay').hide("slide", 
		{ direction: "down" },
		650);
		
		brightenTheLights();
		
		$('#tag-line').show("slide", 
		{ direction: "left" },
		650);
		
	
		return false;
	};
	
	$('.close').hide();
	$('#overlay').removeClass('book-toggle');
	$('#overlay').addClass('movie-toggle');
	$('a.switch-tabs').text('Die Location');
	
	$('#overlay').show("slide", 
		{ direction: "down" },
		650, function() { 
			$('.close').fadeIn('slow');
			$('#vid-player').prepend('<div class="temp-loader"></div>');
			$('.temp-loader').load('http://www.snowkayak.com/trailer.php');
		 }
	);
	return false;
};

	

$('.close').click(function(){
	closeOverlay();
	arrowIn();
	brightenTheLights();
	return false;
});

function textShake() {
	//$('#tag-line-text').effect("shake", { times:2 }, 700);
};	

textShake();

$('#book-overlay').click(function(){
	bookClick();
	return false;
});

$('#movie-overlay').click(function(){
	movieClick();
	return false;
});

$('#nav li.book a').click(function(){
	bookClick();
	return false;
});

$('#nav li.movie a').click(function(){
	movieClick();
	return false;
});

$('#collectors-ed a').click(function(){
	brightenTheLights();
	closeOverlay();
});

$('#vid-copy a').click(function(){
	brightenTheLights();
	closeOverlay();
});

$('a.switch-tabs').click(function(){
	$('#tag-line').hide();
	
	if($('#overlay').hasClass('movie-toggle')) {
		bookClick();
	
		return false;
	} else {

		movieClick();
		
		return false;
	};
});