
var tabs = new Array();
var currentTab = null;

function dwhRegisterTab(id) {
	tabs[id] = document.getElementById(id);
	if (id != 'summary') {
		tabs[id].style.display = 'none';
	}
	else {
		tabs[id].style.display = '';
	}
}

function dwhSelectTab(a, id) {
	for (tabid in tabs) {
		if (tabid == id) {
			tabs[tabid].style.display = '';
		}
		else {
			tabs[tabid].style.display = 'none';
		}
	}
	dwhHighlightLink(id);
	return false;
}

function dwhHighlightLink(id) {
	var L = document.getElementsByTagName('a');
	for (i = 0; i < L.length; ++i) {
		if (L[i].parentNode.tagName == 'LI') {
			if (L[i].href.indexOf('#' + id) > -1) {
				L[i].className = 'highlight';
			}
			else if (L[i].className.indexOf('highlight') > -1) {
				L[i].className = L[i].className.replace(/ ?highlight/, '');
			}
		}
	}
	return false;
}

function dwhToggleAdvanced() {
	var table = document.getElementById('searchbox').getElementsByTagName('div');
	for (var i = 0; i < table.length; ++i) {
		tr = table.item(i);
		if (tr.className == 'options advancedoptions') {
			if (tr.style.display == 'none') {
				tr.style.display = '';
			}
			else {
				tr.style.display = 'none';
			}
		}
	}
	var toggle = document.getElementById('advancedswitch');
	if (toggle) {
		if (toggle.innerHTML == 'Advanced')
			toggle.innerHTML = 'Basic';
		else
			toggle.innerHTML = 'Advanced';
	}
}

// next 4 functions copyright 'free' from quirksmode.org. required for aerial photo overlay
function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function getVertScroll() {
	var y;
	if (self.pageYOffset) // all except Explorer
	{
		y = self.pageYOffset;
	}
	else if (document.documentElement && document.documentElement.scrollTop)
		// Explorer 6 Strict
	{
		y = document.documentElement.scrollTop;
	}
	else if (document.body) // all other Explorers
	{
		y = document.body.scrollTop;
	}
	return y;
}

function getHorizScroll() {
	var x;
	if (self.pageYOffset) // all except Explorer
	{
		x = self.pageXOffset;
	}
	else if (document.documentElement && document.documentElement.scrollTop)
		// Explorer 6 Strict
	{
		x = document.documentElement.scrollLeft;
	}
	else if (document.body) // all other Explorers
	{
		x = document.body.scrollLeft;
	}
	return x;
}

function overlayMap(pageX, pageY, clientX, clientY, width, height) {
	if (document.getElementById) {
		var overlay = document.getElementById('ukmapoverlay');
		var mapWidth = (width=='')?240:width;
		var mapHeight = (height=='')?390:height;
		var clipWidth = Math.round(mapWidth / 2);
		var clipHeight = Math.round(mapHeight / 2);
		
		var posx = 0;
		var posy = 0;
		
		if (pageX || pageY)
		{
			posx = pageX;
			posy = pageY;
		}
		else if (clientX || clientY)
		{
			posx = clientX + getHorizScroll();
			posy = clientY + getVertScroll();
		}
		
		var clipTop = posy - findPosY(overlay) - Math.round(clipHeight/2);
		var clipLeft = posx - findPosX(overlay) - Math.round(clipWidth/2);		
		var clipBot = clipTop + clipHeight;
		var clipRight = clipLeft + clipWidth;
		var defClip = "rect(" + clipTop +"px "+ clipRight +"px "+ clipBot +"px "+ clipLeft +"px)";
		overlay.style['z-index'] = "5";
		overlay.style.visibility = "visible";
		overlay.style.display = "block";		
		overlay.style.width = '240px';
		overlay.style.clip = defClip;
	}
}

function dwhToggleFloorplan(floor) {
	var floorplantoggle = document.getElementById('floorplantoggle');
	var floors = floorplantoggle.getElementsByTagName('div');
	for (var i = 0; i < floors.length; ++i) {
		if (i == floor) {
			floors[i].style.display = 'block';
		}
		else {
			floors[i].style.display = 'none';
		}
	}
	return false;
}

