var animateArray;
var animaticReady = true;
var imageReady = 0;
var imageTotal = 0;
var tTime = 500;

/*
$(document).ready(function(){documentReady()});

function documentReady() {

}
*/

function setAnimationArray(anArray) {
	animateArray = anArray;
}

function checkReady() {
	imageReady++;
	if(imageTotal == imageReady) playSlide();
}

function setKeyNavigation(previous, next) {
	previousURL = previous;
	nextURL = next;
	$('html').keydown(function(event){
		if(event.keyCode == 37) {
			location.href = previousURL;
		}else if(event.keyCode == 39){
			location.href = nextURL;
		}
	});
}

function playSlide() {
	$('#loading').hide();
	$("#titleText").css({'opacity':0});
	i = 0;
	for(object in animateArray) {
		if(animateArray[object]['image']) {
			playImage(animateArray[object]['image'], i);
			
		}else if(animateArray[object]['box']){
			playBox(animateArray[object]['box'], i);
			
		}else if(animateArray[object]['text']){
			playText(animateArray[object]['text'], i);
			
		}else if(animateArray[object]['animatic']){
			playAnimatic(animateArray[object]['animatic'], i);
		}
		i++;
	}
}

function playImage(image, index) {
	setTimeout(function(){ 
		$('#imageShadow'+index).animate({opacity:.5, left:image['endX'], top:image['endY']}, image['time']);
		$('#image'+index).animate({opacity:image['endAlpha'], left:image['endX'], top:image['endY']}, image['time']);
	}, image['delay']);
}

function playBox(box, index) {
	setTimeout(function(){ 
		$('#box'+index).animate({opacity:box['endAlpha'], left:box['endX'], top:box['endY']}, box['time']);
	}, box['delay']);
}
function playText(text, index) {
	setTimeout(function(){ 
		$('#text'+index).animate({opacity:text['endAlpha'], left:text['endX'], top:text['endY']}, text['time']);
	}, text['delay']);
}
function playAnimatic(animatic, index) {
	i = 0;
	delay = 0;
	$('#replay').css({display:'block'});
	for(anImage in animatic) {
		image = animatic[anImage];
		delay += image['delay'];
		playAnimaticImage(image, delay, index, i);
		i++;
	}
	
}
function playAnimaticImage(image, delay, index, i) {
	setTimeout(function(){
		if(i != 0) {
			$('#animaticShadow'+index+(i-1)).css({opacity:0});
			$('#animatic'+index+(i-1)).css({opacity:0});
		}
		$('#animaticShadow'+index+i).animate({opacity:.5, left:image['endX'], top:image['endY']}, image['time']);
		$('#animatic'+index+i).animate({opacity:image['endAlpha'], left:image['endX'], top:image['endY']}, image['time']);
	}, delay);
}
function playArchive() {
	setArchive();
	tTime = 300;
	delay = 100;
	delayCurrent = delay;
	$('#p1').animate({opacity:1},tTime);
	$('#p2').animate({opacity:1},tTime);
	$('#p3').animate({opacity:1},tTime);
	$('#p4').animate({opacity:1},tTime);
	$('#p5').animate({opacity:1},tTime);
	$('#p6').animate({opacity:1},tTime);
	setTimeout(function(){$('.imageShadow').animate({opacity:.5},tTime);}, delayCurrent);
	setTimeout(function(){$('#stockPhone').animate({opacity:1},tTime);}, delayCurrent);
	setTimeout(function(){$('#archiveGallery a').animate({opacity:1},tTime);}, delayCurrent);
}
function playContact() {
	setContact();
	$('.imageShadow').animate({opacity:.5}, tTime);
	$('#contact img').animate({opacity:1}, tTime,function(){
		tTime = 100;
		delay = 50;
		delayCurrent = delay;
		$('#email').animate({opacity:1},tTime);
		setTimeout(function(){$('#billPhone').animate({opacity:1},tTime);}, delayCurrent);
		delayCurrent += delay;
		setTimeout(function(){$('#rep').animate({opacity:1},tTime);}, delayCurrent);
		delayCurrent += delay;
		setTimeout(function(){$('#fredaPhone').animate({opacity:1},tTime);}, delayCurrent);
	});
}
function playClients() {
	setClients();
	$('.imageShadow').animate({opacity:.5}, tTime);
	$('#clients img').animate({opacity:1}, tTime,function(){
		tTime = 100;
		delay = 50;
		delayCurrent = delay;
		$('#c1').animate({opacity:1},tTime);
		setTimeout(function(){$('#c2').animate({opacity:1},tTime);}, delayCurrent);
		delayCurrent += delay;
		setTimeout(function(){$('#c3').animate({opacity:1},tTime);}, delayCurrent);
		delayCurrent += delay;
		setTimeout(function(){$('#c4').animate({opacity:1},tTime);}, delayCurrent);
		delayCurrent += delay;
		setTimeout(function(){$('#c5').animate({opacity:1},tTime);}, delayCurrent);
		delayCurrent += delay;
		setTimeout(function(){$('#c6').animate({opacity:1},tTime);}, delayCurrent);
		delayCurrent += delay;
		setTimeout(function(){$('#c7').animate({opacity:1},tTime);}, delayCurrent);
		delayCurrent += delay;
		setTimeout(function(){$('#c8').animate({opacity:1},tTime);}, delayCurrent);
		delayCurrent += delay;
		setTimeout(function(){$('#c9').animate({opacity:1},tTime);}, delayCurrent);
	});
}
function playHome() {
	setHome();
	$('#logoZ').animate({opacity:1}, tTime,function(){
		$('#bill').animate({left:"453px"}, tTime,function(){
			$('#emanek').animate({left:"15px"},tTime, function(){
				$('#photographer').animate({opacity:1},tTime, function(){
					$('.imageShadow').animate({opacity:.5},tTime);
					$('#homePhoto').animate({opacity:1},tTime, function(){
						playNav();
					});
				});
			});
		});
	});
}
function playSkills(page) {
	tTime = 200;
	delay = 100;
	delayCurrent = delay;
	setSkills();
	
	$('#skills img').animate({opacity:1}, tTime,function(){
		$('h1').animate({opacity:.75}, tTime,function(){
			$('#blueBox').animate({opacity:.75}, tTime,function(){
				$('#r1 .s1').animate({opacity:1}, tTime);
				setTimeout(function(){$('#r1 .s2').animate({opacity:1}, tTime);}, delayCurrent);
				delayCurrent += delay;
				setTimeout(function(){$('#r1 .s3').animate({opacity:1}, tTime);}, delayCurrent);
				delayCurrent += delay;
				setTimeout(function(){$('#r1 .s4').animate({opacity:1}, tTime);}, delayCurrent);
				delayCurrent += delay;
				setTimeout(function(){$('#r1 .s5').animate({opacity:1}, tTime);}, delayCurrent);
				delayCurrent += delay;
				setTimeout(function(){$('#r1 .s6').animate({opacity:1}, tTime);}, delayCurrent);
				delayCurrent += delay;
				setTimeout(function(){$('#r1 .s7').animate({opacity:1}, tTime);}, delayCurrent);
				delayCurrent += delay;
				setTimeout(function(){$('#r1 .s8').animate({opacity:1}, tTime);}, delayCurrent);
				setTimeout(function(){$('#whiteBox').animate({opacity:.75}, tTime, function() {
					delayCurrent = delay;
					$('#r2 span').animate({opacity:1}, tTime);
					/*
$('#r2 .s1').animate({opacity:1}, tTime);
					setTimeout(function(){$('#r2 .s2').animate({opacity:1}, tTime);}, delayCurrent);
					delayCurrent += delay;
					setTimeout(function(){$('#r2 .s3').animate({opacity:1}, tTime);}, delayCurrent);
					delayCurrent += delay;
					setTimeout(function(){$('#r2 .s4').animate({opacity:1}, tTime);}, delayCurrent);
					delayCurrent += delay;
					setTimeout(function(){$('#r2 .s5').animate({opacity:1}, tTime);}, delayCurrent);
					delayCurrent += delay;
					setTimeout(function(){$('#r2 .s6').animate({opacity:1}, tTime);}, delayCurrent);
					delayCurrent += delay;
					setTimeout(function(){$('#r2 .s7').animate({opacity:1}, tTime);}, delayCurrent);
					delayCurrent += delay;
					setTimeout(function(){$('#r2 .s8').animate({opacity:1}, tTime);}, delayCurrent);
*/
				});}, delayCurrent);
			});
		});
	});
}
function playNav() {
	tTime = 200;
	delay = 150;
	delayCurrent = delay;
	$('#portfolio').animate({opacity:1},tTime);
	setTimeout(function(){$('#stories').animate({opacity:1},tTime);}, delayCurrent);
	delayCurrent += delay;
	setTimeout(function(){$('#spaces').animate({opacity:1},tTime);}, delayCurrent);
	delayCurrent += delay;
	setTimeout(function(){$('#wineVine').animate({opacity:1},tTime);}, delayCurrent);
	delayCurrent += delay;
	setTimeout(function(){$('#visions').animate({opacity:1},tTime);}, delayCurrent);
	delayCurrent += delay;
	setTimeout(function(){$('#inPrint').animate({opacity:1},tTime);}, delayCurrent);
	delayCurrent += delay;
	setTimeout(function(){$('#archive').animate({opacity:1},tTime);}, delayCurrent);
	delayCurrent += delay;
	setTimeout(function(){$('#skills').animate({opacity:1},tTime);}, delayCurrent);
	delayCurrent += delay;
	setTimeout(function(){$('#clients').animate({opacity:1},tTime);}, delayCurrent);
	delayCurrent += delay;
	setTimeout(function(){$('#contact').animate({opacity:1},tTime);}, delayCurrent);
}
function setArchive() {
	$('#archiveGallery img, .imageShadow, #archiveGallery a, #archiveGallery #stockPhone').css({opacity:0});
	setImageShadow();
}
function setContact() {
	$('#contact img, .imageShadow, #billInfo div, #fredaInfo div').css({opacity:0});
	setImageShadow();
}
function setClients() {
	$('#clients img, .imageShadow, #left div, #right div').css({opacity:0});
	setImageShadow();
}
function setHome() {
	hideNav();
	$('#bill').css({left:"-55px"});
	$('#emanek').css({left:"-104px"});
	$('#homePhoto, .imageShadow, #logoZ, #photographer').css({opacity:0});
	setImageShadow();
}
function setSkills() {
	$('#skills img, p, .gallery .link, .gallery #links, #whiteBox, #blueBox, span, h1').css({opacity:0});
}
function hideNav() {
	$('#galleries li, #other li').css({opacity:0});
}
function setImageShadow() {
	$('.imageShadow').css({filter: "progid:DXImageTransform.Microsoft.Shadow(Strength=7, Direction=135, Color='#000000')"});
}
