/* VERY quick and dirty JavaScript. I know, I know. */

var slideshow = '<embed id="slideshow" src="swf/slideshow.swf?xml=xml/slides.xml" width="100%" height="100%" wmode="transparent">';
var reelEmbed = '<embed id="reel" src="http://vimeo.com/moogaloop.swf?clip_id=3062496&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=f06465&amp;fullscreen=1&amp;autoplay=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="720" height="405" bgcolor="#000000"></embed>';
var opreEmbed = '<embed id="opre" src="http://vimeo.com/moogaloop.swf?clip_id=6139449&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=f06465&amp;fullscreen=1&amp;autoplay=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="720" height="405" bgcolor="#000000"></embed>';
var kerliEmbed = '<embed id="opre" src="http://vimeo.com/moogaloop.swf?clip_id=10099044&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=f06465&amp;fullscreen=1&amp;autoplay=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="720" height="405" bgcolor="#000000"></embed>';
var FADE_SPEED = 500;

$(function(){
	
	$('body').append(slideshow);
	
	$('#hello a.close').click(function() {
		$('#hello').fadeOut(200);
		$('#nav .hello a').removeClass('active');
		return false;
	});
	
	$('h1 a').click(function() {
		$('#nav a').removeClass('active');
		$('#reel, #opre').remove();
		$('#hello').fadeOut(FADE_SPEED);
		if($('#slideshow').size() === 0) $('body').append(slideshow);
		return false;
	});
	
	$('#nav a').click(function() {
		if($(this).parent().hasClass('work')) return true;
		else if($(this).hasClass('active')) return false;
		
		$('#nav a').removeClass('active');
		$(this).addClass('active');
		
		destruct();
		
		switch($(this).parent().attr('class')) {
			case 'reel':
				$('#slideshow').remove();
				$(reelEmbed).appendTo('body').fadeIn(FADE_SPEED);
				break;
			case 'new':
				$('#slideshow').remove();
				$(kerliEmbed).hide().appendTo('body').fadeIn(FADE_SPEED);
				break;
			case 'hello':
				$('#hello').fadeIn(FADE_SPEED);
				if($('#slideshow').size() === 0) $('body').append(slideshow);
				break;
		}
		
		return false;
	});
	
});

function home() {
	destruct();
	$('#slideshow').remove();
}

/**
 * Load the OPRE page. Called via ExternalInterface from the full-window
 * Flash movie.
 */
function opre() {
	$('#nav a').removeClass('active');
	destruct();
	$('#slideshow').remove();
	$(opreEmbed).hide().appendTo('body').fadeIn(FADE_SPEED);
}



function destruct() {
	$('#hello').hide();
	$('#reel, #opre').remove();
}