$(document).ready(function() {
	$('#publisher_criteria-no').click(function(){
		alert('testing');
	});
	/////////////////////////////////////////////////////////////////////////////
	// VARS
	/////////////////////////////////////////////////////////////////////////////
	var homeContentShown = false;
	var homeTimer = 0;
	
	/////////////////////////////////////////////////////////////////////////////
	// VARS - COLUMN ANIMATION
	/////////////////////////////////////////////////////////////////////////////
	var stageMgr = {chosen: new Object(), chosenBtn: new Object(), onStage: new Array(), toLoad: new Array()};
	var curSel, oldSel = {} ;
	var colxpos = ['0px', '407px', '809px']; // Taken from style.css hard-coded column positions. Can't grab these values automatically for some reason...
	var originalColumns = ['column1', 'column2', 'column3'];
	var curPopup = {};
	var int_slideShow = 0;
	var int_showIconBlock = 0;
	var int_mapPopup = 0;
	var int_mapPopup2 = 0;
	var buttonMode = '';
	var oldButtonText = '';
	var buttonClicked = false;
	var animRandDir = 0;
	var animRandDir2 = 0;
	var animHideDir = new Array();
		animHideDir.push({height: 'hide', opacity: 'hide'});
		animHideDir.push({height: 'hide', opacity: 'hide', top: (!$.browser.msie) ? $('div.column').css('height') : '360px'}); // top: '477px'
//		animHideDir.push({opacity: 'hide',  left: (!$.browser.msie) ? $('div.column').css('width') : '400px'});
//		animHideDir.push({opacity: 'hide', left: (!$.browser.msie) ? '-'+$('div.column').css('width') : '-400px'});
	var animShowDir = new Array();
		animShowDir.push({height: 'show', opacity: 'show'});
		animShowDir.push({height: 'show', opacity: 'show', top: '0px'});
//		animShowDir.push({opacity: 'show', left: '0px'});
//		animShowDir.push({opacity: 'show', left: (!$.browser.msie) ? $('div.column').css('width') : '400px'});
	var caseStudyVisible = false;
	var current_question = 0;
	var requiredInputs = new Object();
	var max_count_questions = $('div.publisher-application div.question').length;

	/////////////////////////////////////////////////////////////////////////////
	// INIT - CUFON FONT REPLACEMENT
	/////////////////////////////////////////////////////////////////////////////
	// http://wiki.github.com/sorccu/cufon/
	// http://cufon.shoqolate.com/generate/
	Cufon.replace(['div#headline h1, div.case-study-detail div.case-study-detail-name, div.iat-copy'], {fontFamily: 'Gotham-Bold'});
	Cufon.replace(['div.iat-stat'], {fontFamily: 'Gotham-Medium'});
	Cufon.replace(['div.case-study-detail div.case-study-detail-section-title'], {fontFamily: 'Gotham-Book'});
	Cufon.replace(['div#headline h2, div#nav a.nav-item'], {fontFamily: 'Archer-Semibold'});
	Cufon.replace(['div.map-popup div.map-popup-num'], {fontFamily: 'Archer-Bold'});
	Cufon.replace(['div.content h3, div.column-category-small-title h4, div.column-category-large-title h4'], {fontFamily: 'Archer-Italic'});
	Cufon.replace(['div.content .button-LG, div.content .button-MD'], {fontFamily: 'Archer-Bold-Italic'});
	Cufon.replace(['div.content h5'], {fontFamily: 'Archer-SemiboldItalic'});

	/////////////////////////////////////////////////////////////////////////////
	// INIT - BUTTON FUNCTIONALITY - HOME
	/////////////////////////////////////////////////////////////////////////////
	$('div.home div.column a.button-LG').click(function(event){
		//event.preventDefault();
		if(buttonClicked == false) {
			if(buttonMode !== 'back') {
				buttonMode = 'back';
				setStageMgr(event, 'home');
				moveStageElements('home');
			} else {
				buttonMode = '';
				setStageMgr(event, 'home_reset');
				moveStageElements('home_reset');
			}
		} // END if(buttonClicked == false)
	}); // END $('div.home div.column a.button-LG').click()

	/////////////////////////////////////////////////////////////////////////////
	// INIT - BUTTON FUNCTIONALITY - INFOGRAPHICS
	/////////////////////////////////////////////////////////////////////////////
	$('div.infographics div.column a.button-MD').click(function(event){
		var cufon_alt_count = 0;
		//if($(this).attr('href').match(new RegExp('#topic')) !== null) {
		if($(this).attr('rel').match(new RegExp('topic')) !== null) {
			//event.preventDefault();
			if(buttonClicked == false) {
				switch($('div#site').hasClass('has-default-state')) {
					case true:
						$('span.cufon-alt', this).each(function() { if($(this).html().match(new RegExp('back'))) { cufon_alt_count++; } });
						// if this button doesn't equal 'back'...
						//if(!$('span.cufon-alt', this).html().match(new RegExp('back'))) { 
						if(cufon_alt_count == 0) {
							buttonMode = 'back';
							setStageMgr(event, 'infographics');
							moveStageElements('infographics');
							alignArrow($(this));
						} else {
							buttonMode = '';
							setStageMgr(event, 'infographics_reset');
							moveStageElements('infographics_reset');
							hideArrow();
						}
					break;
					// If this is a list that defaults on the first button (i.e., "Press", "Resources")
					case false:
						if(!$('span.cufon-alt', this).html().match(new RegExp('viewing'))) { 
							buttonMode = 'viewing';
							setStageMgr(event, 'infographics');
							moveStageElements('infographics');
							// Disable this button while enabling other buttons in the given scope
							enableDisableButton($(this), $(this).parent().parent());
							alignArrow($(this));
						}
					break;
				} // END switch($('div#site').hasClass('has-default-state'))
			} // END if(buttonClicked == false)
		} // END if($(this).attr('href').match(new RegExp('#topic')) !== null)
	}); // END $('div.infographics div.column a.button-MD').click()
	
	/////////////////////////////////////////////////////////////////////////////
	// INIT - BUTTON FUNCTIONALITY - LIST
	/////////////////////////////////////////////////////////////////////////////
	$('div.list div.column a.button-MD').click(function(event){
		var cufon_alt_count = 0;
		//if($(this).attr('href').match(new RegExp('#topic')) !== null) {
		if($(this).attr('rel').match(new RegExp('topic')) !== null) {
			//event.preventDefault();
			if(buttonClicked == false) {
				switch($('div#site').hasClass('has-default-state')) {
					case true:
						// If this is a list with a default state AND none of the buttons in the submenu have been activated...
						$('span.cufon-alt', this).each(function() { if($(this).html().match(new RegExp('back'))) { cufon_alt_count++; } });
						//if(!$('span.cufon-alt', this).html().match(new RegExp('back'))) { 
						if(cufon_alt_count == 0) {
							buttonMode = 'back';
							setStageMgr(event, 'list');
							moveStageElements('list');
							alignArrow($(this));
						} else {
							buttonMode = '';
							setStageMgr(event, 'list_reset');
							moveStageElements('list_reset');
							hideArrow();
						}
					break;
					// If this is a list that defaults on the first button (i.e., "Press", "Resources")
					case false:
						if(!$('span.cufon-alt', this).html().match(new RegExp('viewing'))) { 
							buttonMode = 'viewing';
							setStageMgr(event, 'list');
							moveStageElements('list');
							// Disable this button while enabling other buttons in the given scope
							enableDisableButton($(this), $(this).parent().parent());
							alignArrow($(this));
						}
					break;
				} // END switch($('div#site').hasClass('has-default-state'))
			} // END if(buttonClicked == false)
		} // END if($(this).attr('href').match(new RegExp('#topic')) !== null)
	}); // END $('div.list div.column a.button-MD').click()

	/////////////////////////////////////////////////////////////////////////////
	// INIT - BUTTON FUNCTIONALITY - RESOURCES
	/////////////////////////////////////////////////////////////////////////////
	$('div.glossary ul.glossary-legend a').click(function(event) {
		event.preventDefault();
		var toShow = $(this).attr('href').substring(1, $(this).attr('href').length);
		// Hide currently displayed glossary group...
		$('div.glossary div.glossary-definitions div.gd-group:visible').animate({height: 'hide', opacity: 'hide'}, 'fast', 'easeOutQuad', function() {
			// Reveal selected glossary group
			$('div.glossary div.glossary-definitions div.'+toShow).animate({height: 'show', opacity: 'show'}, 'slow', 'easeOutQuad');
		});
	});
	/////////////////////////////////////////////////////////////////////////////
	// INIT - PAGE-SPECIFIC (HOME)
	/////////////////////////////////////////////////////////////////////////////
	if($('div#site').hasClass('home') && $.cookie('hydra_home') == null) {
		$.cookie('hydra_home', '1', {expires: 365});
		setHomeUserAction();
		homeTimer = setTimeout(showHomeContent, 3500); // wait 3.5sec before automatically showing homepage content
	} else {
		showHomeContentStatic();
	} // END if($('div#site').hasClass('home') && $.cookie('hydra_home') == null)
	
	/////////////////////////////////////////////////////////////////////////////
	// INIT - PAGE-SPECIFIC (#HASH BYPASS; PAGES THAT HAVE NO DEFAULT STATE GET FIRST LINK AUTO-CLICKED)
	/////////////////////////////////////////////////////////////////////////////
	// If the page subnav can be directly accessed (i.e., Press -> Executive Bios) AND there's a valid #hash tag, "click" that button
	//if($('div#site').hasClass('hash-bypass') && document.location.hash !== '') {
	if(document.location.hash !== '') {
		var temph = document.location.hash;
		var tempr = temph.substring(1);
		if($('a.button-topic[href="'+temph+'"]')) {
			$.timer(0, function() {
				$('a.button-topic[href="'+temph+'"]').click();
			});
		}
		// For index page
		if($('a.sliding-column[href="'+temph+'"]')) {
			$.timer(0, function() {
				$('a.sliding-column[href="'+temph+'"]').click();
			});
		}
	// ...if this DOES NOT have a default state
	} else if(!$('div#site').hasClass('has-default-state')) {
		$.timer(0, function() {
			//$('a[href="#topic0"]').click();
			$('a[rel="topic0"]').click();
		});
	}

	/////////////////////////////////////////////////////////////////////////////
	// INIT - PAGE-SPECIFIC (CASE STUDIES)
	/////////////////////////////////////////////////////////////////////////////
	if($('div#site').hasClass('case-studies')) {
		// Add mouse func to symbols
		$('div.plus-symbol')
			.mouseover(popupDelayShow)
			.mouseout(popupDelayHide)
			.click(popupShowCaseStudy);
		// Add mouse func to popup so it doesn't disappear on mouseover
		$('div.map-popup')
			.mouseover(function(){ $.clearTimer(int_mapPopup); })
			.mouseout(popupDelayHide)
			.click(popupShowCaseStudy);
		// Add mouse func to close button for case study detail
		$('div.case-study-detail-close a').click(popupHideCaseStudy);
	} // END if($('div#site').hasClass('case-studies'))

	/////////////////////////////////////////////////////////////////////////////
	// INIT - PAGE-SPECIFIC (INQUIRY FORM)
	/////////////////////////////////////////////////////////////////////////////
	if($('div#site').hasClass('inquiry-form')) {
		$('#registerform input')
			.focus(function(){
				$(this)
					.css({color: '#666'})
					.animate({backgroundColor: '#E9F5F8'}, 500);
			})
			.blur(function(){
				$(this).animate({backgroundColor: '#FBFBFB'}, 300);
			});
		// If this is a standards-compliant browser (that is, not IE)...
		if(!$.browser.msie) {
			$('#registerform select')
				.focus(function(){
					$(this).css({color: '#666'}).animate({backgroundColor: '#E9F5F8'}, 500);
				})
				.blur(function(){
					$(this).animate({backgroundColor: '#FBFBFB'}, 300);
				});
		} else {
			// Any background or color changes to select cause it to behave strangely in IE7/8, so I'm disabling that functionality just for IE7/8
			$('#registerform select').bind('mousedown focus', function() {
				// So it affects IE8
				$(this).css({color: '#666'});
				// For IE7
				$(this).children('option').css({color: '#666'});
			});
			// When the value of the select changes, remove the background color from all options
			//$('#registerform select').bind('propertychange blur', function() {});
		}
	}

	/////////////////////////////////////////////////////////////////////////////
	// INIT - PAGE-SPECIFIC (AGENCIES)
	/////////////////////////////////////////////////////////////////////////////
	if($('div#site').hasClass('agencies')) {
		// If this has an info-block, animate that info-block on a delay
		if($('div.icon-block', $('div#topic0')).length > 0) { showIconBlock($('div.icon-block', $('div#topic0'))); }
	}

	/////////////////////////////////////////////////////////////////////////////
	// INIT - PAGE-SPECIFIC (PUBLISHERS)
	/////////////////////////////////////////////////////////////////////////////
	if($('div#site').hasClass('publishers')) {
		// Record required input names in an Object for ease of reference
		$('div.publisher-application div.question').each(function() {
			var t = String($(this).attr('id'));
			requiredInputs[t] = new Object();
			$('.required-input', this).each(function() {
				var r = String($(this).attr('name'));
				requiredInputs[t][r] = false;
			});
		});
		// Add button functionality
		//$('div.publisher-application button.submit, div.publisher-application a.progress-next').click(function(event) {
		$('div.publisher-application button.submit').click(function(event) {
			event.preventDefault();
			// Check if there's an agreement checkbox in the containing <div>
			// If there is, make sure it's checked before running loadApplicationQuestion()
			// Have to track whether a question has been fully answered before continuing
			if(current_question > -1 && allRequiredFieldsFilled() == true) { loadApplicationQuestion('next'); }
		});
		$('div.publisher-application a.progress-prev').click(function(event) {
			event.preventDefault();
			if(current_question > 0) { loadApplicationQuestion('prev'); }
		});
		// This is to force IE to recognize a change in the value of a radio or checkbox click
		$('div.publisher-application .required-input').bind($.browser.msie ? 'propertychange' : 'change', function(event) {
		//$('div.publisher-application .required-input').change(function() {
			event.preventDefault();
			var q = 'question'+current_question;
			var n = $(this).attr('name');
			// Based on the input/select/textarea type of data, change the value of requiredInputs{}
			if($(this).is('input')) {
				switch($(this).attr('type')) {
					case 'checkbox':
						requiredInputs[q][n] = $(this).is(':checked');
						// Special condition for "Terms & Conditions" checkbox
						if($(this).attr('name') == 'checkbox_terms_and_conditions' && $(this).is(':checked') == true) {
							// Have to calculate bottom of div.container based on dimensions of interior wrapper div
							$('div.container', $(this).parent().parent()).animate({scrollTop: $('div.container div.container-inner', $(this).parent().parent()).outerHeight()+"px"});
						}
					break;
					case 'text':
					case 'radio':
						requiredInputs[q][n] = ($(this).val() !== '') ? true : false;
					break;
				}
			} else if($(this).is('select')) {
				//console.log($(this).val());
			} else if($(this).is('textarea')) {
				//console.log($(this).html());
			}
		});
		//
		/*
		$('div.publisher-application div.referral-contact input.input-text').focus(function(event) {
			event.preventDefault();
			console.log($(this).val());
			if($(this).val() == 'Name' || $(this).val() == 'Company' || $(this).val() == 'Email' || $(this).val() == 'Phone Number' || $(this).val() == 'Hydra Publisher ID (optional)') {
				$(this).val = '';
			}
		});
		*/
	}
	
	/////////////////////////////////////////////////////////////////////////////
	// INIT - MISCELLANEOUS
	/////////////////////////////////////////////////////////////////////////////
	// Reveal div#headline h1 after applying Cufon so there's no flash of unstyled content
	$('div#headline h1').css('display', 'block');
	
	// Disable top-level nav buttons since they don't do anything as far as clicking them is concerned
	$('div#nav ul li a.nav-item').click(function(event) { event.preventDefault(); });
	// Superfish subnav script
	// http://users.tpg.com.au/j_birch/plugins/superfish/#options
	$('ul.sf-menu').superfish({
		disableHI: true,
		delay: 200, // amount of time to wait before hiding drop-down menus
		animation: { height: 'show' },
		speed: 300,
		autoArrows: false,
		dropShadows: false
	});

	// Login
	$('div#login form input#login_user_name').val('User Name');
	$('div#login form input#login_password')
		.before('<input id="login_password_dummy" name="login_password_dummy" type="text" value="Password" />')
		.keyup(function() {
			if($(this).val().length > 2) {
				$('div#login form div.button-wrapper').animate({opacity: 'show'}, 'slow', 'easeOutQuad');
			} else {
				$('div#login form div.button-wrapper').animate({opacity: 'hide'}, 'fast', 'easeOutQuad');
			}
		});
	$('input#login_password').val('').hide();
	// Find a way to insert a plain-text input 'password' field before login_password on-the-fly
	$('div#login input')
		.focus(function(){
			// Force dark-gray color on field once user clicks on it
			$(this).css({color: '#666'});
			// Add class to change color of input field temporarily
			$(this).addClass('input-focus');
			// Clear out the field on focus if the user has not input anything yet
			if($(this).val() == 'User Name' || $(this).val() == 'Password') { $(this).val(''); }
			// If this is the password field, show/hide the dummy input field
			if($(this).attr('id') == 'login_password_dummy') {
				$(this).hide();
				$('input#login_password')
					.show()
					.focus();
			}
		})
		.blur(function(){
			$(this).removeClass('input-focus');
		});
		
	// Search
	// The input#submit button causes conflicts with $('a#icon-search').click(), so just remove it since the button is there for legacy purposes anyways
	$('div#search-field input#submit').remove();
	//
	$('form#cse-search-box').submit(function() {
		if($('div#search-field input#search').val() == '') {
			return false;
		}
	}); // END $('form#cse-search-box').submit()
	$('a#icon-search').click(function(event) {
		event.preventDefault();
		if($(this).attr('chosen') !== 'chosen') {
			$(this)
				.attr('chosen', 'chosen')
				.addClass('icon-search-focus');
			// Reveal search field
			$('div#search-field').animate({ width: 'show' }, 'slow', 'easeOutQuad', function() { $('input#search', this).focus(); });
		} else if($('div#search-field input#search').val() == '') {
			$('div#search-field input#search').focus();
			hilite($('div#search-field'), 'hilite-input');
		} else if($('div#search-field input#search').val() !== '') {
			$('form#cse-search-box').submit();	
		}
	}); // END $('a#icon-search').click()
	$('div#search-field input#search').blur(function() {
		// Have to use $.timer otherwise I can't check the value of what gets $.focused()
		// If, on blur(), focus is transferred to a#icon-search, do nothing. Else, minimize fields
		$.timer(50, function() {
			if($('a#icon-search').attr('id') !== $($.focused()).attr('id')) {
				$('a#icon-search')
					.removeAttr('chosen')
					.removeClass('icon-search-focus');
				// Hide search field
				$('div#search-field').animate({ width: 'hide' }, 'fast', 'easeOutQuad');
			}
		}); // END $.timer()
	}); // END $('div#search-field input#search').blur()

	/////////////////////////////////////////////////////////////////////////////
	// INIT - PAGE-SPECIFIC (FAQ)
	/////////////////////////////////////////////////////////////////////////////
	if($('div#site').hasClass('faq')) {
		// If this has an info-block, animate that info-block on a delay
		//if($('div.icon-block', $('div#topic0')).length > 0) { showIconBlock($('div.icon-block', $('div#topic0'))); }
//		$('div.container', $(this).parent().parent()).animate({scrollTop: $('div.container div.container-inner', $(this).parent().parent()).outerHeight()+"px"});
	
		$('div.faq a.named-anchor').click(function(event) {
			//event.preventDefault();
			if($(this).attr('href') == '#top') {
				scrollToTop();
			} else {
				var href = $(this).attr('href').substring(1);
				var target = $('div.columns a[name="'+href+'"]').offset().top+"px";
				$('html, body').animate({scrollTop: target}, 'slow', 'easeOutQuad');
			}
		});
	}

	
	
	




	/////////////////////////////////////////////////////////////////////////////
	// FUNCTIONS - SHARED
	/////////////////////////////////////////////////////////////////////////////
	function scrollToTop() {
		// Scroll viewable window to top (for links that occur at the bottom of a long list)
		$('html, body').animate({scrollTop: 0}, 'slow', 'easeOutQuad');
	}; // END function scrollToTop()
	function enableDisableButton(btn, scope) {
		$('a.button-MD', scope).each(function() {
			//console.log($(this).attr('href') == btn.attr('href'));
			if($(this).attr('href') == btn.attr('href')) {
				// Disable btn when it's clicked
				$(this).addClass('disabled-button');
			} else {
				// Search for siblings and enable them
				$(this).removeClass('disabled-button');
			}
		});
	}; // END function enableDisableButton()
	function changeButton(btn, type) {
		if(btn.attr !== undefined) {
			//var classToAdd = (btn.attr('class').match(new RegExp('LG'))) ? 'button-LG-back' : 'button-MD-back';
			var classToAdd = (btn.hasClass('button-LG')) ? 'button-LG-back' : 'button-MD-back';
			switch(type) {
				default:
					// Record old button text so I can replace it later
					oldButtonText = $('.cufon-alt', btn).html();
					//
					var h = (type == 'back') ? ('&laquo; '+type) : (type+' &raquo;');
					btn.html(h).addClass(classToAdd);
//					btn.html(type+' &raquo;').addClass(classToAdd);
				break;
				case '':
					btn.html(oldButtonText).removeClass(classToAdd);
				break;
			} // END switch(type)
			Cufon.refresh(btn);
			hilite(btn, 'hilite');
		} // END if(btn.attr !== 'undefined')
	}; // END function changeButton()
	// Flash a color over an element to indicate a change in state
	function hilite(ele, hclass) {
		if(hclass == undefined) { hclass = 'hilite'; }
		ele.append('<span class="'+hclass+'"></span>');
		$('span.'+hclass, ele)
			.css({display: 'block', opacity: 0.8})
			.animate({opacity: 'hide'}, 500, 'easeOutQuad', function() { $(this).remove(); });
	}; // END function hilite()
	// Align div.arrow with element contained inside div.column-lead
	function alignArrow(ele) {
		var newTop = (ele.parent().offset().top - ele.parent().parent().offset().top) + "px"
		// Reveal arrow if it's hidden
		$('div.arrow').animate({right: '-10px'}, 'fast', 'easeOutQuad', function() {
			$(this).css('top', newTop).animate({right: '0px'}, 'slow', 'easeOutQuad');
		}); 
	}; // END function alignArrow()
	function alignArrowSlide(ele) {
		var newTop = (ele.parent().offset().top - ele.parent().parent().offset().top) + "px"
		$('div.arrow').animate({top: newTop}, 'slow', 'easeOutQuad')
		// Reveal arrow if it's hidden
		if($('div.arrow').css('right') !== '0px') { $('div.arrow').animate({right: '0px'}, 'fast', 'easeOutQuad'); }
	}; // END function alignArrowSlide()
	// Hide the arrow
	function hideArrow() {
		$('div.arrow').animate({right: '-10px'}, 'fast', 'easeOutQuad', function() { $(this).css('top', '0px'); });
	}; // END function hideArrow()
	
	/////////////////////////////////////////////////////////////////////////////
	// FUNCTIONS - HOME
	/////////////////////////////////////////////////////////////////////////////
	function showHomeContent() {
		clearTimeout(homeTimer);
		if (!homeContentShown) {
			homeContentShown = true;
			// Animate the Hydra logo into position
			$('div#logo').animate({top: '38px'}, 700, 'easeInOutQuad');
			// Delay animation of the rest of the 'Home' elements
			setTimeout(function() {
				$('div#headline-image, div#headline-subtitle h2, div#nav, div.content, div#column-title h3, div#footer, div#logo h2').animate({'opacity':'show'},750)
			}, 250);
		}
	}; // END function showHomeContent()
	// If site already viewed once, just show "Home" content in their final, static positions
	function showHomeContentStatic() {
		$('div#logo').css({top: '38px'});
		$('div#headline-image, div#headline-subtitle h2, div#nav, div.content, div#column-title h3, div#footer, div#logo h2').animate({'opacity':'show'}, 0);
	}; // END function showHomeContentStatic()
	// Detects when user moves the mouse or presses a key
	function setHomeUserAction() {
		$('html')
			.keydown(function(event){
				// Can detect by event.keyCode, if needed
				clearTimeout(homeTimer);
				showHomeContent();
			})
			.mousemove(function(){
				clearTimeout(homeTimer);
				showHomeContent();
			});
	}; // END function setHomeUserAction()
	
	/////////////////////////////////////////////////////////////////////////////
	// FUNCTIONS - PORTFOLIO
	/////////////////////////////////////////////////////////////////////////////
	function startSlideShow() {
		stopSlideShow();
		$('div.portfolio img').hide();
		$('div.portfolio img:first-child').show();
		int_slideShow = setInterval(function() {
			$('div.portfolio img:first-child')
				.animate({opacity: 'toggle'}, 1000, 'easeOutQuad')
				.next('img')
					.animate({opacity: 'toggle'}, 1000, 'easeOutQuad')
					.end()
				.appendTo('div.portfolio');
		}, 4000);
	}; // END function startSlideShow()
	function stopSlideShow() {
		clearInterval(int_slideShow);
	}; // END function stopSlideShow()
	
	/////////////////////////////////////////////////////////////////////////////
	// FUNCTIONS - COLUMN ANIMATION
	/////////////////////////////////////////////////////////////////////////////
	function setStageMgr(event, type) {
		// Record old button (if applicable)
		oldSel = stageMgr.chosenBtn;
		// Reset stageMgr
		delete stageMgr;
		stageMgr = {chosen: new Object(), chosenBtn: new Object(), onStage: new Array(), toLoad: new Array()};
	
		// Direct reference to stage object parent
		stageMgr.chosen = $(event.currentTarget.parentNode.parentNode);
		// Direct reference to chosen button
		stageMgr.chosenBtn = $(event.currentTarget);
	
		// Apply new parameters to stageMgr
		switch(type) {
			case 'home':
				// Register div.column elements on-stage
				$('div.column').each(function() {
					if($(this).css('display') == 'block' && $(this).attr('id') !== stageMgr.chosen.attr('id')) {
						stageMgr.onStage.push({ref: $(this), xpos: $(this).css('left')});
					// Register div.column elements that match stageMgr.chosen id (but are NOT stageMgr.chosen)
					} else if($(this).attr('id').match(new RegExp(stageMgr.chosen.attr('id'))) && $(this).attr('id') !== stageMgr.chosen.attr('id')) {
						stageMgr.toLoad.push({ref: $(this), xpos: ''});
					}
				}); // END $('div.column').each()
			break;
			case 'home_reset':
				// Register div.column elements on-stage
				$('div.column').each(function() {
					if($(this).css('display') == 'block' && $(this).attr('id') !== stageMgr.chosen.attr('id')) {
						stageMgr.onStage.push({ref: $(this)});
					// Register div.column elements that match originalColumns[] (but are NOT stageMgr.chosen)
					} else if($(this).attr('id').match(new RegExp('(^column1$|^column2$|^column3$)')) !== null && $(this).attr('id') !== stageMgr.chosen.attr('id')) {
						stageMgr.toLoad.push({ref: $(this)});
					}
				}); // END $('div.column').each()
			break;
			case 'list':
			case 'infographics':
				//var topic = stageMgr.chosenBtn.attr('href').substring(1, stageMgr.chosenBtn.attr('href').length);
				var topic = stageMgr.chosenBtn.attr('rel').substring(1, stageMgr.chosenBtn.attr('rel').length);
				$('div.columns div.column').each(function() {
					//if($(this).css('display') == 'block' && $(this).attr('id') !== topic) {
					if($(this).css('display') == 'block' && !$(this).attr('id').match(new RegExp(topic))) {
						stageMgr.onStage.push({ref: $(this)});
					// Register div.column elements that partially match String topic, i.e. 'topic2' will match with 'topic2a' and 'topic2b'
					} else if($(this).attr('id').match(new RegExp(topic))) {
						stageMgr.toLoad.push({ref: $(this)});
					}
				}); // END $('div.columns div.column').each()
			break;
			case 'list_reset':
			case 'infographics_reset':
				var topic = 'topic0';
				$('div.columns div.column').each(function() {
					if($(this).css('display') == 'block' && $(this).attr('id') !== topic) {
						stageMgr.onStage.push({ref: $(this)});
					// Register div.column elements that partially match String topic, i.e. 'topic2' will match with 'topic2a' and 'topic2b'
					} else if($(this).attr('id').match(new RegExp(topic)) !== null) {
						stageMgr.toLoad.push({ref: $(this)});
					}
				}); // END $('div.columns div.column').each()
			break;
		} // END switch()
	}; // END setStageMgr()
	function moveStageElements(type) {
		var time = 0;
		var time2 = 0;
		var int = 250;
		var colcount = 1;
		var colcount_vert = 0;
		var count = 0;
		var count2 = 0;
		var chosenNum = 0;
		// Lock down button functionality until animations are done
		buttonClicked = true;
		// Animate stage objects based on page type (home, list, infographics)
		switch(type) {
			case 'home':
				animRandDir = 0;
				// Hide other stage elements that are not the chosen one
				for(var i in stageMgr.onStage) {
					$.timer(time, function() {
						//console.log(stageMgr.onStage[count].ref);
						stageMgr.onStage[count].ref.animate(animHideDir[animRandDir], 500, 'easeOutQuad', function() {});
						// increment temp vars
						//animRandDir = Math.round(Math.random() * (animHideDir.length - 1));
						animRandDir++;
						count++;
					}); // END $.timer()
					time += int;
				} // END for(var i in stageMgr.onStage)
				// Move chosen element to original column position
				chosenNum = Number(stageMgr.chosen.attr('id').substring(6, stageMgr.chosen.attr('id').length));
				time2 = (chosenNum == 0) ? 0 : time;
				$.timer(time2, function() {
					stageMgr.chosen.animate({left: colxpos[0]}, 500, 'easeOutQuad', function() {});
				}); // END $.timer()
				// Change button to "back"
				$.timer(time2 * 1.5, function() {
					changeButton(stageMgr.chosenBtn, 'back');
				});
				time += int;
				animRandDir2 = 0;
				// Load new content columns
				for(var d in stageMgr.toLoad) {
					$.timer(time, function() {
						//console.log(stageMgr.onStage[count].ref);
						stageMgr.toLoad[count2].ref
							.css({left: colxpos[colcount]})
							.animate(animShowDir[animRandDir2], 500, 'easeOutQuad', function() {
								buttonClicked = (count2 == stageMgr.toLoad.length) ? false : true;
							});
						// increment temp vars
						//animRandDir = Math.round(Math.random() * (animShowDir.length - 1));
						animRandDir2++;
						count2++;
						colcount++;
					});
					time += int;
				} // END for(var d in stageMgr.toLoad)
			break;
			case 'home_reset':
				animRandDir = 0;
				// Hide other stage elements that are not the chosen one
				for(var i in stageMgr.onStage) {
					$.timer(time, function() {
						stageMgr.onStage[count].ref.animate(animHideDir[animRandDir], 500, 'easeOutQuad', function() {});
						// increment temp vars
						//animRandDir = Math.round(Math.random() * (animShowDir.length - 1));
						animRandDir++;
						count++;
					}); // END $.timer()
					time += int;
				} // END for(var i in stageMgr.onStage)
				// Move chosen element to original column position
				chosenNum = Number(stageMgr.chosen.attr('id').substring(6, stageMgr.chosen.attr('id').length)) - 1;
				time2 = (chosenNum == 0) ? 0 : time;
				$.timer(time2, function() {
					stageMgr.chosen.animate({left: colxpos[chosenNum]}, 500, 'easeOutQuad', function() {});
				}); // END $.timer()
				// Change button to original state
				$.timer(time2 * 1.5, function() {
					changeButton(stageMgr.chosenBtn, '');
				});
				time += int;
				animRandDir2 = 0;
				// Load new content columns
				for(var d in stageMgr.toLoad) {
					$.timer(time, function() {
						// have to determine colxpos[#] based on toLoad[#].ref.attr('id')
						chosenNum = Number(stageMgr.toLoad[count2].ref.attr('id').substring(6, stageMgr.toLoad[count2].ref.attr('id').length)) - 1;
						stageMgr.toLoad[count2].ref
							.css({left: colxpos[chosenNum]})
							.animate(animShowDir[animRandDir2], 500, 'easeOutQuad', function() {
								buttonClicked = (count2 == stageMgr.toLoad.length) ? false : true;
							});
						// increment temp vars
						//animRandDir = Math.round(Math.random() * (animShowDir.length - 1));
						animRandDir2++;
						count2++;
					});
					time += int;
				} // END for(var d in stageMgr.toLoad)
			break;
			case 'list':
			case 'infographics':
				// Hide other stage elements that are not the chosen one
				for(var i in stageMgr.onStage) {
					$.timer(time, function() {
						var r = stageMgr.onStage[count].ref;
						stageMgr.onStage[count].ref
							.animate(animHideDir[animRandDir], 500, 'easeOutQuad', function() {
								
							});
						// Add parameter to stop portfolio slideshow
						if($('div#site').hasClass('value-added-services') && $('div.portfolio', stageMgr.onStage[count].ref).length !== 0) { stopSlideShow(); }
						if($('div.icon-block', stageMgr.onStage[count].ref).length > 0) { hideIconBlock($('div.icon-block', stageMgr.onStage[count].ref)); }
						// increment temp vars
						animRandDir = Math.round(Math.random() * (animHideDir.length - 1));
						count++;
					}); // END $.timer()
					time += int;
				} // END for(var i in stageMgr.onStage)
				// Change button to "back" or "viewing"
				$.timer(time * 1.5, function() {
					//var newTxt = (type !== 'infographics') ? 'viewing' : 'back';
					var newTxt = ($('div#site').hasClass('has-default-state')) ? 'back' : 'viewing';
					changeButton(oldSel, '');
					changeButton(stageMgr.chosenBtn, newTxt);
				});
				time += int;
				// Load new content columns
				for(var d in stageMgr.toLoad) {
					$.timer(time, function() {
						stageMgr.toLoad[count2].ref
							.css({left: colxpos[colcount_vert], top: '0px'})
							.animate(animShowDir[animRandDir], 500, 'easeOutQuad', function() {
								buttonClicked = (count2 >= (stageMgr.toLoad.length - 1)) ? false : true;
							});
						// Add parameter to start portfolio slideshow
						if($('div#site').hasClass('value-added-services') && $('div.portfolio', stageMgr.toLoad[count2].ref).length !== 0) { startSlideShow(); }
						// If this has an info-block, animate that info-block on a delay
						if($('div.icon-block', stageMgr.toLoad[count2].ref).length > 0) { showIconBlock($('div.icon-block', stageMgr.toLoad[count2].ref)); }
						// increment temp vars
						animRandDir = Math.round(Math.random() * (animShowDir.length - 1));
						count2++;
						colcount_vert++;
					});
					time += int;
				} // END for(var d in stageMgr.toLoad)
			break;
			case 'list_reset':
			case 'infographics_reset':
				// Hide other stage elements that are not the chosen one
				for(var i in stageMgr.onStage) {
					$.timer(time, function() {
						stageMgr.onStage[count].ref
							.animate(animHideDir[animRandDir], 500, 'easeOutQuad', function() {
								
							});
						// If there's a div.icon-block, hide it
						if($('div.icon-block', stageMgr.onStage[count].ref).length > 0) { hideIconBlock($('div.icon-block', stageMgr.onStage[count].ref)); }
						// increment temp vars
						animRandDir = Math.round(Math.random() * (animHideDir.length - 1));
						count++;
					}); // END $.timer()
					time += int;
				} // END for(var i in stageMgr.onStage)
				// Change button to "back"
				$.timer(time * 1.5, function() {
					changeButton(oldSel, '');
				});
				time += int;
				// Load new content columns
				for(var d in stageMgr.toLoad) {
					$.timer(time, function() {
						stageMgr.toLoad[count2].ref
							.css({left: colxpos[colcount_vert], top: '0px'})
							.animate(animShowDir[animRandDir], 500, 'easeOutQuad', function() {
								buttonClicked = (count2 == stageMgr.toLoad.length) ? false : true;
							});
						// Increment temp vars
						animRandDir = Math.round(Math.random() * (animShowDir.length - 1));
						count2++;
						colcount_vert++;
					});
					time += int;
				} // END for(var d in stageMgr.toLoad)
			break;
		} // END switch()
	}; // END function moveStageElements()
	
	/////////////////////////////////////////////////////////////////////////////
	// FUNCTIONS - CASE STUDIES
	/////////////////////////////////////////////////////////////////////////////
	function popupDelayShow(event) {
		$.clearTimer(int_mapPopup2);
		int_mapPopup2 = $.timer(50, function() { popupShow(event); });
	}; // END function popupDelayShow()
	function popupShow(event) {
		if(caseStudyVisible == false) {
			var e = $(event.target);
			// Record which is the current popup
			curPopup = e;
			// Calculate new left and top positions
			// ctop, cleft = current top and left
			var ctop = $('div.content').css('top').substring(0, $('div.content').css('top').indexOf('px'));
			var cleft = $('div.content').css('left').substring(0, $('div.content').css('left').indexOf('px'));
			// newleft, newtop = new position for popup window
			var newleft = (e.offset().left - cleft - $('div.map-popup').width() + 0) + "px";
			var newtop = (e.offset().top - ctop + 0) + "px";
			// Populate with select data
			$('div.map-popup div.map-popup-name').html(($('div.map-popup-name', e).html()));
			$('div.map-popup div.map-popup-location').html($('div.map-popup-location', e).html());
			$('div.map-popup div.map-popup-num').html($('div.map-popup-num', e).html());
			$('div.map-popup div.map-popup-time').html($('div.map-popup-time', e).html());
			Cufon.refresh('div.map-popup div.map-popup-num');
			// Show popup div
			$('div.map-popup').css({left: newleft, top: newtop});
		}
	}; // END function popupShow()
	function popupDelayHide(event) {
		$.clearTimer(int_mapPopup);
		int_mapPopup = $.timer(50, function() {
			// If an expanded window is not currently displayed, hide the popup div
			curPopup = null;
			$('div.map-popup').css({top: '-999em'});
		});
	}; // END function popupDelayHide()
	function popupShowCaseStudy(event) {
		event.preventDefault();
		caseStudyVisible = true;
		// Hide map-popup
		$('div.map-popup').css({top: '-999em'});
		// Add case study details from chosen event
		//$('div.case-study-detail div.case-study-detail-name').html(cufonAlt($('div.case-study-detail-name', curPopup)));
		$('div.case-study-detail div.case-study-detail-name').html($('div.case-study-detail-name', curPopup).html());
		$('div.case-study-detail div.case-study-detail-left').html($('div.case-study-detail-left', curPopup).html());
		$('div.case-study-detail div.case-study-detail-right').html($('div.case-study-detail-right', curPopup).html());
		Cufon.refresh('div.case-study-detail div.case-study-detail-name');
		// Show case study detail
		$('div.case-study-detail').animate({height: 'show'}, 'slow', 'easeOutQuad', function() {
			// Add click functionality to body to close window
			// Have to set a slight delay timer because  the $('body').click() acts buggy while the case-study-detail animates out, causes it to click prematurely
			$('body').click(function() {
				popupHideCaseStudy(event);
				$('body').unbind('click');
			});
			$('div.case-study-detail, div.plus-symbol, div.map-popup').click(function(event) {
				// If $('div.case-study-detail') is clicked, don't activate the body click
				event.stopPropagation();
			});
		});
	}; // END function popupShowLarge()
	function popupHideCaseStudy(event) {
		event.preventDefault();
	//	caseStudyVisible = false;
		$('div.case-study-detail')
			//.animate({opacity: 'hide'}, 'fast', 'easeOutQuad', function() { $(this).css({top: '-999em'}); });
			.animate({height: 'hide'}, 'fast', 'easeOutQuad', function() {
				caseStudyVisible = false;
			});
	}; // END function popupHideCaseStudy()
	function cufonAlt(e) {
		// Iterate through 'e' and reassemble all the span.cufon-alt instances into a string, then return that string
		var str = '';
		$('span.cufon-alt', e).each(function() { str += ($(this).html() + ' '); });
		// Trim excess white space from string
		return str.replace(/^\s+|\s+$/g, '');
	}; // END function cufonAlt()
	function showIconBlock(iconblock) {
		// Animate block
		$.clearTimer(int_showIconBlock);
		int_showIconBlock = $.timer(500, function() {
			iconblock
				.css({left: '730px'})
				.animate({width: 'show', left: '0px'}, 'slow', 'easeOutQuad');
		});
	}; // END function showIconBlock()
	function hideIconBlock(iconblock) {
		// Animate block
		$.clearTimer(int_showIconBlock);
		int_showIconBlock = $.timer(0, function() {
			//iconblock.animate({width: 'hide', left: '-730px'}, 'fast', 'easeOutQuad');
			iconblock.animate({height: 'hide'}, 'fast', 'easeOutQuad');
		});
	}; // END function hideIconBlock()
	function selectActivated(strName) {
		if(document.getElementById(strName).value != "") {
			document.getElementById(strName).style.color = "#666666";
		} else {
			document.getElementById(strName).style.color = "#C3C4C6";
		}
		document.getElementById(strName).blur();
	}; // END function selectActivated(strName)

	/////////////////////////////////////////////////////////////////////////////
	// FUNCTIONS - PUBLISHER APPLICATION
	/////////////////////////////////////////////////////////////////////////////
	function allRequiredFieldsFilled() {
		var false_count = 0;
		var q = 'question'+current_question;
		for(var i in requiredInputs[q]) {
			// Count the number of false's
			if(requiredInputs[q][i] == false) { false_count++; }
		}
		return (false_count == 0) ? true : false;
	}; // END function allRequiredFieldsFilled()
	function loadApplicationQuestion(dir) {
		// Remove currently displayed question
		// Display next question in either ascending or descending numerical order
		switch(dir) {
			default:
			case 'next':
				$('div.publisher-application div#question'+current_question)
					.animate({left: '-730px', opacity: 'hide'}, 500, 'easeOutQuad', function() {
						current_question = (current_question < max_count_questions) ? current_question + 1 : -1;
						$('div.publisher-application div#question'+current_question)
							.css({left: '730px'})
							.animate({left: '0px', opacity: 'show'}, 500, 'easeOutQuad');
					});
			break;
			case 'prev':
				$('div.publisher-application div#question'+current_question)
					.animate({left: '730px', opacity: 'hide'}, 500, 'easeOutQuad', function() {
						current_question = (current_question > 0) ? current_question - 1 : -1;
						$('div.publisher-application div#question'+current_question)
							.css({left: '-730px'})
							.animate({left: '0px', opacity: 'show'}, 500, 'easeOutQuad');
					});
			break;
		}
	}; // END function loadApplicationQuestion()

}); // END $(document).ready(function()
