var ie = ( navigator.appVersion.indexOf("MSIE") != -1 );
var ie4 = ( navigator.appVersion.indexOf("MSIE 4") != -1 );
var ie5 = ( navigator.appVersion.indexOf("MSIE 5") != -1 );
var mac = ( navigator.userAgent.indexOf("Mac") != -1) ? true : false;
var ns6 = ( (navigator.appName.indexOf("Netscape") != -1) && parseInt(navigator.appVersion) >= 5 );
var moz = ( ns6 && navigator.userAgent.search(/(Chimera)|(Camino)|(Safari)/) == -1 );
var macIE = ( ie5 && mac );

function d(id) { return document.getElementById(id); }
if ( mac && ie5 ) Array.prototype.push = function () {
	var thisArray = this, x;
	for ( x=0; x < arguments.length; x++ ) {
		thisArray[ thisArray.length ] = arguments[x];
	}
	return thisArray.length;
}

var dirPath = "/", linkText, initialLinkText,
	imgDir = dirPath + 'img/',
	Link = new Array(),
	currentPage = ( currentPage ) ? currentPage : false,
	date = new Date();
	currentYear = date.getFullYear();

function header() {
	var ear = "", linkTitle = "", out;
	if ( currentPage == "home" ) {
		dirPath = "";
		imgDir = dirPath + 'img/';
		linkTitleString = '';
		ear = '<table border="0" cellpadding="0" cellspacing="0" width="200" align="center">'
				+ '\n<tr><td width="40" class="contact"><img src="' + imgDir + 'casper.gif" width="40" height="1" alt="" /></td>'
				+ '\n	<td width="160" valign="middle" align="left" class="contact">'
				+ '\n		<img src="' + imgDir + 'phone.gif" alt="phone.gif" width="14" height="15" />  310.446.8667<br />'
				+ '\n		<img src="' + imgDir + 'fax.gif" alt="fax.gif" width="14" height="15" />  310.446.4901<br />'
				+ '\n		<a href="mailto:myamericanpup@gmail.com">info@americanpup.com</a></td></tr></table>';
	}
	else {
		ear = '\n		<div class="navLinks">'
			+ ( ( currentPage == "about" ) 
				? '<div class="activeLink"><img src="' + imgDir + 'about_on.gif" width="81" height="63" border="0" alt="" /></div>'
				: '<a href="' + dirPath + 'about" onmouseover="swapOn(\'about\')" onmouseout="swapOff(\'about\')" id="about"></a>'
			)
			+ ( ( currentPage == "locations" ) 
				? '<div class="activeLink"><img src="' + imgDir + 'locations_on.gif" width="81" height="63" border="0" alt="" /></div>'
				: '<a href="' + dirPath + 'locations" onmouseover="swapOn(\'locations\')" onmouseout="swapOff(\'locations\')" id="locations"></a>'
			)
			+ ( ( currentPage == "paws" ) 
				? '<div class="activeLink"><img src="' + imgDir + 'paws_on.gif" width="81" height="63" border="0" alt="" /></div>'
				: '<a href="' + dirPath + 'paws" onmouseover="swapOn(\'paws\')" onmouseout="swapOff(\'paws\')" id="paws"></a>'
			)
			+ ( ( currentPage == "browse" )
				? '<div class="activeLink"><img src="' + imgDir + 'browse_on.gif" width="81" height="63" border="0" alt="" /></div>'
				: '<a href="' + dirPath + 'browse" onmouseover="swapOn(\'browse\')" onmouseout="swapOff(\'browse\')" id="browse"></a>'
			)
			+ '</div>';
		linkTitleString = '<span id="linkTitle"></span>';
	}
	out = '\n<table border="0" cellpadding="0" cellspacing="0" width="100%" bgcolor="#6F0000">'
		+ '\n<tr><td rowspan="3" width="100" height="100" align="center" valign="middle">\n		<a href="' + dirPath + '" title="American Pup Home"><img src="' + imgDir + 'logo.gif" width="99" height="100" alt="American Pup Home" border="0" /></a></td>'
		+ '\n	<td rowspan="3" width="2" bgcolor="white">\n		<img src="' + imgDir + 'casper.gif" width="2" height="100" alt="" /></td>'
		+ '\n	<td valign="middle" class="address">\n		<img src="' + imgDir + 'casper.gif" width="450" height="10" alt="" /><br />\n		<span class="logo">AMERICAN PUP &reg;</span></td>'
		+ '\n	<td height="63" align="right" class="contact" nowrap="nowrap">' + ear + '</td>'
		+ '\n</tr>'
		+ '\n<tr><td bgcolor="white" colspan="2" height="2">\n		<img src="' + imgDir + 'casper.gif" width="493" height="2" alt="" /></td></tr>'
		+ '\n<tr><td background="' + imgDir + 'star.gif" valign="middle" align="right" colspan="2" height="35">' + linkTitleString + '</td>'
		+ '\n</tr>'
		+ '\n</table>';
	document.write(out);
//Debug(out, true)
}

function footer() {
	var splitter = '<span class="split"> | </span>';
	var out = '\n<div id="footer">'
		+ ( ( currentPage == "home" )
			? 'HOME'
			: ' <a href="' + dirPath + '">HOME</a> '
		) + splitter
		+ ( ( currentPage == "browse" )
			? 'BROWSE'
			: ' <a href="' + dirPath + 'browse">BROWSE</a> '
		) + splitter
		+ ( ( currentPage == "locations" ) 
			? 'LOCATIONS'
			: ' <a href="' + dirPath + 'locations">LOCATIONS</a> '
		) + splitter
// 		+ ( ( currentPage == "tradeshows" ) 
// 			? 'TRADE SHOWS'
// 			: ' <a href="' + dirPath + 'about/tradeshows.html">TRADE SHOWS</a> '
// 		) + splitter
		+ ( ( currentPage == "terms" ) 
			? 'TERMS'
			: ' <a href="' + dirPath + 'about/terms.html">TERMS</a> '
		) + splitter
		+ ( ( currentPage == "raves" ) 
			? 'RAVES'
			: ' <a href="' + dirPath + 'about/raves.html">RAVES</a> '
		) + splitter
		+ ( ( currentPage == "about" ) 
			? 'ABOUT US'
			: ' <a href="' + dirPath + 'about">ABOUT US</a> '
		)
		+ splitter + ' <a href="mailto:info@americanpup.com" title="info@americanpup.com">CONTACT US</a>'
		+ '<br />&copy; ' + currentYear + ' American Pup<br><br>'
		+ '\n<span class="info">Site Design by Samrod Shenassa   -   Photography by Nicholas Melillo</span></div><br />';
		document.write(out);
}

function newLink(id, text) {
	Link[id] = new Object();
	var thisLink = Link[id];
	thisLink.href = id;
	thisLink.text = text;
	thisLink.active = (currentPage == id);
	thisLink.on = new Image();
	thisLink.on.src = imgDir + id + "_on.gif";
}

function swapOn(id)  {
	linkText.innerHTML = Link[id].text;
}

function swapOff(id) {
	linkText.innerHTML = initialLinkText;
}

function init() {
	if ( currentPage == "home" ) dirPath = "";
	else {
		dirPath = "/";
		newLink("browse",		"SWEATSHIRTS &amp; TEES &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;");
		newLink("paws",			"Thunder PAWS&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;");
		newLink("locations",	"STORE LOCATIONS &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ");
		newLink("about",		"WHY AMERICAN PUP? &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;");
	}
	linkText = d('linkTitle');
	initialLinkText = linkText.innerHTML;
	imgDir = dirPath + 'img/';
}

function setPage(page) {
	currentPage = page;
	dirPath = "/";
	imgDir = dirPath + 'img/';
}

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 win_debug = window.open();
	win_debug.document.write(str_debug);
}
