///////////////////////////////////////////////////////////////////
// Written By Collin Schaafsma @ Quick Left (www.quickleft.com) for Theory and Craft //
///////////////////////////////////////////////////////////////////
var graph_key_01=new Array(7);
graph_key_01[0]="5";
graph_key_01[1]="2";
graph_key_01[2]="8";
graph_key_01[3]="11";
graph_key_01[4]="1";
graph_key_01[5]="0";
graph_key_01[6]="4";

var graph_key_02=new Array(7);
graph_key_02[0]="13";
graph_key_02[1]="26";
graph_key_02[2]="7";
graph_key_02[3]="4";
graph_key_02[4]="35";
graph_key_02[5]="11";
graph_key_02[6]="6";

var graph_key_03=new Array(7);
graph_key_03[0]="13";
graph_key_03[1]="7";
graph_key_03[2]="6";
graph_key_03[3]="0";
graph_key_03[4]="26";
graph_key_03[5]="11";
graph_key_03[6]="0";

var graph_key_04=new Array(7);
graph_key_04[0]="52";
graph_key_04[1]="44";
graph_key_04[2]="36";
graph_key_04[3]="28";
graph_key_04[4]="20";
graph_key_04[5]="12";
graph_key_04[6]="4";

var indicator_pos=new Array(1);
indicator_pos[0]="350.3";

$(document).ready(function(){
	//init graphs
	loadGraph('01','false');
	//init graph nav click handlers
	$('#graph-nav-01').click(function () { switchGraph('01'); });
	$('#graph-nav-02').click(function () { switchGraph('02'); });
	$('#graph-nav-03').click(function () { switchGraph('03'); });
	$('#graph-nav-04').click(function () { switchGraph('04'); });
	//init case study nav click handlers
	$('#case-study00').click(function () { loadCaseStudy('0'); });
	$('.lnk-back').click(function () { resetRegions(); });	
});

function switchGraph(key){
	//switch on state in nav
	$('#graph-nav li a').removeClass("on");
	$('#graph-nav-'+key).addClass("on");
	//adjust the graph
	loadGraph(key,'true');
}

function loadGraph(key,reset){
	//reset nav key
	if(reset == 'true') {resetGraphs(key);$('.graph-key').hide();$('#graph_key_'+key).slideDown();};
	//set graph heights for the first time
	if(reset == 'false') {
		$('#graph li.bar-00 div').animate({height:eval("graph_key_"+key)[0]}, {queue: 'graphs',scope: 'graphup',duration: 1000, easing: 'easeInOutExpo'});
		$('#graph li.bar-01 div').animate({height:eval("graph_key_"+key)[1]}, {queue: 'graphs',scope: 'graphup',preDelay: 400, duration: 1000, easing: 'easeInOutExpo'});
		$('#graph li.bar-02 div').animate({height:eval("graph_key_"+key)[2]}, {queue: 'graphs',scope: 'graphup',preDelay: 500, duration: 1000, easing: 'easeInOutExpo'});
		$('#graph li.bar-03 div').animate({height:eval("graph_key_"+key)[3]}, {queue: 'graphs',scope: 'graphup',preDelay: 600, duration: 1000, easing: 'easeInOutExpo'});
		$('#graph li.bar-04 div').animate({height:eval("graph_key_"+key)[4]}, {queue: 'graphs',scope: 'graphup',preDelay: 700, duration: 1000, easing: 'easeInOutExpo'});
		$('#graph li.bar-05 div').animate({height:eval("graph_key_"+key)[5]}, {queue: 'graphs',scope: 'graphup',preDelay: 800, duration: 1000, easing: 'easeInOutExpo'});
		$('#graph li.bar-06 div').animate({height:eval("graph_key_"+key)[6]}, {queue: 'graphs',scope: 'graphup',preDelay: 900, duration: 1000, easing: 'easeInOutExpo'});
	}
}

function loadCaseStudy(study){
	//load external html
	$('#concept-region').load('/case-study/case-'+study+'.html');
	//move red indicator
	moveIndicator(indicator_pos[study]);
	//cycle regions
	$('#work-region').fadeOut({queue: 'regions',scope: 'regionsout',speed:200});
	$('#graph-region').fadeOut({queue: 'regions',scope: 'regionsout',preDelay:200,speed:400});
	$('#mission-region').fadeOut({queue: 'regions',scope: 'regionsout',preDelay:500,speed:500});
	$('#back-region').fadeIn({queue: 'regions',scope: 'regionsin',preDelay:100,speed:800});
	$('#case-study-region-'+study).fadeIn({queue: 'regions',scope: 'regionsin',preDelay:500,speed:1100});
	//show case study
	$('#concept-region').slideDown({queue: 'regions',scope: 'regionsin',preDelay:1000,speed:1100});
}

function moveIndicator(position){
	$('#indicator').animate({left:position}, {duration: 2000, easing: 'easeInOutExpo'});
}

function resetGraphs(key){
	//loop through based on array and adjust heights based on key
	for (i=0;i<=6;i++){
		$('#graph li.bar-0'+i+' div').animate({height:eval("graph_key_"+key)[i]}, {duration: 1000, easing: 'easeInOutExpo'});
	}	
}

function resetRegions(){
	moveIndicator(140.3);
	//show case study
	$('#concept-region').fadeOut({queue: 'regions',scope: 'regionsin',speed:200});
	$('.case-study-region').fadeOut({queue: 'regions',scope: 'regionsin',preDelay:200,speed:400});
	$('#back-region').fadeOut({queue: 'regions',scope: 'regionsin',preDelay:500,speed:500});
	$('#mission-region').fadeIn({queue: 'regions',scope: 'regionsout',preDelay:700,speed:700});
	$('#graph-region').fadeIn({queue: 'regions',scope: 'regionsout',preDelay:900,speed:700});
	$('#work-region').fadeIn({queue: 'regions',scope: 'regionsout',preDelay:1100,speed:700});	
}


