

// idpk will be used to hold various things that determine page state (I suppose maybe it should be called 'state')
var idpk = new Object();


idpk.url = new Object();
idpk.url.base = 'http://www.ideapark.com/';
idpk.url.proxy = 'proxy/?';
idpk.url.blog = 'http://blog.ideapark.com/index.php';

idpk.blog = new Object();
idpk.portfolio = new Object();
idpk.tempControl;


if ((window.location+'').match(/beta.ideapark/) != null) {
	idpk.url.base = 'http://beta.ideapark.com/';
	idpk.url.blog = 'http://blogtest.ideapark.com/index.php';
}
else if ((window.location+'').match(/\/\/ideapark\.com/) != null) {
	idpk.url.base = 'http://ideapark.com/';
}
else if ((window.location+'').match(/projects.ideapark/) != null) {
	idpk.url.base = 'http://projects.ideapark.com/idpk08/';
	idpk.url.blog = 'http://blogtest.ideapark.com/index.php';
}




// this allows us to load multiple functions at window.onload without conflicts
// http://www.sitepoint.com/blogs/2004/05/26/closures-and-executing-javascript-on-page-load/
function addLoadEvent(func) { 
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
} 

addLoadEvent(screens);
addLoadEvent(formLabels);
addLoadEvent(blog);
addLoadEvent(portfolio);
addLoadEvent(contact);
addLoadEvent(scroll);
addLoadEvent(flashPreview);

addLoadEvent(map);





//  screens() - functions for the five screens
// --------------------------------------------



// screens() determines the initial page state, then sets everything up (via other screens_ functions) according to that state

function screens() {
	
	// width of viewport
	idpk.w = window.innerWidth || (window.document.documentElement.clientWidth || window.document.body.clientWidth);
	
	// initial window title, in case we decide to change it at some point
	idpk.title = document.title;
	
	// the five screens for the five sections of the page
	idpk.screen = new Array();
	ids = new Array('WhoWeAre','OurBlog','Home','OurWork','TalkToUs');
	for (i=0; i<ids.length; i++) {
		idpk.screen[i] = new Object();
		idpk.screen[i].id = ids[i];
		idpk.screen[i].ordinal = i - 2;
		idpk.screen[i].el = document.getElementById(idpk.screen[i].id);
		idpk.screen[idpk.screen[i].id] = idpk.screen[i];
	}
	
	
	window.onresize = function() {
		screens_position();
		screens_move(idpk.target,idpk.current,false);
	}
	screens_environ();
	screens_position();
	
	
	idpk.current = idpk.screen['Home'];
	idpk.target = idpk.screen['Home'];
	
	
	values = parseQuery();
	if (values['page'] != undefined) {
		idpk.target = idpk.screen[values['page']];
		screens_move(idpk.target,idpk.current,false);
	}
	
	
	screens_links('a');
	screens_links('area');
	
	
	
	
	
	
/*	if (!document.getElementById('locat')) {
		idpk.locat = document.createElement('iframe');
		idpk.locat.id = 'locat';
		idpk.locat.src = 'window.location';
		document.getElementById('Home').appendChild(idpk.locat);
		idpk.locat.style.display = 'none';
	}*/
	
	idpk.url.observe = new PeriodicalExecuter(urlObserve,.25);
	
	idpk.scrollObserve = new PeriodicalExecuter(function(){window.scrollTo(0,0)},2);
	
}


function urlObserve() {
	
	if (idpk.environ.transition == false) {
		
		values = parseQuery(window.location.hash);
		
		
		// - page
		if (values['page'] != undefined && idpk.current != idpk.screen[values['page']]) {
			idpk.target = idpk.screen[values['page']];
			screens_move(idpk.target,idpk.current);
		}
		else if (values['page'] == undefined && idpk.current != undefined) {
			idpk.target = idpk.screen['Home'];
			screens_move(idpk.target,idpk.current);
		}
		
		
		// - blog
		entry = idpk.url.blog + values['entry'];
		if (values['entry'] == undefined && idpk.blog.entry != undefined) {
			blogGetContent();
			idpk.blog.entry = undefined;
		}
		// blog entry
		else if (values['entry'] != undefined && idpk.blog.entry != entry) {
			blogGetContent(entry);
		}
		
		
		
		// - portfolio
		
		if (values['client'] == undefined && idpk.portfolio.client != undefined) {
			idpk.portfolio.client = undefined;
			portfolio_hide();
		}
		else if (values['client'] != undefined && idpk.portfolio.client == undefined && values['client'] != idpk.portfolio.client) {
			portfolio_show();
			portfolio_getSlide(values['client'],values['slide']);
		}
		else if (values['client'] != undefined && idpk.portfolio.client != undefined && values['client'] != idpk.portfolio.client) {
			portfolio_getSlide(values['client'],values['slide']);
		}
		else if (values['client'] != undefined && values['client'] == idpk.portfolio.client) {
			var slideNo;
			if (idpk.portfolio.slide) {
				slideNo = idpk.portfolio.slide.id.replace(/.+_(\d+)$/,'$1');
			}
			if (values['slide'] != slideNo) {
				if ((values['slide'] == undefined || values['slide'] == 1) && slideNo != 1) {
					portfolio_getSlide(values['client'],values['slide']);
				}
				else if (values['slide'] != undefined && values['slide'] != 1) {
					portfolio_getSlide(values['client'],values['slide']);
				}
			}
		}
		
		/*
		nohash = (window.location + '').replace(window.location.hash,'');
		
		if (idpk.locat.src != nohash + 'x/?u=' + window.location) {
			idpk.locat.src = 'x/?u=' + window.location;
		}*/
		
	}
}


// screens_position() spaces the five screens out horizontally

function screens_position() {
	idpk.w = window.innerWidth || (window.document.documentElement.clientWidth || window.document.body.clientWidth);
	for (i=0; i<idpk.screen.length; i++) {
		d = idpk.screen[i].el;
		d.style.display = 'block'; // temp
		d.style.left = (idpk.w * idpk.screen[i].ordinal) + 'px';
	}
	idpk.current = idpk.screen['Home'];
}


// screens_environ() loads the background layers

function screens_environ() {
	
	idpk.e = document.getElementById('environ');
	
	idpk.environ = new Array();
		idpk.environ[4] = 'e_Hills';
		idpk.environ[3] = 'e_Mountains';
		idpk.environ[2] = 'e_CloudsFront';
		idpk.environ[1] = 'e_CloudsBack';
		idpk.environ[0] = 'e_Sun';
	
	for (i=0; i<idpk.environ.length; i++) {
		
		d = document.createElement('div');
		
		d.id = idpk.environ[i];
		
		if (idpk.environ[i] != 'e_Sun') {
			idpk.e.appendChild(d);
		}
		else {
			idpk.e.parentNode.insertBefore(d,idpk.e);
		}
		
	}
	
	idpk.e.style.width = idpk.w * 50 + 'px';
	idpk.e.style.left = -idpk.w * 50 / 2 + 'px';
	
}


// moves all the screens until the target shows
// moves the background layers, too, unless environToggle is set to false

function screens_move(target,current,environToggle) {
	
	if (!target) {
		target = idpk.target;
	}
	if (!current) {
		current = idpk.current;
	}
	
	d = (current.ordinal - target.ordinal);
	x = idpk.w * d;
	
	for (i=0; i<idpk.screen.length; i++) {	
		if (environToggle != false) {
			new Effect.Move (idpk.screen[i].el,{
				x: x,
				mode: 'relative',
				beforeStart: function() {
					for (s=0; s<idpk.screen.length; s++) {
						idpk.screen[s].el.style.visibility = 'visible';
					}
				},
				afterFinish: function() {
					for (s=0; s<idpk.screen.length; s++) {
						if (target.ordinal + 2 != s) {
							idpk.screen[s].el.style.visibility = 'hidden';
						}
					}
				}
			});
		}
		else {
//			m = idpk.screen[i].style.left.replace(/(\d+)px/,'$1');
			idpk.screen[i].el.style.left = (idpk.w * idpk.screen[i].ordinal) + (idpk.w * d) + 'px';
		}
	}
	
//		new Effect.MoveBy(target, 0, 100, {duration: 0.3, transition: Effect.Transitions.slowstop});
	
	
	
	if (environToggle != false) {
		screens_move_environ(x);
	}
	
	
	idpk.current = target;
	
}

function screens_move_environ(x) {
	
	idpk.environ.transition = true;
	
	idpk.environ.x = new Array();
	idpk.environ.x[1] = .12;
	idpk.environ.x[2] = .25;
	idpk.environ.x[3] = .45;
	idpk.environ.x[4] = .75;
	t = 1;
	
	for (i=1; i<idpk.environ.length; i++) {
		
		e = idpk.environ.x[i] * x;
		
		el = document.getElementById(idpk.environ[i]);
		
		new Effect.Move (el,{
			x: e,
			mode: 'relative',
			afterFinish: function() {
				t++;
				if (t == idpk.environ.length) {
					idpk.environ.transition = false;
				}
			}
		});
	}
	
}

// screens_links takes an element tag name (as a string) and makes all appropriate elements of that type into navigation links

function screens_links(element) {

	links = document.getElementsByTagName(element);
	
	for (i=0; i<links.length; i++) {
		l = links[i];
		l.values = parseQuery(l.href);
		if (l.values['page'] != undefined) {
			l.onclick = function() {
				idpk.target = idpk.screen[this.values['page']];
				screens_move();
			}
		}
	}
}





//  functions for forms
// ---------------------



// formLabels() sets the default value of an input to the text content of its label element, then hides the label

function formLabels() {
	labels = document.getElementsByTagName('label');
	for (i=0; i<labels.length; i++) {
		if (input = document.getElementById(labels[i].htmlFor)) {
			nodes = labels[i].childNodes;
			labelText = '';
			for (n=0; n<nodes.length; n++) {
				if (nodes[n].nodeType == 3) {
					t = nodes[n].nodeValue.replace(/\s+/g,' ');
					t = t.replace(/(^\s*|\s*$)/g,'');
					labelText += t;
					nodes[n].parentNode.removeChild(nodes[n]);
				}
			}
			input.label = labelText;
			
			input.labelElement = labels[i];
			
			// text inputs and textareas
			if (input.type == 'text' || input.nodeName == 'TEXTAREA') {
				if (input.value == '') {
					input.value = input.label;
				}
				input.onfocus = function() {
					if (this.value == this.label || this.value == this.required) {
						this.value = '';
					}
				}
				input.onblur = function() {
					if (this.value == '' || this.value == this.required) {
						this.value = this.label;
//						input.blur();
					}
				}
			}
			
			// selects
			else if (input.nodeName == 'SELECT') {
				option = document.createElement('option');
				option.innerHTML = input.label;
				option.value = '';
				input.insertBefore(option,input.childNodes[0]);
				if (input.selectedIndex == 1) {
					input.selectedIndex = 0;
				}
			}
			
			if (input.labelElement.parentNode.nodeName == 'FORM') {
				input.formElement = input.labelElement.parentNode;
			}
			
			if (input.formElement != undefined && input.formElement.id != 'blogSearch') {
				Event.observe(input.formElement, 'submit', function() {validateForm(this)});
			}
			
		}
	}
}


// validateForm() will eventually remove values from a submitted form if they equal their default value

function validateForm(form) {
	
	for (i=0; i<form.elements.length; i++) {
		
		if (form.elements[i].value == form.elements[i].label) {
			form.elements[i].value = '';
		}
	}
}





//  functions for the blog
// ------------------------



// blog() initializes the blog, natch

function blog() {
	
	values = parseQuery();
	
	if (values['entry'] != null) {
		blogGetContent(idpk.url.blog + values['entry']);
	}
	else {
		blogGetContent();
	}
	
}


// blogGetContent() gets the requested content via AJAX

function blogGetContent(url) {
	
	var url;
	
	if (!url) {
		url = idpk.url.blog;
	}
	else {
		idpk.blog.entry = url;
	}
	
	if (url.match(/^\/search\//)) {
		url = idpk.url.blog + url;
	}
	
	url = idpk.url.base + idpk.url.proxy + url;
	
	url = url.replace(/index.php\/index.php\//gi,'index.php')
	
	var response;
	
	new Ajax.Request(url, {
		method: 'get',
/*		onLoading: function(transport) {
			blogInsertContent('Loading');
		},*/
		onSuccess: function(transport) {
			response = transport.responseText || "Sorry, I couldn\'t find what you wanted.";
		},
		onFailure: function(){
			response = 'Sorry, the page didn\'t load.' + url;
		},
		onComplete: function(){
			blogInsertContent(response);
			scroll_init(document.getElementById('blogPFK_content'));
		}
	});
	
}


// blogInsertContent() puts the blog content into the blog page, then updates the categories and archives and initializes links

function blogInsertContent(content) {
	
	base = document.getElementById('BlogScroll');
	
	$('BlogScroll').update(content);
	document.getElementById('blogPFK_content').className = 'scroll';
	
	search = document.getElementById('blogSearch');
	s = document.getElementById('blogSearch_search');
	
	search.onsubmit = function() {
		s = document.getElementById('blogSearch_search');
		try {
			if (s.value != s.label) {
				for (i=0; i<this.length; i++) {
					searchURL = '/search/' + this.elements[i].value;
					window.location.hash = 'page=OurBlog&entry=' + searchURL;
					blogGetContent(searchURL);
				}
			}
			else {
				if (s = document.getElementById('blogSearch_search')) {
					s.focus();
				}
			}
		}
		catch (e) {
		}
		return false;
	}
	
	
	if (archivesSrc = document.getElementById('blogPFK_archives')) {
		
		archivesOld = document.getElementById('blogNav_archives');
		
		archivesOld_options = archivesOld.getElementsByTagName('option');
		
		for (o=archivesOld_options.length-1; o>0; o--) {
			archivesOld.removeChild(archivesOld_options[o]);
		}
		
		archiveSrc_links = archivesSrc.getElementsByTagName('a');
		
		for (i=0; i<archiveSrc_links.length; i++) {
			option = document.createElement('option');
			option.value = archiveSrc_links[i].href;
			option.innerHTML = archiveSrc_links[i].innerHTML;
			archivesOld.appendChild(option);
		}
		
		archivesSrc.parentNode.removeChild(archivesSrc);
		
		archivesOld.onchange = function() {
			if (this.value.match(/http/)) {
				entry = this.value.replace(idpk.url.blog,'');
				window.location.hash = 'page=OurBlog&entry=' + entry;
				blogGetContent(this.value);
			}
		}
		
	}
	
	
	if (categoriesSrc = document.getElementById('blogPFK_categories')) {
		
		categoriesOld = document.getElementById('blogNav_categories');
		
		categoriesOld_options = categoriesOld.getElementsByTagName('option');
		
		for (o=categoriesOld_options.length-1; o>0; o--) {
			categoriesOld.removeChild(categoriesOld_options[o]);
		}
		
		categoriesrc_links = categoriesSrc.getElementsByTagName('a');
		
		for (i=0; i<categoriesrc_links.length; i++) {
			option = document.createElement('option');
			option.value = categoriesrc_links[i].href;
			option.innerHTML = categoriesrc_links[i].innerHTML;
			categoriesOld.appendChild(option);
		}
		
		categoriesSrc.parentNode.removeChild(categoriesSrc);
		
		categoriesOld.onchange = function() {
			if (this.value.match(/http/)) {
				entry = this.value.replace(idpk.url.blog,'');
				window.location.hash = 'page=OurBlog&entry=' + entry;
				blogGetContent(this.value);
			}
		}
	}
	
	
	links = document.getElementById('blogPFK_content').getElementsByTagName('a');
	
	for (i=0; i<links.length; i++) {
		
		var exp = idpk.url.blog.replace(/index.php/,'');
		
		if (links[i].href.match(idpk.url.blog)) {
			links[i].onclick = function() {
				
				blogGetContent(this.href);
				this.href = '#page=OurBlog&entry=' + this.href.replace(idpk.url.blog,'');
				this.href = this.href.replace(/\?s=/,'blogSearch/');
				this.href = this.href.replace(/index.php\//,'');
				
			}
		}
		
		else if (links[i].href.match(exp)) {
			links[i].onclick = function() {
				
				blogGetContent(this.href);
				exp = idpk.url.blog + 'index.php';
				this.href = '#page=OurBlog';
				
			}
		}
		
	}
	
}





//  functions for the portfolio
// -----------------------------



// portfolio() isn't finished yet

function portfolio() {

	idpk.portfolio.transition = false;
	
	// if the hash has a brand/slide, show it
	values = parseQuery();
	if (values['client'] != undefined) {
		portfolio_show();
		portfolio_getSlide(values['client'],values['slide']);
	}
	
	// initialize the previews on the portfolio page to open their slide
	pre = document.getElementById('portfolioPreview').getElementsByTagName('a');
	for (i=0; i<pre.length; i++) {
		pre[i].values = parseQuery(pre[i].href);
		pre[i].onclick = function() {
			portfolio_show();
			portfolio_getSlide(this.values['client'],this.values['slide']);
		}
	}
	
	// initialize the previews on the portfolio page to open their slide
	nav = document.getElementById('portfolio_nav').getElementsByTagName('a');
	for (i=0; i<nav.length; i++) {
		nav[i].values = parseQuery(nav[i].href);
		nav[i].onclick = function() {
			portfolio_getSlide(this.values['client'],this.values['slide']);
		}
	}
	
	// initialize close links in the portfolio overlay
	port = document.getElementById('portfolio').getElementsByTagName('a');
	for (i=0; i<port.length; i++) {
		port[i].values = parseQuery(port[i].href);
		if (port[i].values['close'] == 'true') {
			port[i].onclick = function() {
				this.href = this.href.replace(/&close=true/,'');
				portfolio_hide();
			}
		}
	}
	
}

function portfolio_show() {
	
	s = document.getElementById('screens');
	p = document.getElementById('overlay');
	
	if (idpk.portfolio.open == undefined || idpk.portfolio.open == false) {
		idpk.portfolio.open = true;
		
		new Effect.Move (s,{
			y: 100,
			mode: 'relative'
		});
		new Effect.Opacity(s,{
			duration: .5,
			from: 1,
			to: 0,
			afterFinish: function() {
				new Effect.Opacity(p,{
					duration: 0,
					to: 0,
					afterFinish: function() {
						p.style.display = 'block';
						new Effect.Opacity(p,{
							duration: .5,
							from: 0,
							to: 1
						});
					}
				});
			}
		});
		
	}
	
}

function portfolio_hide() {
	
	s = document.getElementById('screens');
	p = document.getElementById('overlay');
	
	if (idpk.portfolio.open == undefined || idpk.portfolio.open == true) {
		idpk.portfolio.open = false;
		
		new Effect.Opacity(idpk.portfolio.slide,{
			duration: .1,
			to: 0,
			afterFinish: function() {
				idpk.portfolio.slide.style.display = 'none';
			}
		});
		
		new Effect.Move (s,{
			y: -100,
			mode: 'relative'
		});
		
		new Effect.Opacity(p,{
			duration: .5,
			from: 1,
			to: 0,
			afterFinish: function() {
				new Effect.Opacity(s,{
					duration: .5,
					from: 0,
					to: 1
				});
				p.style.display = 'none';
			}
		});
		
	}
	
}

function portfolio_getSlide(client,slide) {
	
	idpk.portfolio.client = client;
	
	request = idpk.url.base + '';
	request = request.replace(/(#|\?).*/,'');
	
	url = idpk.url.base + idpk.url.proxy + request;
	url += 'portfolio/';
	
	if (client) {
		url += client + '/';
	}
	else {
		url += 'btfe/';
	}
	
	if (!slide) {
		slide = 1;
	}
	
	url += 'slide' + slide + '.html';
	
	
	base = document.getElementById('portfolio_slide');
	
	sliD = 'portfolio_' + client + '_' + slide; // sliD! ha! get it? slide + ID? ok, sorry
	
	if (!document.getElementById(sliD)) {
		newSlide = document.createElement('div');
		newSlide.id = sliD;
		base.appendChild(newSlide);
		new Effect.Opacity (newSlide, {
			duration: 0,
			to: 0
		});
		
		
		content = '';
		
		new Ajax.Request(url, {
			method: 'get',
			onSuccess: function(transport) {
				content = transport.responseText || "Sorry, I couldn\'t find what you wanted.";
			},
			onFailure: function() {
				content = 'Sorry, I couldn\'t get what you asked for.';
			},
			onComplete: function() {
				$(newSlide).update(content);
				portfolio_showSlide(newSlide);
				
				links = newSlide.getElementsByTagName('a');
				
				for (l=0; l<links.length; l++) {
					link = links[l];
					link.values = parseQuery(link.href);
					if (link.values['slide'] != undefined) {
						link.onclick = function() {;
							portfolio_getSlide(this.values['client'],this.values['slide']);
						}
					}
					if (link.values['close'] == 'true') {
						link.onclick = function() {
							this.href = this.href.replace(/&close=true/,'');
							portfolio_hide();
						}
					}
				}
				
			}
		});
		
	}
	
	else {
		portfolio_showSlide(document.getElementById(sliD));
	}
	
}


function portfolio_showSlide(slide) {
	
	
	if (idpk.portfolio.transition == false) {
		idpk.portfolio.transition = true;
		
		if (idpk.portfolio.slide && idpk.portfolio.slide != slide) {
			oldSlide = idpk.portfolio.slide;
			new Effect.Opacity (oldSlide, {
				duration: .2,
				from: 1,
				to: 0,
				afterFinish: function() {
					oldSlide.style.display = 'none';
				}
			});
		}
		
		new Effect.Opacity (slide, {
			beforeStart: function() {
				slide.style.display = 'block';
				client = slide.id.replace(/portfolio_(.+)_\d*/gi,'$1');
				nav = document.getElementById('portfolio_nav');
				regexp = ' ' + nav.client;
				nav.className = nav.className.replace(regexp,'');
				nav.className += ' ' + client;
				nav.client = client;
				
				
			},
			duration: .48,
			from: 0,
			to: .01,
			afterFinish: function() {
				idpk.portfolio.slide = slide;
				idpk.portfolio.transition = false;
				
				if (!(slide.className.match(/scrolled/))) {
					ds = slide.getElementsByTagName('div');
					
					d;
					
					for (f=0; f<ds.length; f++) {
						if (ds[f].className.match(/portfolio_image/)) {
							d = ds[f];
						}
					}
					
					if (d != undefined) {
						scroll_init(d);
					}
					
					slide.className += ' scrolled';
					
					flashPreview(slide);
					
				}
				
				
				new Effect.Opacity (slide, {
					duration: .3,
					from: .1,
					to: 1
				});
				
			}
		});
	}

}





//  functions for the contact page
// --------------------------------



// contact() handles submission (via AJAX (via contactGetContent())) of the contact form

function contact() {
	
	var contactSubmitting = document.getElementById('contactSubmitting');
	var contactThanks = document.getElementById('contactThanks');
	var contactFailure = document.getElementById('contactFailure');
	
	if (document.getElementById('contact')) {
		
		contact = document.getElementById('contact');
		
		$(contact).onsubmit = function() {
			var searchURL = this.action + '?';
			var valid = true;
			for (i=0; i<this.length; i++) {
				
				if (this.elements[i].value == this.elements[i].label) {
					this.elements[i].value = '';
				}
				
				// validation
				this.elements[i].required = 'Required';
				if (this.elements[i].name == 'contact_name' && (this.elements[i].value == '' || this.elements[i].value == this.elements[i].required)) {
					this.elements[i].value = this.elements[i].required;
					valid = false;
				}
				else if (this.elements[i].name == 'contact_email' && (this.elements[i].value == '' || this.elements[i].value == this.elements[i].required)) {
					this.elements[i].value = this.elements[i].required;
					valid = false;
				}
				
				
				var sep = '';
				if (i != 0) {
					sep = '&';
				}
				searchURL += sep + this.elements[i].name + '=' + this.elements[i].value;
			}
			if (valid == false) {
				return false;
			}
			contactGetContent(searchURL);
			return false;
		}
		
		links = document.getElementById('contactContainer').getElementsByTagName('a');
		
		for (i=0; i<links.length; i++) {
			if (links[i].href.match(/#contact/)) {
				links[i].onclick = function() {
					new Effect.Opacity (contact, {
						beforeStart: function() {
							for (f=0; f<contact.elements.length; f++) {
								if (contact.elements[f].label) {
									contact.elements[f].value = contact.elements[f].label;
								}
								if (contact.elements[f].tagName == 'SELECT') {
									contact.elements[f].selectedIndex = 0;
								}
							}
						},
						duration: .25,
						from: 0,
						to: 1
					});
					contactSubmitting.style.display = 'none';
					contactThanks.style.display = 'none';
					contactFailure.style.display = 'none';
					return false;
				}
			}
		}
	
	}
	
	
	function contactGetContent(request) {
		
		url = request.replace(/\n/gi,'%0A');
		
		new Ajax.Request(url, {
			method: 'get',
			onSuccess: function(transport) {
				var response = transport.responseText || "Sorry, I couldn\'t find what you wanted.";
				new Effect.Opacity (contact, {
					duration: .2,
					from: 1.0, to: 0,
					afterFinish: function(){
						new Effect.Opacity ('contactThanks', {
							to: 0,
							afterFinish: function(){
								contactThanks.style.display = 'block',
								new Effect.Opacity ('contactThanks', {
									duration: .2,
									to: 1
								});
							}
						});
					}
				});
			},
			onFailure: function(){
				contactFailure.style.display = 'block';
			}
		});
	
	}
	
}





//  functions for the custom scrollbars
// -------------------------------------



// scroll() adds a stylized vertical scrollbar to selected elements that would otherwise get a browser standard scrollbar

function scroll() {
	scroll_init(document.getElementById('WhoWeAreScroll'));
}

var scrollInt = 0;

function scroll_init(element) {
	
	// an object attached to the original element to contain everything in the scrolling area
	element.scroll = new Object;
	
	
	// allows CSS to style scrolling area
	element.className += ' scroll_box';
	
	
	// base is a new div that will contain the scrolling area and all associated elements
	base = document.createElement('div');
	base.className = 'scroll_base';
	// if the original element doesn't already have an ID, make one up for it
	if (element.id == '') {
		element.id = 'scroll' + scrollInt;
		scrollInt++;
	}
	base.id = element.id + '_scroll_base'; // use the original element's ID to create an ID for the base
	element.parentNode.appendChild(base); // append the base to the elements parent
	$(base).update(element); // append the elemeng to the base (using prototype)
	element.scroll.base = base; // add the base to the elements scroll object
	
	// only add the scrollbar if the orinigal element is taller than its base
	if (element.offsetHeight-2 > element.scroll.base.offsetHeight) {
		
		element.className += ' scroll_complete';
		
		track = document.createElement('div');
		track.className = 'scroll_track';
		base.insertBefore(track,element);
		element.scroll.track = track;
		
		handle = document.createElement('div');
		handle.className = 'scroll_handle';
		track.appendChild(handle);
		element.scroll.handle = handle;
		
		
		topArrow = document.createElement('div');
		topArrow.className = 'scroll_top';
		track.appendChild(topArrow);
		element.scroll.topx = topArrow;
		topArrow.element = element;
		topArrow.onmousedown = function() {
			idpk.tempControl = this;
			element.scroll.v -= .05;
			this.element.scroll.scrollbar.setValue(this.element.scroll.v);
			scroll_mousedown('up');
		}
		topArrow.onmouseup = function() {
			window.clearTimeout(scrolling);
		}
/*		topArrow.ondblclick = function() {
			return false;
		}*/
		
		
		bottomArrow = document.createElement('div');
		bottomArrow.className = 'scroll_bottom';
		track.appendChild(bottomArrow);
		element.scroll.bottomx = bottomArrow;
		bottomArrow.element = element;
		bottomArrow.onmousedown = function() {
			idpk.tempControl = this;
			element.scroll.v += .05;
			this.element.scroll.scrollbar.setValue(this.element.scroll.v);
			scroll_mousedown('down');
		}
		bottomArrow.onmouseup = function() {
			window.clearTimeout(scrolling);
		}
/*		bottomArrow.ondblclick = function() {
			return false;
		}*/
		
		
		track.style.height = track.offsetHeight - topArrow.offsetHeight - bottomArrow.offsetHeight + 'px';
		track.style.top = topArrow.offsetHeight + 'px';
		
		element.scroll.v = 0;
		
		element.scroll.scrollbar = new Control.Slider(handle,track,{
			axis: 'vertical',
			onSlide: function(v) {
				element.scroll.v = v;
				scroll_moveBox(element);
			},
			onChange: function(v) {
				element.scroll.v = v;
				scroll_moveBox(element);
			}
		});
		
		wheel_init(element);
		
		// an empty div that can be styled with a background PNG to make the text fade out at the bottom
		fadeOut = document.createElement('div');
		fadeOut.className = 'scroll_fadeOut';
		base.parentNode.appendChild(fadeOut);
		
	}
	
	else {
		element.className = element.className.replace(/ ?scroll_box/gi,'');
	}
	
}

function scroll_moveBox(element) {
	v = element.scroll.v;
	
	y = element.offsetHeight || (element.clientHeight || element.clientHeight);
	
	b = element.scroll.base.offsetHeight;
	
	m = ((y-b)*v).round();
	
	element.style.marginTop = -m + 'px';
}

function scroll_mousedown(direction) {
	if (direction == 'up') {
		rate = -.05;
	}
	else {
		rate = .05;
	}
	
	scrolling = window.setTimeout(
		function() {
			idpk.tempControl.element.scroll.v += rate;
			idpk.tempControl.element.scroll.scrollbar.setValue(idpk.tempControl.element.scroll.v);
			scroll_mousedown(direction);
		},
		100
	);
	
}




// http://adomas.org/javascript-mouse-wheel/plain.html

var boxes = new Array;

function wheel(event){
	var delta = 0;
	if (!event) event = window.event;
	if (event.wheelDelta) {
		delta = event.wheelDelta/120; 
		if (window.opera) delta = -delta;
	} else if (event.detail) {
		delta = -event.detail/3;
	}
	if (delta) {
		boxes[this.id].scroll.v -= (delta/10);
		boxes[this.id].scroll.scrollbar.setValue(boxes[this.id].scroll.v);
		if (event.preventDefault)
				event.preventDefault();
		event.returnValue = false;
	}
}

/* Initialization code. */
function wheel_init(element) {
	boxes[element.scroll.base.id] = element;
	if (element.scroll.base.addEventListener) {
		element.scroll.base.addEventListener('mousewheel', wheel, false);
		element.scroll.base.addEventListener('DOMMouseScroll', wheel, false);
	}
	else {
		element.scroll.base.onmousewheel = element.scroll.base.onmousewheel = wheel;
	}
}







// flashPreview()


function flashPreview(container) {
	if (container == undefined) {
		container = document;
	}
	links = container.getElementsByTagName('a');
	for (i=0; i<links.length; i++) {
		if (links[i].className.match(/portfolio_image_flash_preview/)) {
			links[i].onclick = function() {
				flashPreview_swap(this);
				return false;
			}
		}
	}
}

function flashPreview_swap(link) {
	
	flash = new Object();
	
	flash.link = link;
	flash.container = link.parentNode;
	
	flash.path = link.href.replace(idpk.url.base,'');
	flash.src = flash.path.replace(/([^\/]+)\.swf/,'$1');
	flash.movie = flash.path.replace(/([^\/]+)\.swf/,'$1');
	flash.id = flash.path.replace(/.+\/([^\/]+)\.swf/,'$1');
	flash.name = flash.id + '_movie';
	
	image = link.getElementsByTagName('img')[0];
	
/*	flash.width = getStyle(image,'width').replace(/(\d+)px/,'$1');
	flash.height = getStyle(image,'height').replace(/(\d+)px/,'$1');*/
	
	flash.width = image.width;
	flash.height = image.height;
/*	
	object = document.createElement('object');
	
		object.classid = 'clsid:d27cdb6e-ae6d-11cf-96b8-444553540000';
		object.codebase = 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0';
		object.src = flash.path;
		
		object.setAttribute('width','100');
		object.setAttribute('height','100');
		*/
/*		var w = document.createAttribute('width');
		w.value = flash.width
		object.setAttributeNode(w);
		
		var h = document.createAttribute('height');
		h.value = flash.height
		object.setAttributeNode(h);*/
		/*
		object.id = flash.id;
		object.align = "middle";
		
		var params = new Object();
		
		params['src'] = flash.path;
		params['allowScriptAccess'] = 'sameDomain';
		params['allowFullScreen'] = 'false';
		params['movie'] = flash.path;
		params['quality'] = 'high';
		params['bgcolor'] = '#ffffff';
		
		for (var key in params) {
			var param = document.createElement('param');
			param.setAttribute('name',key)
			param.setAttribute('value',params[key])
			object.appendChild(param);
		}
		*/
/*	object.innerHTML = '<param name="allowScriptAccess" value="sameDomain" />\
		<param name="allowFullScreen" value="false" />\
		<param name="movie" value="' + flash.path + '" />\
		<param name="quality" value="high" />\
		<param name="bgcolor" value="#ffffff" />\
		<embed src="' + flash.path + '" quality="high" bgcolor="#ffffff" width="' + flash.width + '" height="' + flash.height + '" name="' + flash.name + '" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';*/
	
//	flash.container.innerHTML = '';
//	flash.container.appendChild(object);
	
	flash.container.innerHTML = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="' + flash.width + '" height="' + flash.height + '" id="' + flash.id + '" align="middle">\
		<param name="allowScriptAccess" value="sameDomain" />\
		<param name="allowFullScreen" value="false" />\
		<param name="movie" value="' + flash.path + '" />\
		<param name="quality" value="high" />\
		<param name="bgcolor" value="#ffffff" />\
		<embed src="' + flash.path + '" quality="high" bgcolor="#ffffff" width="' + flash.width + '" height="' + flash.height + '" name="' + flash.name + '" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />\
	</object>';
	
	flash.container.onclick = function() {
		return false;
	}
	
}










function map() {
	if (GBrowserIsCompatible()) {
		var map = new GMap2(document.getElementById("map"));
//		map.setCenter(new GLatLng(44.985609, -93.272338), 15);
		
		var pointMinneapolis = new GLatLng(44.98525, -93.2721);
		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());
		map.setCenter(pointMinneapolis, 15);
		map.addOverlay(new GMarker(pointMinneapolis));
    	
	}
}





















// parseQuery returns an assocaitive array of the name=value pairs in a query string (or a hash formatted as a query) of a URL
// if no string is passed, it uses the current has of the url
function parseQuery(query) {
	
	if (!query) {
		query = window.location.hash;
	}
	
	query = query.replace(/.*(#|\?)(.+)/,'$2');
	
	values = new Array();
	
	params = query.split('&');
	
	for (var q=0; q<params.length; q++) {
		var pos = params[q].indexOf('=');
		name = params[q].substring(0,pos);
		value = params[q].substring(pos+1);
		
		values[name] = value;
		
	}
	
	return values;
	
}


// returns value of a rendered style attribute of an element
// http://www.robertnyman.com/2006/04/24/get-the-rendered-style-of-an-element/
function getStyle(oElm, strCssRule){
	var strValue = "";
	if(document.defaultView && document.defaultView.getComputedStyle){
		strValue = document.defaultView.getComputedStyle(oElm, "").getPropertyValue(strCssRule);
	}
	else if(oElm.currentStyle){
		strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1){
			return p1.toUpperCase();
		});
		strValue = oElm.currentStyle[strCssRule];
	}
	return strValue;
}