﻿/*
	File:	Baby Gear Behaviors
	Site:	Baby Gear
	Author:	Eric Shepherd
	Date:	June 2007
*/

var fp_section_babygear = {
	
	init : function() {
		fp_section_babygear.instructionBox();
		
		//RM 12/01/07: This init method is commented out from FP's request that the catalog not show up in a  MOOdalBox.
		
		//fp_section_babygear.catalog();
	},
	
	instructionBox : function() {
		if (typeof $ != 'undefined') {
			
			var theInstructionToggle = $('instruction-intro');
			
			if (theInstructionToggle) {
				var toggle = false;
				var el = $('instructions').getElementsByTagName('dl')[0];
				$(el).setStyle('overflow', 'hidden');
				var elHeight = el.scrollHeight;
				var instructionFx = new Fx.Style(el, 'height', { duration : 400 });
				instructionFx.start(0);
				
				$(theInstructionToggle).addEvent('click', function(e) {
					if (toggle == false) {
						instructionFx.start(0, elHeight);
						toggle = true;
					} else {
						instructionFx.start(elHeight, 0);
						toggle = false;
					}
				});
			}
		}
	},
	
	catalog : function() {
		if (typeof $ != 'undefined') {
			
			var theCatalog = $('nav-catalog');
			
			if (theCatalog) {
				var theLink = theCatalog.getElementsByTagName('a')[0];
				$(theLink).addEvent('click', function(e) {
					new Event(e).stop();
					MOOdalBox.open(this.href, '', '750px 424px');	
				});
			}
			
		}
	}
	
};



//---------------------------------------------------
//           redefine renderProductShot function
//---------------------------------------------------
			if (typeof ProductHelper != 'undefined') {
				
				ProductHelper.prototype.renderProductShot = function(href, el)
				{
					var theImage = document.createElement('img');
					var tmp = new Date();
					var suffix = tmp.getTime();
					theImage.src = href +'?' + suffix;
					var theChildren = el.childNodes;
					try {
						var c = el.removeChild(theChildren[0]);
					} catch (e) {
					}
					imageAppended = false;
							// fallback for ie, which borks the load event sometimes
							// warning - ie only does this because of a scope error, which is why it's conditionally set
					if (SupportTest.isIE) {
						var imageLoaded = setInterval(appendImage, 1000);
					
						function appendImage() {
							if (imageAppended == false) {
								el.appendChild(theImage);
								imageAppended = true;
								clearInterval(imageLoaded);
							}
						}
					}
							// onload event for image to show - for all nice browsers and ie some of the time
					theImage.onload = function() {
						if (imageAppended == false) {
							theImage.style.visibility = 'hidden';
							el.appendChild(theImage);
							$(theImage).effect('opacity').custom(0,1);
							imageAppended = true;
									// clear the interval just in case ie had to use it, but it only exists for ie
							if (SupportTest.isIE) {
								clearInterval(imageLoaded);
							}
						}
					}
				}
			}
				
//---------------------------------------------------
//           end redefine renderProductShot 
//---------------------------------------------------


EventHelper.AddEvent(window, 'load', fp_section_babygear.init, false);

