
//CORE SCRIPTS FOR ATD3 DESIGN

var ATD3Core = 
{
	init: function() //call and initializes all functions for ATD3 design
	{
		preloadRollovers.init();
		ATD3Core.hoverSwitch();
		NavMap.init();
		LightBox.init();
		ScrollBar.init();
		TabbedNavigation.init();
		ArticlePreview.init();
		ListItemArticleBrowser.init();
		BackToBrowser.init();
		HoverBox.init();
	},
	
	hoverSwitch: function() //switches the src of all images with class 'hoverSwitch' from off to ON and back again
	{
		if (document.getElementsByClassName('hoverSwitch'))
		{
			var imageToSwitch = document.getElementsByClassName('hoverSwitch'); //sets up event listeners on all elements with 'hoverSwitch' class
			for (var i = 0; i < imageToSwitch.length; i++)
			{
				Event.observe(imageToSwitch[i], "mouseover", ATD3Core.swapImageOn.bindAsEventListener(imageToSwitch[i]));
				Event.observe(imageToSwitch[i], "mouseout", ATD3Core.swapImageOff.bindAsEventListener(imageToSwitch[i]));
				//Event.observe(imageToSwitch[i], "click", ATD3Core.swapImageOff.bindAsEventListener(imageToSwitch[i]));
			}
		}
	},
	
	swapImageOn: function() //replaces ...off... for ...ON...
	{
		var sourceString = this.src;
		var newSource = sourceString.replace("Off", "ON");
		this.src = newSource;
	}, 
	
	swapImageOff: function() //replaces ...ON... with ...Off...
	{
		var sourceString = this.src;
		var newSource = sourceString.replace("ON", "Off");
		this.src = newSource;
	}
};

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



//PRELOAD IMAGES FOR ROLLOVERS
var preloadRollovers =
{
	init: function()
	{
		if (document.images)
		{
			var imageList = new Array();
			var offImageSrc = new Array();
			var onImageSrc = [ //manually entered images because hover switch work around for transarent .png files
				"/artman2/images/images3/MatchesON150x84.png",
				"/artman2/images/images3/AskMeghanON227x147.png",
				"/artman2/images/images3/SortByDateON131x34.png",
				"/artman2/images/images3/SortByMaterialON131x34.png",
				"/artman2/images/images3/SortByRoomON131x52.png",
				"/artman2/images/images3/SortBySeasonON131x34.png",
				"/artman2/images/images3/SortByStyleON131x34.png",
				"/artman2/images/images3/BackStickyON77x196.png"
			];
			var offStateImageElements = $$('img.hoverSwitch'); //get off-state image objects, i want to load ON states
			
			for (var i = 0; i < offStateImageElements.length; i++)
			{
				offImageSrc[offImageSrc.length] = offStateImageElements[i].src; //make array of off image sources
				onImageSrc[onImageSrc.length] = offImageSrc[i].replace("Off", "ON"); //make array of ON image sources by replacing 'Off' with 'ON'
			}
			
			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]);
				//imageList[imageList.length] = preloadedImages[j];
			}
			//alert(imageList);	
		}
	}
};





//START search button hove script
// copyright 1999-2001 Idocs, Inc. http://www.idocs.com/tags/
// Distribute this script freely, but keep this 
// notice with the code.
var submitRolls = new Object();

function submitroll(src, oversrc, name)
{
this.src=src;
this.oversrc=oversrc;
this.name=name;
this.alt="Search";
this.write=submitroll_write;
}

function submitroll_write()
{
var thisform = 'document.forms[' + (document.forms.length - 1) + ']';
submitRolls[this.name] = new Object();
submitRolls[this.name].over = new Image();
submitRolls[this.name].over.src = this.oversrc;
submitRolls[this.name].out = new Image();
submitRolls[this.name].out.src = this.src;

document.write
	(
	'<A onMouseOver="if (document.images)document.images[\'' + this.name + "'].src=submitRolls['" + this.name + '\'].over.src"' + 
	' onMouseOut="if (document.images)document.images[\'' + this.name + "'].src=submitRolls['" + this.name + '\'].out.src"' + 
	' HREF="javascript:'
	);

if (this.sendfield)
	{
	if (! this.sendvalue)
		this.sendvalue = 1;
	document.write(thisform, ".elements['", this.sendfield, "'].value='", this.sendvalue, "';");
	}

document.write(thisform + '.submit();void(0);"');
if (this.msg)document.write(' onClick="return confirm(\'' , this.msg, '\')"');
document.write('>');

document.write('<IMG SRC="' + this.src + '" ALT="' + this.alt + '" BORDER=0 NAME="' + this.name + '"');
if (this.height)document.write(' HEIGHT=' + this.height);
if (this.width)document.write(' WIDTH='  + this.width);
if (this.otheratts)document.write(' ' + this.otheratts);
document.write('></A>');
if (this.sendfield)
	{
	document.write('<INPUT TYPE=HIDDEN NAME="' + this.sendfield + '">');
	document.forms[document.forms.length - 1].elements[this.sendfield].value='';
	}
}
//End search button hover script






//START NAVIGATION MAP SCRIPT
/*
Based on an excerpt from "Pragmatic Ajax" ****** GoogleMaps - step 4*******
Visit http://www.pragmaticprogrammer.com/titles/ajax for more book information.
*/


var NavMap = 
{
	dragging: false,
	topper: "",
	left: "",
	dragStartTop: "",
	dragStartLeft: "",	
		
	init: function()
	{
		if($('outerMap'))
		{
			// make inner div big enough to display the map
			NavMap.setInnerDivSize('751px', '551px');
	
			// set initial position of map from top and left
			NavMap.setInitPos();
	
			// wire up the mouse listeners to do dragging
			var outerDiv = $("outerMap");
			outerDiv.onmousedown = 	NavMap.startMove;
			document.onmousemove = NavMap.processMove;
			document.onmouseup = NavMap.stopMove;
	
			// necessary to enable dragging on IE
			outerDiv.ondragstart = function() { return false; }
		}
	},
	
	startMove: function(event) 
	{
		// necessary for IE
		if (!event) event = window.event;

		NavMap.dragStartLeft = event.clientX;
		NavMap.dragStartTop = event.clientY;
		var innerDiv = $("innerMap");
		innerDiv.style.cursor = "-moz-grab";

		NavMap.topper = NavMap.stripPx(innerDiv.style.top);
		NavMap.left = NavMap.stripPx(innerDiv.style.left);
		NavMap.dragging = true;
		return false;
	},

	processMove: function(event) 
	{
		if (!event) event = window.event;  // for IE
		var innerDiv = $("innerMap");
		var outerDiv = $("outerMap");
		if (NavMap.dragging) {
			innerDiv.style.top =  NavMap.topper + (event.clientY - NavMap.dragStartTop) + "px";
			innerDiv.style.left = NavMap.left + (event.clientX - NavMap.dragStartLeft) + "px";
		}
	},

	stopMove: function() 
	{
		var innerDiv = $("innerMap");
		innerDiv.style.cursor = "";
		NavMap.dragging = false;
	},

   stripPx: function(value) 
   {
		if (value == "") return 0;
		return parseFloat(value.substring(0, value.length - 2));
	},
	
	// END:dragstuff
	setInnerDivSize: function(width, height) 
	{
		var innerDiv = $("innerMap");
		innerDiv.style.width = width;
		innerDiv.style.height = height;
	},
	
	setInitPos: function()
	{	
		//retrieve position data from div's title and assign it to top and left values
		var innerDiv = $("innerMap");
		var innerDivTitle = innerDiv.title;
		var endTopLength = innerDiv.title.indexOf('l');
		var fromTop = innerDivTitle.substring(3, endTopLength);
		var fromLeft = innerDivTitle.substring(endTopLength + 4, innerDiv.title.length);
		innerDiv.style.top = fromTop + "px";
		innerDiv.style.left = fromLeft +"px";
		innerDiv.title = "Ask the Decorator Site Map";
	}
	
};






//START CATEGORY PREVIEW SCRIPT - updated March 2008 adding first item auto highlight and stick highlight
var ArticlePreview = 
{
	timer: "",
	firstListItem: "",
	listArray: "",
	listItemArrayLength: "",

	init: function()
	{
		if ($("articleList"))
		{
			var listElement = $("articleList"); //get ul element of article list
			var listElementChildren = listElement.childNodes; //get all ul children
			var listElementChildrenLength = listElementChildren.length; //get the array of children's length
			var listItemArray = [];
			ArticlePreview.listItemArrayLength = listItemArray.length;
			
			for (var i = 0; i < listElementChildrenLength; i++) //sort out to only find the li children, assign them to array and add event listener
				{
					if(listElementChildren[i].nodeType == 1)
						{
							listItemArray[ArticlePreview.listItemArrayLength] = listElementChildren[i];
							Event.observe(listItemArray[ArticlePreview.listItemArrayLength], 'mouseover', ArticlePreview.preview.bindAsEventListener(listItemArray[ArticlePreview.listItemArrayLength]));
							//Event.observe(listItemArray[ArticlePreview.listItemArrayLength], 'mouseout', ArticlePreview.hide.bindAsEventListener(listItemArray[ArticlePreview.listItemArrayLength]));
							Event.observe(listItemArray[ArticlePreview.listItemArrayLength], 'click', ArticlePreview.goTo.bindAsEventListener(listItemArray[ArticlePreview.listItemArrayLength]));
							ArticlePreview.listItemArrayLength++;
						}	
				}
			//select and display first item listed
			listItemArray[0].addClassName('color');
			$(listItemArray[0].id +"B").style.visibility = "visible";
			//ArticlePreview.firstListItem = listItemArray[0];
			ArticlePreview.listArray = listItemArray;
		}	
	},
	
	preview: function() //show preview, receives li element from listener
	{	
		var listArrayLength = ArticlePreview.listArray.length;
		for(var j = 0; j < listArrayLength; j++)
		{
			if(ArticlePreview.listArray[j].hasClassName('color'))//checks and then removes any preview item
			{
				ArticlePreview.listArray[j].removeClassName('color');
				$(ArticlePreview.listArray[j].id + "B").style.visibility = "hidden";
			}
		}
		
		//clearTimeout(this._timer);
		
		this.addClassName('color'); //add 'color' class so IE6 has background color
		listItemId = this.id;
		var previewDiv = $(listItemId + "B");
		previewDiv.style.visibility = "visible";
	},
	
	/*
	hide: function() //hide preview, receives li element from listener
	{
		var theItem = this;
		
		this._timer = setTimeout(function()
		{
			theItem.removeClassName('color'); //remove 'color' class so IE6 has no background color
			listItemId = theItem.id;
			var previewDiv = $(listItemId + "B");
			previewDiv.style.visibility = "hidden";
		}, 10);
	
	},
	*/	
	
	goTo: function()
	{
		var theLink = this.getElementsByClassName('goTo');
		window.location = theLink;
	}
	
};


//By Date Video Browser Script
var ListItemArticleBrowser =
{
	init: function()
	{
		if ($('videoBrowserContainer'))
		{
			var articleListItemsArray = $('videoBrowserContainer').select('li');
			var theArrayLength = articleListItemsArray.length;
			for(var i = 0; i < theArrayLength; i++)
			{
				Event.observe(articleListItemsArray[i], 'mouseover', function(e){
					clearTimeout(this._timer);//timer prevents IE background color stuttering
					this.addClassName('hover');
				});
				Event.observe(articleListItemsArray[i], 'mouseout', function(e){
					var theItem = this;
					this._timer = setTimeout(function()
					{
						theItem.removeClassName('hover'); 
					}, 10);
				});
				articleListItemsArray[i]._url = articleListItemsArray[i].getAttribute('title');
				articleListItemsArray[i].removeAttribute('title');
				Event.observe(articleListItemsArray[i], 'click', function(e){
					if(this._url)
					{
						window.location = this._url;
					}
				});
			}
		}
		else if ($('relatedVideosContent'))
		{
			var articleListItemsArray = $('relatedVideosContent').select('li');
			var theArrayLength = articleListItemsArray.length;
			for(var i = 0; i < theArrayLength; i++)
			{
				Event.observe(articleListItemsArray[i], 'mouseover', function(e){
					clearTimeout(this._timer);//timer prevents IE background color stuttering
					this.addClassName('hover');
				});
				Event.observe(articleListItemsArray[i], 'mouseout', function(e){
					var theItem = this;
					this._timer = setTimeout(function()
					{
						theItem.removeClassName('hover'); 
					}, 10);
				});
				articleListItemsArray[i]._url = articleListItemsArray[i].getAttribute('title');
				articleListItemsArray[i].removeAttribute('title');
				Event.observe(articleListItemsArray[i], 'click', function(e){
					if(this._url)
					{
						window.location = this._url;
					}
				});
			}
		}
	}
};





//myLightBox 10-14-07

var LightBox = 
{
	counter: 0,
	
	init: function()
	{
		if (document.getElementsByClassName('lightBox'))
		{
			var lightBoxLinkElements = document.getElementsByClassName('lightBox');  //sets click listender to all links of class .lightBox
			for (var i = 0; i < lightBoxLinkElements.length; i++)
			{
				Event.observe(lightBoxLinkElements[i], 'click', LightBox.animate.bindAsEventListener(lightBoxLinkElements[i]));
			}
		}
	},
	
	animate: function(e)
	{
		var linkId = $w(this.className)[0];  //get first class name of the link clicked, ex: someText, by get string of names, split into array by whitespace, take the first one
		var textId = linkId + 1;  // id of text that matches link, ex: someText1
		var textElement = $(textId);  //get div element by id that matches link, contains the hidden text
		
		var innerContent = textElement.innerHTML;  //get html inside the hidden text, dom node work is too hard
		var displayBox = $("box");  //get lightbox display div
		displayBox.innerHTML = innerContent;  //put html content from hidden div into lightbox div
		
		new Effect.Appear('screen', {duration:0.5, from:0.0, to:0.7});
		
		new Effect.Appear('box', {duration:0.5, from:0.0, to:1.0});
		
		ATD3Core.hoverSwitch(); //re-call image switcher to make work on hover boxes images
		var clickCloseDiv = $('box').select('div.clickClose')[0]; //get div.clickClose
		Event.observe(clickCloseDiv, 'click', LightBox.close.bindAsEventListener(LightBox));
		
		//preventing the default action of the click
		//Event.stop(e);
	},
	
	close: function(e)
	{
		new Effect.Fade('screen', {duration:0.5, from:0.7, to:0.0});
		new Effect.Fade('box', {duration:0.5, from:1.0, to:0.0});
	}
	
};


//SCROLL BAR SCRIPT
var ScrollBar = 
{
	articleSlider: "",
	blogSlider: "",
	searchResultsSlider: "",
	aboutSlider: "",
	relatedVideosSlider: "",
	
	init: function()
	{
		if($('handle'))
		{
			// vertical slider control
			var slider = new Control.Slider('handle', 'track', {
				axis: 'vertical',
				onSlide: function(v) { ScrollBar.scrollVertical(v, $('articleListContainer'), slider);  },
				onChange: function(v) { ScrollBar.jumpVertical(v, $('articleListContainer'), slider); }
			});
			
			Event.observe('scrollBarDown', 'click', ScrollBar.clickDownValue.bindAsEventListener(slider));
			Event.observe('scrollBarUp', 'click', ScrollBar.clickUpValue.bindAsEventListener(slider));
	
			// disable vertical scrolling if text doesn't overflow the div
			if ($('articleListContainer').scrollHeight <= $('articleListContainer').offsetHeight) {
				slider.setDisabled();
				$('sliderArea').hide();
			}
		}
		else if($('artHandle'))
		{
			// vertical slider control
			ScrollBar.articleSlider = new Control.Slider('artHandle', 'artTrack', {
				axis: 'vertical',
				onSlide: function(v) { ScrollBar.scrollVertical(v, $('articleText'), ScrollBar.articleSlider);  },
				onChange: function(v) { ScrollBar.jumpVertical(v, $('articleText'), ScrollBar.articleSlider); }
			});
			
			MouseWheel.init(ScrollBar.articleSlider); //send slider element to MouseWheel object
					
			// disable vertical scrolling if text doesn't overflow the div
			if ($('articleText').scrollHeight <= $('articleText').offsetHeight) {
				ScrollBar.articleSlider.setDisabled();
				$('articleSliderContainer').hide();
			}
		}
		else if($('videoHandle'))
		{
			// vertical slider control
			ScrollBar.videoSlider = new Control.Slider('videoHandle', 'videoTrack', {
				axis: 'vertical',
				onSlide: function(v) { ScrollBar.scrollVertical(v, $('videoDescription'), ScrollBar.videoSlider);  },
				onChange: function(v) { ScrollBar.jumpVertical(v, $('videoDescription'), ScrollBar.videoSlider); }
			});
			
			MouseWheel.init(ScrollBar.videoSlider); //send slider element to MouseWheel object
					
			// disable vertical scrolling if text doesn't overflow the div
			if ($('videoDescription').scrollHeight <= $('videoDescription').offsetHeight) {
				ScrollBar.videoSlider.setDisabled();
				$('videoSliderContainer').hide();
			}
		}	
		else if($('searchResultsHandle'))
		{
			// vertical slider control
			ScrollBar.searchResultsSlider = new Control.Slider('searchResultsHandle', 'searchResultsTrack', {
				axis: 'vertical',
				onSlide: function(v) { ScrollBar.scrollVertical(v, $('searchResultsText'), ScrollBar.searchResultsSlider); },
				onChange: function(v) { ScrollBar.jumpVertical(v, $('searchResultsText'), ScrollBar.searchResultsSlider); }
			});
			
			MouseWheel.init(ScrollBar.searchResultsSlider); //send slider element to MouseWheel object

					
			// disable vertical scrolling if text doesn't overflow the div
			if ($('searchResultsText').scrollHeight <= $('searchResultsText').offsetHeight) {
				ScrollBar.searchResultsSlider.setDisabled();
				$('searchResultsSliderContainer').hide();
			}	
		}
		else if($('aboutHandle'))
		{
			// vertical slider control
			ScrollBar.aboutSlider = new Control.Slider('aboutHandle', 'aboutTrack', {
				axis: 'vertical',
				onSlide: function(v) { ScrollBar.scrollVertical(v, $('aboutText'), ScrollBar.aboutSlider); },
				onChange: function(v) { ScrollBar.jumpVertical(v, $('aboutText'), ScrollBar.aboutSlider); }
			});
			
			MouseWheel.init(ScrollBar.aboutSlider); //send slider element to MouseWheel object

					
			// disable vertical scrolling if text doesn't overflow the div
			if ($('aboutText').scrollHeight <= $('aboutText').offsetHeight) {
				ScrollBar.aboutSlider.setDisabled();
				$('aboutSliderContainer').hide();
			}	
		}
		else if($('videoBrowserHandle'))
		{
			// vertical slider control
			ScrollBar.videoBrowserSlider = new Control.Slider('videoBrowserHandle', 'videoBrowserTrack', {
				axis: 'vertical',
				onSlide: function(v) { ScrollBar.scrollVertical(v, $('videoBrowserContainer'), ScrollBar.videoBrowserSlider); },
				onChange: function(v) { ScrollBar.jumpVertical(v, $('videoBrowserContainer'), ScrollBar.videoBrowserSlider); }
			});
			
			MouseWheel.init(ScrollBar.videoBrowserSlider); //send slider element to MouseWheel object

			// disable vertical scrolling if text doesn't overflow the div
			if ($('videoBrowserContainer').scrollHeight <= $('videoBrowserContainer').offsetHeight) {
				ScrollBar.videoBrowserSlider.setDisabled();
				$('videoBrowserSliderArea').hide();
			}	
		}
		if($('relatedVideosHandle'))
		{
			// vertical slider control
			ScrollBar.relatedVideosSlider = new Control.Slider('relatedVideosHandle', 'relatedVideosTrack', {
				axis: 'vertical',
				onSlide: function(v) { ScrollBar.scrollVertical(v, $('relatedVideosContent'), ScrollBar.relatedVideosSlider);  },
				onChange: function(v) { ScrollBar.jumpVertical(v, $('relatedVideosContent'), ScrollBar.relatedVideosSlider); }
			});
			
			//MouseWheel.init(ScrollBar.relatedVideosSlider); //send slider element to MouseWheel object
					
			// disable vertical scrolling if text doesn't overflow the div
			if ($('relatedVideosContent').scrollHeight <= $('relatedVideosContent').offsetHeight) {
				ScrollBar.relatedVideosSlider.setDisabled();
				$('relatedVideosSliderContainer').hide();
			}	
		}
		
	},
	
	clickDownValue: function()
	{	
		this.setValueBy(1/(ArticlePreview.listItemArrayLength-5)); //value is 100% height (aka 1), divided by #of display items minus the 5 already shown
		if (typeof event == "undefined") // IE bug fix for assigning event
		{
			event = window.event;
		}
		if (typeof event.preventDefault != "undefined") //if not IE run first, if IE run second to cancel default action
		{
			event.preventDefault();
		}
		else
		{
			event.returnValue = false;
		}
	},
	
	clickUpValue: function()
	{
		this.setValueBy(-(1/(ArticlePreview.listItemArrayLength-5)));
		if (typeof event == "undefined") // IE bug fix for assigning event
		{
			event = window.event;
		}
		if (typeof event.preventDefault != "undefined") //if not IE run first, if IE run second to cancel default action
		{
			event.preventDefault();
		}
		else
		{
			event.returnValue = false;
		}
	},
	
	scrollVertical: function(value, element, slider) // scroll the element vertically based on its width and the slider maximum value
	{
		element.scrollTop = Math.round(value/slider.maximum*(element.scrollHeight-element.offsetHeight));
	},
	
	jumpVertical: function(value, element, slider) //handles clicking in the slidebar
	{
		var sliderValue = Math.round(value/slider.maximum*(element.scrollHeight-element.offsetHeight));//set value of slider location
		//alert(sliderValue);
		var originOffset = element.scrollTop; //set origin, start offset location
		var currentOffset = element.scrollTop; //track current location of overflow
		
		
		var factor = 1;//set decceleration variable based on whether using mouse wheel or scroll bar, prevent stutter on mouse wheel
		if (MouseWheel.shouldItListen == 1)
		{
			factor = 1;
		}
		else if (MouseWheel.shouldItListen == 0)
		{
			factor = 3;
		}
	
		var frameRate = 25; //framerate for animation
		
		if (sliderValue > originOffset) // if the slider moves down and the text hasn't or oposite
		{
			animateUp();
		}
		else if (sliderValue < originOffset)
		{
			animateDown();
		}
		
		function animateUp()
		{
			currentOffset += (sliderValue - currentOffset) / factor;
			
			if (sliderValue > originOffset && Math.round(currentOffset) >= sliderValue)
			{
				currentOffset = sliderValue;
			}
			else
			{
				var timeUp = setTimeout(animateUp, 1000 / frameRate);
			}
			
			element.scrollTop = Math.round(currentOffset);
		}
			
		function animateDown()
		{
			currentOffset -= (currentOffset - sliderValue) / factor;
			
			if (sliderValue < originOffset && Math.round(currentOffset) <= sliderValue)
			{
				currentOffset = sliderValue;
			}
			else
			{
				var timeDown = setTimeout(animateDown, 1000 / frameRate);
			}
			
			element.scrollTop = Math.round(currentOffset);
		}
	}
};



/*HANDLE THE MOUSE WHEEL MOVEMENT TO SCROLL TEXT AREAS
*activated inside the init function of scrollbar Object
*each individual handle calls its own mouse wheel script
*/


var MouseWheel =
{
	delta: 0,
	shouldItListen: 0,
	theSlider: "",
	
	init: function(slider)
	{
		if ($$('div.scrollableArea'))
		{
			var textElement = $$('div.scrollableArea'); //get the area to be scrolled
			MouseWheel.theSlider = slider; //assign slider to global variable
			
			//initilize wheel tracking only when over articleText div
			Event.observe(textElement[0], 'mouseover', MouseWheel.startListening);
			Event.observe(textElement[0], 'mouseout', MouseWheel.stopListening);
			
			//set up event listener for mouse wheel
			// mozilla
				Event.observe(textElement[0], 'DOMMouseScroll', MouseWheel.wheel, false);
			// IE/Opera
				Event.observe(textElement[0], 'mousewheel', MouseWheel.wheel, false);
		}	
		
	},
	
	startListening: function() //used to modify decceleration factor of animation
	{
		MouseWheel.shouldItListen = 1;
	},
	
	stopListening: function() //used to modify decceleration factor of animation
	{
		MouseWheel.shouldItListen = 0;
	},
	
	wheel: function(event) //handle wheel's number generation for cross browser usability
	{	
		if (!event) event = window.event;
		
		if (event.wheelDelta) {
			MouseWheel.delta = event.wheelDelta/120; 
			if (window.opera) MouseWheel.delta = MouseWheel.delta; //took minus out to correct Operas direction
		} else if (event.detail) {
			MouseWheel.delta = -event.detail/3;
		}
		
		if (MouseWheel.delta)
			MouseWheel.handle(MouseWheel.delta);
		
		if (event.preventDefault)//try to prevents default browser scrolling
		{
			event.preventDefault();
		}
		else
		{
			event.returnValue = false;
		}
		Event.stop(event); //prototype method that stops default action
	},
	
	handle: function(deltaValue) //takes value and sends it to scroller to make text area move
	{
		if (MouseWheel.shouldItListen == 1)
		{
			var valueForSlider = -deltaValue/100;
			
			MouseWheel.theSlider.setValueBy(valueForSlider);//increase or decrease slider by the supplied value
		}
	}
};








/*TABBED NAVIGATION CONTROLS FOR HOMEPAGE*/

var TabbedNavigation =
{
	tabDivs: [], //declare global array for the weekly tab div elements, there are three of them: last week, this week, next week
	contentDivIds: [], //declare globl array for each week's associated content area's id: lastWeekContent, thisWeekContent, nextWeekContent
	contentDivElements: [], //declare globl array of each content area div element, there are three of them

	init: function()
	{
		if($('weeklyNavigation') && $('thisWeekContent'))
		{
			var tabsDiv = $('weeklyNavigation');
			var childrenDivs = tabsDiv.childNodes;
			for (var i = 0; i < childrenDivs.length; i++)
			{
				if(childrenDivs[i].nodeType == 1) //if its a tag not undefined
				{
					TabbedNavigation.tabDivs[TabbedNavigation.tabDivs.length] = childrenDivs[i]; //define tab divs to global array variable
				}
			}
			for (var j = 0; j < TabbedNavigation.tabDivs.length; j++) //set even listeners to weekly tabs
			{
				Event.observe(TabbedNavigation.tabDivs[j], 'mouseover', TabbedNavigation.focusBlur.bindAsEventListener(TabbedNavigation.tabDivs[j]));
				Event.observe(TabbedNavigation.tabDivs[j], 'mouseout', TabbedNavigation.focusBlur.bindAsEventListener(TabbedNavigation.tabDivs[j]));
				Event.observe(TabbedNavigation.tabDivs[j], 'click', TabbedNavigation.changeContent.bindAsEventListener(TabbedNavigation.tabDivs[j]));
			}
		}
	},

	focusBlur: function() //receives div element 'this' and mouse event 'event'
	{
		if (this.hasClassName('back')) //if not chosen/current div toggle class, making gray/black
		{
			this.toggleClassName('notHighlighted');
		}
		
	},
	
	changeContent: function() //reveals clicked tab's associated content, hide other tabs' content divs, and changes classes of tabs to display propperly for changed selection
	{
		for (var i = 0; i < TabbedNavigation.tabDivs.length; i++) //get array of ids of content areas from ids of tabs and assign each element with id to global element array	
		{
			TabbedNavigation.contentDivIds[TabbedNavigation.contentDivIds.length] = TabbedNavigation.tabDivs[i].id + "Content"; //create array of content area ids
			TabbedNavigation.contentDivElements[TabbedNavigation.contentDivElements.length] = $(TabbedNavigation.contentDivIds[i]); //create array of contetn area div elements
		}
		
		for (var j = 0; j < TabbedNavigation.contentDivElements.length; j++) //add class name 'tabContentHidden' to any content area div that doesn't have it to hide non-selected tab's associated content
		{
			if (TabbedNavigation.contentDivElements[j].hasClassName('tabContentHidden') == false) //if content area doesn't have class 'tabContentHidden', add it, to hide all content
			{
				TabbedNavigation.contentDivElements[j].addClassName('tabContentHidden');
			}
		}
		
		var tabDivId = this.id; //get id of clicked tab
		var tabsContentId = tabDivId + "Content"; //get id of associtated content by adding 'Content' to tabs id
		$(tabsContentId).removeClassName('tabContentHidden') //remove 'tabContentHidden' class from associated content's div to display selected week's content
		
		for (var k = 0; TabbedNavigation.tabDivs.length; k++) //remove class name 'back' from clicked tab div and add it to non-selected tab divs
		{
			if (TabbedNavigation.tabDivs[k].hasClassName('back') == false)
			{
				TabbedNavigation.tabDivs[k].addClassName('back');
				TabbedNavigation.tabDivs[k].addClassName('notHighlighted');
			}
			this.removeClassName('back');
			this.removeClassName('notHighlighted');
		}
	}
};


/*SETS THE LINK VALUE FOR THE STICKY NOTE LINK TAKING PEOPLE TO CORRECT VIDEO BROWSER PAGE*/
var BackToBrowser = 
{
	categorypage: "",
	
	init: function()
	{	
		// if it's a category page set cookie value with url
		if (BackToBrowser.categorypage == true)
			Cookies.createCookie('backToBrowser', window.location);
		// get backToBrowser cookie value	
		var lastLocation = Cookies.readCookie('backToBrowser');
		// set stick note link to default value or cookie's value
		if($('backToBrowser'))
		{
			if(lastLocation != null) {
				$('backToBrowser').select('a')[0].setAttribute('href',lastLocation);
			} else {
				$('backToBrowser').select('a')[0].setAttribute('href', "http:\/\/www.askthedecorator.com/By_Date.shtml");
			}
		}
	}
};



/*BASIC COOKIES OBJECT WITH METHODS FOR READING, WRITING AND DELETING COOKIES*/
var Cookies = 
{
	createCookie: function(name,value,days) 
	{
		if (days) {
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
		else var expires = "";
		document.cookie = name+"="+value+expires+"; path=/";
	},

	readCookie: function(name) 
	{
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) {
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return null;
	},

	eraseCookie: function(name) 
	{
		Cookies.createCookie(name,"",-1);
	}
};



/*SOCIAL BOOKMARK HOVER BOX*/

var HoverBox = 
{
	currentBox: "",

	init: function()
	{
		if($$('div.dropdownContainer'))
		{
			var containerElement = $$('div.dropdownContainer'); //create array of div elements with class 'dropdownContainer'
			
			for (var i = 0; i < containerElement.length; i++)
			{
				//Event.observe(containerElement[i], 'mouseover', HoverBox.displayHide.bindAsEventListener(containerElement[i]));
				//Event.observe(containerElement[i], 'mouseout', HoverBox.displayHide.bindAsEventListener(containerElement[i]));
				
				Event.observe(containerElement[i], 'mouseover', HoverBox.display.bindAsEventListener(containerElement[i]));
				Event.observe(containerElement[i], 'mouseout', HoverBox.hide.bindAsEventListener(containerElement[i]));
						
			}
		}
	},
	
	display: function()
	{
		
		clearTimeout(HoverBox.currentBox); //clear out timer that is going to make box dissapear
	
		var hiddenList = this.select('ul li ul')[0]; //get array of all hidden ul's that are hidden
		hiddenList.addClassName('show');
	},
	
	hide: function()
	{
		var theBox = this; //assign 'this' to local variable to create closure, retain value of 'this'
		HoverBox.currentBox = setTimeout(function() //function delays closing box, prevents IE stuttering
		{
			var hiddenList = theBox.select('ul li ul')[0]; //get array of all hidden ul's that are hidden
			hiddenList.removeClassName('show');
		}, 1);
		
	}
	
};


