/*
	jquery.team2.js
	Custom jQuery addon for Team2
*/

	if(typeof(teamtwo) == 'undefined'){

		/* functions */
		teamtwo = {
			cache : [],
			// implements uniform event handlers
			events : {
				// gracefully add an event handler
				add : function(node, eventName, eventHandler){
					// prefered method
					if('addEventListener' in node){
						node.addEventListener(eventName, eventHandler, false);
					}
					// alternative method
					else if('attachEvent' in node){
						node.attachEvent('on'+eventName, function(event){eventHandler(event)});
					}
					// desperate method
					else{
						node['on'+eventName] = eventHandler;
					}
					// report success
					return true;
				},
				set : function(node, eventName, eventHandler){
					node['on'+eventName] = eventHandler;
				},
				// trigger an event handler manually
				trigger : function(node, eventName){
					// prefered method
					if('fireEvent' in node){
						node.fireEvent('on' + eventName);
					}
					// alternative method
					else if('dispatchEvent' in node){
						var evt = document.createEvent('HTMLEvents');
						evt.initEvent(eventName, false, true);
						node.dispatchEvent(evt);
					}
					// desperate method
					else{
						eval('node.on' + eventName + '()');
					}
					// report success
					return true;
				}
			},
			// provided a debug console for the framework
			reports : {
				// report a console message
				send : function(message){
					// if the reporting panel doesn't exist
					var reportPanel = document.getElementById('reportPanel');
					if(reportPanel == null){
						// create the panel
						var reportPanel = document.createElement('DIV');
						reportPanel.id = 'reportPanel';
						reportPanel.style.background = '#fff none';
						reportPanel.style.border = 'solid 1px #000';
						reportPanel.style.padding = '10px';
						reportPanel.style.position = (navigator.userAgent.indexOf('MSIE 6')>-1) ? 'absolute' : 'fixed' ;
						reportPanel.style.right = '10px';
						reportPanel.style.bottom = '10px';
						reportPanel.style.width = '180px';
						reportPanel.style.height = '320px';
						reportPanel.style.overflow = 'auto';
						reportPanel.style.zIndex = '100000';
						reportPanel.innerHTML = '&nbsp;';
						// store a copy of this node in the move buffer
						document.body.appendChild(reportPanel);
					}
					// truncate the queue
					var reportString = (reportPanel.innerHTML.length < 1000) ? reportPanel.innerHTML : reportPanel.innerHTML.substring(0, 800);
					// output the queue to the panel
					reportPanel.innerHTML = message + '<br/>' + reportString;
				},
				test : function(node, event){
					// write the properties of the node into a string
					var reportString = 'Node properties: ';
					reportString += node.nodeName;
					if(node.id) reportString += '#' + node.id;
					if(node.className) reportString += '.' + node.className.split(' ').join('.');
					// print the string
					teamtwo.reports.send(reportString);
					// cancel the click is need be
					if(event != null){
						event.preventDefault ? event.preventDefault() : event.returnValue = false;
					}
				}
			},
			// uses CSS selectors assign behaviours
			selectors : {
				// contains a temprary stylesheet for IE to work with
				stylesheet : null,
				// checks if a node is related to a (common) parent
				related : function(node, parent){
					// if the parent is null
					if(parent == null){
						// don't even look
						return true;
					}else{
						// for all child nodes of the parent
						var allChildNodes = parent.getElementsByTagName('*');
						for(var a=0; a<allChildNodes.length; a++){
							// if this childnode is the given node
							if(node == allChildNodes[a]){
								// return true
								return true;
							}
						}
					}
					// return false if nothing was found at all
					return false;
				},
				// get the DOM elements that belong to the selectors
				query : function(selector){
					// if the browser supports query selectors
					if(document.querySelectorAll){
						// select elements that match the selector
						return document.querySelectorAll(selector);
					// else use jQuery
					}else if(typeof(jQuery) != 'undefined'){
						return $(selector).get();
					// else use a fall back [1]
					}else{
						// create a stylesheet or use an existing one
						if(teamtwo.selectors.styleSheet == null){
							teamtwo.selectors.styleSheet = document.createStyleSheet();
						}
						// add a generic rule to the stylesheet
						teamtwo.selectors.styleSheet.addRule(selector, "foo:bar");
						// for all nodes in the document
						var allNodes = document.all;
						var affectedNodes = [];
						for (var a=0, b=allNodes.length; a<b; a++){
							// if this node has the generic style
							if(allNodes[a].currentStyle.foo === "bar"){
								// store it in the results list
								affectedNodes.push(allNodes[a]);
							}
						}
						// remove the generic style
						teamtwo.selectors.styleSheet.removeRule(0);
						// return the list of results
						return affectedNodes;
					}
				},
				// processes the queued selectors
				process : function(queue, parent){
					// for all selectors in the queue
					for(var selector in queue){
						// get the nodes matching the selector
						var nodes = teamtwo.selectors.query(selector);
						// for all matching nodes
						for(var a=0; a<nodes.length; a++){
							// if the objects share the common parent
							if(teamtwo.selectors.related(nodes[a], parent)){
								// handle the rules in the object
								teamtwo.selectors.handle(nodes[a], queue[selector]);
							}
						}
					}
				},
				// handles the rules of a selector
				handle : function(node, rules){
					// for all rules
					for(var rule in rules){
						// select the intended condition or event handler
						switch(rule){
							// immediately
							case 'start' :
								// execute the rule(s)
								teamtwo.selectors.execute(node, null, rules[rule], rules);
								break;
							// in internet explorer
							case 'msie' :
								// if this is internet explorer
								if(navigator.userAgent.indexOf('MSIE')>-1){
									// execute the rule(s)
									teamtwo.selectors.execute(node, null, rules[rule], rules);
								}
								break;
							// assume an event handler
							default :
								// add the event handler
								teamtwo.events.add(node, rule, (
									// with a copy of the subnode pointer
									function(node, functions, settings){
										return function(event){
											// execute the rule(s)
											teamtwo.selectors.execute(node, event, functions, settings);
										}
									}(node, rules[rule], rules)
								));
						}
					}
				},
				// execute the functions belonging to a rule
				execute : function(node, event, functions, settings){
					// if the object is an array
					if(Object.prototype.toString.call(functions) == "[object Array]"){
						// for every function in the array
						for(var a=0; a<functions.length; a++){
							// execute it
							functions[a](node, event, settings);
						}
					// else
					}else{
						// execute it
						functions(node, event, settings);
					}
				},
				// waits for enough of the document to load
				wait : function(queue, parent){
					// check if enough of the DOM was loaded
					if(/interactive|loaded|complete/i.test(document.readyState)){
						// start the parser with a delay
						setTimeout(function(){
							// process the queued up selectors
							teamtwo.selectors.process(queue, parent);
						}, 200);
					// else
					}else{
						// wait a while
						setTimeout(function(){
							// check again
							teamtwo.selectors.wait(queue, parent);
						}, 200);
					}
				}
			},
			// loading and saving cookies and local data
			storage : {
				// returns a space to store generic configuration data
				settings : function(id){
					// if there no configuration object
					if(teamtwo.cache[id] == null){
						teamtwo.cache[id] = {};
					}
					// return the configuration object that goes with this id
					return teamtwo.cache[id];
				},
				// stores the value in a HTML node
				set : function(node, name, value){
					if(node!=null){
						// create a default value, if there isn't one
						if(node.className==null){
							node.className = '';
						}
						if(node.className.indexOf(' ' + name + '_')<0){
							node.className += ' ' + name + '_0';
						}
						// get the old value
						var current = teamtwo.storage.get(node, name, null);
						// replace the old value
						if(current != null){
							node.className = node.className.replace(name + '_' + current, name + '_' + value);
						}
					}
				},
				// retrieves the value from a HTML node
				get : function(node, name, backup){
					// if the node exists
					if(node != null){
						// get the value from the class name or use the default
						var value = (node.className.indexOf(' ' + name + '_')>-1) ?
							node.className.split(' ' + name + '_')[1].split(' ')[0] :
							backup ;
						// return the value as a number or a string
						return (isNaN(parseInt(value))) ?
							value :
							parseFloat(value.toString().replace('D','.')) ;
					// else
					}else{
						// return the default
						return backup;
					}
				},
				// calculates an expiration date for cookies
				expiration : function(days){
					// return a date object in the future
					return new Date(
						new Date().getTime() + days * 24 * 60 * 60 * 1000
					);
				},
				// save a value into a cookie
				save : function(name, value, expires, path, domain, secure) {
					// formulate the cookie
					document.cookie = name + "=" + escape(value) +
						((expires) ? "; expires=" + expires.toGMTString() : "") +
						((path) ? "; path=" + path : "") +
						((domain) ? "; domain=" + domain : "") +
						((secure) ? "; secure" : "");
				},
				// loads a value from a cookie
				load : function(name) {
					// return the clipped value from the cookie
					return (
						(document.cookie.indexOf(name + '=') > -1) ?
							unescape(document.cookie.split(name + '=')[1].split(';')[0]) :
							null
					);
				},
				// clears the value from a cookie
				clear : function(name, path, domain) {
					// if the cookie exists
					if(teamtwo.storage.load(name)){
						// clear and expire it
						document.cookie = name + "=" +
						((path) ? "; path=" + path : "") +
						((domain) ? "; domain=" + domain : "") +
						"; expires=Thu, 01-Jan-70 00:00:01 GMT";
					}
				}
			},
			// selectively turns DOM elements on and off
			toggles : {
				// stores the group that is currently processed
				group : null,
				// sets the initial toggle state
				init : function(node, event, options){
					// get the target rule
					var targetRule = (options.target.rule != null) ?
						options.target.rule :
						'#' + node.href.split('#')[1] ;
					// get the target node
					var targetNode = (node.href != null) ?
						document.getElementById(node.href.split('#')[1]) :
						teamtwo.toggles.sibling(node);
					// get the target siblings
					var siblingTargets = teamtwo.selectors.query(targetRule);
					// determine if this is the first in a group
					var isFirstInGroup = ((teamtwo.toggles.group != options.source.rule) && options.grouped);
					teamtwo.toggles.group = options.source.rule;
					// set the source' initial state if there's not already one
					var modifyNode = teamtwo.toggles.parent(node, options.source.parent);
					if(
						modifyNode.className.indexOf(options.source.classes[0]) < 0 &&
						modifyNode.className.indexOf(options.source.classes[1]) < 0
					){
						modifyNode.className += (isFirstInGroup && options.initial) ?
							' ' + options.source.classes[1] :
							' ' + options.source.classes[0] ;
					}
					// for all nodes that match the rule
					for(var a=0; a<siblingTargets.length; a++){
						// set the target's initial state if there's not already one
						var modifyNode = teamtwo.toggles.parent(siblingTargets[a], options.target.parent);
						if(
							modifyNode.className.indexOf(options.target.classes[0]) < 0 &&
							modifyNode.className.indexOf(options.target.classes[1]) < 0
						){
							modifyNode.className += (isFirstInGroup && options.initial && siblingTargets[a] == targetNode) ?
								' ' + options.target.classes[1] :
								' ' + options.target.classes[0] ;
						}
					}
					// the auto property
					if(options.auto != null){
						teamtwo.toggles.auto(node, targetNode, options);
					}
				},
				auto : function(node, targetNode, options){
					// get the persistent settings for this group of elements
					var cycleConfig  = teamtwo.storage.settings(options.source.rule + ',' + options.target.rule);
					// if the same group has not already been processed
					if(cycleConfig.active == null){
						// mark this cycle as active
						cycleConfig.active = true;
						// set up a loop for this group of sources / targets
						cycleConfig.timeout = setInterval(function(){
							teamtwo.toggles.cycle(options);
						}, options.auto);
					}
					// set the mouse pause / resume events for the cycle on each source
					teamtwo.events.add(node, 'mouseover', function(){
						clearInterval(cycleConfig.timeout);
					});
					teamtwo.events.add(node, 'mouseout', function(){
						cycleConfig.timeout = setInterval(function(){
							teamtwo.toggles.cycle(options);
						}, options.auto);
					});
					// set the mouse pause / resume events for the cycle on each target
					teamtwo.events.add(targetNode, 'mouseover', function(){
						clearInterval(cycleConfig.timeout);
					});
					teamtwo.events.add(targetNode, 'mouseout', function(){
						cycleConfig.timeout = setInterval(function(){
							teamtwo.toggles.cycle(options);
						}, options.auto);
					});
				},
				cycle : function(options){
					// get the objects involved in this cycle
					var siblingSources = teamtwo.selectors.query(options.source.rule);
					var siblingTargets = teamtwo.selectors.query(options.target.rule);
					// check all sources
					var currentActive = -1;
					var a = 0;
					while(a < siblingSources.length && currentActive < 0){
						// if the source if active
						if(siblingSources[a].className.indexOf(options.source.classes[1]) > -1){
							// store it
							currentActive = a;
							foundActive = true;
						}
						// increase the index
						a++;
					}
					// pick the next active
					var nextActive = (a < siblingSources.length) ? a : 0 ;
					// deactivate the current active toggle if there is no group action active
					if(!options.grouped && currentActive > -1){
						teamtwo.toggles.execute(siblingSources[currentActive], null, options);
					}
					// activate the next active toggle
					teamtwo.toggles.execute(siblingSources[nextActive], null, options);
				},
				// toggle between two states
				execute : function(node, event, options){
					// get the source node
					var sourceNode = node;
					// get the target node
					var targetNode = (node.href != null) ?
						document.getElementById(node.href.split('#')[1]) :
						teamtwo.toggles.sibling(sourceNode);
					// get the delays if any
					var openDelay = (options.delay != null) ? options.delay.open : 0 ;
					var closeDelay = (options.delay != null) ? options.delay.close : 0 ;
					// get the sibling nodes
					var siblingSources = teamtwo.selectors.query(options.source.rule);
					var siblingTargets = teamtwo.selectors.query(options.target.rule);
					// for all sibling nodes
					for(var a=0, b=siblingTargets.length; a<siblingTargets.length; a++){
						// if this sibling is not the target
						if(targetNode == siblingTargets[a]){
							setTimeout((function(a, siblingSources, siblingTargets, options){
								return function(){
									// toggle the source' state
									var modifyNode = teamtwo.toggles.parent(sourceNode, options.source.parent);
									if(modifyNode.className.indexOf(options.source.classes[0]) < 0 && !options.grouped){
										teamtwo.transitions.tween(modifyNode, options.source.classes[1], options.source.classes[0]);
									}else{
										teamtwo.transitions.tween(modifyNode, options.source.classes[0], options.source.classes[1]);
									}
									// toggle the target's state
									var modifyNode = teamtwo.toggles.parent(targetNode, options.target.parent);
									if(modifyNode.className.indexOf(options.target.classes[0]) < 0 && !options.grouped){
										teamtwo.transitions.tween(modifyNode, options.target.classes[1], options.target.classes[0]);
									}else{
										teamtwo.transitions.tween(modifyNode, options.target.classes[0], options.target.classes[1]);
									}
								}
							}(a, siblingSources, siblingTargets, options)), openDelay);
						// else
						}else if(options.grouped){
							setTimeout((function(a, siblingSources, siblingTargets, options){
								return function(){
									// make source' state passive
									var modifyNode = teamtwo.toggles.parent(siblingSources[a], options.source.parent);
									teamtwo.transitions.tween(modifyNode, options.source.classes[1], options.source.classes[0]);
									// make the target's state closed
									var modifyNode = teamtwo.toggles.parent(siblingTargets[a], options.target.parent);
									teamtwo.transitions.tween(modifyNode, options.target.classes[1], options.target.classes[0]);
								}
							}(a, siblingSources, siblingTargets, options)), closeDelay);
						}
					}
					// cancel the click event
					if(event != null) event.preventDefault ? event.preventDefault() : event.returnValue = false;
				},
				// finds the parent node
				parent : function(node, recursions){
					// get the indicated parent of the node
					if(recursions != null){
						for(var a = 0; a < recursions; a++){
							node = node.parentNode;
						}
					}
					// return it
					return node;
				},
				// finds the next sibling node
				sibling : function(node){
					// look for the next likely node
					var nextNode = node.nextSibling;
					while(nextNode.nodeName.indexOf('#') > -1){
						nextNode = nextNode.nextSibling;
						if(nextNode==null){
							nextNode = node;
						}
					}
					// return it
					return nextNode;
				},
				// finds the position of the element, relative to the document
				position : function(node) {
					// define a position object
					var position = {
						'x' : 0,
						'y' : 0,
						'scroll' : 0
					};
					// if offsetparent exists
					if(node.offsetParent){
						// add every parent's offset
						do{
							position.x += node.offsetLeft;
							position.y += node.offsetTop;
						}while (node = node.offsetParent);
					}
					// find the current position in the document
					position.scroll = (self.pageYOffset) ?
						self.pageYOffset :
						(document.documentElement) ?
							document.documentElement.scrollTop :
							document.body.scrollTop ;
					// return the object
					return position;
				}
			},
			// emulates CSS3 transitions
			transitions : {
				// stores the compatibility with CSS3
				css3 : false,
				// gets the affecting styles from the stylesheet
				style : function(node, attribute){
					var property = null;
					// if currentStyle is supported
					if(node.currentStyle){
						// get the style this way
						var property = node.currentStyle[attribute];
					// else if getComputedStyle is supported
					}else if(window.getComputedStyle){
						// get the style this way
						var property = document.defaultView.getComputedStyle(node, null).getPropertyValue(attribute);
					}
					// return the style
					return property;
				},
				// initiates a transition between two class names
				tween : function(node, oldClassName, newClassName, onComplete){
					// if a change in classnames is requested
					if(oldClassName != newClassName){
						// shortcut pointers
						var st = teamtwo.transitions;
						var ss = teamtwo.storage;
						// check compatibility
						st.css3 = st.compatibility(node);
						// initiate the transition the browser supports
						switch(st.css3){
							case true :
								// define a self-destructive oncomplete handler function
								if(onComplete != null){
									var whenComplete = function(){
										onComplete();
										node.removeEventListener('transitionend', whenComplete, true);
									}
									node.addEventListener('transitionend', whenComplete, true);
								}
								// trigger the transition
								node.className = node.className.replace(new RegExp(oldClassName,'g'), newClassName);
								break;
							case 'mozilla' :
								// define a self-destructive oncomplete handler function
								if(onComplete != null){
									var whenComplete = function(){
										onComplete();
										node.removeEventListener('transitionend', whenComplete, true);
									}
									node.addEventListener('transitionend', whenComplete, true);
								}
								// trigger the transition
								node.className = node.className.replace(new RegExp(oldClassName,'g'), newClassName);
								break;
							case 'opera' :
								// define a self-destructive oncomplete handler function
								if(onComplete != null){
									var whenComplete = function(){
										onComplete();
										node.removeEventListener('oTransitionEnd', whenComplete, true);
									}
									node.addEventListener('oTransitionEnd', whenComplete, true);
								}
								// trigger the transition
								node.className = node.className.replace(oldClassName, newClassName);
								break;
							case 'webkit' :
								// define a self-destructive oncomplete handler function
								if(onComplete != null){
									var whenComplete = function(){
										onComplete();
										node.removeEventListener('webkitTransitionEnd', whenComplete, true);
									}
									node.addEventListener('webkitTransitionEnd', whenComplete, true);
								}
								// trigger the transition
								node.className = node.className.replace(new RegExp(oldClassName,'g'), newClassName);
								break;
							default :
								// if the transitions emulator has been included
								if(st.loop != null){
									// get the styles associated with the old class name and add the current measurable styles to the old class name
									var oldStyles = st.get(node, st.rules(oldClassName));
									//  get the styles associated with the new class name
									var newStyles = st.rules(newClassName);
									// give the object an id if it doesn't already have one
									node.id = (node.id) ? node.id : 'transition_' + st.instance++ ;
									// halt its current transition
									clearTimeout(ss.settings(node.id).timeout);
									// start the transition loop
									st.loop(
										node,
										oldClassName,
										newClassName,
										onComplete,
										oldStyles,
										newStyles,
										new Date().getTime(),
// TODO: get the transition time from the stylesheet
										new Date().getTime() + 300
									);
								// else if no transitions emulator is present
								}else{
									// replace the class name
									node.className = node.className.replace(new RegExp(oldClassName,'g'), newClassName);
									// trigger the end event
									if(onComplete != null){
										onComplete(node);
									}
								}
						}
					}
				},
				// checks transition compatibility
				compatibility : function(node){
					// assume the worst
					var hasCSS3 = false;
					// check the generic transition support
					try{
						document.createEvent('transitionEvent');
						hasCSS3 = true;
					}catch(e){}
					// check the opera transition support
					try{
						document.createEvent('OTransitionEvent');
						hasCSS3 = 'opera';
					}catch(e){}
					// check the webkit transition support
					try{
						document.createEvent('WebKitTransitionEvent');
						hasCSS3 = 'webkit';
						// if there's a flash object on screen in Safari on OS X, the transitions stop working (yay)
						if(navigator.userAgent.indexOf('Safari')>-1 && navigator.userAgent.indexOf('Macintosh')>-1 && navigator.userAgent.indexOf('Chrome')<0){
							hasCSS3 = false;
						}
					}catch(e){}
					// check the mozilla transition support
					var newDiv = document.createElement('div');
					if(typeof(newDiv.style.MozTransition) != 'undefined'){
						hasCSS3 = 'mozilla';
					}
					newDiv = null;
					// pass back the news
					return hasCSS3;
				}
			}
		}

		/* jQuery integration */
		if(typeof(jQuery)!='undefined'){
			(function($){
				var methods = {
					init : function(options){
						return this.each(function(){
							teamtwo.selectors.handle($(this).context, options);
						});
					},
					test : function(){
						return this.each(function(){
							teamtwo.reports.test($(this).context);
						});
					}
				};
				$.fn.teamtwo = function(method){
					if(methods[method]){
						return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
					}else if(typeof method === 'object' || !method){
						return methods.init.apply(this, arguments);
					}else{
						$.error('Method ' +  method + ' does not exist on teamtwo.js');
					}
				};
			})(jQuery);
		}

		/* shortcuts */
		var debug = teamtwo.reports.send;

	}

/*
	Project Tabs
*/

	teamtwo.tabs = {
		config : {},
		resize : function(node, event, settings){
			// get the target node
			var targetNode = (node.href != null) ?
				document.getElementById(node.href.split('#')[1]) :
				teamtwo.toggles.sibling(node);
			// apply its size to the root node
			if(targetNode.offsetHeight && targetNode.offsetHeight > 0){
//				targetNode.parentNode.style.height = (targetNode.offsetHeight) + 'px';
			}
		},
		reclick : function(node, event, settings){
			// trigger the click event of the target node
			var reclickNode = document.getElementById(node.href.split('#')[1]);
			teamtwo.toggles.execute(reclickNode, null, settings.config);
			teamtwo.tabs.resize(reclickNode, null, settings.config);
			// cancel the click event
			if(event != null) event.preventDefault ? event.preventDefault() : event.returnValue = false;
		},
		show : function(){
			// show the nav bar
			document.getElementById('projectlists').style.visibility = 'visible';
		},
		hide : function(){
			// hide the nav bar
			setTimeout(function(){
				document.getElementById('projectlists').style.visibility = 'hidden';
			}, 700);
		}
	}

/*
	Slideshow
*/

	teamtwo.slideshow = {
		index : 0,
		setup : function(node, event, settings){
			// resize event
			teamtwo.events.add(window, 'resize', function(event){
				teamtwo.slideshow.adjust(node, event, settings);
			});
			// onload function
			teamtwo.events.add(window, 'load', function(event){
				teamtwo.slideshow.adjust(node, event, settings);
			});
			// initial state
			teamtwo.slideshow.adjust(node, event, settings);
		},
		adjust : function(node, event, settings){
			// for all the items that belong to the rule
			var allSlideshows = teamtwo.selectors.query(settings.targets);
			for(var a=0; a<allSlideshows.length; a++){
				// measure the size of the first slide
				var slideHeight = allSlideshows[a].getElementsByTagName('IMG')[0].offsetHeight;
				// adjust the parent node
				allSlideshows[a].style.height = (slideHeight + settings.offset) + 'px';
			}
		},
		build : function(node, event, settings){
			// if this slideshow doesn't have a pager in it already
			var possiblePagers = node.getElementsByTagName('UL');
			if(possiblePagers.length == 0){
				// if the slideshow doesn't have an id
				if(node.id == null || node.id == ''){
					// give it an id
					node.id = 'slideshow_' + teamtwo.slideshow.index++;
				}
				// get the slides in the slideshow
				var allSlides = node.getElementsByTagName('IMG');
				// build the pager parent
				var pagerParent = document.createElement('UL');
				pagerParent.className = 'pager';
				// for every slide
				for(var a=0; a<allSlides.length; a++){
					// give the slide its classname
					allSlides[a].className = 'slide';
					// if the slide doesn't have an id
					if(allSlides[a].id == null || allSlides[a].id == ''){
						// give it an id
						allSlides[a].id = 'slideshow_slide_' + teamtwo.slideshow.index++;
					}
					// create the pager entry
					var pagerEntry = document.createElement('LI');
					var pagerLink = document.createElement('A');
					pagerLink.innerHTML = a;
					pagerLink.href = '#' + allSlides[a].id;
					pagerEntry.appendChild(pagerLink);
					pagerParent.appendChild(pagerEntry);
				}
				// add the pager parent to the slideshow
				node.appendChild(pagerParent);
				node.className += ' slides_active';
				// modify a custom slideshow config
				var newSlideshowConfig = new teamtwo.tabs.config.makeSlideshow;
				newSlideshowConfig.source.rule = newSlideshowConfig.source.rule.replace('{parent}', '#' + node.id);
				newSlideshowConfig.target.rule = newSlideshowConfig.target.rule.replace('{parent}', '#' + node.id);
				var newSlideshow = {}
				newSlideshow['#' + node.id + ' ul.pager li a'] = newSlideshowConfig;
				// start the slideshow
				teamtwo.selectors.process(newSlideshow);
			}
		},
		resize : function(node, event, settings){
			// get the target node
			var targetNode = (node.href != null) ?
				document.getElementById(node.href.split('#')[1]) :
				teamtwo.toggles.sibling(node);
			// apply its size to the root node
			if(targetNode.offsetHeight && targetNode.offsetHeight > 0){
				targetNode.parentNode.style.height = (targetNode.offsetHeight) + 'px';
			}
		}
	}

/*
	Project Jump
*/

	teamtwo.projectjump = {
		config : null,
		init : function(node, event, settings){
			node.selectedIndex = 0;
		},
		jump : function(node, event, settings){
			var targetHash = node.value.split('#');
			if(targetHash.length > 1){
				document.location.hash = targetHash[1];
			}
		}
	}

/*
	Meta Navigation
*/

	teamtwo.meta = {
		untoggle : function(node, event, settings){
			// get all the elements that match this rule
			var allToggles = teamtwo.selectors.query(settings.targets);
			// de-activate their toggle status
			for(var a=0; a<allToggles.length; a++){
				//teamtwo.transitions.tween(allToggles[a], settings.classes[1], settings.classes[0]);
				allToggles[a].className = allToggles[a].className.replace(settings.classes[1], settings.classes[0]);
			}
			// cancel the click
			//if(event != null) event.preventDefault ? event.preventDefault() : event.returnValue = false;
		}
	}

/*
	Navigation Scroll Lock
*/

	teamtwo.scrolllock = {
		repositionTimeout : null,
		adjustTimeout : null,
		redrawTimeout : null,
		browser : {
			'mobile' : (navigator.userAgent.indexOf('Mobile') > -1),
			'ios4' : (navigator.userAgent.indexOf('Mobile') > -1 && navigator.userAgent.indexOf('Apple') > -1 && navigator.userAgent.indexOf('Version/4') > -1),
			'ios5' : (navigator.userAgent.indexOf('Mobile') > -1 && navigator.userAgent.indexOf('Apple') > -1 && navigator.userAgent.indexOf('Version/5') > -1)
		},
		watch : function(node, event, settings){
			// when the page is scrolled
			teamtwo.events.add(window, 'scroll', function(e){
				// adjust the position of the node
				teamtwo.scrolllock.adjust(node, settings);
				// and again after a while
				clearTimeout(teamtwo.scrolllock.adjustTimeout);
				teamtwo.scrolllock.adjustTimeout = setTimeout(function(){
					teamtwo.scrolllock.adjust(node, settings);
				}, 100);
				// if this is an iPad running iOS 5+
				if(teamtwo.scrolllock.browser.ios5){
					// regularly
					clearInterval(teamtwo.scrolllock.redrawTimeout);
					teamtwo.scrolllock.redrawTimeout = setTimeout(function(){
						// force a redraw on the fixed element
						teamtwo.scrolllock.redraw(node, settings);
					}, 500);
				}
			});
		},
		adjust : function(node, settings){
			// get the current scroll position
			var scrollPos = (self.pageYOffset) ?
				self.pageYOffset :
				(document.documentElement) ?
					document.documentElement.scrollTop :
					document.body.scrollTop ;
			// if scrolled far enough
			if(scrollPos > settings.offset && document.body.offsetWidth > 780){
				// apply the scroll lock style
				node.className = 'scrolllock';
// project specific exception
document.getElementById('contentarea').style.paddingTop = node.offsetHeight + 'px';
				// if this is iOS 4
				if(teamtwo.scrolllock.browser.mobile && teamtwo.scrolllock.browser.ios4){
					// wait a moment
					clearTimeout(teamtwo.scrolllock.repositionTimeout);
					teamtwo.scrolllock.repositionTimeout = setTimeout(function(){
							// reposition the node at the scroll position
							node.style.position = 'absolute';
							node.style.marginTop = scrollPos + 'px';
					}, 200);
				}
			// else
			}else if(scrollPos < settings.offset){
				// remove the scroll lock style
				node.className = 'scrollfree';
// project specific exception
document.getElementById('contentarea').style.paddingTop = '0px';
				// if this is iOS 4
				if(teamtwo.scrolllock.browser.mobile && teamtwo.scrolllock.browser.ios4){
					// put the node back to a neutral position
					node.style.position = 'relative';
					node.style.marginTop = '0px';
				}
			}
		},
		redraw : function(node, settings){
			// get the current scroll position
			var scrollPos = (self.pageYOffset) ?
				self.pageYOffset :
				(document.documentElement) ?
					document.documentElement.scrollTop :
					document.body.scrollTop ;
// project specific exception
if(document.body.offsetWidth > 780){
				// change the position to absolute
				node.style.position = 'absolute';
				node.style.marginTop = scrollPos + 'px';
				// wait a while
				setTimeout(function(){
					// if scrolled far enough
					if(scrollPos > settings.offset){
						// reset the position to fixed
						node.style.position = 'fixed';
						node.style.marginTop = '0px';
					}else{
						// rest the position to neutral
						node.style.position = 'relative';
						node.style.marginTop = '0px';
					}
				}, 1);
}else{
	// reset the position to neutral
	node.style.position = 'relative';
	node.style.marginTop = '0px';
}
		}
	}

/*
	Top Link Scroll Lock
*/

	teamtwo.toplink = {
		watch : function(node, event, settings){
			teamtwo.events.add(window, 'scroll', function(e){
				teamtwo.toplink.adjust(node, settings);
			});
			teamtwo.toplink.adjust(node, settings);
		},
		adjust : function(node, settings){
			// get the current scroll position
			var scrollPos = (self.pageYOffset) ?
				self.pageYOffset :
				(document.documentElement) ?
					document.documentElement.scrollTop :
					document.body.scrollTop ;
			// if the position is far enough
			if(scrollPos > settings.offset){
				node.style.visibility = 'visible';
			}else{
				node.style.visibility = 'hidden';
			}
		}
	}

/*
	Placeholder Images (until scrolled into view)
*/

	teamtwo.placeholders = {
		hold : false,
		browser : {
			'mobile' : (navigator.userAgent.indexOf('Mobile') > -1)
		},
		watch : function(node, event, settings){
			// after scrolling
			teamtwo.events.add(window, 'scroll', function(event){
				// if the function was not put on hold
				if(!teamtwo.placeholders.hold){
					// check for images to preload
					teamtwo.placeholders.preload(node, event, settings);
				}
			});
			// initial preload
			teamtwo.placeholders.preload(node, event, settings);
		},
		preload : function(node, event, settings){
			// for all images
			var allImages = teamtwo.selectors.query(settings.images);
			for(var a=allImages.length-1; a>-1; a--){
				// get the current scroll position
				var scrollPos = (self.pageYOffset) ?
					self.pageYOffset :
					(document.documentElement) ?
						document.documentElement.scrollTop :
						document.body.scrollTop ;
				// if the image still has a placeholder and is within view
				if(
					allImages[a].parentNode.offsetTop > scrollPos - settings.offset - settings.offset &&
					allImages[a].parentNode.offsetTop < scrollPos + settings.offset
				){
					// replace the placeholder with the longdesc
					teamtwo.placeholders.load(allImages[a], event, settings);
				}else if(teamtwo.placeholders.browser.mobile){
					// replace the longdesc with the placeholder
					teamtwo.placeholders.unload(allImages[a], event, settings);
				}
			}
		},
		load : function(node, event, settings){
			// replace the placeholder with the longdesc
			if(node.getAttribute('longdesc') != ''){
				node.src = node.getAttribute('longdesc');
				node.setAttribute('longdesc', '');
				// adjust the size after loading
				teamtwo.events.add(node, 'load', function(){
					// adjust the parent node height
					node.parentNode.style.height = node.offsetHeight + 'px';
				});
			}
		},
		unload : function(node, event, settings){
			// replace the placeholder with the longdesc
			if(node.getAttribute('longdesc') == ''){
				// replace the image with the placeholder
				node.setAttribute('longdesc', node.src);
				node.src = settings.placeholder;
			}
		}
	}

/*
	Animated Scrolling to Hash
*/

	teamtwo.animatedscroll = {
		interval : null,
		start : function(){
			// startup
		},
		find : function(node) {
			// define a position object
			var position = {
				'x' : 0,
				'y' : 0
			};
			// if offsetparent exists
			if(node.offsetParent){
				// add every parent's offset
				do{
					position.x += node.offsetLeft;
					position.y += node.offsetTop;
				}while (node = node.offsetParent);
			}
			// return the object
			return position;
		},
		move : function(node, event, settings){
// project specific exception
if(document.getElementById('maincolumn').offsetWidth < 781){
	// reduce the offset
	settings.offset = 0;
}else{
	// increase the offset
	settings.offset = -160;
}
			// cancel any current scrolling
			clearTimeout(teamtwo.animatedscroll.interval);
			// lock the preloader
			if(teamtwo.placeholders != null){
				teamtwo.placeholders.hold = true;
			}
			// if this link has a hash to jump to
			var targetHash = node.hash;
			if(targetHash != null && targetHash != ''){
				// check if the target hash is on the ignore list
				var ignoreHash = false;
				for(var a=0; a<settings.ignore.length; a++){
					if(targetHash.indexOf(settings.ignore[a]) > -1){
						ignoreHash = true;
					}
				}
				if(!ignoreHash){
					// find the targetted element
					var targetElement = document.getElementById(targetHash.split('#')[1]);
					// if the element exists
					if(targetElement != null){
						// find the target position in the document
						var scrollTarget = teamtwo.animatedscroll.find(targetElement).y;
// project specific exception
//if(document.getElementById('projectsmenu').className == 'scrollfree'){
//	scrollTarget = scrollTarget + settings.offset;
//}
						//var scrollTarget = targetElement.offsetTop;
						// move the scroll position from the current to the target position
						teamtwo.animatedscroll.interval = setInterval(function(){
							// find the current position in the document
							var scrollPos = (self.pageYOffset) ?
								self.pageYOffset :
								(document.documentElement) ?
									document.documentElement.scrollTop :
									document.body.scrollTop ;
							// calculate te difference in position
							var scrollDifference = scrollTarget - scrollPos + settings.offset;
							// if the document isn't at the correct position yet
							if(Math.abs(scrollDifference) > settings.approach && teamtwo.animatedscroll.difference != scrollDifference){
								// store the position
								teamtwo.animatedscroll.difference = scrollDifference;
								// divide the distance to the destination
								window.scrollTo(0, scrollPos + (scrollDifference / settings.divider));
							}else{
								// finish the scroll
								document.location.hash = targetHash.split('#')[1];
								window.scrollTo(0, scrollTarget + settings.offset);
								// cancel the scrolling
								clearTimeout(teamtwo.animatedscroll.interval);
								// clear the stored position
								teamtwo.animatedscroll.difference = 0;
								// unlock the preloader
								if(teamtwo.placeholders != null){
									teamtwo.placeholders.hold = false;
								}
							}
						}, settings.delay);
						// cancel the click
						if(event != null) event.preventDefault ? event.preventDefault() : event.returnValue = false;
					}
				}
			}
		},
		cancel : function(node, event, settings){
			if(node.hash != null && node.hash != ''){
				// cancel the click
				if(event != null) event.preventDefault ? event.preventDefault() : event.returnValue = false;
			}
		},
		initial : function(node, event, settings){
			setTimeout(function(){
				// set the deeplinked hash position
				var targetHash = document.location.hash;
				document.location.hash = '#';
				document.location.hash = targetHash;
				// wait a while
				setTimeout(function(){
					// find the current position in the document
					var scrollPos = (self.pageYOffset) ?
						self.pageYOffset :
						(document.documentElement) ?
							document.documentElement.scrollTop :
							document.body.scrollTop ;
					// apply the offset
					window.scrollTo(0, scrollPos + settings.offset);
				}, 100);
			}, settings.delay);
		}
	}

/*
	Page Builder
*/

	teamtwo.page = {
		build : function(node, event, settings){
			// fill in "CAREERS"
			teamtwo.page.meta(
				document.getElementById('careerspopup'),
				teamtwo.page.find('CAREERS', settings.data)
			);
			// fill in "CONTACT US"
			teamtwo.page.meta(
				document.getElementById('contactpopup'),
				teamtwo.page.find('CONTACT US', settings.data)
			);
			// fill in "Header Content"
			setTimeout(function(){
				teamtwo.page.headcontent(
					document.getElementById('headcontent'),
					{
						"our-philosophy": teamtwo.page.find('Our Philosophy', settings.data),
						"our-people": teamtwo.page.find('Our People', settings.data),
						"news": teamtwo.page.find('News', settings.data)
					},
					"our-philosophy"
				);
			}, 100);
			// fill in "Our Clients"
			teamtwo.page.clients(
				document.getElementById('clientslist'),
				teamtwo.page.find('Our Clients', settings.data)
			);
			// fill in "Private Houses"
			teamtwo.page.projects(
				document.getElementById('filter_privatehouses'),
				teamtwo.page.find('Private Houses', settings.data)
			);
			// fill in "Commercial"
			teamtwo.page.projects(
				document.getElementById('filter_commercialprojects'),
				teamtwo.page.find('Commercial', settings.data)
			);
			// fill in "Multi Unit Residential"
			teamtwo.page.projects(
				document.getElementById('filter_multiunitresidential'),
				teamtwo.page.find('Multi Unit Residential', settings.data)
			);
			// fill in "Industrial"
			teamtwo.page.projects(
				document.getElementById('filter_industrialprojects'),
				teamtwo.page.find('Industrial', settings.data)
			);
			// fill in "Healthcare Projects"
			teamtwo.page.projects(
				document.getElementById('filter_healthcareprojects'),
				teamtwo.page.find('Healthcare', settings.data)
			);
			// fill in "Leisure and Hospitality"
			teamtwo.page.projects(
				document.getElementById('filter_leisureandhospitality'),
				teamtwo.page.find('Leisure and Hospitality', settings.data)
			);
			// hide busy indicator
// TODO: Loading the content may leave a jarring pause
		},
		find : function(source, data){
			var foundContent = null;
			var allContent = data.getElementsByTagName('content');
			for(var a=0; a<allContent.length; a++){
				if(allContent[a].getAttribute('title') == source){
					// merge all text nodes
					var textStrings = [];
					var textNodes = allContent[a].getElementsByTagName('copy')[0].childNodes;
					for(var b=0; b<textNodes.length; b++){
						textStrings.push(textNodes[b].nodeValue);
					}
					// build a reply object
					foundContent = {
						'node' : allContent[a],
						'copy' : textStrings,
						'title' : source,
						'images' : allContent[a].getElementsByTagName('image')
					}
				}
			}
			return foundContent;
		},
		meta : function(target, content){
			// fill the content
			if(content != null){
				target.getElementsByTagName('ARTICLE')[0].innerHTML = content.copy.join('');
			}
		},
        cleanCopy: function(copy){
            /* clean up the content to remove empty rows and <br> tags */
            var content = $.map( copy, function(item) {
                var cleanContent = item.replace(/^\s+$/, "");
                cleanContent = cleanContent.replace(/<br>/g, "");
                return ( cleanContent !== "" ? "<p>" + cleanContent + "</p>" : null );
            });
            return copy.join("\n");
        },
		headcontent : function( target, content, selected ) {
            for ( var key in content )
            {
                var $elem = $(target).find("#content-" + key);
                /* clean up the content to remove empty rows and <br> tags */
                var copy = this.cleanCopy(content[key].copy);

                /* set the element content */
                $elem.html( copy );
                //$elem.columnize({width: 290}).hide();//{ width: 290 }).hide();

                var $navItem = $(target).find("#nav-" + key).data("contentKey", key);
            }
		},
		clients : function(target, content){
			// calculate the amount of clients per column
			var perColumn = content.copy.length / 5;
			// for all columns
			var menuColumns = [];
			for(var a=0; a<5; a++){
				// create a menu element
				var newMenu = document.createElement('MENU');
				newMenu.className = (a<3) ? 'clients_left' : 'clients_right' ;
				menuColumns.push(newMenu);
			}
			// for all clients
			for(var a=2; a<content.copy.length; a++){
				// create a client entry
				var menuItem = document.createElement('LI');
				menuItem.innerHTML = content.copy[a];
				// insert it into the correct menu
				var columnIndex = parseInt((a - 2) / perColumn);
				menuColumns[columnIndex].appendChild(menuItem);
			}
			// insert all menus into the document
			for(var a=0; a<menuColumns.length; a++){
				target.getElementsByTagName('DIV')[0].appendChild(
					menuColumns[a]
				);
			}
		},
		projects : function(target, content){
			// if there's content for thei query
			if(content != null){
				// navigation stats
				var sectionContent = [];

				// PROJECT ARTICLES
                if ( content.hasOwnProperty("copy") )
                {
                    var copy = this.cleanCopy(content.copy);
                    var intro = "<h2>" + content.title + "</h2>\n" + copy;
                    var sectionHeader = document.createElement("article");
                    sectionHeader.className = "header";
                    sectionHeader.innerHTML = intro;
                    target.appendChild(sectionHeader);
                    if(copy != ''){
                    	$(target).append($("<div class='divider'><hr/></div>"));
                    }else{
                    	sectionHeader.className += ' empty';
                    }
                }

				// for all content nodes of the section
				var allContents = content.node.getElementsByTagName('content');
				for(var a=0; a<allContents.length; a++){
					// make a new article element
					var newArticle = document.createElement('article');
					newArticle.className = 'project';
					newArticle.className += (a%2 == 0) ? ' odd' : ' even' ;
					newArticle.id = '_' + allContents[a].getAttribute('title').replace(/ /gi, '').toLowerCase();
					// make a new title
					var newTitle = document.createElement('h3');
					newTitle.innerHTML = allContents[a].getAttribute('title');
					// add the title to the article
					newArticle.appendChild(newTitle);
					// get the copy
					var newCopy = teamtwo.page.find(
						allContents[a].getAttribute('title'),
						content.node
					);
					// make a new slideshow
					newSlideshow = document.createElement('figure');
					newSlideshow.className = 'slideshow';
					// for all images
					var allImages = newCopy.images;
					for(var b=0; b<allImages.length; b++){
						// make a new slide
						var newSlide = document.createElement('img');
						newSlide.src = './images/placeholder.gif';
						newSlide.setAttribute('longdesc', allImages[b].firstChild.nodeValue);
						// add it to the slideshow
						newSlideshow.appendChild(newSlide);
					}
					// add the slideshow to the article
					newArticle.appendChild(newSlideshow);
					// add the copy to the article
					var newCopyWrapper = document.createElement('span');
					newCopyWrapper.innerHTML = newCopy.copy.join('');
					newArticle.appendChild(newCopyWrapper);
					// add the article to the target
					target.appendChild(newArticle);
					// if this is an odd article (or the last article, but not the very last article)
					if(a%2 == 1 || a == allContents.length - 1){
						// add a divider after
						var newDivider = document.createElement('div');
						newDivider.className = 'divider';
						var newRuler = document.createElement('hr');
						newDivider.appendChild(newRuler);
						target.appendChild(newDivider);
					}
					// store the stats for the navigation
					sectionContent.push({
						'title' : allContents[a].getAttribute('title'),
						'id' : newArticle.id
					});
				}

				// MOBILE DROPDOWN NAVIGATION
				// create a header element
				var newHeader = document.createElement('header');
				newHeader.className = 'projectjump';
				// create a title
				var newTitle = document.createElement('h2');
				newTitle.innerHTML = content.title;
				// add the title to the header
				newHeader.appendChild(newTitle);
				// create a select
				var newSelect = document.createElement('select');
				var newOption = document.createElement('option');
				var newOptionText = document.createTextNode('Select a project...');
				newOption.appendChild(newOptionText);
				newOption.value = '#';
				newSelect.appendChild(newOption);
				// for every entry in the stat
				for(var a=0; a<sectionContent.length; a++){
					// create an option element
					var newOption = document.createElement('option');
					var newOptionText = document.createTextNode(sectionContent[a].title);
					newOption.appendChild(newOptionText);
					newOption.value = '#' + sectionContent[a].id;
					// add the option to the select
					newSelect.appendChild(newOption);
				}
				// add the select to the header
				newHeader.appendChild(newSelect);
				// add the header before the content in the section
				target.insertBefore(newHeader, target.firstChild);

				// PROJECTS NAVIGATION
				// get the target menu
				var targetMenu = target.id.replace('filter_', 'menu_');
				var menuWrapper = document.getElementById(targetMenu).getElementsByTagName('div')[0];
				// create the menu columns
				var menuColumns = [];
				for(var a=0; a<4; a++){
					menuColumns.push(
						document.createElement('menu')
					);
				}
				// calculate the amount of items per column
				var itemsPerColumn = sectionContent.length / 4;
				// for all project entries
				for(var a=0; a<sectionContent.length; a++){
					// create a menu item
					var newMenuItem = document.createElement('li');
					var newMenuLink = document.createElement('a');
					newMenuLink.href = '#' + sectionContent[a].id;
					newMenuLink.innerHTML = sectionContent[a].title;
					newMenuItem.appendChild(newMenuLink);
					// add the menu item to the corrent column
					var itemColumn = parseInt(a / itemsPerColumn);
					menuColumns[itemColumn].appendChild(newMenuItem);
				}
				// add all columns to the menu
				for(var a=0; a<menuColumns.length; a++){
					menuWrapper.appendChild(menuColumns[a]);
				}
			}
		}
	}

/*
	Scroll Driven Navigation Highlights
*/

	teamtwo.hashnavhighlight = {
		interval : null,
		watch : function(node, event, settings){
			// periodically check the scroll position
			teamtwo.hashnavhighlight.interval = setInterval(function(){
				teamtwo.hashnavhighlight.check(node, event, settings);
			}, settings.interval);
		},
		check : function(node, event, settings){
			// for all links in this parent
			var sourceLinks = node.getElementsByTagName('A');
			for(var a=0; a<sourceLinks.length; a++){
				// if the node is a hash link
				var targetHash = sourceLinks[a].hash;
				if(targetHash != null && targetHash != '' && targetHash.indexOf('menu_') < 0){
					// look up the element belonging to this link
					var targetElement = document.getElementById(targetHash.split('#')[1]);
					// if the element exists
					if(targetElement != null){
						// get the position of the element
						var targetPosition = teamtwo.toggles.position(targetElement);
						// get the height of the element
						var targetHeight = targetElement.offsetHeight;
//debug(targetHash);
//debug(targetPosition.scroll + ' ' + targetPosition.y + ' ' + (targetPosition.y + targetHeight));
						// if the scroll position is within this element's reach
						if(targetPosition.scroll + settings.offset > targetPosition.y && targetPosition.scroll + settings.offset < targetPosition.y + targetHeight){
							// highlight the link
							sourceLinks[a].className = sourceLinks[a].className.replace('_passive', '_active');
						// else
						}else{
							// unhighlight the link
							sourceLinks[a].className = sourceLinks[a].className.replace('_active', '_passive');
						}
					}
				}
			}
		}
	}

/*
	Configuration
*/

	// the projects navigation uses generic tab strip functionality
	teamtwo.tabs.config.navigation = {
		'start' : [
			teamtwo.toggles.init,
			teamtwo.tabs.resize
		],
		'click' : [
			teamtwo.tabs.show,
			teamtwo.toggles.execute,
			teamtwo.tabs.resize
		],
		'source' : {
			'rule' : 'nav#projectsmenu div.projectstype a.viewall',
			'classes' : [
				'tab_closed',
				'tab_open'
			],
			'parent' : 1
		},
		'target' : {
			'rule' : 'nav#projectsmenu div.projectslist',
			'classes' : [
				'list_closed',
				'list_open'
			],
			'parent' : 0
		},
		'grouped' : true,
		'initial' : false,
		'auto' : null,
		'delay' : {
			'close' : 0,
			'open' : 0
		}
	}

	// allows modified slideshow configs to be made on the fly
	teamtwo.tabs.config.makeSlideshow = function(){
		this['start'] = [teamtwo.toggles.init, teamtwo.slideshow.resize];
		this['click'] = [teamtwo.toggles.execute, teamtwo.slideshow.resize];
		this['source'] = {
			'rule' : '{parent} ul.pager li a',
			'parent' : 0,
			'classes' : ['slide_passive', 'slide_active']
		};
		this['target'] = {
			'rule' : '{parent} img.slide',
			'parent' : 0,
			'classes' : ['slide_closed', 'slide_open']
		};
		this['grouped'] = true;
		this['initial'] = 'first';
		this['auto'] = null;
		this['delay'] = {
			'close' : 0,
			'open' : 0
		}
	}

/*
	Start-up Sequence
*/

	if(typeof(jQuery)!='undefined'){
		$(document).ready(function(){
			// start by loading the content file
			$.ajax({
				url: "./assets/content.xml",
				context: document.body,
				success: function(data){

					// process the data into page content
					$('body').teamtwo({
						'start' : teamtwo.page.build,
						'data' : data
					});

					// handles the header content tabs
					$('#headcontent menu a').teamtwo({
						'start' : [
							teamtwo.toggles.init,
							teamtwo.tabs.resize
						],
						'click' : [
							teamtwo.toggles.execute,
							teamtwo.tabs.resize
						],
						'source' : {
							'rule' : '#headcontent menu a',
							'parent' : 0,
							'classes' : [
								'head_passive',
								'head_active'
							]
						},
						'target' : {
							'rule' : '#headcontent article',
							'parent' : 0,
							'classes' : [
								'head_closed',
								'head_open'
							]
						},
						'grouped' : true,
						'initial' : 'first',
						'auto' : null,
						'delay' : {
							'close' : 0,
							'open' : 500
						}
					});

					// jump between projects using a select element
					$('header.projectjump select').teamtwo({
						'start' : teamtwo.projectjump.init,
						'change' : teamtwo.projectjump.jump
					});

					// open the project navigation
					$('nav#projectsmenu div.projectstype a.viewall').teamtwo(
						teamtwo.tabs.config.navigation
					);

					// close the project navigation
					$('nav#projectsmenu div.projectslist a').teamtwo({
						'click' : [teamtwo.tabs.reclick, teamtwo.tabs.hide],
						'config' : teamtwo.tabs.config.navigation
					});

					// make slideshows out of the images in articles
					$('figure.slideshow').teamtwo({
						'start' : teamtwo.slideshow.build
					});

					// start the slideshows simultaneously
					$('body').teamtwo({
						'start' : teamtwo.slideshow.setup,
						'targets' : 'figure.slideshow',
						'offset' : 0
					});

					// toggles for the meta navigation
					$('menu#metanavigation li a').teamtwo({
						'start' : teamtwo.toggles.init,
						'click' : teamtwo.toggles.execute,
						'source' : {
							'rule' : 'menu#metanavigation ul li a',
							'parent' : 0,
							'classes' : ['meta_passive', 'meta_active']
						},
						'target' : {
							'rule' : 'section.metapopup',
							'parent' : 0,
							'classes' : ['meta_closed', 'meta_open']
						},
						'delay' : {
							'close' : 0,
							'open' : 500
						}
					});
					$('section.metapopup header h2 a').teamtwo({
						'click' : teamtwo.meta.untoggle,
						'targets' : 'section.metapopup',
						'classes' : ['meta_closed', 'meta_open']
					});
					$('body').teamtwo({
						'click' : teamtwo.meta.untoggle,
						'targets' : 'section.metapopup',
						'classes' : ['meta_closed', 'meta_open']
					});

					// navigation scroll lock
					$('nav#projectsmenu').teamtwo({
						'start' : teamtwo.scrolllock.watch,
						'offset' : 315
					});

					// top link scroll lock
					$('menu#toplink').teamtwo({
						'start' : teamtwo.toplink.watch,
						'offset' : 768
					});

					// image placeholders until scrolled into view
					$('body').teamtwo({
						'start' : teamtwo.placeholders.watch,
						'images' : 'figure.slideshow img',
						'placeholder' : './images/placeholder.gif' ,
						'offset' : 720
					});
					$('figure.slideshow img').teamtwo({
						'mouseover' : teamtwo.placeholders.load
					});

					// animated scroll to hash
					$('a').teamtwo({
						'start' : teamtwo.animatedscroll.start,
						'mousedown' : teamtwo.animatedscroll.move,
						'click' : teamtwo.animatedscroll.cancel,
						'offset' : -160,
						'approach' : 100,
						'divider' : 5,
						'delay' : 10,
						'ignore' : ['popup', 'type_', 'menu_', 'slideshow_','content-']
					});
					$('body').teamtwo({
						'start' : teamtwo.animatedscroll.initial,
						'offset' : -160,
						'delay' : 700
					});

					/* scroll driven navigation highlight */
					$('nav#projectsmenu div.projectstype menu').teamtwo({
						'start' : teamtwo.hashnavhighlight.watch,
						'interval' : 250,
						'offset' : 200
					});

					/* Google tracking for the PDFs */
					$('a.pdf').click(function() {
						_gaq.push(['_trackEvent', 'PDF', 'Downloaded', $(this).attr('href')]);
					});

				}
			});
		});
	}


