
var preloadedImages = Array();

// wires up image map rollover events
addLoadEvent(initBridgeRollovers);

// wires up bridge design popups
addLoadEvent(initBridgePops);

// wires up bridge detail popups
addLoadEvent(initBridgeDetail);

// wires up bridge chart popups
addLoadEvent(initBridgeChart);

// show splash
//addLoadEvent(splashIn);

// wires up bridge design gallery images
addLoadEvent(initFinalDesignGallery);

// this function finds all anchor tags with rel="designdetail" and wires up onmouseover handlers
function initFinalDesignGallery()
{
	if (!document.getElementsByTagName) return;
		
	var anchors = document.getElementsByTagName("a");
	if (anchors == null) return;
	
	var lblCaption = document.getElementById("lblCaption");
	if (!lblCaption) return;
	
	var imgGallery = document.getElementById("imgGallery");
	if (!imgGallery) return;
	
	for (var i=0; i<anchors.length; i++)
	{
		var anchor = anchors[i];
		if (anchor.getAttribute("href") && (anchor.getAttribute("rel") == "designdetail"))
		{
			// preload the gallery image
			preloadImage(anchor.getAttribute('href'));
					
			// create the mouseover event
			anchor.onmouseover = function () 
			{
				// get the link and title
				var url = this.getAttribute('href');
				var title = this.getAttribute('title');
				
				// switch to the correct image
				imgGallery.src = url;
				
				// clear the caption
				while(lblCaption.firstChild) 
					lblCaption.removeChild(lblCaption.firstChild);
				
				// set the caption to the title of the link
				lblCaption.appendChild(document.createTextNode(title));
			}
			
			// wire up a "do nothing" onclick handler
			anchor.onclick = function () 
			{
				return false;
			}	
					
		}
	}
}

// this function finds all anchor tags with rel="chart" and wires up onclick handlers
function initBridgeChart()
{
	if (!document.getElementsByTagName) return;
		
	var anchors = document.getElementsByTagName("a");
	if (anchors == null) return;
	
	for (var i=0; i<anchors.length; i++)
	{
		var anchor = anchors[i];
		if (anchor.getAttribute("href") && (anchor.getAttribute("rel") == "chart"))
		{
			anchor.onclick = function () 
			{
				return showBridgeChart(this);
			}
		}
	}
}

// this function finds all anchor tags with rel="bridgedetail" and wires up onclick handlers
function initBridgeDetail()
{
	if (!document.getElementsByTagName) return;
		
	var anchors = document.getElementsByTagName("a");
	if (anchors == null) return;
	
	for (var i=0; i<anchors.length; i++)
	{
		var anchor = anchors[i];
		if (anchor.getAttribute("href") && (anchor.getAttribute("rel") == "bridgedetail"))
		{
			anchor.onclick = function () 
			{
				return showBridgeDetail(this);
			}
		}
	}
}

// this function finds all area tags with rel="bridgespot" and wires up event handlers
function initBridgeRollovers()
{
	if (!document.getElementsByTagName) return;
	
	var bridge = document.getElementById('imgBridge');
	if (bridge == null) return;
	
	var anchors = document.getElementsByTagName("area");
	if (anchors == null) return;
	
	var origsrc = bridge.src;

	for (var i=0; i<anchors.length; i++)
	{
		var anchor = anchors[i];
		if (anchor.getAttribute("href") && (anchor.getAttribute("rel") == "bridgespot"))
		{
			var link = anchor.getAttribute("href");
			preloadImage(link);
			anchor.onclick = function () { return false; }
			anchor.onmouseover = function() { bridge.src = this.href; }
			anchor.onmouseout = function() { bridge.src = origsrc; }			
		}
	}
}

// this function finds all anchor tags with rel="bridgedesign" and wires up onclick handlers
function initBridgePops()
{
	if (!document.getElementsByTagName) return;
		
	var anchors = document.getElementsByTagName("a");
	if (anchors == null) return;
	
	for (var i=0; i<anchors.length; i++)
	{
		var anchor = anchors[i];
		if (anchor.getAttribute("href") && (anchor.getAttribute("rel") == "bridgedesign"))
		{
			anchor.onclick = function () 
			{
				return showBridge(this);
			}
		}
	}
}

function preloadImage(src)
{
	var i = preloadedImages.length;
	var img = new Image();
	img.src = src;
	preloadedImages[i] = img;
}

// opens up bridge design windows
function showBridge(link)
{
	var url = link.getAttribute('href');
	var theWin = window.open(url, 'design', 'menubar=no,location=no,resizable=no,scrollbars=no,status=no,width=800,height=500');
	if (theWin != null)
	{
		theWin.focus();
		return false;
	}
	return true;
}

// opens up bridge detail windows
function showBridgeDetail(link)
{
	var url = link.getAttribute('href');
	var theWin = window.open(url, 'bridgedetail', 'menubar=no,location=no,resizable=no,scrollbars=yes,status=no,width=675,height=700');
	if (theWin != null)
	{
		theWin.focus();
		return false;
	}
	return true;
}

// opens up bridge chart windows
function showBridgeChart(link)
{
	var url = link.getAttribute('href');
	var theWin = window.open(url, 'bridgechart', 'menubar=no,location=no,resizable=no,scrollbars=yes,status=no,width=670,height=500');
	if (theWin != null)
	{
		theWin.focus();
		return false;
	}
	return true;
}

function addLoadEvent(func)
{	
	var oldonload = window.onload;
	if (typeof window.onload != 'function')
	{
		window.onload = func;
	} 
	else 
	{
		window.onload = function()
		{
			oldonload();
			func();
		}
	}
}

function toggleSection(id)
{
	section = document.getElementById('div' + id);
	exImg = document.getElementById('ex' + id);
	colImg = document.getElementById('col' + id);

	if (section.style.display != 'none')
	{
		section.style.display = 'none';
		exImg.style.display = 'none';
		colImg.style.display = 'inline';
	}
	else
	{
		section.style.display = 'block';
		exImg.style.display = 'inline';
		colImg.style.display = 'none';
	}
	return true;
}

function splashIn()
{
	preloadImage('../images/homesplash/dtalt2.jpg');
	preloadImage('../images/homesplash/eealt3.jpg');
	
	var blackout = document.getElementById('blackout');
	if (blackout)
	{
		var arrayPageSize = getPageSize();
		blackout.style.height = (arrayPageSize[1] + 'px');
		blackout.style.width = (arrayPageSize[0] + 'px');
		fadeIn('splash', 0, 100, 50);
		fadeIn('blackout', 0, 70, 50);		
	}
}

function fadeIn(objId, start, end, delay)
{
	var obj = document.getElementById(objId);
	if (obj)
	{
		if (start <= end)
		{
			setOpacity(obj, start);
			start += 5;
			window.setTimeout("fadeIn('" + objId + "', " + start + ", " + end + ", " + delay + ")", delay);
		}
		else if (objId == 'splash')
		{
			var dtf = new SWFObject("../Flash/Unveil/dtalt2.swf", "dtalt2", "350", "233", "7", "#0066ff");
			if (!dtf.write("tdDowntown"))
			{
				document.getElementById('imgDowntown').src = '../images/homesplash/dtalt2.jpg';
			}
						
			var eef = new SWFObject("../Flash/Unveil/eealt3.swf", "eealt3", "350", "233", "7", "#0066ff");
			if (!eef.write("tdEastEnd"))
			{
				document.getElementById('imgEastEnd').src = '../images/homesplash/eealt3.jpg';
			}
		}
	}
}

function splashOut()
{
	document.getElementById('tdDowntown').innerHTML= '<img src="../images/homesplash/dtalt2.jpg" width="350" height="233" alt="" />';
	document.getElementById('tdEastEnd').innerHTML= '<img src="../images/homesplash/eealt3.jpg" width="350" height="233" alt="" />';
	fadeOut('splash', 100, 0, 50);
	fadeOut('blackout', 70, 0, 50);
	return false;
}

function fadeOut(objId, start, end, delay)
{
	var obj = document.getElementById(objId);
	if (obj)
	{	
		if (start >= end)
		{
			setOpacity(obj, start);
			start -= 5;
			window.setTimeout("fadeOut('" + objId + "', " + start + ", " + end + ", " + delay + ")", delay);
		}
	}
}

function setOpacity(obj, opacity)
{
	if (opacity == 0)
	{
		obj.style.display = 'none';
	}
	else
	{
		obj.style.display = 'block';
	}
	
	obj.style.filter = "alpha(opacity:" + opacity + ")";
	obj.style.KHTMLOpacity = opacity/100;
	obj.style.MozOpacity = opacity/100;
	obj.style.opacity = opacity/100;
}


//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function eeClick()
{
	window.location.replace('../Wcf1cc3383f1fc.htm');
}

function dtClick()
{
	window.location.replace('../Wcf1cc3383f1fc.htm');
}
