/*
	File:	Behaviors for Preschool Electronics
	Author:	Eric Shepherd
	Date:	July 2006
	Site:	Preschool Electronics
*/


EventHelper.AddEvent(window, 'load', pestart, false);

// instantiate ProductHelper
var p = new ProductHelper();

function pestart() {
	p.init();
	p.swapInit();
	p.awardInit();
}

ProductHelper.prototype.awardInit = function() {
	var awards = DomHelper.GetElementsByClassName("award", "dd");
	if (awards) var award = awards[0];
	if (award) {
		var theLink = award.getElementsByTagName('a')[0];
		var thisRef = this;
		EventHelper.AddEvent(theLink, 'click', ptr = function(e) {DomHelper.NewWin(this, e, 'popup', this.href, 'award', 364, 180); }, false);
	}
}

ProductHelper.prototype.swapInit = function() 
// attaches the event to run the function which styles the active Browse All link
{
	if (DomHelper.GetElementsByClassName) {
		var theBrowseLinks = DomHelper.GetElementsByClassName('browse-link');
		for (i=0; i<theBrowseLinks.length; i++) {
			EventHelper.AddEvent(theBrowseLinks[i], 'click', this.swapActive, false);
		}
	}
}

ProductHelper.prototype.swapActive = function(e)
// this switches the active Browse All link so it appears highlighted when selected
{
	var browseLinks = DomHelper.GetElementsByClassName('browse-link');
	for (i=0; i<browseLinks.length; i++) { // first we kill all the on classes on all the links
		browseLinks[i].className = browseLinks[i].className.replace(' on', '');
	}
	this.className += ' on'; // then we add the class only for the selected link
}
