var sourceText,
	rightImage,
	currentPage = window.location.pathname,
	globalLinks = [
		newLink( "home",				"/"),
		newLink( "offroading",			"/offroading/" ),
		newLink( "birdwatching",		"/birdwatching/" ),
		newLink( "overview",			"/overview/" ),
		newLink( "location",			"/location/" ),
		newLink( "contact&nbsp;us",		"/contactus/" )
	];

function newLink( name, href )
{
	var thisLink = new Object();
	thisLink.name = name;
	thisLink.href = href;
	return thisLink;
}


function init( firstImage )
{
	sourceText = document.createElement('span');
	sourceText.innerHTML = d("sourceText").innerHTML.replace(/XXX/gi, '');
	d("leftColumn").appendChild(sourceText);
	rightImage = d("rightColumnBg");
//Debug(d("leftColumn").innerHTML, true);
}

function buildTemplate()
{
	var x, thisLink,
		out = '<center>'
			+ '\n<div id="contentBg">'
			+ '\n	<div id="rightColumnBg">'
			+ '\n		<div id="dropShadow">'
			+ '\n			<div id="footerBg">'
			+ '\n				<div id="mainContainer">'
			+ '\n					<table border="0" cellpadding="0" cellspacing="0" width="800" height="509" id="leftColumnBg">'
			+ '\n					<tr><td width="314" height="100" valign="top"><img src="/img/logo.gif" width="314" height="100" alt="SaltonSea Mobile Home Park" /></td>'
			+ '\n						<td id="navbar" width="481">';
	for ( x=0; x < globalLinks.length; x++ )
	{
		thisLink = globalLinks[x];
		out += ( currentPage == thisLink.href )
				? '<span class="activeLink">' + thisLink.name + '</span>'
				: '<a href="' + thisLink.href + '">' + thisLink.name + '</a>';
		if ( x < globalLinks.length-1 ) out += '&nbsp;|&nbsp;';
	}
	out += '</td>'
		+ '\n					</tr>'
		+ '\n					<tr><td valign="top" colspan="2" id="leftColumn"></td></tr>'
		+ '\n					<tr><td class="footerText" colspan="2">'
		+ '\n							<b>Ocotillo Wells Accommodations</b><div class="source">Adult Desert Living</div><br />'
		+ '\n							&copy; 2010 Salton Sea MHP<br /><br /><br /></td>'
		+ '\n					</tr>'
		+ '\n					</table></div></div></div></div></div></center>';
	document.write( out );
//Debug(out, true);
}

var previousLink;
function showPic( thisImg )
{
	rightImage.style.backgroundImage = 'url("/img' + currentPage + thisImg + '.jpg")';

	d(previousLink).className = 'inactiveLink';
	d(thisImg).className = 'activeLink';

	Hide(previousLink + 'Text');
	Show( thisImg + 'Text');
	previousLink = thisImg;
}

function d(id) { return document.getElementById(id); }
function Show( id ) { d(id).style.display = "inline"; }
function Hide( id ) { d(id).style.display = "none"; }

/* Sets a Cookie with the given name and value.
	name       Name of the cookie
	value      Value of the cookie
	[expires]  Expiration date of the cookie (default: end of current session)
	[path]     Path where the cookie is valid (default: path of calling document)
	[domain]   Domain where the cookie is valid
					(default: domain of calling document)
	[secure]   Boolean value indicating if the cookie transmission requires a
					secure transmission
*/

function setCookie(name, value, path, expires, domain, secure)
{
	document.cookie = 
		name + "=" + escape(value) +
		((expires) ? "; expires=" + expires.toGMTString() : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");
}

function clearCookie ( name )
{
	var cookie_date = new Date ( );  // current date & time
	cookie_date.setTime ( cookie_date.getTime() - 1 );
	document.cookie = name += "=; expires=" + cookie_date.toGMTString();
}

function getCookie(name)
{
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1) {
		begin = dc.indexOf(prefix);
		if (begin != 0) return null;
	}
	else
	{
		begin += 2;
	}
	var end = document.cookie.indexOf(";", begin);
	if (end == -1)
	{
		end = dc.length;
	}
	return unescape(dc.substring(begin + prefix.length, end));
}

function Debug(str,code)
{
	var str_debug = "";
	if ( code ) {
		str_debug += '<html><body marginheight="0" style="white-space: pre;font-family: Monaco,Courier;font-size:9px;">\n\n';
		str_debug += str.replace(/</g, "&lt;").replace(/>/g, "&gt;");
	}
	else {
		str_debug += '<body marginheight="0" marginwidth="0">\n\n';
		str_debug += str;
	}
	str_debug += "\n\n</body></html>";
	var debugWindow = window.open();
	debugWindow.document.write(str_debug);
}
