/**
 * @author tkahn
 */

//cookie reading
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

//end cookies
//Browser Detection
var d, dom, ie, ie4, ie5x, moz, mac, win, lin, old, ie5mac, ie5xwin, op, other;

d = document;
n = navigator;
na = n.appVersion;
nua = n.userAgent;
win = ( na.indexOf( 'Win' ) != -1 );
mac = ( na.indexOf( 'Mac' ) != -1 );
lin = ( nua.indexOf( 'Linux' ) != -1 );

if ( !d.layers ){
	dom = ( d.getElementById );
	op = ( nua.indexOf( 'Opera' ) != -1 );
	konq = ( nua.indexOf( 'Konqueror' ) != -1 );
	saf = ( nua.indexOf( 'Safari' ) != -1 );
	moz = ( nua.indexOf( 'Gecko' ) != -1 && !saf && !konq);
	ie = ( d.all && !op );
	ie4 = ( ie && !dom );

	/*
	ie5x tests only for functionality. ( dom||ie5x ) would be default settings. 
	Opera will register true in this test if set to identify as IE 5
	*/

	ie5x = ( d.all && dom );
	ie5mac = ( mac && ie5x );
	ie5xwin = ( win && ie5x );
}
//End Browser Detection
function appear(){
	// if 'effects' cookie is set (should be '1', execute effects
	if (readCookie('effects') > 0 || readCookie('effects')==null)
	{
		var i;
		if (document.getElementById('categoryContent')){
			Effect.Appear('categoryContent', { duration: 2.0, from: 0.0});
		}
		if (saf || konq)
		{
			//Webkit does not play well
			setTimeout("document.getElementById('imageContainer').style.display='block'", 10);
		}
		else{
			Effect.Appear('imageContainer', { duration: 2.0, from: 0.1});
		}
		
		if (document.getElementById('categoryLinks')) {
			Effect.Appear('categoryLinks', {duration: 2.0, from: 0.1})
		}
		
		if (document.getElementById('categoryContentCreative')) {
			Effect.BlindDown('categoryContentCreative', {duration: 2.5});
			
		}
	
		// special vertical cascade fade-in on whoweare\awards\index.html
		if(document.getElementById('listItem0'))
		{
			for(i=0; document.getElementById('listItem'+i); i++)
			{
				setTimeout("Effect.Appear('listItem"+i+"', {duration: 3.0, from: 0.0})", i*50);
			}
		}
	}
	else {
		if (document.getElementById('categoryContent')){
			document.getElementById('categoryContent').style.display="block";
		}
		if (saf || konq)
		{
			//Webkit does not play well
			document.getElementById('imageContainer').style.display='block';
		}
		else{
			document.getElementById('imageContainer').style.display="block";
		}
		
		if (document.getElementById('categoryLinks')) {
			document.getElementById('categoryLinks').style.display="block";
		}
	
		if (document.getElementById('categoryContentCreative')) {
			document.getElementById('categoryContentCreative').style.display="block";
		
		}
		if(document.getElementById('listItem0'))
		{
			for(i=0; document.getElementById('listItem'+i); i++)
			{
				//Effect.Appear('listItem'+i, {duration: 3.0, from: 0.0});
				document.getElementById('listItem'+i).style.display="block";
			}
		
		}
	}
	
}
// if user clicks the "ask our clients" link on whoweare\ourcommitments\index.html, loop through the bell plus four client quote images
// by fading them in, holding for waitTime seconds, fading them out and moving to the next
function showClients(){
	if (started < 1) //started == 0
	{
		started = 2;
		var waitTimeFirst = 4.0;
		var waitTimeSecond = 4.0;
		var waitTimeThird = 5.0;
		var waitTimeFourth = 5.0;
		var total = waitTimeFirst + waitTimeSecond + waitTimeThird + waitTimeFourth;
		var aduration = 2.0;
		var fduration = 1.0;
		
		var fwait = new Array();
		var await = new Array();
		
		await[0] = fduration * 1000;
		fwait[0] = waitTimeFirst * 1000 + await[0];
		
		await[1] = fduration * 1000 + fwait[0];
		fwait[1] = waitTimeSecond * 1000 + await[1];
		
		await[2] = fduration * 1000 + fwait[1];
		fwait[2] = waitTimeThird * 1000 + await[2];
		
		await[3] = fduration * 1000 + fwait[2];
		fwait[3] = waitTimeFourth * 1000 + await[3];
		
		await[4] = fduration * 1000 + fwait[3];
		
		Effect.Fade('imageContainer', {duration: fduration});
		setTimeout("Effect.Appear('askClient0', {duration: " + aduration + "})", await[0]);
		
		for (i = 0; document.getElementById('askClient' + i); i++) {
			
			setTimeout("Effect.Fade('askClient" + i + "', {duration: " + fduration + "})", fwait[i]);
			setTimeout("Effect.Appear('askClient" + (i + 1) + "', {duration: " + aduration + "})", await[i + 1])
			
			if (!document.getElementById('askClient' + (i+1))) {
				
				setTimeout("Effect.Fade('askClient" + (i+1) + "', {duration: " + fduration + "})", fwait[i + 1]);
				setTimeout("Effect.Appear('imageContainer', {duration: " + aduration + "})", await[i+1]);
				
			}
		}
		// this line protects the script from breaking if the user clicks "Ask our Clients" while the images are fading in and out
		setTimeout("started=0",((total+7)*1000));
	}
	else{
		;
	}
}

// controls fade-in of interns on whoweare\interns\index.html
// maximum pixel height of 1000 pixels or it becomes auto height
function internsAppear(){
	if (readCookie('effects') > 0 || readCookie('effects')==null)
	{
	Effect.Appear('heather', {duration: 3.0});
	setTimeout("Effect.Appear('courtney', {duration: 3.0})", 1000);
	setTimeout("Effect.Appear('agnes', {duration: 3.0})", 2000);
	setTimeout("Effect.Appear('minji', {duration: 3.0})", 3000);
	setTimeout("Effect.Appear('nick', {duration: 3.0})", 4000);
	setTimeout("Effect.Appear('sarah', {duration: 3.0})", 5000);
	
	setTimeout("document.getElementById('centerContainer2').style.height='auto';", 1000)
	}
	else {
		document.getElementById('heather').style.display="block";
		document.getElementById('courtney').style.display="block";
		document.getElementById('agnes').style.display="block";
		document.getElementById('minji').style.display="block";
		document.getElementById('nick').style.display="block";
		document.getElementById('sarah').style.display="block";
		document.getElementById('centerContainer2').style.height='auto';
	}
}

function contactUsClick(){
	//add href = #
	document.getElementById('currentPage').id=null;
	document.getElementById('formPage').id="currentPage";
	if (document.getElementById('categoryContent2')){
		Effect.Fade('categoryContent', { duration: .75, from: 0.0});
		setTimeout("Effect.Appear('categoryContent2', { duration: 1.0, from: 0.0})", 750);
	}
}

// switches between div firstDiv and div additionalLinks on whoweare\awards\index.html
function showAdditionalLinks()
{
	Effect.Fade('firstDiv', {duration: 1.0});
	setTimeout("Effect.Appear('additionalLinks', {duration: 3.0})", 1000);
	document.getElementById('eventStart').onclick=";";
}

// absolutely positions featured project div rightContainer on whatwevedone\index.html
// because in IE6 it is too wide for the containing div and is forced to the next line (box model bug)
function fixIE6Featured()
{
	// var ie is set at the top of this js include script
	// window.XMLHttpRequest is a function that IE6 can't do but IE7 can
	if (ie && !window.XMLHttpRequest)
	{
		document.getElementById('rightContainer').style.position="absolute";
		document.getElementById('rightContainer').style.top="90px";
		document.getElementById('rightContainer').style.left="500px";
	}
}
