/*
	Sequence.com Custom Wordpress Theme Javascript
	Written by Amadeus Demarzi
	Copyright 2009, Sequence
*/
var cookieStatus = Cookie.read('interactive');
// If the user is using IE6 or an iPod/iPhone, turn off interactive mode
//Browser.Platform.ipod
if((Browser.Engine.version==4 && Browser.Engine.name=='trident') || (window.screen.height<=768))
{
	Cookie.write('interactive','no',{ duration:365, domain:window.location.hostname, path:'/' });
	// There was no cookie originally, set the flag to show the lofi message
	if(cookieStatus==null) window.showMessage = true;
}
// Respect the clients choice if they prefer low-fi mode, otherwise give them hi-fi by default
else if(cookieStatus==null)
{
	Cookie.write('interactive','yes',{ duration:365, domain:window.location.hostname, path:'/' });
	cookieStatus = 'yes';
}
// If client is PC based...
if(cookieStatus=='yes')
{
	// Ensure the user is not being hotlinked to a direct URL.
	// If so, rewrite the URL to the homepage with the interactive URL
	// Otherwise, proceed with document initialization
	var tLoc = window.location;
	if(tLoc.pathname.length>1) tLoc.replace('http://'+tLoc.hostname+'#'+tLoc.pathname);
	else window.addEvent('domready',function(){ utils.checkRes(); interactive.init(); });
}
else
{
	
	window.addEvent('domready',function()
	{
		if(window.showMessage)
		{
			utils.showAlert();
			Cufon.replace('#lofi_alert h4');
		}
		utils.checkRes();
		utils.setCufon();
		whatsnew.init();
		utils.ranHome();
		utils.injectEmail();
		utils.loadMap();
		utils.accordianInit();
		
		utils.fixIETeam();
		
		if($('client_list'))
		{
			$('client_list').addEvent('mouseover',function(){ this.style.height = 'auto'; });
			$('client_list').addEvent('mouseout',function(){ this.style.height = '0'; });
		}
		
		utils.clearLoginForm('add');
		
		if($('mediaspace'))
		{
			$('mediaspace').addEvent('click',function(){
				if(!window.temp)
				{
					window.temp = true;
					var so = new SWFObject('http://sequence.com/wp-content/general_assets/player.swf','mpl','625','440','9');
					so.addParam('allowfullscreen','true');
					so.addParam('allowscriptaccess','always');
					so.addParam('wmode','transparent');
					so.addVariable('file','http://sequence.com/wp-content/general_assets/HolidayCard_512K.flv');
					so.addVariable('autostart','true');
					so.addVariable('screencolor','transparent');
					so.write('mediaspace');
				}
			});
			
			$('page_shh').addEvents({
				'mousedown':function(e){ e.stopPropagation(); },
				'click':function(e){ e.stopPropagation(); }
			});
		}
		
		// Make sure the user is not using IE6 or an iPhone/iPod
		if((Browser.Engine.version!=4 && Browser.Engine.name!='trident') && !Browser.Platform.ipod) utils.createHifi(false);
	});
}

var interactive =
{
	shade: null,
	body: null,
	bodyInfo: null,
	
	mapContainer: null,
	map: null,
	
	textView: null,
	
	xConstant: null,
	yConstant: 70,
	
	dragMe: null,
	dragging:false,
	
	init: function()
	{
		// Setup scope shortcut
		var th = window.interactive;
		
		// Setup body object
		th.body = $(document.body);
		th.bodyInfo = th.body.getSize();
		
		// Setup shade object
		var tSh = new Element('div',{ id:'shade' });
		tSh.inject(th.body);

		th.shade = new Fx.Elements([tSh,$('mast_head')],{
			duration:500,
			fps:1000,
			link:'cancel',
			transition: 'sine:out',
			onStart: function(){ interactive.animating = true; },
			onComplete: function(){ interactive.animating = false; }
		});
		
		// Remove the footer
		$('footer').destroy();
		
		// Start creating the dynamic layers
		th.mapContainer = new Element('div',{ id:'mapContainer' });
		var tMap = new Element('div',{ id: 'map' });
		
		tMap.inject(th.mapContainer);
		
		th.textView = new Element('div',{ id:'text_view' });
		
		data.preLoad = new Element('div',{ id: 'pre_load' });
		$('page_home').inject(data.preLoad);
		
		dialogue.container = new Element('div',{ id: 'dialogue' });
		dialogue.container.style.display = 'none';
		dialogue.loaderObj = new Element('div',{ id: 'loader' });
		dialogue.projectObj = new Element('div',{ id: 'project_info_window' });
		var tempLoaderS = new Element('div',{ id: 'spinner' });
		
		tempLoaderS.inject(dialogue.loaderObj);
		dialogue.loaderObj.inject(dialogue.container);
		dialogue.projectObj.inject(dialogue.container);
		
		th.mapContainer.inject(tSh,'before');
		dialogue.container.inject(tSh,'after');
		th.textView.inject(tSh,'after');
		data.preLoad.inject(dialogue.container,'after');
		
		presentation.load();
		
		// Map Animator
		th.map = new Fx.Morph(tMap,{
			duration:1500,
			fps:1000,
			transition:'quad:out',
			onStart: function()
			{
				interactive.animating = true;
			},
			onComplete: function()
			{
				interactive.map.options.duration = 1000;
				interactive.map.options.transition = 'quad:in:out';
				interactive.animating = false;
				nav.interpret();
			}
		});
		
		// Set Masthead positioning
		th.shade.set({
			0:{ width:th.bodyInfo.x,height:th.bodyInfo.y},
			1:{ position:'fixed',margin:'0',top:-94}
		});
		
		if(window.IE7) window.IE7.recalc();
		
		// Initiate Resize
		th.resize();
		
		// Move the map up, and our of view
		var wInfo = window.getSize();
		interactive.map.set({top:wInfo.y+20});
		
		window.addEvent('resize',interactive.resize);
		
		data.get('load');
	},
	
	resize: function()
	{
		var th = window.interactive;
		var wInfo = window.getSize();
		var bInfo = th.body.getSize();
		
		th.xConstant = parseInt(bInfo.x/2,10);
		th.xConstant = th.xConstant - 440;
		
		th.mapContainer.style.width = bInfo.x+'px';
		th.mapContainer.style.height = wInfo.y+'px';
		
		presentation.container.style.width = bInfo.x+'px';
		presentation.container.style.height = wInfo.y+'px';
		presentation.toolbar.style.left = th.xConstant+'px';
		presentation.viewer.style.width = bInfo.x-40+'px';
		presentation.viewer.style.height = wInfo.y-210+'px';
		
		
		var animTo = utils.getSet(loc.current.coords[0],loc.current.coords[1]);
		th.map.set(animTo);
		
		th.shade.set({ 
			0:{ width:bInfo.x,height:wInfo.y },1:{ 'left':th.xConstant }
		});
		
		if(window.IE7) window.IE7.recalc();
	},
	
	setZoneState: function(type)
	{
		var th = interactive;
		//if(el.obj.className!='zone') 
		if(type=='reset') loc.zones.each(function(el){ el.obj.className='zone dragging'; });
		else
		{
			var currentId = loc.current.zone_id;
		
			loc.zones.each(function(el){
				if(el.obj.id==currentId && el.obj.className!='zone') el.obj.className='zone';
				else if(el.obj.className!='zone secondary' && el.obj.id!=currentId) el.obj.className='zone secondary';
			});
			interactive.dragging = false;
		}
	},
	
	setupDragDrop: function()
	{
		interactive.dragMe = new Drag($(interactive.map.element),
		{
			onStart: function()
			{
				if(loc.current.list[0]=='team' && loc.current.list[1]) team.currentSubPage = loc.current.list[1];
				if(interactive.animating==true)
				{
					interactive.dragMe.stop();
					return;
				}
				// Disable drag if on the selected zone
				if(interactive.dragging==true)
				{
					interactive.dragging=false;
					interactive.dragMe.stop();
				}
				else
				{
					clearInterval(nav.timer);
					interactive.dragging = true;
					interactive.setZoneState('reset');
					document.body.style.cursor = 'move';
				}
			},
			onComplete: function()
			{
				// Get Drag Element, it's grid position, and zone name
				var el = this.element;
				var newLoc = utils.determineLocation(el.style.top,el.style.left);
				var tString = utils.gridToString(newLoc[0],newLoc[1]);
				
				if(loc.current.list[0]=='team' && tString=='team' && team.currentSubPage) // If we are snapping back to the teampage with a subview!
				{
					tString+='/'+team.currentSubPage;
					team.currentSubPage = null;
				}
				
				// Set animation options for dragging
				interactive.map.options.duration = 400;
				interactive.map.options.transition = 'back:out';
				document.body.style.cursor = 'auto';
				
				// Check if we are at a new location, if so, update URL, otherwise snap back
				if(window.location.hash!='#/'+tString+'/')
				{
					window.location.hash = '/'+tString+'/';
					nav.detect(window.location.hash);
				}
				else
				{
					
					var animTo = utils.getSet(newLoc[0],newLoc[1]);
					interactive.map.start(animTo);
				}
			}
		});
	}
};

var loc =
{
	current:
	{
		hash:'/load/',
		list:['load'],
		view:null,
		zone_id:null,
		coords:[0,1]
	},
	
	stored: {
		hash:null,
		list:[],
		view:null,
		zone_id:null,
		coords:[null,null]
	},
	
	zones:
	[
		{
			name:'whatwedo',
			coords:[0,0],
			obj:null
		},
		{
			name:'home',
			coords:[0,1],
			obj:null
		},
		{
			name:'whoweare',
			coords:[0,2],
			obj:null
		},
		{
			name:'team',
			coords:[1,0],
			obj:null
		},
		{
			name:'ourwork',
			coords:[1,1],
			obj:null
		},
		{
			name:'whatsnew',
			coords:[1,2],
			obj:null
		},
		{
			name:'shh',
			coords:[2,0],
			obj:null
		},
		{
			name:'careers',
			coords:[2,1],
			obj:null
		},
		{
			name:'contact',
			coords:[2,2],
			obj:null
		}
	],
	
	set: function(string,tList,view)
	{
		if(string) loc.current.hash = utils.rebuildHash(string);
		if(tList)
		{
			loc.current.list.length = 0;
			for(var x=0;x<tList.length;x++) loc.current.list[x] = tList[x];
			
			var index = utils.getZoneIndex(loc.current.list[0]);
			loc.current.coords = loc.zones[index].coords;
			loc.current.zone_id = loc.zones[index].obj.id;
		}
		if(view) loc.current.view = view;
	}
};

var data =
{
	job_email:"<n uers=\"znvygb:wbof\100frdhrapr\056pbz\">wbof\100frdhrapr\056pbz<\057n>".replace(/[a-zA-Z]/g,function(c){return String.fromCharCode((c<="Z"?90:122)>=(c=c.charCodeAt(0)+13)?c:c-26);}),
	// Info Email-to be enabled when ready!
	contact_email: "<n uers=\"znvygb:vasb\100frdhrapr\056pbz\">vasb\100frdhrapr\056pbz<\057n>".replace(/[a-zA-Z]/g, function(c){return String.fromCharCode((c<="Z"?90:122)>=(c=c.charCodeAt(0)+13)?c:c-26);}),
	//contact_email: "<n uers=\"znvygb:frgu\100frdhrapr\056pbz\">frgu\100frdhrapr\056pbz<\057n>".replace(/[a-zA-Z]/g, function(c){return String.fromCharCode((c<="Z"?90:122)>=(c=c.charCodeAt(0)+13)?c:c-26);}),
	// Holds all blocks of content, returned on AJAX calls
	content: null,
//	contentTotal:null,
	contentCount:0,
	// Type of calls being specified
	type: null,
	
	homeURLs:
	[
		'whatwedo/',
		'whoweare/',
		
		'team/',
		'ourwork/',
		'whatsnew/',
		
		'shh/',
		'careers/',
		'contact/'
	],
	
	ajax: new Request.HTML({
		method: 'get',
		link:'chain',
		//url: 'http://'+window.location.host+'/wp-content/themes/sequence/launch_pad.php',
		url: 'http://'+window.location.host+'/',
		onRequest: function()
		{
			dialogue.show('loader');
		},
		onSuccess: function(rObj,rEls,rHTML)
		{
			var th = window.data;
			
			// Preload content
			th.preLoad.innerHTML += rHTML;
			th.content = th.preLoad.getChildren();
			
			// Set any children A tags with Click Intercept
			var aTags = th.content.getElements('a');
			utils.setAnchorIntercept(aTags);
			
			// Proceed with injection
			th.inject();
		},
		// Will be fleshed out to use real dialogues later
		onFailure: function() { console.log('whoops!'); }
	}),

	get: function(type,urls)
	{
		var th = window.data;
		th.type = type;
		switch(type)
		{
			case 'load':
				th.contentTotal = th.homeURLs.length;
				th.homeURLs.each(function(url){
					new Request.HTML({
						method:'get',
						url: 'http://'+window.location.host+'/',
						onSuccess: function(rObj,rEls,rHTML)
						{
							var th = window.data;
							th.preLoad.innerHTML += rHTML;
							th.contentCount++;
							
							if(th.contentCount == th.homeURLs.length)
							{
								th.content = th.preLoad.getChildren('.zone');
								
								var aTags = th.content.getElements('a');
								utils.setAnchorIntercept(aTags);
								
								th.inject();
							}
						}
					}).get(url+'?min=true');
				});
				
				break;
			case 'team-member':
				th.ajax.get(urls+'?min=true');
				break;
			default: break;
		}
	},
	
	inject: function()
	{
		var th = window.data;
		
		if(th.type=='load')
		{
			// Inject content into pre-loader, and setup the data objects
			th.content.each(function(el)
			{ 
				el.inject(interactive.map.element);
				
				var tId = utils.convertId(el.id);
				tId = utils.getZoneIndex(tId);
				loc.zones[tId].obj = el;
			});
			
			utils.ranHome();
			utils.injectEmail();
			utils.loadMap();
			utils.setCufon();
			utils.accordianInit();
			utils.fixIETeam();
			utils.clearLoginForm('add');			
			interactive.setupDragDrop();
			utils.createHifi(true);
			whatsnew.init();
			
			var wI = window.getSize();
			dialogue.hide('loader');
			interactive.shade.chain(
				function()
				{
					this.start({
						0:{'top':wI.y/2,'height':0},
						1:{'top':0}
					});
				},
				function()
				{
					this.set({ 0:{'top':0,'display':'none' }});
					if(window.IE7) window.IE7.recalc();
					nav.init();
				}
			);
			
			if($('mediaspace'))
			{
				$('mediaspace').addEvent('click',function(){
					if(!window.temp)
					{
						window.temp = true;
						
						window.temp = true;
						var so = new SWFObject('http://sequence.com/wp-content/general_assets/player.swf','mpl','625','440','9');
						so.addParam('allowfullscreen','true');
						so.addParam('allowscriptaccess','always');
						so.addParam('wmode','transparent');
						so.addVariable('file','http://sequence.com/wp-content/general_assets/HolidayCard_512K.flv');
						so.addVariable('autostart','true');
						so.addVariable('screencolor','transparent');
						so.write('mediaspace');
						
						$('page_shh').addEvents({
							'mousedown':function(e){ e.stopPropagation(); },
							'click':function(e){ e.stopPropagation(); }
						});
					}
				});
			}
			
			interactive.shade.callChain();
		}
		if(th.type=='team-member')
		{
			th.content[0].getElement('h2').destroy();
			th.content[0].style.visibility = 'hidden';
			
			th.content[0].inject(loc.zones[3].obj.getElement('.content'));
			
			th.content = null;
			dialogue.hide('loader');
			team.show();
		}
	}
};

var nav =
{
	timer: null,
	
	zoneObjects: {},
	view: null,
	
	init: function()
	{
		var th = window.nav;
		
		// If there is no hash, set it!
		if(!window.location.hash)
		{
			th.view = 'view-zone';
			loc.current.view = 'view-zone';
			window.location.replace('http://'+window.location.hostname+'#/home/');
			//window.location.hash = '/home/';
		}
		else
		{
			var newHash = utils.rebuildHash(window.location.hash);
			th.view = th.determineView(newHash);
			//th.view = 'view-zone';
			loc.current.view = 'view-zone';
			window.location.replace('http://'+window.location.hostname+'#'+newHash);
		}
		
		var headerLinks = $$('#mast_head a');
		utils.setAnchorIntercept(headerLinks);
		
		th.timer = setInterval(function(){ nav.detect(window.location.hash); },100);
	},
	
	// Only used for loading. This needs to be managed independently
	determineView: function(hash)
	{
		var list = nav.convert(hash);
		var tempView = 'view-zone';
		
		if(list[1])
		{
			switch(list[0])
			{
				case 'ourwork':
					tempView = 'view-presentation';
					break;
				case 'team':
					tempView = 'view-sub_zone';
					break;
				default: break;
			}
		}
		return tempView;
	},
	
	clickIntercept: function(e)
	{
		// Get HREF and Rel
		var href = this.href;
		if(this.rel) var rel = this.rel;
		else var rel = 'view-zone';
		
		var pZone = this.getParent('.zone');
		
		if((pZone==null && interactive.dragging==false) || (pZone && pZone.className=='zone' && interactive.dragging==false))
		{
			e.preventDefault();
			if(href.test(utils.isHome))
			{
				var loc = href.replace(utils.isHome,'');
				
				// If Home Page
				if(loc.length<3)
				{
					rel = 'view-zone';
					nav.view = rel;
					window.location.hash = "/home/";
				}
				// Otherwise put up the location as a hash tag!
				else
				{
					loc = utils.rebuildHash(loc);
					nav.view = rel;
					window.location.hash = loc;
				}
			}
			else if(href=='http://blog.sequence.com/') window.location = href;
			else window.open(this.href);
		}
		else e.preventDefault();
	},
	
	detect: function(hash)
	{
		var th = window.nav;
		
		// Clean up the hash
		hash = utils.rebuildHash(hash);
		// Are we moving to a new location?
		if(hash!=loc.current.hash)
		{
			clearInterval(th.timer);
			window.location.replace('http://'+window.location.hostname+'#'+hash);
			
			loc.stored.hash = hash;
			loc.stored.list = th.convert(hash);
			if(!nav.view) loc.stored.view = th.determineView(hash);
			else loc.stored.view = nav.view;
			
			nav.view = null;
			
			th.interpret();
		}
	},
	
	// This is the meat and potatoes! it determines what to do with the URL!
	interpret: function()
	{
		
		var th = window.nav;
		// If we have finished the movement - clear the stored variable and exit out
		if((loc.current.hash==loc.stored.hash) || loc.stored.hash==null )
		{
			clearInterval(nav.timer);
			interactive.setZoneState();
			utils.resetStored();
			nav.setNavBar();
			nav.setTitle();
			
			if(loc.current.list[0]=='team' && team.currentSubPage!=null) // We have a sub page to enable
			{
				window.location.replace('http://'+window.location.hostname+'/#/team/'+team.currentSubPage+'/');
				loc.current.list[1] = team.currentSubPage;
				loc.set('/team/'+team.currentSubPage+'/',[loc.current.list[0],team.currentSubPage],'view-sub_zone');
				team.currentSubPage = null;
			}
			
			nav.timer = setInterval(function(){ nav.detect(window.location.hash); },100);
			return;
		}
		// Are we in the right zone yet?
		if(loc.current.list[0]!=loc.stored.list[0] && loc.current.view=='view-presentation') // Not in the right zone, with a presentation subview 
		{
			//console.log('2. Not in the right zone, with a subview');
			var viewToRemove = loc.current.view;
			loc.set(loc.current.list[0],[loc.current.list[0]],'view-zone');
			var properties = [viewToRemove,loc.current.list[0]];
			th.execute('remove',properties);
			return;
		}
		if(loc.current.list[0]!=loc.stored.list[0] && loc.current.view=='view-sub_zone') // Not in the right zone, with a team member
		{
			//console.log('2.1 Not in the right zone, with a subview that we are leaving...');
			team.currentSubPage = loc.current.list[1];
			loc.set(loc.stored.list[0], [loc.stored.list[0]],'view-zone');
			var index = utils.getZoneIndex(loc.stored.list[0]);
			th.execute('move',loc.zones[index].coords);
			return;
		}
		if(loc.current.list[0]!=loc.stored.list[0] && loc.current.view=='view-zone') // Not in the right zone, with no subview
		{
			//console.log('3. Not in the right zone, with no subview');
			loc.set(loc.stored.list[0], [loc.stored.list[0]]);
			var index = utils.getZoneIndex(loc.stored.list[0]);
			th.execute('move',loc.zones[index].coords);
			return;
		}
		if(loc.current.list[0]==loc.stored.list[0] && loc.current.view!=loc.stored.view && loc.current.list.length>loc.stored.list.length) // In the right zone, need to hide a sub view
		{
			//console.log('4. In the right zone, need to hide a sub view');
			var viewToRemove = loc.current.view;
			loc.set(window.location.hash,loc.stored.list,loc.stored.view);			
			var properties = [viewToRemove,loc.stored.list[0]];
			th.execute('remove',properties);
			return;
		}
		if(loc.current.list[0]==loc.stored.list[0] && loc.current.view!=loc.stored.view && loc.current.list.length<loc.stored.list.length) // In the right zone, need to show a sub view
		{                                                                                                                                     
			//console.log('5. In the right zone, need to show a sub view');
			loc.set('/'+loc.stored.list[0]+'/'+loc.stored.list[1]+'/',[loc.stored.list[0],loc.stored.list[1]],loc.stored.view);
			var properties = [loc.stored.view,'/'+loc.stored.list[0]+'/'+loc.stored.list[1]+'/'];
			if(loc.current.list[0]=='team' && team.currentSubPage) return nav.interpret(); // We actually do not need to show a subview if on the teampage and there is a stored page there
			else th.execute('show',properties);
		}
		// In the right zone, just need to update the zone location
		else
		{
			//console.log('6. In the right zone, just need to update the zone location');
			if(loc.current.view=='view-presentation')
			{
				if(!window.loc.stored.list[2]) // Error checking in case a bad variable is given
				{
					loc.stored.list[2] = 0;
					var tempHash = '/'+loc.stored.list[0]+'/'+loc.stored.list[1]+'/'+loc.stored.list[2]+'/';
					loc.stored.hash = tempHash;
					window.location.replace('http://'+window.location.hostname+'#'+loc.stored.hash);
				}
				loc.set(window.location.hash, loc.stored.list);
				th.execute('change',[loc.current.view,loc.current.list[1],loc.current.list[2]]);
				return;
			}
			if(loc.current.view=='view-sub_zone')
			{
				loc.set(window.location.hash, loc.stored.list);
				th.execute('change',[loc.current.view,loc.current.hash]);
			}
		}
	},
	
	execute: function(type,properties)
	{
		switch(type)
		{
			case 'move':
				interactive.setZoneState('reset');
				var animTo = utils.getSet(properties[0],properties[1]);
				interactive.map.start(animTo);
				break;
			case 'remove':
				if(properties[0]=='view-presentation') presentation.hide(properties[1]);
				if(properties[0]=='view-sub_zone') team.remove();
				break;
			case 'show':
				if(properties[0]=='view-presentation') presentation.show(properties[1]);
				if(properties[0]=='view-sub_zone') team.get(properties[1]);
				break;
			case 'change':
				if(properties[0]=='view-presentation')
				{
					presentation.location = [loc.current.list[2],loc.current.list[1]];
					presentation.placeImage();
				}
				if(properties[0]=='view-sub_zone')
				{
					team.get(properties[1]);
				}
				break;
			default:
				console.log('not sure what to do with: '+type);
				break;
		}
	},
	
	convert: function(string)
	{
		// Split hash based on slashes
		var tlist = string.split('/');
		
		// Clean up array - remove hash and spaces
		tlist.each(function(string,index,container){ if(string=='#' || string=='') container.splice(index,1); });
		return tlist;
	},
	
	setNavBar: function()
	{
		var newId = 'nav_'+loc.current.list[0];
		var els = $('navigation').getElements('li');
		
		els.each(function(el){
			if(el.id==newId) el.className = 'current_page';
			else el.className = '';
		});
	},
	
	setTitle: function()
	{
		var titleString = '';
		switch(loc.current.list[0])
		{
			case 'whatwedo':
				titleString = 'sequence :: what we do';
				break;
			case 'whoweare':
				titleString = 'sequence :: who we are';
				break;
			case 'team':
				titleString = 'sequence :: team';
				break;
			case 'ourwork':
				titleString = 'sequence :: our work';
				break;
			case 'whatsnew':
				titleString = 'sequence :: what\'s new';
				break;
			case 'shh':
				titleString = 'sequence :: shh';
				break;
			case 'careers':
				titleString = 'sequence :: careers';
				break;
			case 'contact':
				titleString = 'sequence :: contact';
				break;
			default:
				titleString = 'sequence :: brand experience strategy and design';
				break;
		}
		
		if(loc.current.list[1])
		{
			switch(loc.current.list[1])
			{
				case 'chipotle':
					titleString += ' :: chipotle';
					break;
				case 'sonos':
					titleString += ' :: sonos';
					break;
				case 'chevron':
					titleString += ' :: chevron';
					break;
				case 'nclr':
					titleString += ' :: nclr';
					break;
				case 'myspace':
					titleString += ' :: myspace';
					break;
				case 'zinio':
					titleString += ' :: zinio';
					break;
				case 'other':
					titleString += ' :: other great peeps';
					break;
				default: break;
			}
		}
		
		document.title = titleString;
	}
};

var whatsnew = {
	blogContainer:null,
	blogPos:null,
	blogNext:null,
	blogPrev:null,
	blogEntries:null,
	
	init: function()
	{
		var th = whatsnew;
		if($('blog_entries'))
		{
			th.blogContainer = $('blog_entries');
		
			var els = th.blogContainer.getElements('.blog_entry');
		
			th.blogEntries = new Fx.Elements(els,{
				duration:500,
				fps:1000
			});
		
			th.blogEntries.set({
				0:{ position:'absolute', opacity:1, left:0 },
				1:{ position:'absolute', opacity:0, left:0 },
				2:{ position:'absolute', opacity:0, left:0 }
			});
		
			th.blogNext = new Element('div',{ id:'btn_blog_next',html:'next' });
			th.blogPrev = new Element('div',{ id:'btn_blog_prev',html:'previous' });
		
			th.blogNext.addEvent('click',function(){ whatsnew.cycle('next'); });
			th.blogPrev.addEvent('click',function(){ whatsnew.cycle('prev'); });
		
			th.blogNext.addEvent('mouseover',function(){ this.className='hovered'; });
			th.blogNext.addEvent('mouseout',function(){ this.className=''; });
			th.blogPrev.addEvent('mouseover',function(){ this.className='hovered'; });
			th.blogPrev.addEvent('mouseout',function(){ this.className=''; });
		
			$('page_whatsnew').getElement('.content').adopt(th.blogNext,th.blogPrev);
		
			th.blogPos = 0;
		}
	},
	
	cycle: function(direction)
	{
		var th = whatsnew;
		
		var setObj = {};
		var animObj = {};
		
		if(direction=='next')
		{
			var oldPos = th.blogPos;
			th.blogPos++;
			if(th.blogPos==th.blogEntries.elements.length) th.blogPos = 0;
			
			setObj[th.blogPos] = { opacity:0, left:300 };
			
			animObj[th.blogPos] = { opacity:1, left:0 };
			animObj[oldPos] = { opacity:0, left:-800 };
		}
		if(direction=='prev')
		{
			var oldPos = th.blogPos;
			th.blogPos--;
			if(th.blogPos<0) th.blogPos = th.blogEntries.elements.length-1;
			
			setObj[th.blogPos] = { opacity:0, left:-300 };
			
			animObj[th.blogPos] = { opacity:1, left:0 };
			animObj[oldPos] = { opacity:0, left:800 };
		}
		
		th.blogEntries.set(setObj);
		th.blogEntries.start(animObj);
	}
};

var team =
{
	currentSubPage: null,
	currentMember: null,
	
	get: function(properties){ data.get('team-member',[properties]); },
	show: function()
	{
		var th = team;
		var els = $('page_team').getElements('.sub_zone');
		
		th.currentMember = new Fx.Elements(els,{
			duration:500,
			fps:1000
		});
		
		if(els.length==1)
		{
			th.currentMember.set({
				0:
				{
					opacity:0,
					visibility:'hidden'
				}
			});
			
			th.currentMember.chain(
				function(){ this.start({0:{ opacity:1 }}); },
				function(){ nav.interpret(); }
			);
		}
		if(els.length==2)
		{
			th.currentMember.set({
				1:
				{
					opacity:0,
					visibility:'visible'
				}
			});
			
			th.currentMember.chain(
				function()
				{
					this.start({ 1:{ opacity:1 } });
				},
				function()
				{
					this.elements[0].destroy();
					nav.interpret();
				}
			);
		}
		
		th.currentMember.callChain();

	},
	remove: function()
	{
		var th = team;
		var el = $('page_team').getElement('.sub_zone');
		
		th.currentMember = new Fx.Morph(el,{
			duration:500,
			fps:1000
		});
		
		th.currentMember.chain(
			function()
			{
				this.start({ opacity: 0 });
			},
			function()
			{
				this.element.destroy();
				nav.interpret();
			}
		);
		
		th.currentMember.callChain();
	}
};

// Utility functions
var utils =
{
	zWidth: 880,
	zHeight: 540,
	lowRes: false,
	
	checkRes: function()
	{
		var th = utils;
		
		th.lowRes = [screen.width,screen.height];
	},
	
	showAlert: function()
	{
		var th = utils;
		
		th.lofiAlert = new Element('div',{
			id:'lofi_alert',
			html:'<h4>Welcome!</h4><p>Based on the settings we are able to detect from your computer, we have customized our site to best match your browser and monitor configuration. You’ll still get all the same information and images, but if you get a chance, check it out with a more recent browser and/or a larger screen for a higher-fidelity, more dynamic user-experience.</p><div id="lofi_close_button" onclick="$(\'lofi_alert\').destroy();">Continue</div>'
		});
		
		th.lofiAlert.inject($(document.body));
	},
	
	clearLoginForm: function(type)
	{
		if(type=='username' && $('username').value=='username')
		{
			$('username').value='';
			$('username').removeEvents('focus');
		}
		if(type=='pword' && $('pword').value=='password')
		{
			$('pword').value='';
			$('pword').removeEvents('focus');
		}
		if(type=='add')
		{
			$('username').addEvent('focus',function(){ utils.clearLoginForm('username'); });
			$('pword').addEvent('focus',function(){ utils.clearLoginForm('pword'); });
		}
	},
	
	injectEmail: function()
	{
		if($('careers_job_email')) $('careers_job_email').innerHTML = data.job_email;
		if($('contact_email')) $('contact_email').innerHTML = data.contact_email;
	},
	
	ranHome: function(){ if($('page_home')) $('page_home').getElement('.content').style.backgroundImage = 'url(/wp-content/themes/sequence/images/home/zone'+$random(0,3)+'.jpg)'; },
	
	createHifi: function(checked)
	{
		var hifi_container = new Element('div',{ id:'hifi_container' });
		var hifi_label = new Element('label',{
			'for':'hifi',
			html:'hi-fi'
		});
		var hifi_check = new Element('input',{
			type:'checkbox',
			checked:checked,
			id:'hifi'
		});
		
		hifi_container.adopt(hifi_check,hifi_label);
		
		hifi_check.addEvent('click',function(){ setTimeout(utils.refreshLocation,1); });
		
		hifi_container.style.display = 'none';
		
		window.addEvent('keydown', function(event)
		{
			if(event.code==192 && event.shift==true)
			{
				event.preventDefault();
				if($('hifi_container').style.display=='none') $('hifi_container').style.display='block';
				else $('hifi_container').style.display='none';
			}
//			if(event.key=='s') utils.showAlert();
		});
		
		hifi_container.inject($('mast_head').getElement('.content'));
	},
	
	determineLocation: function(y,x)
	{
		// Remove px from values if needed
		x = parseInt(x,10);
		y = parseInt(y,10);
		
		// Ensure movement is not out of scope
		y-=interactive.yConstant;
		if(y>100) y = 0;
		else if(y<(-1080)) y = -(1080);
		
		x-=interactive.xConstant;
		if(x>0) x=0;
		else if(x<-(1620+interactive.xConstant)) x = 1620+interactive.xConstant;
		
		// Set x and y as absolute values (fixes negative value problems)
		x = Math.abs(x);
		y = Math.abs(y);
		
		// Determine the remainders
		var xR = x%utils.zWidth;
		var yR = y%utils.zHeight;
		
		// Determine whole divisions
		var xW = (x-xR)/utils.zWidth;
		var yW = (y-yR)/utils.zHeight;
		
		// Round up, according to remainders
		if(xR>440) xW++;
		if(yR>270) yW++;
		
		return [yW,xW];
	},
	
	setCufon: function()
	{
		Cufon.replace('.title_blurb h3');
		if(Browser.Engine.name!='trident')
		{
			Cufon.replace('h2');
			Cufon.replace('.blurb');
			Cufon.replace('.blog_entry h3');
			Cufon.replace('.accordian_handle');
		}
	},
	
	getSet: function(y,x)
	{
		return {
			top: -(y*utils.zHeight)+interactive.yConstant,
			left: -(x*utils.zWidth)+interactive.xConstant-4 //the 10 is for some bizarre offset...haven't really worked out why yet
		};
	},
	
	gridToString: function(row,col)
	{
		var tLoc;
		for(var x=0;x<loc.zones.length;x++)
		{
			if(loc.zones[x].coords[0]==row && loc.zones[x].coords[1]==col)
			{
				tLoc = loc.zones[x].name;
				break;
			}
		}
		return tLoc;
	},

	stripHash: function(string){ return string.replace(/#/,''); },
	
	convertId: function(string){ return string.replace(/page_/,''); },
	
	// This function cleans up the hash, so it is proper
	rebuildHash: function(string)
	{
		string = string.split('/');
		var newString = '/';
		string.each(function(arg,index,container){ if(arg!='#' && arg!='') newString += string[index]+'/'; });
		return newString;
	},
	
	getZoneIndex: function(string)
	{
		var tempIndex;
		for(var x=0;x<loc.zones.length;x++)
		{
			if(loc.zones[x].name==string)
			{
				tempIndex = x;
				break;
			}
		}
		return parseInt(tempIndex,10);
	},
	
	setAnchorIntercept: function(els){ els.each(function(el){ el.addEvent('click',nav.clickIntercept); }); },
	
	isHome: new RegExp('http://'+window.location.hostname),
	
	resetStored: function()
	{
		loc.stored.hash = null;
		loc.stored.list.length = 0;
		loc.stored.coords = [null,null];
		loc.stored.view = null;
		loc.stored.zone_id = null;
	},
	
	getPresIndex: function(string)
	{
		var index = 0;
		presentation.galleries.each(function(client,x,group){
			if(group[x].client==string) index = x;
		});
		
		return index;
	},
	
	refreshLocation: function()
	{
		var checked = $('hifi').checked;
		if(checked==true)
		{
			Cookie.write('interactive','yes',{ duration:365, domain:window.location.hostname, path:'/' });
			var tLoc = window.location;
			if(tLoc.pathname.length>1) tLoc.replace('http://'+tLoc.hostname+'#'+tLoc.pathname);
			else window.location.reload();
		}
		else
		{
			Cookie.write('interactive','no',{ duration:365, domain:window.location.hostname, path:'/' });
			var tString = '/';
			for(var x=0;x<loc.current.list.length;x++) tString+=loc.current.list[x]+'/';
			if(loc.current.list[0]=='home') window.location = 'http://'+window.location.hostname;
			else window.location = 'http://'+window.location.hostname+tString;
		}
	},
	
	loadMap: function()
	{
		if (GBrowserIsCompatible() && $('location_map'))
		{
			var map = new GMap2($('location_map'));
			var geocoder = new GClientGeocoder();
			var point = new GLatLng(37.763762, -122.398689);
			var address = '<strong>Sequence </strong><br />1501 Mariposa Street, Suite 200<br />San Francisco, CA 94107<br />415-489-4480';
			address += "<br /><br />";
			address += "<a href=\"http://maps.google.com/maps?daddr=1501%20Mariposa%20Street,%20San%20Francisco,%20CA%2094107\" target=\"_new\">Get directions</a>";
		
			// Create a Sequence icon
			var icon = new GIcon();
			icon.image = "http://beta.sequence.com/images/sequence_icon.png";
			icon.shadow = "http://beta.sequence.com/images/sequence_icon_shadow.png";
			icon.iconSize = new GSize(19, 40);
			icon.shadowSize = new GSize(37, 40);
			icon.iconAnchor = new GPoint(15, 25);
			icon.infoWindowAnchor = new GPoint(5, 1);
		
			// Add map controls
			map.addControl(new GSmallMapControl());
			map.addControl(new GMapTypeControl());
			map.addControl(new GScaleControl());
			map.setCenter(point, 16);
			var marker = new GMarker(point, icon, {clickable: true});
			map.addOverlay(marker);
			marker.openInfoWindowHtml(address);
		}
	},
	
	fixIETeam: function()
	{
		if(Browser.Engine.name=='trident' && $('page_team'))
		{
			var els = $$('.team_location');
			
			els.each(function(el)
			{
				el.addEvent('mouseover',function(){ this.style.zIndex = 5; });
				el.addEvent('mouseout',function(){ this.style.zIndex = 1; });
			});
		}
	},
	
	accordianInit: function()
	{
		if($('page_whatwedo'))
		{
			$('page_whatwedo').getElement('.content').style.height = '520px';
			
			interactive.accordion = new Fx.Accordion($$('.accordian_handle'), $$('.accord_el'), {
				display: 0,
				alwaysHide: false,
				initialDisplayFx: false,
				duration:360,
				transition:'sine:out',
				onActive: function(el)
				{
					$$('.accordian_handle').each(function(el){ el.className = 'accordian_handle'; });
					el.className = 'accordian_handle open';
				}
			});
		}
	}
};

var presentation =
{
	// Images array
	location:{},
	galleries:null,
	
	// Gallery HTML
	container:null,
	toolbar:null,
	casestudies:null,
	viewer:null,
	presFx:null,
	imgFx:null,
	busy:false,
	
	load: function()
	{
		var th = window.presentation;
		
		th.container = new Element('div',{ id:'presentation_view' });
		th.viewer = new Element('div',{ id:'pview_viewer'});
		th.toolbar = new Element('div',
		{
			id: 'pview_toolbar',
			html: '<h2>Our Work</h2><ul class="alt_menu" id="client_list2"><li id="ourwork_home_link" class="parent_link"><a href="#/ourwork/">Our Work</a></li><li><h4>Case Studies</h4></li><li><a href="#/ourwork/chipotle/" rel="view-presentation">Chipotle</a></li><li><a href="#/ourwork/sonos/" rel="view-presentation">Sonos</a></li><li><a href="#/ourwork/chevron/" rel="view-presentation">Chevron</a></li><li><a href="#/ourwork/nclr/" rel="view-presentation">NCLR</a></li><li><a href="#/ourwork/myspace/" rel="view-presentation">MySpace</a></li><li><a href="#/ourwork/zinio/" rel="view-presentation">Zinio</a></li><li><a href="#/ourwork/teambeachbody/" rel="view-presentation">Team Beachbody</a></li><li><a href="#/ourwork/ventana/" rel="view-presentation">Ventana</a></li><li><a href="#/ourwork/bottlenotes/" rel="view-presentation">Bottlenotes</a></li><li><a href="#/ourwork/turn/" rel="view-presentation">Turn</a></li><li><a href="#/ourwork/vontu/" rel="view-presentation">Vontu</a></li><li><a href="#/ourwork/aexjet/" rel="view-presentation">AEXJet</a></li><li><a href="#/ourwork/mokafive/" rel="view-presentation">MokaFive</a></li><li><a href="#/ourwork/zing/" rel="view-presentation">Zing</a></li><li><a href="#/ourwork/turnhere/" rel="view-presentation">TurnHere</a></li></ul> <h3 id="pres_client"></h3> <div id="pres_info">Overview</div> <p id="pres_description"></p> <div id="close_button"><a href="#/ourwork/">close</a></div> '
		});
		
		th.casestudies = new Element('ul', {
			id: 'pview_casestudies',
			html: '<li id="cstudy_shortcut_chipotle"><a href="#/ourwork/chipotle/" rel="view-presentation">Chipotle</a></li><li id="cstudy_shortcut_sonos"><a href="#/ourwork/sonos/" rel="view-presentation">Sonos</a></li><li id="cstudy_shortcut_bottlenotes"><a href="#/ourwork/bottlenotes/" rel="view-presentation">Bottlenotes</a></li><li id="cstudy_shortcut_nclr"><a href="#/ourwork/nclr/" rel="view-presentation">NCLR</a></li><li id="cstudy_shortcut_myspace"><a href="#/ourwork/myspace/" rel="view-presentation">Myspace.com</a></li><li id="cstudy_shortcut_zinio"><a href="#/ourwork/zinio/" rel="view-presentation">Zinio</a></li>'
		});
		th.btn_next = new Element('div', { id:'btn_next' });
		th.btn_prev = new Element('div', { id:'btn_prev' });
		
		th.btn_zone_next = new Element('div', { id:'btn_zone_next' });
		th.btn_zone_prev = new Element('div', { id:'btn_zone_prev' });
		
		th.btn_zone_next.addEvent('click',function(e){ if(presentation.busy==false) presentation.nav('next'); else e.preventDefault(); });
		th.btn_zone_prev.addEvent('click',function(e){ if(presentation.busy==false) presentation.nav('prev'); else e.preventDefault(); });
		th.navBtnLogic.elFx = new Fx.Elements([th.btn_next,th.btn_prev],{
			duration: 500,
			fps:1000,
			link:'cancel',
			transition:'sine:out'
		});
		
		th.btn_zone_next.addEvent('mouseover',function()
		{
			if(Browser.Engine.name=='trident') presentation.navBtnLogic.elFx.set({ 0:{ visibility:'visible' }, 1:{ visibility:'hidden' } });
			else presentation.navBtnLogic.elFx.start({ 0:{ opacity:1 }, 1:{ opacity:0 } });
		});
		th.btn_zone_next.addEvent('mouseout',function()
		{
			if(Browser.Engine.name=='trident') presentation.navBtnLogic.elFx.set({ 0:{ visibility:'hidden' }, 1:{ visibility:'hidden' } });
			else presentation.navBtnLogic.elFx.start({ 0:{ opacity:0 }, 1:{ opacity:0 } });
		});
		
		th.btn_zone_prev.addEvent('mouseover',function()
		{
			if(Browser.Engine.name=='trident') presentation.navBtnLogic.elFx.start({ 0:{ visibility:'hidden' }, 1:{ visibility:'visible' } });
			else presentation.navBtnLogic.elFx.start({ 0:{ opacity:0 }, 1:{ opacity:1 } });
		});
		th.btn_zone_prev.addEvent('mouseout',function()
		{
			if(Browser.Engine.name=='trident') presentation.navBtnLogic.elFx.set({ 0:{ visibility:'hidden' }, 1:{ visibility:'hidden' } });
			else presentation.navBtnLogic.elFx.start({ 0:{ opacity:0 }, 1:{ opacity:0 } });
		});
		
		th.container.adopt([th.viewer,th.toolbar,th.casestudies,th.btn_prev,th.btn_next,th.btn_zone_next,th.btn_zone_prev]);
		
		th.presFx = new Fx.Morph(th.container,{
			duration:500,
			fps:1000,
			transition:'sine:out',
			onStart: function(){ presentation.busy = true; },
			onComplete: function(){ presentation.busy = false; }
		});
		
		th.imgFx = new Fx.Elements([],{
			duration:300,
			fps:1000,
			transition:'quad:out',
			onStart: function(){ presentation.busy = true; },
			onComplete: function(){ presentation.busy = false; }
		});
		
		th.presFx.set({ opacity:0 });
		
		th.container.inject($('shade'),'after');
		
		// Quick fix for button functionality in the interest of time... yeah, it's gehetto, I know!
		$('pres_info').addEvent('click',function(){ dialogue.show('project-info'); });
	},
	
	init: function()
	{
		var th = presentation;
		if(!window.loc.stored.list[2]) 
		{
			loc.stored.list[2] = 0;
			loc.stored.hash += '0/';
						
			window.location.replace('http://'+window.location.hostname+'#'+loc.stored.hash);
		}
		
		var index = utils.getPresIndex(loc.current.list[1]);
		
		if(!th.galleries[index].imgs)
		{
			dialogue.show('loader');
			th.galleries[index].imgs = new Asset.images(th.galleries[index].urls,{ onComplete: function(){ dialogue.hide('loader'); presentation.create(); } });
		}
		else presentation.create();
	},
	
	show: function(properties)
	{
		var index = utils.getZoneIndex(loc.current.list[0]);
		var zInfo = loc.zones[index].obj.getCoordinates();
		
		interactive.shade.set({
			0:{
				top:zInfo.top+9,
				left:zInfo.left+9,
				width:zInfo.width-18,
				height:zInfo.height-18,
				opacity:0,
				display:'block'
			}
		});
		
		if(window.IE7) window.IE7.recalc();
		
		interactive.shade.options.duration = 300;
		interactive.shade.options.transition = 'sine:in:out';
		
		//presentation.navBtnLogic.elFx.set({ 0:{ opacity:0 }, 1:{ opacity:0 }});
		
		interactive.shade.chain(
			function(){ this.start({ 0:{opacity:1} }); },
			function()
			{
				interactive.shade.options.duration = 500;
				interactive.shade.options.transition = 'quad:in:out';
				var wInfo = window.getSize();
				interactive.shade.start({
					0:{
						top:0,
						left:0,
						width:wInfo.x,
						height:wInfo.y
					},
					1:{ top:-94 }
				});
			},
			function()
			{
				// if(window.IE7) window.IE7.recalc();
				$('mapContainer').style.display='none';
				if(!presentation.galleries)
				{
					new Request.JSON({
						noCache:true,
						url: 'http://'+window.location.hostname+'/galleries/galleries.json',
						onComplete: function(json)
						{
							// Duplicate returned array into presentation class
							presentation.galleries = $A(json);
							
							// Create image url array
							presentation.galleries.each(function(client,x,array)
							{
								presentation.galleries[x].urls = [];
								for(var y=0;y<presentation.galleries[x].imageInfo.length;y++) presentation.galleries[x].urls[y] = presentation.galleries[x].imageFolder+'/'+y+'.jpg';
							});
							presentation.init();
						}
					}).get();
				}
				else presentation.init();
			}
		);
		
		interactive.shade.callChain();
	},
	
	hide: function(properties)
	{
		var th = presentation;
		$('mapContainer').style.display='block';
		var index = utils.getZoneIndex(properties);
		var zInfo = loc.zones[index].obj.getCoordinates();
		
		interactive.shade.chain(
			function()
			{
				this.start({
					0:{
						top:zInfo.top+9,
						left:zInfo.left+9,
						width:zInfo.width-18,
						height:zInfo.height-18
					},
					1:{ top:0 }
				});
			},
			function()
			{
				this.options.duration = 300;
				this.options.transition = 'sine:in:out';
				this.start({0:{opacity:0}});
			},
			function()
			{
				if(window.IE7) window.IE7.recalc();
				nav.interpret();
			}
		);
		
		
		th.presFx.chain(
			function()
			{
				this.start({ opacity: 0 });
			},
			function()
			{
				presentation.container.style.display = 'none';
				presentation.viewer.innerHTML = '';
				interactive.shade.callChain();
			}
		);
		
		th.presFx.callChain();
	},
		
	create: function()
	{
		var th = window.presentation;
		
		//th.container.style.display='block';
		th.presFx.set({
			opacity:0,
			display:'block'
		});
		
		th.presFx.chain(
			function()
			{
				this.start({ opacity:1 });
			},
			function()
			{
				dialogue.hide('loader');
				nav.interpret();
			}
		);
		
		th.presFx.callChain();
	},
	
	placeImage: function()
	{
		var th = window.presentation;
		var index = utils.getPresIndex(th.location[1]);
		
		if(!th.galleries[index].imgs)
		{
			dialogue.show('loader');
			th.galleries[index].imgs = new Asset.images(th.galleries[index].urls,{ onComplete: function(){ dialogue.hide('loader'); presentation.placeImage(); } });
			return;
		}
		
		var tLis = $$('#pview_casestudies li');
		for(var x=0;x<tLis.length;x++)
		{
			var tId = 'cstudy_shortcut_'+th.location[1];
			if(tLis[x].id==tId) tLis[x].className='current';
			else tLis[x].className='';
		}
		
		var image = th.galleries[index].imgs[th.location[0]].clone(true);
		image.style.visibility = 'hidden';
		th.viewer.adopt(image);
		
		var info = image.getSize();
		
		
		var imgWidth = image.width;
		var imgHeight = image.height;
		var ratio = imgWidth/imgHeight;
		
		var viewerWidth = th.viewer.getSize().x;
		var viewerHeight = parseInt(th.viewer.style.height,10);
		var viewMiddle = parseInt(viewerWidth/2,10);

		if(imgWidth>viewerWidth)
		{
			imgWidth = viewerWidth;
			imgHeight = parseInt(viewerWidth/ratio,10);
		}
		if(imgHeight>viewerHeight)
		{
			imgHeight = viewerHeight;
			imgWidth = parseInt(viewerHeight*ratio,10);
		}
		
		image.width = imgWidth;
		image.height = imgHeight;
		image.style.marginTop = '-'+parseInt(imgHeight/2,10)+'px';
		image.style.marginLeft = '-'+parseInt(imgWidth/2,10)+'px';
		image.style.left = viewMiddle+'px';
		
		$('pres_description').innerHTML = th.galleries[index].imageInfo[loc.current.list[2]];
		$('pres_client').innerHTML = th.galleries[index].clientString;
		
		var els = th.viewer.getElements('img');
		
		th.imgFx.elements = els;
		
		if(els.length==1)
		{
			var animObj1 = { 0:{ opacity:1 } };
			th.imgFx.set({
				0:{
					opacity:0,
					visibility:'visible'
				}
			});
			th.imgFx.start({ 0:{opacity:1} }).chain(function(){ nav.interpret(); });
		}
		else if(els.length==2)
		{
			var animObj1 = { 0:{ opacity:0 } };
			var animObj2 = { 1:{ opacity:1 } };
			
			th.imgFx.set({
				1:{
					opacity:0,
					visibility:'hidden'
				}
			});
			
			th.imgFx.chain(
				function(){
					this.options.transition = 'quad:in';
					this.start(animObj1);
				},
				function(){
					this.options.transition = 'quad:out';
					this.start(animObj2);
				},
				function(){
					this.elements[0].destroy();
					nav.interpret();
				}
			);
			
			th.imgFx.callChain();
		}
	},
	
	nav: function(direction)
	{
		var th = presentation;
		var clientLoc = th.location[0];
		var index = utils.getPresIndex(th.location[1]);
		var clientTotal = th.galleries[index].urls.length;
		
		if(direction=='next')
		{
			clientLoc++;
			if(clientLoc>=clientTotal)
			{
				clientLoc=0;
				index++;
				if(index>=th.galleries.length) index = 0;
			}
		}
		else
		{
			clientLoc--;
			if(clientLoc<0)
			{
				index--;
				if(index<0) index = th.galleries.length-1;
				clientLoc = th.galleries[index].urls.length-1;
			}
		}
		var client = th.galleries[index].client;
		var newHash = '/'+loc.current.list[0]+'/'+client+'/'+clientLoc+'/';
		window.location.hash = newHash;
		clearInterval(nav.timer);
		nav.interpret();
	},
	
	navBtnLogic: {
		elFx: null
	}
};


var dialogue =
{
	container:null,
	loaderObj:null,
	projectObj:null,
	
	show: function(type)
	{
		var th = dialogue;
		
		switch(type)
		{
			case 'loader':
				th.loader('show');
				break;
			case 'project-info':
				th.project('show');
				break;
			default: break;
		}
	},
	
	hide: function(type)
	{
		var th = dialogue;
		
		switch(type)
		{
			case 'loader':
				th.loader('hide');
				break;
			case 'project-info':
				th.project('hide');
				break;
			default: break;
		}
	},
	
	loader: function(showHide)
	{
		var th = dialogue;
		
		if(showHide=='show')
		{
			th.container.style.display = 'block';
			th.loaderObj.style.display = 'block';
			th.loaderObj.style.visibility = 'visible';
		}
		else
		{
			th.container.style.display = 'none';
			th.loaderObj.style.display = 'none';
			th.loaderObj.style.visibility = 'hidden';
		}
	},
	
	project: function(type)
	{
		var th = dialogue;
		if(type=='show')
		{
			var pr = presentation;
			var tLoc = utils.getPresIndex(pr.location[1]);
			
			th.projectObj.innerHTML = '<div class="project_info_close" onclick="dialogue.hide(\'project-info\')">close</div><h3>'+pr.galleries[tLoc].clientString+'</h3>'+pr.galleries[tLoc].info;
			th.projectObj.style.display = 'block';
			th.container.style.display = 'block';
			th.container.addEvent('click',dialogue.tempRemove);
			Cufon.replace('#project_info_window h3');
		}
		if(type=='hide')
		{
			th.projectObj.innerHTML = '';
			th.container.style.backgroundColor = '';
			th.projectObj.style.display = 'none';
			th.container.style.display = 'none';
		}
	},
	
	tempRemove: function()
	{
		var th = dialogue;
		dialogue.hide('project-info');
		th.container.removeEvents('click');
	}
};