/**JAVASCTIPT METHODS AND PROPERTIES FOR NEW SALES PAGES
***ORIGINALLY CREATED JUNE 16, 2008***
***2 Methods: (1)Hover box for Ebook explanation***
***           (2)Image 3 State Rollovers
***
*** Updated July 2, 2008 to make triggered box on click and clicked closed button
***/


var SalesStuff =
{
	init: function ()
	{
		SalesStuff.showHiddenContent();
		SalesStuff.image3States();
	},
	
	showHiddenContent: function()
	{
		if ($$(".hiddenContentTrigger"))
		{
			var triggersArray = $$(".hiddenContentTrigger"); //get all triggers by class name
			for (var i = 0; i < triggersArray.length; i++)
			{
				triggersArray[i]._hiddenContenID = triggersArray[i].id + 2; //set trigger's corresponding hidden content ID to property of trigger
				//sets up show and hide content event listeners
				Event.observe(triggersArray[i], 'click', function(e){ 
					clearTimeout(this._timer);//timer prevents stuttering
					$(this._hiddenContenID).appear();
					Event.stop(e); //stop default action
				}, false);
				
				triggersArray[i]._closeDiv = $(triggersArray[i]._hiddenContenID).select('div.close')[0]; //get the div.close element related to each trigger
				
				Event.observe(triggersArray[i]._closeDiv, 'click', function(e){
					var theDiv = this.ancestors()[0]; //get the hidden content div
					theDiv._timer = setTimeout(function()
					{
						theDiv.fade(); //make hidden content div fade
					}, 10);
					Event.stop(e); //stop default action
				}, false);
			}
		}
	},
	
	image3States: function()
	{
		if (document.images)
		{
			//list of all images SRCs to be preloaded
			var onImageSrc = [
				"images/kw/buttonON.jpg",
				"images/kw/buttonClick.jpg"
			];
			//preload images
			var preloadedImages = new Array(); //initialize array for preloaded images
			for (var j = 0; j < onImageSrc.length; j++) //run throught all ON sources, creating image for each
			{
				preloadedImages[j] = document.createElement('img');
				preloadedImages[j].setAttribute('src',onImageSrc[j]);
			};
			
			//switch images SRC for Off, ON, Click
			var offImageArray = $$("img.threeState");
			for (var i = 0; i < offImageArray.length; i++)
			{
				Event.observe(offImageArray[i], 'mouseover', function(e){
					if ((this.src.indexOf("ON") == -1)) //as long as it's not already ON
						this.src = this.src.replace("Off", "ON");
				});
				Event.observe(offImageArray[i], 'mouseout', function(e){
					if ((this.src.indexOf("Off") == -1)) //as long as it's not already Off
						this.src = this.src.replace("ON", "Off");
				});
				Event.observe(offImageArray[i], 'mousedown', function(e){
					if ((this.src.indexOf("Click") == -1)) //as long as it's not already Click
						this.src = this.src.replace("ON", "Click");
				});
				Event.observe(offImageArray[i], 'mouseup', function(e){
					if ((this.src.indexOf("ON") == -1)) //as long as it's not already ON
						this.src = this.src.replace("Click", "ON");
				});
			}
		}
	}
};

Event.observe(window, 'load', SalesStuff.init);