// eu.css
// Containing javascript for Indiana Eugenics project
// public website.


// pageInit
// Desc.:	Put anything you want to run on page load
//			in here.
//
// In:		None
// Out:		Returns either true or false, based on the
//			successful execution of the methods to which
//			it reaches out.
function pageInit() {
	if (ie6Check() && doRandomBannerImage())
	{
		return true;
	}

	else { return false; }
}


// ie6Check
// Checks if we're running ie6, because that is a concern
// with this particular site.
function ie6Check () {
	if (BrowserDetect.browser == 'Explorer'
		&& Number(BrowserDetect.version) <= 6)
	{
		ie6MenuWorkaround();
	}
	
	return true;
}



// Class name given to elements which require
// a workaround in ie6 to achieve a background image
// change on rollover. Achieved with a :hover pseudo
// selector on other platforms.
var menuElementClass = "ie6ro";


// ie6MenuWorkaround
// Desc.:	Triggered in body onload only when platform is
//			verified as ie6. Looks for elements of type td
//			and the class specified above in menuElementClass,
//			and assigns mouseover and mouseout events to them
//			to replace the :hover selector, which is non-functional
//			in ie6.
//
// In:		None
// Out:		Returns true.
// Depends:	Depends on getElementsByClassName, defined in utility.js,
//			and on a correct value being present in menuElementClass and
//			on a correct class value having been set on the target elements.
function ie6MenuWorkaround() {

	//alert("working around ie6");

	var targetElements = getElementsByClassName(document, "td", menuElementClass);

	for (n in targetElements)
	{
		targetElements[n].onmouseover = function() { changeBackgroundImage(this, 'url(images/paperTexture_ACCENT.jpg)'); return false; }
		targetElements[n].onmouseout= function () { changeBackgroundImage(this, ''); return false; }
	}

	return true;
}


// changeBackgroundImage
// Desc.:	Changes a specified element's background-image
//			style definition to a specified value.
//
// In:		targetElement - element to have its background changed
//			newBgImage - new value for element's style.backgroundImage
// Out:		Returns true.
// Depends:	Depends on presence of style object.
function changeBackgroundImage(targetElement, newBgImage) {
	targetElement.style.backgroundImage = newBgImage;
	targetElement.style.backgroundPosition = 'right';
	return true;
}


// openBioWindow
// opens a bio popup
function openBioWindow (url) {
	var featureString = "toolbar=no, location=no, menubar=no, resizable=no, status=no, titlebar=no, toolbar=no, scrollbars=yes, width=460, height=600";
	window.open (url, "bio", featureString);
	return false;
}




// BANNER RANDOMIZING PIECE
//
// The IDs used for the banners in the actual pages
fullBannerId = "fullBanner";
slimBannerId = "slimBanner";


// doRandomBannerImage
// Desc.:	Selects a random index within the length range of the
//			banner image arrays declared above (slimBannerArray and
//			fullBannerArray, then writes the src, alt and title attributes
//			of either the full or slim banner, depending on which exists
//			on the target page.)
//
// In:		n/a
// Out:		Returns true.
// Depends:	Depends on presence of style object.
function doRandomBannerImage()
{
	if (document.getElementById(fullBannerId))
	{ targetBannerId = fullBannerId; targetBannerArray = fullBannerArray; }
	
	else if (document.getElementById(slimBannerId))
	{ targetBannerId = slimBannerId; targetBannerArray = slimBannerArray; }
	
	var targetElement = document.getElementById(targetBannerId);
	var randomImageIndex = Math.floor(Math.random() * (targetBannerArray.length));
	
	if (targetElement && (randomImageIndex < targetBannerArray.length))
	{
		var bannerSrc = targetBannerArray[randomImageIndex][0];
		var bannerAlt = targetBannerArray[randomImageIndex][1];
		var bannerTitle = targetBannerArray[randomImageIndex][1];
		
		targetElement.src = bannerSrc;
		targetElement.alt = bannerAlt;
		targetElement.title = bannerTitle;
	}
	
	//alert(bannerTagString);
	return true;
	
}