// Email Spam hiding.
function popMail(host,user) {
	var acct = user +'@'+ host;
	self.location.href = 'mailto:'+ acct;
}
function linkMail(host,user,cls) {
	document.write('<a href="javascript:popMail(\''+ host +'\',\''+ user +'\');"');
	if (cls) {
		document.write(' class="'+ cls +'"');
	}
	document.write('>');
	showMail(host,user);
	document.write('</a>');
}
function showMail(host,user) {
	var acct = user +'@'+ host;
	document.write(acct);
}





function moreSidebar()
{
	var content = $('sidebar_moreContent');
	var container = $('sidebar_container');
	var links = $$('#sidebar_moreLink a');
	var link = links[0];
	
	if(content.visible()) {
		content.hide();
		link.innerHTML = '+ More';
		container.removeClassName('more');
	} else {
		content.show();
		link.innerHTML = '- Less';
		container.addClassName('more');
	}
}

function homeNavOver(elm)
{
	var id = _getAncestorId(elm);
	$('rollover_' + id).show();
	if(null != $('container_' + id)) {
		$('container_' + id).show();
		$('background_' + id).setStyle({height:  $('copy_' + id).getHeight() + 'px'});
		switch (id)
		{
			case 'architecture':
				var height = $('copy_' + id).getHeight() + 299;
				break;
			case 'animals':
				var height = $('copy_' + id).getHeight() + 164 + 8;
				break;
			case 'people':
				var height = $('copy_' + id).getHeight()
				break;
		}
		$('container_' + id).setStyle({bottom:  height + 'px'});
	}
}

function homeNavOut(elm)
{
	var id = _getAncestorId(elm);
	$('rollover_' + id).hide();
	if(null != $('container_' + id)) {
		$('container_' + id).hide();
	}
}

function _getAncestorId(elm)
{
	return $(elm).ancestors()[0].identify();
}

function switchProjectBackground(id, stopRotation)
{
	if('undefined' != pt && stopRotation == true)
	{
		clearTimeout(pt);
	}
	if($('featuredBackgroundSwitch_' + id).hasClassName('selected')) {
		return;
	}
	var backgrounds = $$('.featuredBackgroundImage');
	backgrounds.each(function(background){
		if(background.visible()) {
			background.fade({ duration: 1.0 });
		}
	});
	var labels = $$('.featuredBackgroundLabel');
	labels.each(function(label){
		if(label.visible()) {
			label.fade({ duration: 1.0 });
		}
	});
	var links = $$('#featuredBackgroundSwitch .inner .selected');
	links.each(function(link){
		link.removeClassName('selected');
	});
	$('featuredBackgroundImage_' + id).appear({ duration: 1.0 });
	$('featuredBackgroundLabel_' + id).appear({ duration: 1.0 });
	$('featuredBackgroundSwitch_' + id).addClassName('selected');
}

function openModal(id)
{
	if('project_map' == id) {
		$('grid').hide();
	}
	$('modal_' + id).show();
	var contentHeight = $('modal_content_' + id).getHeight();
	if(contentHeight < $('modal_content_container_' + id).getHeight()) {
		$("ScrollbarContainer_modal_" + id).show();
		var scroller = new jsScroller(document.getElementById("modal_content_inner_" + id), 309, 259);
		var scrollbar = new jsScrollbar (document.getElementById("ScrollbarContainer_modal_" + id), scroller, false); 
	} else {
		$("ScrollbarContainer_modal_" + id).hide();
	}
}

function closeModal(id)
{
	if('project_map' == id) {
		$('grid').show();
	}
	$('modal_' + id).hide();
	
}

function loadLandingPage()
{
	if(null != $('landing_page_headings_background') && null != $('landing_page_headings')) {
		$('landing_page_headings').show();
		var height = $('landing_page_headings').getHeight();
		var top = 177 - height;
		$('landing_page_headings').setStyle({top: top + 'px'});
		$('landing_page_headings_background').setStyle({top: top + 'px', height: height + 'px'});
		$('landing_page_headings_background').show();
	}
	if(null != $('landing_page_main') && null != $('landing_page_content_background')) {
		_showLandingPageContent('main');
	}
}

function showHeading(id)
{
	if(null != $('landing_page_main_subpages')) {
		$('landing_page_main_subpages').hide();
	}
	if(null != $('landing_page_' + id) && null != $('landing_page_content_background')) {
		var contents = $$('.landing_page_content');
		contents.each(function(content){
			content.hide();
		});
		_showLandingPageContent(id);
	}
}

function _showLandingPageContent(id)
{
	$('landing_page_content_background').show();
	$('landing_page_' + id).show();
	var scrollboxHeight = $('scrollbox_inner_container_' + id).getHeight();
	var subpageHeight = null == $('landing_page_main_subpages') ?
							0 : $('landing_page_main_subpages').getHeight();
	/*if($('project_landing_page_rows') != null) {
		var height = 177 - 10 - subpageHeight;
		$('landing_page_' + id).setStyle({height: height + 'px'});
		$('ScrollbarContainer_' + id).setStyle({height: '155px'});
		$$('#ScrollbarContainer_' + id + ' .Scrollbar-Track')[0].setStyle({height: '155px'});
	} else*/ if((scrollboxHeight + subpageHeight + 10) > 298) {
		var height = 298 - 10 - subpageHeight;
		$('landing_page_' + id).setStyle({height: height + 'px'});
		$('landing_page_content_background').setStyle({	height: '298px'});
	} else {
		height = scrollboxHeight + 20 + subpageHeight;
		if(height > 298) {
			height = 298;
		}
		$('landing_page_' + id).setStyle({height: (scrollboxHeight + 10) + 'px'});
		$('landing_page_content_background').setStyle({	height: height + 'px'});
	}
	
	if($('scrollbox_inner_container_' + id).getHeight() > $('landing_page_' + id).getHeight()) {
		$('ScrollbarContainer_' + id).show();
		var scroller = new jsScroller(document.getElementById("scrollbox_" + id), $('scrollbox_inner_container_' + id).getWidth(), $("landing_page_" + id).getHeight());
		var scrollbar = new jsScrollbar (document.getElementById("ScrollbarContainer_" + id), scroller, false);
	}
	/*
	if(null == $('landing_page_main_subpages')) {
		contentHeight = contentHeight + 20;
	} else {
		contentHeight = contentHeight - 20 - heightOffset;
	}
	$('landing_page_' + id).setStyle({	height: contentHeight + 'px'});
	height = height + heightOffset;
	$('landing_page_content_background').setStyle({	height: height + 'px'});
	*/
}

function flipTile(elm)
{
	elm = $(elm);
	if(elm.hasClassName('selected')) {
		elm.removeClassName('selected');
	} else {
		elm.addClassName('selected');
	}
}

function loadProjectDetailPage()
{
	$('content').setStyle({zIndex: 1000});
	var headerHeight = $$('#project_content h1')[0].getHeight();
	var outer = $('project_content_outer').getHeight();
	if(headerHeight < 40) {
		outer = outer + (40 - headerHeight);
		$('project_content_outer').setStyle({height: outer + 'px'});
	} else if(headerHeight > 40) {
		outer = outer - (headerHeight - 40);
		$('project_content_outer').setStyle({height: outer + 'px'});
	}
	
	if($('project_content_scrollbox').getHeight() > outer) {
		$('project_content_ScrollbarContainer').show();
		var scroller = new jsScroller(document.getElementById("project_content_scrollbox"), $('project_content_outer').getWidth(), outer);
		var scrollbar = new jsScrollbar (document.getElementById("project_content_ScrollbarContainer"), scroller, false);
	}
}

function swapDetail(id)
{
	var details = $$('.project_detail_image');
	details.each(function(detail){
		if(detail.visible()) {
			detail.fade({ duration: 1.0 });
		}
	});
	$('detail_' + id).appear({ duration: 1.0 });
}

function loadHealthyHabitsPage()
{
	$('content').setStyle({zIndex: 1000});
	var outer = $('project_content_outer').getHeight();
	if($('project_content_scrollbox').getHeight() > outer) {
		$('project_content_ScrollbarContainer').show();
		var scroller = new jsScroller(document.getElementById("project_content_scrollbox"), $('project_content_outer').getWidth(), outer);
		var scrollbar = new jsScrollbar (document.getElementById("project_content_ScrollbarContainer"), scroller, false);
	}
}

function loadPeopleLandingPage()
{
	$('landing_page_main').setStyle({	height: '165px', width: '296px'});
	$('landing_page_content_background').setStyle({	height: '177px', width: '296px'});
	$('landing_page_content_background').show();
	$('landing_page_main').show();
	//$('scrollbox_main').setStyle({	height: '165px'});
	var scrollboxInnerHeight = $('scrollbox_inner_container_main').getHeight();
	var scrollboxHeight = $('landing_page_main').getHeight();
	if(scrollboxInnerHeight > scrollboxHeight) {
		$('ScrollbarContainer_main').show();
		$('ScrollbarContainer_main').setStyle({height: '150px'});
		$$('#ScrollbarContainer_main .Scrollbar-Track')[0].setStyle({height: '150px'});
		var scroller = new jsScroller(document.getElementById("scrollbox_main"), 256, 165);
		var scrollbar = new jsScrollbar (document.getElementById("ScrollbarContainer_main"), scroller, false);
	}
}

function loadNewsEventsDetailPage()
{
	$('landing_page_content_background').show();
	$('landing_page_main').show();
	var scrollboxInnerHeight = $('scrollbox_inner_container_main').getHeight();
	var scrollboxHeight = $('landing_page_main').getHeight();
	if(scrollboxInnerHeight > scrollboxHeight) {
		$('ScrollbarContainer_main').show();
		var scroller = new jsScroller(document.getElementById("scrollbox_main"), 256, 165);
		var scrollbar = new jsScrollbar (document.getElementById("ScrollbarContainer_main"), scroller, false);
	}
}

function loadSiteMapPage()
{
	$('grid').hide();
}

function loadContactPage()
{
	$$('#grid .horizontal')[0].hide();
}

function loadHomePage()
{
	$('rollover_architecture').setStyle({width: ($('architecture').getWidth() - 14) + 'px'});
	$$('#rollover_architecture li')[0].setStyle({width: $('rollover_architecture').getWidth() + 'px'});
	$('rollover_animals').setStyle({width: ($('animals').getWidth() - 13) + 'px'});
	$$('#rollover_animals li')[0].setStyle({width: $('rollover_animals').getWidth() + 'px'});
	$('rollover_people').setStyle({width: ($('people').getWidth() - 13) + 'px'});
	$$('#rollover_people li')[0].setStyle({width: $('rollover_people').getWidth() + 'px'});
	$('rollover_contact').setStyle({width: ($('contact').getWidth() - 13) + 'px'});
	$$('#rollover_contact li')[0].setStyle({width: $('rollover_contact').getWidth() + 'px'});
	loadHomeSlideShow();
}

var pt = setTimeout('',1);
var main_image_fade_duration = 1;

function loadHomeSlideShow()
{
	var images = $$('#featuredBackgroundSwitch a');
	var lastImage = images.length;
	//_switchProjectBackground(1, lastImage);
	
	
	pt = setTimeout('_switchProjectBackground(1, ' + lastImage + ');',5000);
}

function _switchProjectBackground(showImage, lastImage)
{
	switchProjectBackground(showImage, false);
	
	if(showImage == lastImage) {
		showImage = 1;
	} else {
		showImage++;
	}
	pt = setTimeout('_switchProjectBackground(' + showImage + ', ' + lastImage + ');',5000 + (main_image_fade_duration * 1000));
}
