

function highlightNav()
{
	var navLinks = $$('#nav_container a');
	bindEvents(navLinks);
	function bindEvents(elements)
	{
		for ( i = 0; i < elements.length; i++ ) {
			Event.observe(elements[i], 'mouseover', handler.bindAsEventListener(elements[i], 1));
			Event.observe(elements[i], 'mouseout', handler.bindAsEventListener(elements[i], 0));
		}
	}
}

function handler(e, zoom)
{
	var element = Event.element(e);
	
	if ( zoom ) {
		element.src = element.src.replace(/\.gif/, '_hover.gif');
	}
	else {
		element.src = element.src.replace(/(_hover)?\.gif/, '.gif');
	}
	
}





var currentChannel = 'design';
var cycleChannels = true;
var channelArray = new Array('design', 'pre', 'core', 'fixtures', 'lifestyle');
var currentIndex = 0;

window.setTimeout('cycleChannelSelector(1)', 3000);

function cycleChannelSelector(newIndex)
{
	if ( cycleChannels && $('homepage_channel_title') ) {
		
		if ( newIndex >= channelArray.length ) {
			newIndex = 0;
		}
		
		chooseChannel(channelArray[newIndex]);
		cycleChannels = true;
		
		currentIndex = newIndex;
		newIndex = newIndex + 1;
	}
	
	window.setTimeout('cycleChannelSelector(' + newIndex + ')', 3000);
}

function chooseChannel(channel)
{
	if ( channel ) {
		cycleChannels = false;
		
		$('homepage_channel_title_' + currentChannel).style.display = 'none';
		$('homepage_channel_text_' + currentChannel).style.display = 'none';
		$(currentChannel + '_logo').src = $(currentChannel + '_logo').src.replace('tm2.','tm.');
		
		$('homepage_channel_title_' + channel).style.display = '';
		$('homepage_channel_text_' + channel).style.display = '';
		$(channel + '_logo').src = $(channel + '_logo').src.replace('tm.','tm2.');
		
		currentChannel = channel;
	}
	else {
		cycleChannels = true;
	}
}

function navChannel(channel)
{
	/*if (currentChannel) {
		alert('channel_nav_text_' + currentChannel);
		$('channel_nav_text_' + currentChannel).style.display = 'none';
	}
	
	if ( channel ) {
		$('channel_nav_text_' + channel).style.display = '';
	}
	
	currentChannel = channel;*/
}


function syncHeight()
{
	var channelHeight = $('channel_sidebar').getHeight();
	var bodyHeight = $('content_container').getHeight() + 30;
	
	var bannerHeight = $('banner_sidebar') ? $('banner_sidebar').getHeight() + 30 : 0;
	
	var largestHeight = Math.max(channelHeight,Math.max(bannerHeight, bodyHeight));
	
	var minHeight = 700;
	
	largestHeight = Math.max(minHeight, largestHeight) + 30;
	
	$('channel_sidebar').style.height = largestHeight + "px";
	$('content_container').style.height = (largestHeight - 30) + "px";
	
	if ( $('banner_sidebar') ) {
		$('banner_sidebar').style.height = (largestHeight - 30) + "px";	
	}	
}


function switchTab(number, tabIdName, contentContainerName)
{
	displayTab(number, tabIdName, contentContainerName)
	//syncHeight();	
}

// open external links in a new window.
Event.observe(window, 'load', function() {

	var domain = document.location.toString();
	domain = domain.replace(/http:\/\//, '');
	domain = domain.substring(0, domain.indexOf('/'));
	
    $$('a[href!=""]').each(function(link){
    	var siteregex = new RegExp("^(http:\\/\\/)([a-z]*\\.)?(" + domain + ")", "i");
    	
        if(link.readAttribute('href').startsWith('http://') &&
          !link.readAttribute('href').match(siteregex)){
            link.writeAttribute('target','_blank');
            link.writeAttribute('rel','external');
        }
    });
});

function setRealEstateSearchAction()
{
	var searchType = $F('real_estate_search_type');
	$('real_estate_search_form').action = '/real-estate/' + searchType + '/index.php';
}

function ValidateTagForm()
{
	if (!$F('Tag')) {
		alert("No tag was provided.");
		$('Tag').focus();
		return false;
	}
	
	return true;
}

function verifyNewsetterSignup() {
	if ( !$F('EmailAddress') ) {
		alert("A valid email address is required.");
		return false;	
	}
	
	return true;
}

function setProfileHeight() {
	var profileElems = $$('.company_profile .company_info');
	for (var index = 0; index < profileElems.length; index++) {
		var item = profileElems[index];
		if ( item.getHeight() < 100 ) {
			item.style.height = '100px';
		}
	}	
}