{
	workOpen = false;
	twitterOpen = false;
	playOpen = false;
	contactOpen = false;	
	animationStart = false;
}

jQuery.fn.checkBtns = function() {
	if(workOpen == true) {
		setTimeout(function(){$('#item1').fadeOut();},100);	
		$('.label1').fadeOut("fast");
		$('#workContent').fadeOut(),
		$('#workGuy').fadeOut(),
		setTimeout(function(){$(this).returnBtns()},1000);
		workOpen = false;
		$('#workBG').fadeOut();
		$('#workFullContent').fadeOut();
	}
	if(twitterOpen == true) {
		setTimeout(function(){$('#item2').fadeOut();},100);	
		$('.label2').fadeOut();
		$('#twitterContent').fadeOut(),
		$('#bird').fadeOut(),
		setTimeout(function(){$(this).returnBtns()},1000);
		twitterOpen = false;
		$('#twitterBG').fadeOut();
	}
	if(playOpen == true) {
		setTimeout(function(){$('#item3').fadeOut();},100);	
		$('.label3').fadeOut();
		$('#playContent').fadeOut(),
		$('#skateboard').fadeOut(),
		setTimeout(function(){$(this).returnBtns()},1000);
		playOpen = false;
		$('#playBG').fadeOut();
	}
}

jQuery.fn.returnBtns = function() {
	if (workOpen == false){
		 $('#item1').css({'margin-left':'0px','width':'50px','height':'100px','margin-top':'10px'}),
		 $('.label1').css({'margin-left':'0px','margin-top':'50px'}),
		 $('#item1').fadeIn();
		 $('.label1').fadeIn();
		 $('#workContent').fadeOut("fast");
		 $('#workFullContent').fadeOut("fast");
	} if (twitterOpen == false){
		 $('#item2').css({'margin-left':'0px','width':'50px','height':'111px','margin-top':'120px'}),
		 $('.label2').css({'margin-left':'0px','margin-top':'160px'}),
		 $('#item2').fadeIn();
		 $('.label2').fadeIn();
		 $('#twitterContent').fadeOut("fast");
	} if (playOpen == false){
		 $('#item3').css({'margin-left':'0px','width':'50px','height':'83px','margin-top':'241px'}),
		 $('.label3').css({'margin-left':'0px','margin-top':'279px'}),
		 $('#item3').fadeIn();
		 $('.label3').fadeIn();
		 $('#playContent').fadeOut("fast");
	} 
}

$(document).ready(function(){

	/**$("#content a").click(function(event){
     	event.preventDefault();
     });**/

	$('.label1').click(function(event) {
		if (workOpen == false && animationStart == false){
			 $('#item1').animate({'margin-left':'160px','width':'650px'},1000),
			 $('.label1').animate({'margin-left':'760px'},990),
			 $('#item1').animate({'height':'100%','margin-top':'0px'},1000),
			 $('#workBG').animate({'opacity':'1'});
			setTimeout(function(){ jQuery('#workContent').fadeIn(),setTimeout(function(){$(animationStart = false)},500)},2000);
			setTimeout(function(){ jQuery('#workGuy').fadeIn()},2000);
			setTimeout(function(){$(workOpen = true)},1000);
			$('#workBG').fadeIn();
			animationStart = true;
			bgShown = true;
			$(this).checkBtns();
			$(this).startRotation();
			$('#welcome').fadeOut();
		} if(workOpen == true) {
			$('#workFullContent').fadeOut();
			setTimeout(function(){ jQuery('#workContent').fadeIn(),setTimeout(function(){$(animationStart = false)},500)},1000);
		}
		event.preventDefault();
	});
	
	$('.label2').click(function(event) {
		 if(twitterOpen == false && animationStart == false){
			 $('#item2').animate({'margin-left':'160px','width':'650px'},1000),
			 $('.label2').animate({'margin-left':'760px'},990),
			 $('#item2').animate({'height':'100%','margin-top':'0px'},1000),
			 $('.label2').animate({'margin-top':'50px'},1000),
			 $('#twitterBG').animate({'opacity':'1'});
			 setTimeout(function(){ jQuery('#twitterContent').fadeIn(),setTimeout(function(){$(animationStart = false)},500)},2000);
			 setTimeout(function(){ jQuery('#bird').fadeIn()},2000);
			 setTimeout(function(){$(twitterOpen = true)},1000);
			 $('#twitterBG').fadeIn();
			 animationStart = true;
			 bgShown = true;
		 	 $(this).checkBtns();
			 $('#welcome').fadeOut();
		}
		event.preventDefault();
	});
	
	$('.label3').click(function(event) {
		if(playOpen == false && animationStart == false){
			 $('#item3').animate({'margin-left':'160px','width':'650px'},1000),
			 $('.label3').animate({'margin-left':'760px'},990),
			 $('#item3').animate({'height':'100%','margin-top':'0px'},1000),
			 $('.label3').animate({'margin-top':'50px'},1000),
			 $('#playBG').animate({'opacity':'1'});
			 setTimeout(function(){ jQuery('#playContent').fadeIn(),setTimeout(function(){$(animationStart = false)},500)},2000);
			 setTimeout(function(){ jQuery('#skateboard').fadeIn()},2000);
			 setTimeout(function(){$(playOpen = true)},1000);
			 $('#playBG').fadeIn();
			 animationStart = true;
			 bgShown = true;
			 $(this).checkBtns();
			 $('#welcome').fadeOut();
		}
		event.preventDefault();
	});
	
	
	jQuery.fn.fadeInItem = function() {
		if(workOpen == false && twitterOpen == false && playOpen == false && contactOpen == false  && animationStart == false) {
			$(this).fadeIn();
		}
	}
	
	jQuery.fn.fadeOutItem = function() {
		if(workOpen == false && twitterOpen == false && playOpen == false && contactOpen == false  && animationStart == false) {
			$(this).fadeOut();
			$('#mainBG').fadeIn();
		}
	}
	
	jQuery.fn.switchBG = function() {
		$(this).css({'background-position':'20px'});
	}

	jQuery.fn.switchBack= function() {
		$(this).css({'background-position':'0px'});
	}
		
	function fadeInWork() {
		$('#workBG').fadeInItem();
		$('#mainBG').fadeOut();
	}
	
	function fadeOutWork() {
		$('#workBG').fadeOutItem();	
	}
	
	function fadeInTwitter() {
		$('#twitterBG').fadeInItem();
		$('#mainBG').fadeOut();
	}
	
	function fadeOutTwitter() {
		$('#twitterBG').fadeOutItem();	
	}
	
	function fadeInPlay() {
		$('#playBG').fadeInItem();
		$('#mainBG').fadeOut();
	}
	
	function fadeOutPlay() {
		$('#playBG').fadeOutItem();	
	}
	
	function fadeInContact() {
		$('#contactBG').fadeInItem();
		$('#mainBG').fadeOut();
	}
	
	function fadeOutContact() {
		$('#contactBG').fadeOutItem();	
	}

	function emailFI() {
		$('.email').fadeIn();
		$(this).switchBG();
	}
	
	function emailFO() {
		$('.email').fadeOut();
		$(this).switchBack();
	}
	
	function resumeFI() {
		$('.resume').fadeIn();
		$(this).switchBG();
	}
	
	function resumeFO() {
		$('.resume').fadeOut();
		$(this).switchBack();
	}
	
	function fbFI() {
		$('.facebook').fadeIn();
		$(this).switchBG();
	}
	
	function fbFO() {
		$('.facebook').fadeOut();
		$(this).switchBack();
	}
	
	function linkedinFI() {
		$('.linkedin').fadeIn();
		$(this).switchBG();
	}
	
	function linkedinFO() {
		$('.linkedin').fadeOut();
		$(this).switchBack();
	}
	
	function twitterFI() {
		$('.twitter').fadeIn();
		$(this).switchBG();
	}
	
	function twitterFO() {
		$('.twitter').fadeOut();
		$(this).switchBack();
	}
	
	$(".label1").hoverIntent(fadeInWork,fadeOutWork);
	$(".label2").hoverIntent(fadeInTwitter,fadeOutTwitter);
	$(".label3").hoverIntent(fadeInPlay,fadeOutPlay);
		
	$('.emailBtn').hoverIntent(emailFI,emailFO);
	$('.resumeBtn').hoverIntent(resumeFI,resumeFO);
	$('.linkedinBtn').hoverIntent(linkedinFI,linkedinFO);
	$('.twitterBtn').hoverIntent(twitterFI,twitterFO);
	$('.fbBtn').hoverIntent(fbFI,fbFO);
});

