// When images are loaded, start the slideshow
$(window).load(function() {
	showIntro();
	//showContact();
	//showMenu();
});

var fadeout = hideIntro;

$(function() {
  $("img.rollover").hover(function() {
	$(this).attr("src", $(this).attr("src").split(".").join("-hover."));
  }, function() {
	$(this).attr("src", $(this).attr("src").split("-hover.").join("."));
  });
});


function showIntro() {
	$('#v1').delay(500, function() {
		$('.gutter').show();
		$('.visualsWrapper').show();
		$('#v1').show();
	});
	$('#v1').animate({opacity:1}, 500);											// Big Blue Ball
	$('#v2').delay(1000, function() { $('#v2').show(); });
	$('#v2').animate({opacity:1}, 300);											// Tan Ball
	$('#v3').delay(1300, function() { $('#v3').show(); });
	$('#v3').delay(0, function() {												// Replace with Combined Logo Icon
		$('#v3').css({'opacity':1});
		$('#v1').hide();
		$('#v2').hide();
	});
	
	$('#v4').delay(1300, function() { $('#v4').show(); });
	$('#v4').animate({opacity:1}, 300);											// Fade in Title
	//$('#v5').delay(1300).animate({'left':630, 'opacity':1}, 1200);				// Slide in tagline
	$('#v5').delay(1300).animate({'left':394, 'opacity':1}, 1200);				// Slide in tagline
	$('#v6').delay(2600, function() { $('#v6').show(); });
	$('#v6').delay(0, function() {												// Replace with Combined Title/Tagline Image
		$('#v6').css({'opacity':1});
		$('#v4').hide();
		$('#v5').hide();
	});
	
	$('#v3').delay(2300).animate({'top':0, 'width':67, 'height':58}, 700);		// Slide Icon to Top
	$('#v6').delay(1000).animate({'top':64, 'width':451, 'height':18}, 700);	// Slide Title to Top
	$('#v7').delay(4300, function() {											// Replace with Combined Title/Tagline Image
		$('#v7').show();
		$('#v7').css({'opacity':1});
		$('#v3').hide();
		$('#v6').hide();
	});
	
	$('#v8').delay(4500, function() { $('#v8').show(); });
	$('#v8').animate({'opacity':1}, 700);							// Slideshow Images
	$('#v8').delay(3000, function() { $('#v8').hide(); });
	$('#skip-intro').delay(5000, function() {$(this).show();});
	$('#skip-intro').animate({'opacity':1}, 700);
	
	$('#v9').delay(6500, function() { $('#v9').show(); });
	$('#v9').animate({'opacity':1}, 700);
	$('#v9').delay(2000, function() { $('#v9').hide(); });
	
	$('#v10').delay(7500, function() { $('#v10').show(); });
	$('#v10').animate({'opacity':1}, 700);
	$('#v10').delay(2000, function() { $('#v10').hide(); });
	
	$('#v11').delay(8500, function() { $('#v11').show(); });
	$('#v11').animate({'opacity':1}, 700);
	$('#v11').delay(2000, function() { $('#v11').hide(); });
	
	$('#v12').delay(9500, function() { $('#v12').show(); });
	$('#v12').animate({'opacity':1}, 700);
	$('#v12').delay(2000, function() { $('#v12').hide(); });
	
	$('#v13').delay(10500, function() { $('#v13').show(); });
	$('#v13').animate({'opacity':1}, 700);
	$('#v13').delay(2000, function() { $('#v13').hide(); });
	
	$('#v14').delay(11500, function() { $('#v14').show(); });
	$('#v14').animate({'opacity':1}, 700);
	$('#v14').delay(2000, function() { $('#v14').hide(); });
	
	$('#v15').delay(12500, function() { $('#v15').show(); });
	$('#v15').animate({'opacity':1}, 700);
	$('#v15').delay(2000, function() { $('#v15').hide(); });
	
	$('#v16').delay(13500, function() { $('#v16').show(); });
	$('#v16').animate({'opacity':1}, 700);
	$('#v16').delay(2000, function() { $('#v16').hide(); });
	
	$('#v17').delay(14500, function() { $('#v17').show(); });
	$('#v17').animate({'opacity':1}, 700);
	
	$('#skip-intro').delay(14500, function(){ $(this).hide(); });
	
	$('#menu').delay(15500, function() { showMenu(); });
}


function showMenu() {
	$("#menu > ul > li").css('opacity',0);
	$("#menu").show();
	var delayNum=0;
	$("#menu > ul > li").each(function(){
		$(this).delay(delayNum).animate({'opacity':1}, 200);
		delayNum += 200;
	});
	$("#blog").delay(delayNum, function(){ $(this).fadeIn(500); });
}

function hideIntro(callback) {
	$("#intro").fadeOut();
	callback();
}

function skipIntro() {
	$("#intro img").stop();
	$("#menu").stop();
	$("#intro img").hide();
	$("#v17").fadeIn(700);
	showMenu();
}

function showBio() {
	$("#bio .img, #bio .text").hide();
	$("#bio").show();
	$("#bio .img").fadeIn(1000);
	$("#bio .text").delay(800, function(){ $(this).fadeIn(500);});
	fadeout = hideBio;
}

function hideBio(callback) {
	if (callback == showBio) return;
	$("#bio").fadeOut();
	callback();
}

function showSkills() {
	$("#skills .bg").hide();
	$("#skills .text").hide();
	$("#skills").show();
	$("#skills .bg").fadeIn(700);
	$("#skills .text").delay(700, function(){$(this).fadeIn(500);});
	fadeout = hideSkills;
}

function hideSkills(callback) {
	if (callback == showSkills) return;
	$("#skills").fadeOut();
	callback();
}

function showClients() {
	$("#clients .bg").hide();
	$("#clients .text").hide();
	$("#clients .textunderlay").css('opacity',0);
	$("#clients").show();
	$("#clients .bg").fadeIn(700);
	$("#clients .textunderlay").delay(700, function(){$(this).fadeTo(700, 0.3);});
	$("#clients .text").delay(1200, function(){$(this).fadeIn(500);});
	fadeout = hideClients;
}

function hideClients(callback) {
	if (callback == showClients) return;
	$("#clients").fadeOut();
	callback();
}

function showContact() {
	$("#contact .bg, #contact .bg2, #contact .bottom, #contact #mini-images img").hide();
	$("#contact-main img").hide();
	
	$("#contact").show();
	$("#contact .bg").fadeIn(700);
	$("#contact .bg2").delay(500, function() { $(this).fadeIn(700); });
	$("#contact #img1").delay(1000, function(){
		$(this).show('slide',{},500);
		$(this).delay(2000, function(){$(this).attr('src', 'images/animated-visuals/watermelon-explosion.gif');});
	});
	$("#contact #img2").delay(1500, function(){$(this).show('slide',{},500);});
	$("#contact #img3").delay(2000, function(){$(this).show('slide',{},500);});
	$("#contact #img4").delay(2500, function(){$(this).show('slide',{},500);});
	
	$("#contact-main").delay(3000, function(){ showContactMain(); });
	$("#contact .bottom").delay(6000, function() { $(this).fadeIn(700); });
	
	fadeout = hideContact;
}

function showContactMain() {
	$("#contact-main .text, #contact-main .click-here, #contact-main .text").hide();
	$("#contact-main").show();
	$("#contact .text1").fadeIn(700);
	$("#contact .text2").delay(700, function(){$(this).fadeIn(700);});
	$("#contact .text3").delay(1400, function(){$(this).fadeIn(700);});
	$("#contact .text4").delay(2100, function(){$(this).fadeIn(700);});
	fadeout = hideContact;
}

function showContactMainQuick() {
	$("#contact-main *").show();
	$("#contact-main").hide();
	$("#contact-main").fadeIn(700);
	fadeout = hideContact;
}

function hideContact(callback) {
	if (callback == showContact) return;
	if (callback == showContact1 || callback == showContact2 || callback == showContact3 || callback == showContact4) {
		$("#contact-main, #contact-main img ").hide();
	}
	else {
		$("#contact1").hide();
		$("#contact2").hide();
		$("#contact3").hide();
		$("#contact4").hide();
		$("#contact-main").show();
		$("#contact").hide();
	}
	callback();
}

function showContact1() {
	$("#contact1 .text img").hide();
	$("#contact1 .title img").hide();
	$("#contact1 .back").hide();
	$("#contact1").show();
	$("#contact1 .title img").show('slide',{'direction':'right'},700);
	$("#contact1 .text img").delay(700, function(){ $(this).fadeIn(300);});
	$("#contact1 .back").delay(1000,function(){$(this).fadeIn(700);});
	
	fadeout = hideContact1;
}

function hideContact1(callback) {
	if (callback == showContact1) return;
	if (callback == showContact) {
		$("#contact1").hide();
		showContactMainQuick();
	}
	else {
		hideContact(callback);
	}
}

function showContact2() {
	$("#contact2 .text img").hide();
	$("#contact2 .title img").hide();
	$("#contact2 .back").hide();
	$("#contact2").show();
	$("#contact2 .title img").show('slide',{'direction':'right'},700);
	$("#contact2 .text img").delay(700, function(){ $(this).fadeIn(300);});
	$("#contact2 .back").delay(1000,function(){$(this).fadeIn(700);});
	
	fadeout = hideContact2;
}

function hideContact2(callback) {
	if (callback == showContact2) return;
	if (callback == showContact) {
		$("#contact2").hide();
		showContactMainQuick();
	}
	else {
		hideContact(callback);
	}
}

function showContact3() {
	$("#contact3 .text img").hide();
	$("#contact3 .title img").hide();
	$("#contact3 .back").hide();
	$("#contact3").show();
	$("#contact3 .title img").show('slide',{'direction':'right'},700);
	$("#contact3 .text img").delay(700, function(){ $(this).fadeIn(300);});
	$("#contact3 .back").delay(1000,function(){$(this).fadeIn(700);});
	
	fadeout = hideContact3;
}

function hideContact3(callback) {
	if (callback == showContact3) return;
	if (callback == showContact) {
		$("#contact3").hide();
		showContactMainQuick();
	}
	else {
		hideContact(callback);
	}
}

function showContact4() {
	$("#contact4 .text img").hide();
	$("#contact4 .title img").hide();
	$("#contact4 .back").hide();
	$("#contact4").show();
	$("#contact4 .title img").show('slide',{'direction':'right'},700);
	$("#contact4 .text img").delay(700, function(){ $(this).fadeIn(300);});
	$("#contact4 .back").delay(1000,function(){$(this).fadeIn(700);});
	
	fadeout = hideContact4;
}

function hideContact4(callback) {
	if (callback == showContact4) return;
	if (callback == showContact) {
		$("#contact4").hide();
		showContactMainQuick();
	}
	else {
		hideContact(callback);
	}
}
