jQuery(document).ready(function($){
	
//******************* Font Replacement

	Cufon.replace('div#header h2, div#header p');
	Cufon.replace('div#details div.work-text p.label, div#details div.work-text span.label');
	Cufon.replace('div#work-nav div.item p');
	Cufon.replace('div#work-nav h3');
	Cufon.replace('div#details span.fancy');
	Cufon.replace('div#details div#tab p');
	Cufon.replace('div#footer p');
	Cufon.replace('.modalBody p, .modalBody h2');
	
	var currWork = null;
	var currSection = null;

	currWork = $('div.selected').attr('id');
	currSection = 'home';
	

//******************* Handle Contact Form open & close
	$('div#nav p#contact').click(function(){
		$('div#contact-page').fadeIn();		
	});

	$('span#contact').click(function(){
		$('div#contact-page').fadeIn();		
	});

	$('p#contact-close').click(function(){
		$('div#contact-page').fadeOut();
	});


//******************* Handle Work Detail Tab Rollover
	$('div#tag').hover(function(){
		
	});

//******************* Handle Work Detail Animation
	$('div#tab').toggle(
		function() {
			$('div#arrow img.up').fadeOut();
			$('div#arrow img.down').fadeIn();
			$('div#details').animate({top: -200}, 700, 
				function() {
					//console.log('done!');
				});
		},
		function() {
			$('div#arrow img.up').fadeIn();
			$('div#arrow img.down').fadeOut();
			$('div#details').animate({top: -26}, 700, 
				function() {
					//console.log('done!');
  			});
	});
	
	
//******************* Handle Work Images
	$('div#work-nav div.item').click(function(){
		
		$('div#work-nav div.selected').removeClass('selected');
		$('div#work-nav div#'+$(this).attr('id')).addClass('selected');
		
		// Swap work text block		
		$('div#details div.selected').removeClass('selected');		
		$('div#worktext-'+$(this).attr('id')).addClass('selected');
		
		if(currWork!==$(this).attr('id')){
			Cufon.refresh();
			
			// Set the current piece to the selected item ID
			currWork=$(this).attr('id');
			
			// Swap-a-rooni the image
			$('img#image-'+$(this).attr('id')).animate(
				{left:0},
				1200,
				function(){
					$('img.selected').css('left','-1220px').removeClass('selected');
					$('img#'+$(this).attr('id')).addClass('selected');
					//console.log('animation done');
				}
			);
		}
		
		
	});
	
	$('div#work-nav div.item').hover(function(){
		$(this).children('p').css('color','#FFFFF');
		Cufon.refresh();
	});
	

//******************* Handle Page Switching
	$('div#nav p#about').click(function(){
		if(currSection!=='about'){
			$('div#work').css('margin-top','-564px');
			$('div#holder').css('margin-top','0px').show();
			$("div#holder").load('wp-content/themes/ea_2011/includes/php/about-snippet.php', function() {
				$('div#about').animate({'margin-top':'0px'}, 860);
				currSection = 'about';
			});
		} else {
			$('div#about').animate({'margin-top':'-564px'}, 860, function(){
				$('div#about').remove();
				$('div#work').css('margin-top','0px');
				$('div#holder').hide();
			});
		}
	});

	$('div#logo').click(function(){
		if(currSection=='about'){
			$('div#about').animate({'margin-top':'-564px'}, 860, function(){
				$('div#about').remove();
				$('div#work').css('margin-top','0px');
				$('div#holder').hide();
			});
		}
	});

	
});
