//global js variables
var templateModalDiv;
var templateOverallDiv;
var templateBodyDiv;

//page events setup
onload   = initialize_page;
onunload = destroyTyndaleDOM;
onresize = initialize_page;

//function definitions
function initialize_page()
{
	//setup modal heights and widths
	templateModalDiv   = document.getElementById('template_modal');
	templateOverallDiv = document.getElementById('template_container');
	templateBodyDiv    = document.getElementById('template_body');
	
	//Set style adjustments
	templateModalDiv.style.width    = templateOverallDiv.offsetWidth+'px';
	templateModalDiv.style.height   = parseInt(templateOverallDiv.offsetHeight-140)+'px';
	templateModalDiv.style.position = 'absolute';
	templateModalDiv.style.left     = parseInt(((templateBodyDiv.offsetWidth-templateOverallDiv.offsetWidth)/2)+1)+'px';
	templateModalDiv.style.top      = '135px';
	
	//Other Function Calls
	
	//Set up global search ASW	
	positionalizedGlobalSearchASW();
	
	function positionalizedGlobalSearchASW () {
		var o=document.getElementById('searchHead_ASW_Container');
		var r=o.style;
		r.position='absolute';  /* for IE */
		r.left = ((document.body.clientWidth/2) + 172) + 'px'; 
		r.display = "block"; /* for IE */
	}
	
}


//these functions attempt to break any residual circular references in the DOM
// in order to fix garbage collection and prevent page to page memory leaks
function destroyTyndaleDOM()
{
	destroyDOM(document.getElementById('template_body'));
}

function destroyDOM(rootNode)
{
	if (rootNode.childNodes!=undefined)
	{
		if (rootNode.childNodes.length!=null && rootNode.childNodes.length!=undefined)
		{
			for (var i=0; i<rootNode.childNodes.length; i++)
			{
				destroyDOM(rootNode.childNodes[i]);
			}
		}
	}
	rootNode=null;
}
