/* 	GLOBALS
 *

 *	Cat: possibilities for category
 */
var Cat = 
	{
	"HOME_PAGE"			: 0, 
	"FREE_SOFTWARE"		: 1, 
	"SOFTWARE_RACK"		: 2, 
	"FREE_MAGAZINES"	: 3,
	"BOOKSTORE"			: 4, 
	"ARTICLE_LIBRARY"	: 5, 
	"HOUSE_PLANS"		: 6,
	"ARCHITECTURE"		: 7, 
	"CONSTRUCTION"		: 8, 
	"LANDSCAPE"			: 9, 
	"CONTACT_POLICY"	: 10,
	"ABOUT_THE_FIRM"	: 11
	};

/*	FUNCTION:	findFirstChildElementNode
 *
 *	INPUT:		parent:	the div that contains the child nodes
 *
 *	OUTPUT:		the first non text-only child element of the parent
 *
 *	PURPOSE:	finds the first child element that is not a text node 
 *				(i.e. finds the first nested html element that isn't just text)
 */
function findFirstChildElementNode(parent) {
	var foundIndex = -1
	for (i in parent.childNodes) {
		if (parent.childNodes[i].nodeType == 1) {
			foundIndex = i
			break
		}
	}
	if (foundIndex != -1)
		return parent.childNodes[foundIndex]
	else
		return null
}

/*	FUNCTION:	navLinkMouseover
 *
 *	INPUT:		obj:	the div containing the navigation item
 *
 *	PURPOSE:	styles the left navigation div and top/bottom sub navigation div when mouse is moved over it
 */
function navLinkMouseover(obj) {
	obj.style.backgroundColor='White'
	var child = findFirstChildElementNode(obj)
	child.style.color = "#686AB0"
	child.style.textDecoration = "underline"
}

/*	FUNCTION:	navLinkMouseout
 *
 *	INPUT:		obj:	the div containing the navigation item
 *
 *	PURPOSE:	styles the left navigation div and top/bottom sub navigation div when the mouse is moved out of it
 */
function navLinkMouseout(obj) {
	obj.style.backgroundColor='#7E7E7E'
	var child = findFirstChildElementNode(obj)
	child.style.color = "white"
	child.style.textDecoration = "none"
}

/*	FUNCTION:	makeUnhighlightedHeading
 *
 *	INPUT:	  	href: 	web address that link goes to
 *				text: 	text to display for the category
 *
 *	OUTPUT:		the div that contains the category
 *
 *	PURPOSE: 	used for making a category div that is unhighlighted (user is not viewing content from that category)
 */
function makeUnhighlightedHeading(href, text) {
	return "<div style=\"overflow:hidden\" class='nav_link' onmouseover='navLinkMouseover(this)' onmouseout='navLinkMouseout(this)'>\
				<a class='nav_link' href=" + href + ">" + text + "</a>\
			</div>"
}

/*	FUNCTION:	makeHighlightedHeading
 *
 *	INPUT:		text:	text to display for the category
 *
 *	OUTPUT:		the div that contains the category
 *
 *	PURPOSE: 	used for making a category div that is highlighted (user is viewing content from that category)
 */
function makeHighlightedHeading(text) {
	return "<div style=\"overflow:hidden\" class='nav_link nav_link_sel'><span class='nav_link'>" + text + "</span></div>"
}

/*	FUNCTION:	loadTemplate
 *
 *	INPUT:		cat:	picked from the Cat variable above, gives information on the category to highlight
 *
 *	OUTPUT:		the template html
 *
 *	LOCALS:		vleft_div:				left div that contains logo, navigation, and ads
 *				vleft_div_img:			logo for left div
 *				vleft_div_nav:			navigation for left div
 *				vleft_div_ad:			ads for left div
 *				vheader_div:			header div that contains dropdown nav list, search site, etc.
 *				vcontent_div:			div for the content of the page
 *				vfooter_div:			footer div that contains 'rate our site', copyright info, etc.
 *				site_search_values:		array holding web addresses for the dropdown nav list
 *				site_search_text:		array holding the text that is shown in the dropdown nav list
 *				site_search_contents:	holds dropdown nav list and search site text field with google and houseplanz radio buttons
 *				nav_href:				array holding web addresses for the category navigation divs
 *				nav_text:				array holding text shown on each category navigation div
 *				nav_href_targets		array holding targets for nav links
 *				ad_link_targets:		array holding targets for left div ad links
 *				ad_link_refs:			array holding web addresses for left div ad links
 *				ad_headings:			array holding heading text for left div ad links
 *				ad_captions:			array holding body text for left div ad links
 *				vleft_div_ad_str:		div containing all left div ad links
 *
 *	PURPOSE:	creates the content for the template
 */
function loadTemplate(cat) {
	/* LOCALS */
	var vleft_div		= document.getElementById('left_div');
	var vleft_div_img	= document.getElementById('left_div_img');
	var vleft_div_nav	= document.getElementById('left_div_nav');
	var vleft_div_ad	= document.getElementById('left_div_ad');
	var vheader_div		= document.getElementById('header_div');
	var vcontent_div	= document.getElementById('content_div');
	var vfooter_div		= document.getElementById('footer_div');
var	site_search_values = new Array
	(
	"", 
	"site_search.html", 
	"associations.html",
	"mortgage.html", 
	"mortgage_calculators.html",
	"decor.html",	
	"free_stuff.html", 
	"sitemap.html"
	)
var site_search_text = new Array
	(
	" More Design-Build Resources", 
	" &nbsp; Search Site", 
	" &nbsp; Associations", 
	" &nbsp; Mortgage", 
	" &nbsp; Mortgage Calculators",
	" &nbsp; Decor, Furniture, More",	
	" &nbsp; Free Stuff", 
	" &nbsp; Site Map"
	)
var site_search_contents = ""
var nav_href = new Array
	(
	"index.html", 
	"free_cad_software.html", 
	"cad.html", 
	"http://houseplanz.tradepub.com/?pt=cat&page=Cons",
	"books_arch.html", 
	"article.html", 
	"topsites.html", 
	"architecture.html", 
	"cinformation.html", 
	"garden.html", 
	"contact.html", 
	"background.html"
	)
var nav_text = new Array
	(
	"Home Page", 
	"Free Software", 
	"Software Rack", 
	"Free Magazines", 
	"Bookstore",
	"Article Library", 
	"House Plans", 
	"Architecture", 
	"Construction", 
	"Landscape", 
	"Contact | Policy", 
	"About the Firm"
	)
var ad_link_targets = new Array
	(
	"_self",
	"_self",
	"_self",
	"_self",
	"_blank"
	)
var ad_link_refs = new Array
	(
	"free_cad_software.html", 
	"home_building_ebook.html",
	"mortgage_calculators.html", 
	"free_stuff.html", 
	"http://www.coolhouseplans.com/index.html?ordercode=C113&source=houseplanz"
	)
var ad_headings = new Array
	(
	"Free Software", 
	"Free House Plans",
	"Free Calculators", 
	"Free Stuff", 
	"Cool Houseplans"
	)
var ad_captions = new Array
	(
	"Quality full-version,<br /> CD-ROM software", 
	"Included with the<br /> homebuilding eBook.",
	"Calculate Loans<br /> and Mortgages.", 
	"Grab-bag of stuff<br /> absolutely FREE.", 
	""
	)
var vleft_div_ad_str = ""
	
	/* HEADER */
	/* <HOLD HEADER> vheader_div.innerHTML = "<h3>Your Source for Home Planning & Building Resources</h3>" */
	site_search_contents += "<select onchange='window.location=this.value' style='float:left; margin-left:0em; margin-top:0em; font-size:16px'>"
	for(i in site_search_values ) {
	//for (var i=0; i<site_search_values.length; i++) {
		site_search_contents += "<option value=\"http://www.houseplanz.com/" + site_search_values[i] + "\">" + site_search_text[i] + "</option>"
	}
	site_search_contents += "</select>"
	site_search_contents += '<div id="google_search" style="float:left; margin-left:50px">'
	site_search_contents += '	<form method="get" action="http://www.google.com/custom" target="_top">'
	site_search_contents += '		<input type="hidden" name="domains" value="houseplanz.com" />'
	site_search_contents += '		<input type="text" name="q" size="20" maxlength="255" value="" />'
	site_search_contents += '		<input type="submit" name="sa" value="Search" /><br />'
	site_search_contents += '		<div style="font-size:14px">'
	site_search_contents += '			<input type="radio" name="sitesearch" value="HouseplanZ.com" checked="checked" /><span>Houseplanz.com</span>'
	site_search_contents += '			<input style="margin-left:0.5em;" type="radio" name="sitesearch" value="Google.com" /><span>Google.com</span>'
	site_search_contents += '		</div>'
	site_search_contents += '		<input type="hidden" name="client" value="pub-4390297581622485" />'
	site_search_contents += '		<input type="hidden" name="forid" value="1" />'
	site_search_contents += '		<input type="hidden" name="ie" value="ISO-8859-1" />'
	site_search_contents += '		<input type="hidden" name="oe" value="ISO-8859-1" />'
	site_search_contents += '		<input type="hidden" name="cof" value="GALT:#008000;GL:1;DIV:#336699;VLC:663399;AH:center;BGC:F6EDDB;LBGC:336699;ALC:0000FF;LC: 0000FF;T:000000;GFNT:0000FF;GIMP:0000FF;LH:35;LW:100;L:http://www.houseplanz.com/files/logohz.gif;S:http://;LP:1;FORID:1;" />'
	site_search_contents += '		<input type="hidden" name="hl" value="en" />'
	site_search_contents += '	</form>'
	site_search_contents += '</div>'
	vheader_div.innerHTML += site_search_contents

	/* NAV */
	vleft_div_img.src = "logo1.gif";
	vleft_div_img.onclick = function() { window.location="index.html" };
	vleft_div_nav.innerHTML = ""
	for (var i=0; i<nav_href.length; i++) {
		if (i == cat)	vleft_div_nav.innerHTML += makeHighlightedHeading(nav_text[i])
		else			vleft_div_nav.innerHTML += makeUnhighlightedHeading(nav_href[i], nav_text[i])
	}
	for (var i=0; i<ad_headings.length; i++) {
		if (ad_captions[i] != "")
			vleft_div_ad_str += "<a target='" + ad_link_targets[i] + "' href='" + ad_link_refs[i] + "'>" + ad_headings[i] + "</a><br />" + ad_captions[i]
		else
			vleft_div_ad_str += "<a target='" + ad_link_targets[i] + "' href='" + ad_link_refs[i] + "'>" + ad_headings[i] + "</a>"
		vleft_div_ad_str += "<br /><br />"
	}
	vleft_div_ad.innerHTML = vleft_div_ad_str
	vleft_div_ad.style.overflow = "hidden"
	
	/* FOOTER */
	vfooter_div.innerHTML = ""
	bottom_link_style = "float:left; width:11em; height:1em; font-weight:bold; text-align:center; padding-top:0.2em;margin-left:0.3em"
	vfooter_div.innerHTML +="<img id=\"footer_gif\" style=\"border:0px; float:left\" src='files/house_home_3.gif'\
onclick=\"window.location='home_building_ebook.html'\" alt='Save Thousands When Building a New Home!'\
title='Save Thousands When Building a New Home!'/>"
	
	vfooter_div.innerHTML += "<div style=\"clear:both\"></div>"
	vfooter_div.innerHTML += "<span>Copyright © 1990 - 2011 ABGoodman HouseplanZ - All Rights Reserved</span>"
	vfooter_div.innerHTML += "<div style=\"clear:both\"></div><br />"
}


