function init()
{
	// Create Flash object
	var mainGraphic = document.getElementById("maingraphic");
	var flashContent = document.getElementById("flashcontent");
	if (mainGraphic && flashContent)
	{
		mainGraphic.style.display = "none";
		var randomnumber = Math.floor(Math.random()*5) + 1;
		var so = new SWFObject("flash/cashome" + randomnumber + ".swf", "thinkAgain", "585", "265", "8", "#FFFFFF");
		so.write("flashcontent");
	}
	
	// Set up Multi level navigation
	setNav();

	// Show County Dropdown	
	setCountyDropdown()

	
	// Resize columns to fit
	resizeColumns();
	

	// Set External Links
	setExternalLinks()
}

function initTextResizeDetector()  {
   var iBase = TextResizeDetector.addEventListener(resizeColumns,null);
}

//id of element to check for and insert control
TextResizeDetector.TARGET_ELEMENT_ID = 'inner';

//function to call once TextResizeDetector has init'd
TextResizeDetector.USER_INIT_FUNC = initTextResizeDetector;

function resizeColumns()
{
	// Magic Number: Total vertical (top + bottom) padding of leftnav
	// If we change the CSS, we have to change it here, too
	var theLeftNavPadding = 142;

	var theLeft = document.getElementById("leftcontent");
	var theLeftNav = document.getElementById("leftnav");
	var theRight = document.getElementById("rightcontent");
	var theContact = document.getElementById("contact");
	var theAdminLinks = document.getElementById("adminlinks");
	var theGraphic = document.getElementById("imgcontent");
	var therightitems = document.getElementById("rightitems");
	var theArticle = document.getElementById("articles");

	if (! theGraphic)
	{
		theGraphic = document.createElement("div");
	}

	if (! theAdminLinks)
	{
		theAdminLinks = document.createElement("div");
	}

	// Setting the heights for all pages
	if (theLeft && theRight && theLeftNav && theContact)
	{
		if (theLeft.offsetHeight && theRight.offsetHeight && 
			theLeftNav.offsetHeight && theContact.offsetHeight)
		{
			// Initialize all heights to "auto" to deal with font size changes
			theLeft.style.height = "auto";
			theRight.style.height = "auto";
			theLeftNav.style.height = "auto";

			if (theArticle)
			{
				theArticle.style.height = "auto";	
			}
		
			// Calculate max height of leftcontent and rightcontent
			var maxHeight=Math.max(theLeft.offsetHeight,theRight.offsetHeight);
						
			// Set both heights to the same (max) value
			theLeft.style.height = maxHeight + "px";
			theRight.style.height = maxHeight + "px";

			// Set the leftnav height to the leftcontent, minus the contact, minus the padding
			theLeftNav.style.height = (theLeft.offsetHeight - theContact.offsetHeight - theLeftNavPadding) + "px";

			// Setting the height for the additional elements on the front page					

			if (theAdminLinks && theGraphic && therightitems)
			{
				if (theAdminLinks.offsetHeight || theGraphic.offsetHeight || 
					therightitems.offsetHeight)
				{
					// Initialize all heights to "auto" to deal with font size changes
					therightitems.style.height = "auto";
			
					// Total height of all elements inside 
					var totalHeight = theAdminLinks.offsetHeight + theGraphic.offsetHeight + therightitems.offsetHeight;

					// Here's a fudge factor to get the gray "rightitems" div to the right height.  Sorry.
					var rightFudgeFactor = 7;
					
					if (theAdminLinks.offsetHeight == 0)
					{
						rightFudgeFactor++;
					}

					if (theGraphic.offsetHeight == 0)
					{
						rightFudgeFactor++;
					}

					
					// If it's IE, make it a -2.
					if (document.all)
					{
						rightFudgeFactor = 0;
					}
					
					// Calculate height difference
					var theHeightDiff = maxHeight - totalHeight - rightFudgeFactor;							
					
					// If it's greater than zero, set a new height.
					if (theHeightDiff > 0)
					{
						var newHeight = therightitems.offsetHeight + theHeightDiff;
						therightitems.style.height = newHeight + "px";
					}

				}
			}
		
		}
		else if (theLeft.pixelHeight && theRight.pixelHeight && 
			theLeftNav.pixelHeight && theContact.pixelHeight)
		{
			// Initialize all heights to "auto" to deal with font size changes
			theLeft.style.height = "auto";
			theRight.style.height = "auto";
			theLeftNav.style.height = "auto";	
			
			// Calculate max height of leftcontent and rightcontent
			var maxHeight=Math.max(theLeft.pixelHeight,theRight.pixelHeight);
						
			// Set both heights to the same (max) value
			theLeft.style.height = maxHeight + "px";
			theRight.style.height = maxHeight + "px";
			
			// Set the leftnav height to the leftcontent, minus the contact, minus the padding
			theLeftNav.style.height = (theLeft.pixelHeight - theContact.pixelHeight - theLeftNavPadding) + "px";

			// Setting the height for the additional elements on the front page					

			if (theAdminLinks && theGraphic && therightitems)
			{
				if (theAdminLinks.pixelHeight || theGraphic.pixelHeight || 
					therightitems.pixelHeight)
				{
					// Initialize all heights to "auto" to deal with font size changes
					therightitems.style.height = "auto";
					
					// Total height of all elements inside 
					var totalHeight = theAdminLinks.pixelHeight + theGraphic.pixelHeight + therightitems.pixelHeight;

					// Here's a fudge factor to get the gray "rightitems" div to the right height.  Sorry.
					var rightFudgeFactor = 4;

					if (theAdminLinks.offsetHeight == 0)
					{
						rightFudgeFactor++;
					}

					if (theGraphic.offsetHeight == 0)
					{
						rightFudgeFactor++;
					}
										
					// If it's IE, make it a -2.
					if (document.all)
					{
						rightFudgeFactor = -2;
					}
					
					// Calculate height difference
					var theHeightDiff = maxHeight - totalHeight - rightFudgeFactor;							
					
					// If it's greater than zero, set a new height.
					if (theHeightDiff > 0)
					{
						var newHeight = therightitems.pixelHeight + theHeightDiff;
						therightitems.style.height = newHeight + "px";
					}

				}
			}
		
		}
		
	}
	
	// Focus and blur on search box
	theSearch = document.getElementById("searchbox");

	if(theSearch)
	{
		theSearch.onfocus = function () {
			this.value = "";
		}
		
		theSearch.onblur = function () {
			if (this.value == "auto")
			{
				this.value = "Search College";
			}
		}
	}

}


function setCountyDropdown()
{
	var theDiv = document.getElementById("countylistdiv");
	var theDropDown = document.getElementById("countylist");
	var theButton = document.getElementById("gotocounty");	

	if (theDiv && theDropDown && theButton)
	{
		theButton.myList = theDropDown;
		
		theButton.onclick = function() {
			theURL = this.myList.options[this.myList.selectedIndex].value;
			if (theURL)
			{
				document.location.href = theURL;
			}
		}
		
		theDiv.style.display = "block";
	}

}

function setExternalLinks()
{
	links = document.getElementsByTagName("a");
	for (i=0; i<links.length; i++)
	{
		if (links[i].href.match(/^https*:\/\//) && !links[i].href.match(/psu\.edu/))
		{
			links[i].target = "_blank";
		}
	}
}
