// Centralized place for onload function call
function onloadfunctions() {
	// Initialize IE Hover Element
	if (window.attachEvent) window.attachEvent("onload", sfHover);

	// Initialize Header Image Replacement
	imageReplacementInit();

	// Initialize XHTML External Link replacement
	externalLinks();
}

// Write Flash Objects
function writeflash(src, width, height, name, align, bgcolor, version) {
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=' + version + '" width="' + width + '" height="' + height + '" id="' + name + '" align="' + align + '">');
	document.write('<param name="allowScriptAccess" value="sameDomain" />');
	document.write('<param name="movie" value="/images/flash/' + src + '" />');
	document.write('<param name="quality" value="high" />');
	document.write('<param name="bgcolor" value="#' + bgcolor + '" />');
	document.write('<embed src="/images/flash/' + src + '" quality="high" bgcolor="#' + bgcolor + '" width="' + width + '" height="' + height + '" name="' + name + '" align="' + align + '" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	document.write('</object>');
}

// Generate Anti-SPAM E-Mail
function generate_address(appearance, username, hostname, tld)
{
	var atsign = "&#64;";

	// If SAMEADDRSS is present, then the E-mail address will be shown instead of a custom value
	if (appearance == "SAMEADDRESS")
	{
		appearance = username + atsign + hostname + "." + tld;
	}

	var addr = username + atsign + hostname + "." + tld;
	document.write("<" + "a" + " " + "href=" + "mail" + "to:" + addr + ">" + appearance + "<\/a>");
}

// IE Hover Element Function
function sfHover() {
	var sfEls = document.getElementById("navigation").getElementsByTagName("li");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}

/* Accessable Image Replacement */
// Image replacement for Web Accessability
// Courtesy Of: http://www.quirksmode.org/dom/fir.html
function imageReplacementInit()
{
	var test = new Image();
	var tmp = new Date();
	var suffix = tmp.getTime();
	test.src = '/images/h1/accessibilitytest.gif?'+suffix;
	test.onload = imageReplacement;
}

function imageReplacement()
{
	replaceThem(document.getElementsByTagName('h1'));
}

function replaceThem(x)
{
	var replace = document.createElement('img');
	for (var i=0;i<x.length;i++)
	{
		if (x[i].id)
		{
			var y = replace.cloneNode(true);
			y.src = '/images/h1/' + x[i].id + '.gif';
			y.alt = x[i].firstChild.nodeValue;
			x[i].replaceChild(y,x[i].firstChild);
		}
	}
}

/* XHTML Compliant Open Window */
function externalLinks() {
	if (!document.getElementsByTagName) return;
		var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external")
			anchor.target = "_blank";
	}
}

/* Google Maps */
var map;
var mm;

function createMarker(point,html) {
	// Create our "tiny" marker icon
	var icon = new GIcon();
   icon.image = "http://www.wolffservices.com/images/marker.png";
	icon.shadow = "http://www.wolffservices.com/images/shadow.png";
	icon.iconSize = new GSize(20, 16);
	icon.shadowSize = new GSize(30, 16);
	icon.iconAnchor = new GPoint(6, 20);
	icon.infoWindowAnchor = new GPoint(10, 5);

	var marker = new GMarker(point, icon);
	GEvent.addListener(marker, "click", function() {
		marker.openInfoWindowHtml(html);
	});
	return marker;
}

function startmap(latitude, longitude, zoom)
{
	if (GBrowserIsCompatible()) { 
		// Display the map, with some controls and set the initial location 
		map = new GMap2(document.getElementById("map"));
		map.addControl(new GLargeMapControl());
		map.setCenter(new GLatLng(latitude,longitude),zoom);
		mm = new GMarkerManager(map, {borderPadding:1});
	}
	
	// display a warning if the browser was not compatible
	else {
		alert("Sorry, the Google Maps API is not compatible with this browser");
	}
}

function addMarker(latitude, longitude, html)
{
	// Set up three markers with info windows 
	//var point = new GLatLng(43.65654,-79.90138);
	var point = new GLatLng(latitude,longitude);
	var marker = createMarker(point,'<div style="width:250px">' + html + '</div>')
	mm.addMarker(marker,0,17); 
}

function refreshMap()
{
	mm.refresh();
}

// Swap images function.
function wm_imageswap(dasrc, daimage)
{
	var objStr,obj;

	if(document.images)
	{
		if (typeof(daimage) == 'string')
		{
			objstr = 'document.' + daimage;
			obj = eval(objstr);
			obj.src = dasrc;
		}
		else if ((typeof(daimage) == 'object') && daimage && daimage.src)
		{
			daimage.src = dasrc;
		}
	}
}