var currentPage = '/' + location.pathname.split( "/" )[1],
	currentSub = false,
	links = [
		new Link( 'home',		'/' ),
		new Link( 'physicians',	'/physicians' ),
		new Link( 'services',	'/services' ),
		new Link( 'resources',	'/resources' ),
		new Link( 'location',	'/location' ),
		new Link( 'articles',	'/articles' ),
		new Link( 'Contact Us',	'/contact' )
	],
	physicians = [
		new Link( 'Robert Wolfe, M.D. F.C.C.P.',	'/wolfe.html' ),
		new Link( 'Andrew S Wachtel, M.D. F.C.C.P.','/wachtel.html' ),
		new Link( 'Roy Artal, M.D. F.C.C.P.',		'/artal.html'  )
	];

function Link( name, href )
{
	this.name = name;
	this.href = href;
	return this;
}

function listLinks()
{
	var out = '', thisLink, x;
	for ( x=0; x<links.length; x++ )
	{
		thisLink = links[x];
		out += ( currentPage == thisLink.href )
			? '\n		 	<div class="active">' + thisLink.name + '</div>'
			: '\n 			<a href="' + thisLink.href + '">' + thisLink.name + '</a>';
	}
	return out;
}

function buildHeader()
{
	var out = '\n<div align="center">'
			+ '\n	<div id="page">'
			+ '\n		<div id="navbar">\n		<div class="nav">' + listLinks() + '</div>'
			+ '\n		</div>' + buildSubnav()
			+ '\n	<img id="logo" src="/img/logo.gif" width="232" height="138" alt="" />'
			+ '\n	<div id="sandbox">'
	document.write( out );
//Debug( out );
}

function buildSubnav()
{
	var out = '', x, thisPhysician;
	if ( currentSub )
	{
		out += '\n	<div id="subnavbar">\n		<div class="nav">';
		for ( x=0; x < physicians.length; x++ )
		{
			thisPhysician = physicians[x];
			out += ( thisPhysician.name.indexOf(currentSub) > -1 )
				? '\n		<div class="active">' + thisPhysician.name + '</div>'
				: '\n		<a href="/physicians' + thisPhysician.href + '">' + thisPhysician.name + '</a>';
		}
		out += '\n		</div>\n	</div>';
	}
	return out;	
}

function buildFooter()
{
	var out = '\n</div></div></div>';
	document.write( out );
}

function Debug(str,code)
{
	var str_debug = "";
	if ( code )
	{
		str_debug += '<body marginheight="0" marginwidth="0">\n\n';
		str_debug += str;
	}
	else
	{
		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;");
	}
	str_debug += "\n\n</body></html>";
	var win_debug = window.open();
	win_debug.document.write(str_debug);
}


