/* 
		File: Behavior file for Babygear Product Page
		Author:	Eric Shepherd
		Desc:	This file was added in April 2006 to handle the swapping of safety and product information
			on the Babygear product page. It is not intended to be reused or extended.
			
		Requires:	/pages/v4/script/dhtml_lib.js
							/pages/v4/script/ProductHelper.js
*/

EventHelper.AddEvent(window, 'load', init, false);

function init() {	
	var p = new ProductHelper();
	p.init();
}

// override the init function to eliminate the functionality we don't need

ProductHelper.displayed = ''; // will store which of the two content items is shown

ProductHelper.prototype.init = function()
//initialize event listeners and other housekeeping tasks
{
	
	// return if no dom support
	if (!SupportTest.hasDom) return; 

	var theContainer = document.getElementById('tabs');
	if (theContainer) {
		
		// get the individual boxes and links
		var theEls = theContainer.getElementsByTagName('li');
		var theLinks = theContainer.getElementsByTagName('a');
		theEl = theEls[0];
		
		// add event listener to swap larger images when thumbnails are clicked
		for (var i=0; i<theLinks.length; i++) {
			
			var thisReference = this; // required because scope will change from class to event
			EventHelper.AddEvent(theLinks[i], 'click', swapPtr = function(e) {thisReference.changeContent(this, thisReference, e); }, false);
			if (SupportTest.isSafari) theLinks[i].onclick = EventHelper.CancelClickSafari; //safari still doesn't support cancelDefault()
		}
		// call method to swap active and inactive thumbnails - we do this at init to remove link from first thumbnail
		this.activateElement(theEl, 'span', 'bgStorage');
		// hide safety information
		var safetyInfo = document.getElementById('product-safety');
		if (safetyInfo) safetyInfo.style.display = 'none';
		this.displayed = 'product';
	}
}

ProductHelper.prototype.changeContent = function(theLink, theClass, theEvent)
// swap the description and safety information content
{
	var desc = document.getElementById('product-description');
	var safe = document.getElementById('product-safety');
	var liDesc = document.getElementById('li-description');
	var liSafe = document.getElementById('li-safety');
	
	if (this.displayed == 'product') {
		desc.style.display = 'none';
		safe.style.display = 'block';
		this.deactivateElement(liDesc, 'span', 'bgStorage');
		this.activateElement(liSafe, 'span', 'bgStorage');
		this.displayed = 'safety';
	} else {
		safe.style.display = 'none';
		desc.style.display = 'block';
		this.deactivateElement(liSafe, 'span', 'bgStorage');
		this.activateElement(liDesc, 'span', 'bgStorage');
		this.displayed = 'product';
	}
}
