var cartHoverObj;

function getIEVersion() {
	var version = -1, usrAgt, regExp;
	if (navigator.appName === 'Microsoft Internet Explorer') {
		usrAgt = navigator.userAgent;
		regExp = new RegExp('MSIE ([0-9]{1,}[.0-9]{0,})');
		if (regExp.exec(usrAgt) !== null) {
			version = parseFloat(regExp.exec(usrAgt)[1]);
		}
	}
	if (version === 7) {
		version = (document.documentMode) ? 8 : 7;
	}
	return version;
}

Array.prototype.inArray = function (value) {
	for (var i = 0; i < this.length; i++) {
		if (this[i] === value) {
			return true;
		}
	}
	return false;
};

// mobile browser detect from detectmobilebrowser.com modified to return true/false instead of redirecting, call - mobile(navigator.userAgent||navigator.vendor||window.opera)
function mobile(a){if(/android|avantgo|blackberry|blazer|compal|elaine|fennec|hiptop|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile|o2|opera mini|palm( os)?|plucker|pocket|pre\/|psp|smartphone|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce; (iemobile|ppc)|xiino/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|e\-|e\/|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(di|rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|xda(\-|2|g)|yas\-|your|zeto|zte\-/i.test(a.substr(0,4)))return true;else return false}

// returns an array of all tags of a certain class
function getElementsByClassName(obj, theClass, theTag) {
	var allTagsWithClass = [],
		thisTag, i;
	
	for (i = 0; (thisTag = obj.getElementsByTagName(theTag ? theTag : '*')[i]); i++) {
		if (thisTag.className === theClass) {
			allTagsWithClass.push(thisTag);
		}
	}
	return allTagsWithClass;
}

function createEl(elType, elExtras, elParent) {
	var attribute,
	el = document.createElement(elType);
	for (attribute in elExtras) {
		if (elExtras[attribute] !== '') {
			if (attribute === 'class') {
				el.setAttribute('className', elExtras[attribute]);
			}
			el.setAttribute(attribute, elExtras[attribute]);
		}
	}
	if (elParent) {
		elParent.appendChild(el);
	}
	return el;
}

// Adds script tag to head of the page
function addScriptToHead(source, code, type) {
	var script = document.createElement('script');
	if (type === 'js') {
		script.setAttribute('type', 'text/javascript');
	}
	if (source !== '') {
		script.setAttribute('src', source);
	}
	if (code !== '') {
		if (document.all && !window.opera)	{
			script.text = code;
		} else {
			script.innerHTML = code;
		}
	}
	document.getElementsByTagName('head')[0].appendChild(script);
}

// Cookie handling
function Cookie(name) {
	this.setValue = function (value, hours, bridge) {
		var cookieString, date;
		cookieString = name + "=" + escape(value);
		if (hours) {
			date = new Date();
			date.setTime(date.getTime() + (hours * 60 * 60 * 1000));
			cookieString += "; expires=" + date.toGMTString();
		}
		cookieString += "; path=/";
		document.cookie = cookieString;
		if (bridge) {
			// send cookie info to check in
			cookiesForBridge.push(cookieString);
		}
	};
	
	this.getValue = function () {
		var results = document.cookie.match('(^|;) ?' + name + '=([^;]*)(;|$)');
		return results ? unescape(results[2]) : null;
	};
	
	this.remove = function () {
		this.setValue("", -1);
	};
}

/// Question and Answer
function QNA() {
	var checkHash, eventOverOut, eventClick, qNaCurrent, theQuestion, i, cookieVal, num,
	lastHash = null,
	containers = [],
	page = window.location.pathname.substring(window.location.pathname.lastIndexOf('/') + 1),
	cookie = new Cookie(page),
	mainPanel = document.getElementById('main-panel');

	// Check if we need to follow an anchor
	checkHash = function () {
		return function () {
			var sectionToDisplay;
			if (document.location.hash && lastHash !== document.location.hash) {
				lastHash = document.location.hash;
				sectionToDisplay = document.getElementById(document.location.hash.split('#')[1]);
				if (sectionToDisplay && sectionToDisplay.className === 'collapsible-content-question hide-answer') {
					sectionToDisplay.className = sectionToDisplay.className.replace(new RegExp(" hide-answer\\b"), "");
				}
			}
		};
	};
	
	// returns an event handler for Q&A mouse over and out events
	eventOverOut = function () {
		return function (e) {
			if (this.className === 'qna-question') {
				this.className += ' qna-hover';
			} else {
				this.className = this.className.replace(new RegExp(" qna-hover\\b"), "");
			}
		};
	};
	
	// returns an event handler for Q&A click
	eventClick = function () {
		return function (e) {
			var i, newValue;
			if (this.parentNode.className === 'collapsible-content-question') {
				this.parentNode.className += ' hide-answer';
				if (document.location.hash) {
					if (this.parentNode.id === document.location.hash.split("#")[1]) {
						document.location.hash = '';
					}
				}
			} else {
				this.parentNode.className = this.parentNode.className.replace(new RegExp(" hide-answer\\b"), "");
			}
			
			// sets a cookie to tell us which qna's were open
			newValue = '|';
			for (i = 0; i < containers.length; i += 1) {
				if (containers[i].className === 'collapsible-content-question') {
					if (i < 10) {
						newValue += '0';
					}
					newValue += i + '|';
				}
			}
			cookie.setValue(newValue);
		};
	};
	
	// init this thing
	if (mainPanel) {
		containers = getElementsByClassName(mainPanel, 'collapsible-content-question', 'div');
		containers = containers.concat(getElementsByClassName(mainPanel, 'collapsible-content-question', 'span'));
		if (containers.length > 0) {
			// checks cookie to see which qna's were left open last time they were on this page
			cookieVal = cookie.getValue();
			for (i = 0; i < containers.length; i += 1) {
				qNaCurrent = containers[i];
				if (cookieVal) {
					num = (i < 10) ? '0' + i : i;
					qNaCurrent.className += (cookieVal.match(num)) ? '' : ' hide-answer';
				} else {
					qNaCurrent.className += ' hide-answer';
				}
				
				theQuestion = getElementsByClassName(qNaCurrent, 'qna-question', 'div');
				if (theQuestion.length > 0) {
					theQuestion = theQuestion[0];
					theQuestion.innerHTML = theQuestion.innerHTML.replace("<span>", "").replace("</span>", ""); // temp fix for Chrome
					theQuestion.onmouseover = eventOverOut();
					theQuestion.onmouseout = eventOverOut();
					theQuestion.onclick = eventClick();
				}
			}
			window.setInterval(checkHash(), 200);
		}
	}
}

// Bundle hide and seek
function bundles() {
	var table, i, tbody, rows, span1, span2, hideShow, eventOverOut, createButtonRow;
	tbody = null;
	rows = null;
	span1 = document.createElement('span');
	span2 = document.createElement('span');
	
	// Hides and shows the extra rows in bundles table
	hideShow = function () {
		return function () {
			var i;
			for (i = 4; i < rows.length - 2; i++) {
				rows[i].className = (rows[i].className === 'top-nav-hidden') ? '' : 'top-nav-hidden';
			}
			span1.className = (span1.className === 'selectors-button-more') ? 'selectors-button-less' : 'selectors-button-more';
			span1.innerHTML = (span1.innerHTML === 'More') ? 'Less' : 'More';
		};
	};
	
	// Mouse over event
	eventOverOut = function () {
		return function (e) {
			span2.className = (span2.className === 'bundles-button') ? 'bundles-button-hover' : 'bundles-button';
		};
	};
	
	// Creates the row, and its contents, for the more-less button
	createButtonRow = function () {
		var row, padCell, cell;
		span1.className = 'selectors-button-more';
		span1.innerHTML = 'More';
		
		span2.className = 'bundles-button';
		span2.appendChild(span1);
		
		cell = document.createElement('td');
		cell.className = 'optioninput';
		cell.colSpan = '2';
		cell.appendChild(span2);
		
		padCell = document.createElement('td');
		padCell.className = 'optioninputbox';
		padCell.innerHTML = '&nbsp;';
		
		row = document.createElement('tr');
		row.appendChild(padCell);
		row.appendChild(padCell.cloneNode(true));
		row.appendChild(cell);
		
		row.onclick = hideShow();
		row.onmouseover = eventOverOut();
		row.onmouseout = eventOverOut();
		
		tbody.insertBefore(row, rows[rows.length - 1]);
	};
	
	// init
	table = document.getElementById('bundles-table');
	if (table) {
		tbody = table.getElementsByTagName('tbody')[0];
		if (tbody) {
			rows = tbody.getElementsByTagName('tr');
			if (rows.length > 6) {
				for (i = 4; i < rows.length - 1; i++) {
					rows[i].className = 'top-nav-hidden';
				}
				createButtonRow();
			}
		}
	}
}

// Grids with flexible number of columns
function FlexColGrid(name, minCellWidth) {
	this.redraw = function (gridContainer) {
		var lastCols = 0, numNodes, gridWidth, numCols, boxWidth, extraWidth, lastWindowWidth = 0, pixelBoxWidth, primeIt = 3, i, row, widthAdjust,
		nodes = getElementsByClassName(gridContainer, 'item-grid-cell', 'div'),
		panelWidth = 260,
		pageContainer = document.getElementById('page-container');
		numNodes = nodes.length;
		if (pageContainer.className.match(/no-left-panel/)) {
			panelWidth -= 180;
		}
		return function () {
			if (lastWindowWidth !== document.body.offsetWidth &&  document.body.offsetWidth > 0) {
				lastWindowWidth = document.body.offsetWidth - primeIt;
				gridWidth = lastWindowWidth - panelWidth;
				numCols = Math.min(Math.floor(gridWidth / minCellWidth), numNodes);
				if (numCols === 0) {
					numCols = 1;
				} else {
					while ((Math.ceil(numNodes / numCols) === Math.ceil(numNodes / (numCols - 1))) && numCols > 1) {
						numCols--;
					}
				}
				version = getIEVersion();
				if ((version == 7) ^ (version == 8) ^ (version == 6)) {
					$addwidth = 99;
				} else {
					$addwidth = 100;
				}
				gridContainer.style.width = (Math.ceil(gridWidth / numCols) * numCols) + 'px';
				if (lastCols !== numCols) {
					lastCols = numCols;
					boxWidth = Math.floor(100 / numCols);
					extraWidth = $addwidth - (boxWidth * numCols);
					widthAdjust = extraWidth;
					row = numCols;
					for (i = 0; i < numNodes; i++) {
						if (i === row) {
							widthAdjust = extraWidth;
							row += numCols;
						}
						pixelBoxWidth = (widthAdjust > 0) ? boxWidth + 1 : boxWidth;
						nodes[i].style.width = (numNodes > 1) ? pixelBoxWidth + '%' : minCellWidth + 'px';
						widthAdjust -= 1;
					}
				}
				if (primeIt > 0) {
					primeIt -= 3;
				}
			}
		};
	};
	window.setInterval(this.redraw(document.getElementById(name)), 60);
}

function selectors() {
	var lists, i, j, l, li, button,
	container = document.getElementById('selectors-container'),
	
	openCloseSelector = function () {
		return function () {
			if (this.parentNode.className === 'selectors-collapsed') {
				this.innerHTML = '<span>Less</span>';
				this.parentNode.className = '';
			} else {
				this.innerHTML = '<span>' + (this.parentNode.getElementsByTagName('li').length - 6) + ' More</span>';
				this.parentNode.className = 'selectors-collapsed';
			}
		};
	};
	
	// init
	if (container) {
		lists = getElementsByClassName(container, 'selectors-collapsed', 'ul');
		for (i = 0, l = lists.length; i < l; i++) {
			li = lists[i].getElementsByTagName('li');
			if (li.length > 6) {
				button = li[li.length - 1];
				button.innerHTML = '<span>' + (li.length - 6) + ' More</span>';
				button.onclick = openCloseSelector();
			}
		}
	}
}

function AlphaList(id, hideable) {
	var linksContainer, alphaLinks, i, showList, allLists, alphaLists = [], liWidths = [], lastCols = [], liLinks, j, windowResize, lastWindowWidth = 0, colsHeight = [], createCols, colsTotalWidth = [], colsList = [], slideMe, slideInt = null, slideCount = 1, slideAmt, heightDiff =  0, maxCols = [], maxWidth, numCols = [], lastShown = null, titleList = [], title = [], k,  noTitleList = false, seeAll, showAll,
	container = document.getElementById(id),
	ieVersion = getIEVersion();
	
	slideMe = function (closeMe, list, cols) {
		return function () {
			if (closeMe) {
				if (slideCount < 9) {
					colsList[list][cols].style.height = colsList[list][cols].offsetHeight - slideAmt + 'px';
					slideCount++;
				} else {
					colsList[list][cols].style.height = '0px';
					alphaLists[list].className = 'shop-by-lists';
					window.clearInterval(slideInt);
					slideInt = null;
				}
			} else {
				if (slideCount > 2) {
					colsList[list][cols].style.height = colsList[list][cols].offsetHeight + slideAmt + 'px';
					slideCount--;
				} else {
					colsList[list][cols].style.height = colsHeight[list][cols] + 'px';
					colsList[list][cols].className = '';
					window.clearInterval(slideInt);
					slideInt = null;
				}
			}
		};
	};
	
	windowResize = function () {
		return function () {
			if (lastWindowWidth !== document.body.offsetWidth) {
				lastWindowWidth = document.body.offsetWidth;
				if (lastShown !== null) {
					for (i = maxCols[lastShown] - 1; i > -1; i--) {
						if (colsTotalWidth[lastShown][i] < container.offsetWidth) {
							numCols[lastShown] = i;
							break;
						}
					}
					if (numCols[lastShown] !== lastCols[lastShown]) {
						colsList[lastShown][lastCols[lastShown]].className = 'hide-lists';
						colsList[lastShown][numCols[lastShown]].style.height = colsHeight[lastShown][numCols[lastShown]] + 'px';
						colsList[lastShown][numCols[lastShown]].className = '';
						alphaLists[lastShown].removeChild(colsList[lastShown][lastCols[lastShown]]);
						alphaLists[lastShown].appendChild(colsList[lastShown][numCols[lastShown]]);
						lastCols[lastShown] = numCols[lastShown];
					}
				} else if (!hideable || seeAll.innerHTML.match('hide all')) {
					for (i = 0; i < alphaLists.length; i++) {
						for (j = maxCols[i]; j > -1; j--) {
							if (colsTotalWidth[i][j] < container.offsetWidth) {
								numCols[i] = j;
								break;
							}
						}
						if (numCols[i] !== lastCols[i]) {
							alphaLists[i].removeChild(colsList[i][lastCols[i]]);
							alphaLists[i].appendChild(colsList[i][numCols[i]]);
							lastCols[i] = numCols[i];
						}
						if (hideable) {
							colsList[i][numCols[i]].style.height = '';
							colsList[i][numCols[i]].style.paddingTop = '20px';
							colsList[i][numCols[i]].style.borderBottom = '1px solid #fff';
						}
					}
				}
			}
		};
	};
	
	createCols = function (num) {
		var listItems, rows, start, end, list, k, rowsHeight;
		colsTotalWidth[num] = [];
		colsList[num] = [];
		colsHeight[num] = [];
		listItems = alphaLists[num].getElementsByTagName('a');
		maxCols[num] = 11;
		for (i = 1; i < maxCols[num]; i++) {
			rows = Math.ceil(listItems.length / i);
			if (i > 1 && rows < 3) {
				maxCols[num] = i - 1;
				break;
			}
			if (!noTitleList) {
				colsTotalWidth[num][i] = (hideable) ? 80 : 130;
			} else {
				colsTotalWidth[num][i] = 0;
			}
			start = 0;
			end = rows;
			colsList[num][i] = document.createElement('li');
			rowsHeight = rows * 18;
			colsHeight[num][i] = (rowsHeight > 63) ? rowsHeight : 63;
			if (hideable) {
				colsList[num][i].style.height = '0px';
			}
			if (!noTitleList) {
				colsList[num][i].appendChild(title[num].cloneNode(true));
			}
			for (j = 0; j < i; j++) {
				if (listItems[start]) {
					list = document.createElement('ul');
					maxWidth = 0;
					for (k = start; k < end; k++) {
						if (listItems[k]) {
							list.appendChild(listItems[k].parentNode.cloneNode(true));
							if (liWidths[num][k] > maxWidth) {
								maxWidth = liWidths[num][k];
							}
						}
					}
					if (hideable) {
						maxWidth += 20;
					} else {
						maxWidth += 50;
					}
					colsTotalWidth[num][i] += maxWidth;
					if (ieVersion === 6) {
						list.style.width = maxWidth - 30 + 'px';
					}
					start += rows;
					end += rows;
					colsList[num][i].appendChild(list);
				}
			}
		}
	};
	
	showList = function (num) {
		return function () {
			this.blur();
			if (slideInt !== null) {
				return false;
			}
			if (!colsList[num]) {
				createCols(num);
			}
			for (i = maxCols[num]; i > -1; i--) {
				if (colsTotalWidth[num][i] < container.offsetWidth) {
					numCols[num] = i;
					break;
				}
			}
			if (lastShown !== null) {
				alphaLinks[lastShown].className = '';
				if (lastShown === num) {
					colsList[lastShown][lastCols[lastShown]].className = 'hide-lists';
					slideCount = 1;
					slideAmt = colsHeight[lastShown][numCols[lastShown]] / 10;
					slideAmt = (ieVersion > 0) ? Math.floor(slideAmt) : slideAmt;
					slideInt = window.setInterval(slideMe(true, lastShown, numCols[lastShown]), 25);
					lastShown = null;
					return false;
				}
				heightDiff = colsHeight[num][numCols[num]] - colsHeight[lastShown][lastCols[lastShown]];
				colsList[num][numCols[num]].style.height = colsList[lastShown][lastCols[lastShown]].offsetHeight + 'px';
				colsList[lastShown][lastCols[lastShown]].className = 'hide-lists';
				colsList[lastShown][lastCols[lastShown]].style.height = '0px';
				alphaLists[lastShown].className = 'shop-by-lists';
				if (heightDiff === 0) {
					alphaLinks[num].className = 'shop-by-alpha-letter-selected';
					alphaLists[num].className += ' show-list';
					colsList[num][numCols[num]].className = '';
					if (numCols[num] !== lastCols[num]) {
						alphaLists[num].innerHTML = '';
						alphaLists[num].appendChild(colsList[num][numCols[num]]);
						lastCols[num] = numCols[num];
					}
					lastShown = num;
					return false;
				}
			}
			if (numCols[num] !== lastCols[num]) {
				alphaLists[num].innerHTML = '';
				alphaLists[num].appendChild(colsList[num][numCols[num]]);
				lastCols[num] = numCols[num];
			}
			alphaLinks[num].className = 'shop-by-alpha-letter-selected';
			alphaLists[num].className += ' show-list';
			slideCount = 10;
			slideAmt = (heightDiff !== 0) ? heightDiff / 10 : colsHeight[num][numCols[num]] / 10;
			slideAmt = (ieVersion > 0) ? Math.floor(slideAmt) : slideAmt;
			colsList[num][numCols[num]].className = 'hide-lists';
			slideInt = window.setInterval(slideMe(false, num, numCols[num]), 25);
			lastShown = num;
			heightDiff = 0;
			return false;
		};
	};
	
	showAll = function () {
		return function () {
			if (seeAll.innerHTML === '+ show all') {
				for (k = 0; k < alphaLinks.length; k++) {
					alphaLists[k].className = alphaLists[k].className.replace(new RegExp(' show-list\\b'), '');
					alphaLinks[k].onclick = null;
					alphaLists[k].className += ' show-list';
					alphaLinks[k].className = '';
					
					if (!colsList[k]) {
						createCols(k);
					}
					for (i = maxCols[k]; i > -1; i--) {
						if (colsTotalWidth[k][i] < container.offsetWidth) {
							numCols[k] = i;
							break;
						}
					}
					if (numCols[k] !== lastCols[k]) {
						alphaLists[k].innerHTML = '';
						alphaLists[k].appendChild(colsList[k][numCols[k]]);
						lastCols[k] = numCols[k];
					}
					colsList[k][numCols[k]].style.height = '';
					colsList[k][numCols[k]].style.padding = '10px 0';
					colsList[k][numCols[k]].style.borderBottom = '1px solid #fff';
				}
				lastShown = null;
				seeAll.innerHTML = '&mdash; hide all';
			} else {
				for (k = 0; k < alphaLinks.length; k++) {
					alphaLinks[k].onclick = showList(k);
					alphaLists[k].className = alphaLists[k].className.replace(new RegExp(' show-list\\b'), '');
					colsList[k][numCols[k]].style.height = '0px';
					colsList[k][numCols[k]].style.padding = '';
					colsList[k][numCols[k]].style.borderBottom = '';
				}
				seeAll.innerHTML = '+ show all';
			}
			return false;
		};
	};
	
	// init
	if (container) {
		if (hideable) {
			linksContainer = getElementsByClassName(container, 'shop-by-alpha-links', 'span')[0];
			alphaLinks = linksContainer.getElementsByTagName('a');
			for (i = 0; i < alphaLinks.length; i++) {
				alphaLinks[i].onclick = showList(i);
			}
			seeAll = document.createElement('a');
			seeAll.innerHTML = '+ show all';
			seeAll.href = '#';
			seeAll.onclick = showAll();
			seeAll.id = 'shop-by-show-all';
			linksContainer.parentNode.insertBefore(seeAll, linksContainer);
		}
		allLists = getElementsByClassName(container, 'shop-by-lists', 'ul');
		for (k = 0; k < allLists.length; k++) {
			alphaLists[k] = allLists[k];
			liWidths[k] = [];
			lastCols[k] = -1;
			liLinks = alphaLists[k].getElementsByTagName('a');
			for (j = 0; j < liLinks.length; j++) {
				liWidths[k][j] = liLinks[j].offsetWidth;
			}
			titleList[k] = allLists[k].getElementsByTagName('ul')[0];
			if (titleList[k].getElementsByTagName('li')[0].className === 'shop-by-pic-link' || titleList[k].getElementsByTagName('li')[0].className === 'shop-by-big-letter') {
				title[k] = titleList[k].cloneNode(true);
				alphaLists[k].getElementsByTagName('li')[0].removeChild(titleList[k]);
			} else {
				noTitleList = true;
			}
			if (!hideable) {
				alphaLists[k].className += ' show-list';
				createCols(k);
				alphaLists[k].innerHTML = '';
				alphaLists[k].appendChild(colsList[k][1]);
				lastCols[k] = 1;
			}
		}
		window.setInterval(windowResize(), 200);
		container.className += ' shop-by-script';
	}
}

function ImageSwapper() {
	var mainImg, links, i, bigUrl, eventOver, eventOut, eventClick, origMainImg, origMainAlt, currentImg, currentAlt, popDiv, popImg, hideImage, linksImg, faderDiv, centerPopDiv, myInterval = null, winH = 0, winW = 0, newImg, setOpacity, fadeIn, fadeInTimer = [], fadeInOpac = [], fadeOut, fadeOutTimer = [], fadeOutOpac = [], nextDiv = null, prevDiv = null, nextPrev, popAlt, magGlass, closeImg, keyDownEvent, popIcons = [], getScroll, topPos, scrollFix, iconContainer, preLoader = [], loadingImg, preLoaded = [], popLoadingImg, setNewSizes, setSelected, setNewImage, switchBox, picButton, vidButton, moviePlayer, toggleSwitch, movieObject, playlist = [], addPlaylist, flashLink, lastItem = 0, movieNum = 0, movieFile, playlistSpot, flashVars, flashParams, flashAttributes, embedFlash, video, findMovie,
	picBlock = document.getElementById('pictureblock'),
	mainLink = document.getElementById('main-picture'),
	midUrl = 'http://images1.' + php_image_domain + '180-180-ffffff/',
	objects = document.getElementsByTagName('object'),
	videoList = document.getElementById('caption-documents-flv'),
	isMobile = mobile(navigator.userAgent||navigator.vendor||window.opera);
	fadeInOpac[1] = 0;
	fadeInOpac[0] = 0;
	fadeInTimer[1] = null;
	fadeInTimer [0] = null;
	fadeOutTimer[1] = null;
	fadeOutTimer [0] = null;
	
	// Gets any offset if the user has scrolled down the page
	getScroll = function () {
		var scrollY = 0;
		if (typeof(window.pageYOffset) === 'number') {
			scrollY = window.pageYOffset;
		} else if (document.body && document.body.scrollTop) {
			scrollY = document.body.scrollTop;
		} else if (document.documentElement && document.documentElement.scrollTop) {
			scrollY = document.documentElement.scrollTop;
		}
		return scrollY;
	};
	
	// All the calculating and size setting for centering on resize
	setNewSizes = function (imgW, imgH, popH, loadTop, loadLeft, colDivider) {
		var colAmt, newWidth, leftPos;
		popDiv.style.height = popH + 'px';
		if (mainLink) {
			bigUrl = 'http://images1.' + php_image_domain + imgW + '-' + imgH + '-ffffff/';
			if (!popImg.src.match(imgW + '-' + imgH)) {
				currentImg = bigUrl + popImg.src.split('-ffffff/')[1];
				popImg.src = bigUrl + popImg.src.split('-ffffff/')[1];
			}
			iconContainer.style.height = imgH + 'px';
			iconContainer.style.left = imgW + 'px';
			popLoadingImg.style.top = loadTop + 'px';
			popLoadingImg.style.left = loadLeft + 'px';
			colAmt = (Math.ceil(popIcons.length / colDivider)) * 70;
			iconContainer.style.width = colAmt + 'px';
			newWidth = (popIcons.length > 1) ? imgW + colAmt : imgW;
		} else {
			newWidth = imgW;
		}
		popDiv.style.width = newWidth + 2 + 'px';
		topPos = (winH - popH) / 2 - 10;
		scrollFix = getScroll();
		popDiv.style.top = ((topPos + scrollFix) > 0) ? topPos + scrollFix + 'px' : '0px';
		leftPos = (winW - newWidth) / 2 - 10;
		popDiv.style.left = (leftPos > 0) ? leftPos + 'px' : '0px';
		if (playlist.length > 0) {
			if (!movieObject) {
				if (flashLink) {
					flashLink.style.width = newWidth + 'px';
					flashLink.style.height = popH - 27 + 'px';
				}
				movieObject = document.getElementById('flvMoviePlayer');
			}
			if (movieObject) {
				movieObject.style.width = newWidth + 4 + 'px';
				movieObject.style.height = popH - 26 + 'px';
			}
		}
	};
	
	addPlaylist = function () {
		return function () {
			if (movieObject && typeof(movieObject.sendEvent) === 'function') {
				movieObject.sendEvent('LOAD', playlist);
				movieObject.sendEvent('ITEM', movieNum);
				if (mainLink && vidButton.className !== 'selected') {
					movieObject.sendEvent('STOP', movieNum);
				}
			} else {
				window.setTimeout(addPlaylist(), 100);
			}
		};
	};
	
	// Determines the window size and calls the function above to resize
	centerPopDiv = function () {
		return function () {
			if (((document.all && !window.opera) ? document.documentElement.clientHeight : window.innerHeight) !== winH || ((document.all && !window.opera) ? document.body.offsetWidth : window.innerWidth) !== winW) {
				winH = (document.all && !window.opera) ? document.documentElement.clientHeight : window.innerHeight;
				winW = (document.all && !window.opera) ? document.body.offsetWidth : window.innerWidth;
				if (winW > 1170 && winH > 710) {
					setNewSizes(1020, 680, 707, 250, 420, 9);
				} else if (winW > 900 && winH > 530) {
					setNewSizes(750, 500, 527, 160, 285, 7);
				} else {
					setNewSizes(480, 320, 347, 70, 150, 4);
				}
			}
			if (playlist.length > 1) {
				if (movieObject && typeof(movieObject.getConfig) === 'function') {
					if (lastItem !== movieObject.getConfig()['item']) {
						lastItem = movieObject.getConfig()['item'];
						movieNum = lastItem;
						popAlt.innerHTML = playlist[lastItem].title;
					}
				}
			}
		};
	};
	
	setOpacity = function (el, opacity) {
		opacity = '' + (opacity / 5);
		el.style.opacity = opacity;		// For CSS 3 compliant browsers
		el.style["-moz-opacity"] = opacity;	// For old FF
		el.style.filter = 'alpha(opacity=' + opacity * 100 + ')';	// For IE
	};
	
	fadeIn = function (obj, fadeStop, a) {
		return function () {
			if (fadeInTimer[a] !== null && fadeInOpac[a] < fadeStop) {
				setOpacity(obj, fadeInOpac[a]);
				obj.className = '';
				fadeInOpac[a]++;
			} else {
				setOpacity(obj, fadeStop);
				window.clearInterval(fadeInTimer[a]);
				fadeInTimer[a] = null;
				fadeOutOpac[a] = fadeStop;
				if (a === 1 && playlist.length > 1) {
					window.setTimeout(addPlaylist(), 100);
				}
			}
		};
	};
	
	fadeOut = function (obj, fadeStop, a) {
		return function () {
			if (fadeOutTimer[a] !== null && fadeOutOpac[a] > fadeStop) {
				setOpacity(obj, fadeOutOpac[a]);
				fadeOutOpac[a]--;
			} else {
				setOpacity(obj, fadeStop);
				obj.className = 'hidden-object';
				window.clearInterval(fadeOutTimer[a]);
				fadeOutTimer[a] = null;
				fadeInOpac[a] = fadeStop;
				for (i = 0; i < objects.length; i++) {
					if (objects[i].id !== 'flvMoviePlayer') {
						objects[i].style.visibility = '';
					}
				}
			}
		};
	};
	
	// Handles all image changes for mouseovers and clicks, includes preload
	setNewImage = function (img, popArea, changeCurrent) {
		var imgSrc, skip = false, url, setImg, setAlt, tempImg;
		imgSrc = img.src.split('/');
		imgSrc = imgSrc[imgSrc.length - 1].split('.', 1);
		setImg = bigUrl + imgSrc + '.jpg';
		setAlt = img.alt;
		if (popArea || changeCurrent) {
			tempImg = popImg;
			popAlt.innerHTML = setAlt;
		} else {
			tempImg = mainImg;
			mainImg.alt = setAlt;
		}
		for (url in preLoaded) {
			if (setImg === preLoaded[url]) {
				skip = true;
				break;
			}
		}
		setImg = (popArea || changeCurrent) ? setImg : midUrl + imgSrc + '.jpg';
		if (!skip) {
			tempImg.className = 'top-nav-hidden';
			preLoader[setImg] = new Image();
			preLoader[setImg].onload = function () {
				tempImg.src = this.src;
				tempImg.className = '';
				preLoaded.push(this.src);
			};
			preLoader[setImg].src = setImg;
		} else {
			tempImg.src = setImg;
		}
		if (changeCurrent) {
			currentImg = setImg;
			currentAlt = setAlt;
		}
	};
	
	// Sets class names to properly show currently selected image and adjust next/prev buttons
	setSelected = function () {
		for (i = 0; i < popIcons.length; i++) {
			if (popIcons[i].src.split('-ffffff')[1].replace('.png', '') === currentImg.split('-ffffff')[1].replace('.jpg', '')) {
				popIcons[i].className = 'selected-image';
				prevDiv.className = (i > 0) ? '' : 'disable-me';
				prevDiv.onclick = (i > 0) ? nextPrev('back') : null;
				nextDiv.className = (i < (popIcons.length - 1)) ? '' : 'disable-me';
				nextDiv.onclick = (i < (popIcons.length - 1)) ? nextPrev('forward') : null;
			} else {
				popIcons[i].className = '';
			}
		}
	};
	
	// Hides pop up window and fader div and stops interval that centers pop up window on resize
	hideImage = function () {
		return function (e) {
			if (myInterval !== null) {
				window.clearInterval(myInterval);
				myInterval = null;
			}
			if (fadeInTimer[1] === null && fadeInTimer[0] === null && fadeOutTimer[0] === null && fadeOutTimer[1] === null) {
				if (movieObject && typeof(movieObject.sendEvent) === 'function') {
					movieObject.sendEvent('STOP');
				}
				if (document.all && !window.opera || isMobile) {
					popDiv.className = 'hidden-object';
					faderDiv.className = 'hidden-object';
					if (flashLink) {
						flashLink.style.display = 'none';
					}
				} else {
					fadeOutTimer[1] = window.setInterval(fadeOut(popDiv, 0, 1), 50);
					fadeOutTimer[0] = window.setInterval(fadeOut(faderDiv, 0, 0), 50);
				}
				document.onkeydown = null;
			}
		};
	};
	
	// Mouse over event handler
	eventOver = function () {
		return function (e) {
			var inPopUp;
			if (this.parentNode.id === 'pop-icon-container') {
				newImg = this;
				inPopUp = true;
			} else {
				newImg = this.getElementsByTagName('img')[0];
				inPopUp = false;
			}
			setNewImage(newImg, inPopUp, false);
		};
	};
	
	// Mouse out event handler
	eventOut = function () {
		return function (e) {
			//preLoader.onload = null;
			if (this.parentNode.id === 'pop-icon-container') {
				popImg.src = currentImg;
				popImg.className = '';
				popAlt.innerHTML = currentAlt;
			} else {
				mainImg.src = origMainImg;
				mainImg.alt = origMainAlt;
				mainImg.className = '';
			}
		};
	};
	
	// Switches back and forth from movies to pictures in the pop up
	toggleSwitch = function (showVid) {
		return function () {
			if (showVid) {
				if (mainLink) {
					vidButton.className = 'selected';
					vidButton.onclick = null;
					picButton.className = '';
					picButton.onclick = toggleSwitch(false);
				}
				moviePlayer.style.visibility = '';
				popAlt.innerHTML = playlist[movieNum].title;
				if (flashLink) {
					flashLink.style.display = 'block';
				}
				if (nextDiv !== null && prevDiv !== null) {
					nextDiv.className = 'disable-me';
					nextDiv.style.display = 'none';
					nextDiv.onclick = null;
					prevDiv.className = 'disable-me';
					prevDiv.style.display = 'none';
					prevDiv.onclick = null;
				}
				if (playlist.length > 1) {
					window.setTimeout(addPlaylist(), 100);
				} else if (movieObject && typeof(movieObject.sendEvent) === 'function') {
					movieObject.sendEvent('ITEM', '0');
				}
			} else {
				if (movieObject && typeof(movieObject.sendEvent) === 'function') {
					movieObject.sendEvent('STOP');
				}
				vidButton.className = '';
				vidButton.onclick = toggleSwitch(true);
				picButton.className = 'selected';
				picButton.onclick = null;
				if (flashLink) {
					flashLink.style.display = 'none';
				}
				moviePlayer.style.visibility = 'hidden';
				popAlt.innerHTML = currentAlt;
				if (nextDiv !== null && prevDiv !== null) {
					nextDiv.style.display = 'block';
					prevDiv.style.display = 'block';
					setSelected();
				}
			}
		};
	};
	
	// Mouse click event handler
	eventClick = function (movNum) {
		return function (e) {
			if (movNum < 0) {
				var inPopUp;
				if (this.parentNode.id === 'pop-icon-container') {
					newImg = this;
					inPopUp = true;
				} else if (this.id === 'enlarge-text') {
					newImg = mainImg;
					inPopUp = false;
				} else {
					newImg = this.getElementsByTagName('img')[0];
					inPopUp = false;
				}
				setNewImage(newImg, inPopUp, true);
				setSelected();
			}
			if (this.parentNode.id !== 'pop-icon-container') {
				myInterval = window.setInterval(centerPopDiv(), 250); // Starts up centering function so pop up stays centered on window resize
				if (fadeInTimer[1] === null && fadeInTimer[0] === null && fadeOutTimer[0] === null && fadeOutTimer[1] === null) {
					for (i = 0; i < objects.length; i++) {
						if (objects[i].id !== 'flvMoviePlayer') {
							objects[i].style.visibility = 'hidden';
						}
					}
					if (document.all && !window.opera || isMobile) {
						faderDiv.className = '';
						popDiv.className = '';
					} else {
						fadeInTimer[0] = window.setInterval(fadeIn(faderDiv, 4, 0), 50);
						fadeInTimer[1] = window.setInterval(fadeIn(popDiv, 5, 1), 50);
					}
					document.onkeydown = keyDownEvent();
					scrollFix = getScroll();
					popDiv.style.top = topPos + scrollFix + 'px';
				}
				if (playlist.length > 0) {
					movieNum = (movNum > -1) ? movNum : 0;
					window.setTimeout(toggleSwitch(movNum > -1), 1);
				}
			}
			return false;
		};
	};
	
	// Event handler for next and prev buttons in pop up
	nextPrev = function (direction) {
		return function (e) {
			for (i = 0; i < popIcons.length; i++) {
				if (popIcons[i].className === 'selected-image') {
					if (direction === 'back' && i > 0) {
						newImg = popIcons[i - 1];
						break;
					} else if (direction === 'forward' && i < (popIcons.length - 1)) {
						newImg = popIcons[i + 1];
						break;
					}
				}
			}
			setNewImage(newImg, true, true);
			setSelected();
			return false;
		};
	};
	
	keyDownEvent = function () {
		return function (e) {
			var keynum = (window.event) ? window.event.keyCode : e.which;
			switch (keynum) {
			case 37: // left arrow key press
				if (prevDiv !== null && prevDiv.className !== 'disable-me') {
					window.setTimeout(nextPrev('back'), 1);
				}
				break;
			case 39: // right arrow key press
				if (nextDiv !== null && nextDiv.className !== 'disable-me') {
					window.setTimeout(nextPrev('forward'), 1);
				}
				break;
			case 27: // escape key press
				if (popDiv.className !== 'hidden-object') {
					window.setTimeout(hideImage(), 1);
				}
				break;
			}
		};
	};
	
	findMovie = function () {
		return function () {
			if (!movieObject) {
				movieObject = document.getElementById('flvMoviePlayer');
				winH = 0;
			} else {
				window.setTimeout(findMovie(), 50);
			}
		};
	};
	
	embedFlash = function () {
		return function () {
			if (typeof(swfobject) === 'object') {
				swfobject.embedSWF(php_layout_full_path + '/player-licensed.swf', 'flv-movie', '1020', '680', '9', false, flashVars, flashParams, flashAttributes);
				findMovie()();
			} else {
				window.setTimeout(embedFlash(), 50);
			}
		};
	};
	
	// init
	if (picBlock && mainLink || videoList) {
		if (mainLink) {
			magGlass = createEl('img', {'id': 'mag-glass-img', 'src': php_layout_full_path + '/images/tiny-mag-glass.png', 'width': '12', 'height': '10'}, mainLink); // This adds the magnifying glass image over the main image
			
			mainImg = mainLink.getElementsByTagName('img')[0]; // This block sets orig and current vars for the main image on the page and in the pop up
			origMainImg = mainImg.src;
			origMainAlt = mainImg.alt;
			currentImg = mainImg.src.replace('180-180-ffffff', '1020-680-ffffff');
			currentAlt = mainImg.alt;
			
		} else {
			currentAlt = '';
		}
		
		popDiv = createEl('div', {'id': 'pop-up-window', 'class': 'hidden-object'}); // Creates and sets attributes for elements for pop up area
		closeImg = createEl('div', {'id': 'pop-close-button'}, popDiv);
		closeImg.onclick = hideImage();
		popAlt = createEl('p', {'id': 'pop-img-alt', 'innerHTML': currentAlt}, popDiv);
		if (mainLink) {
			popLoadingImg = createEl('img', {'id': 'pop-loading-img', 'src': php_layout_full_path + '/images/loading.gif'}, popDiv);
			popImg = createEl('img', {'src': currentImg, 'id': 'pop-main-img'}, popDiv);
			popImg.onclick = hideImage();
			iconContainer = createEl('div', {'id': 'pop-icon-container'}, popDiv);
			links = picBlock.getElementsByTagName('a');
			if (links.length > 1) {
				for (i = 0; i < links.length; i++) { // Loops through the small images and creates new ones from it for the pop up and adds events
					linksImg = links[i].getElementsByTagName('img')[0];
					if (linksImg.src.match(/\?video\=/)) {
						video = linksImg.src.split(/\?video\=/)[1];
						playlist.push({description: "", file: "http://images1." + php_image_domain + "flv/" + video + ".flv", title: linksImg.alt, type: "video"});
						links[i].onclick = eventClick(playlist.length - 1);
					} else {
						if (links[i].id !== 'main-picture') {
							links[i].onmouseover = eventOver();
							links[i].onmouseout = eventOut();
							newImg = createEl('img', {'src': linksImg.src.replace('88-40-ffffff', '66-66-ffffff'), 'alt': linksImg.alt}, iconContainer);
						} else {
							newImg = createEl('img', {'src': linksImg.src.replace('180-180-ffffff', '66-66-ffffff'), 'alt': linksImg.alt}, iconContainer);
						}
						newImg.onmouseover = eventOver();
						newImg.onmouseout = eventOut();
						newImg.onclick = eventClick(-1);
						popIcons.push(newImg);
						links[i].onclick = eventClick(-1);
					}
					links[i].href = '#';
				}
				if (popIcons.length > 1) {
					nextDiv = createEl('div', {'id': 'next-img-div'}, popDiv);
					nextDiv.onclick = nextPrev('forward');
					prevDiv = createEl('div', {'id': 'prev-img-div'}, popDiv);
					prevDiv.onclick = nextPrev('back');
				}
			} else {
				mainLink.onclick = eventClick(-1);
			}
		} else {
			for (i = 0; (links = videoList.getElementsByTagName('a')[i]); i++) {
				video = links.href.split(/video\=/)[1];
				playlist.push({description: "", file: "http://images1." + php_image_domain + "flv/" + video + ".flv", title: links.innerHTML, type: "video"});
				links.onclick = eventClick(playlist.length - 1);
			}
		}
		if (playlist.length > 0) {
			if (mainLink) {
				switchBox = createEl('div', {'id': 'pic-video-switch-box'}, popDiv);
				picButton = createEl('div', {}, switchBox);
				picButton.innerHTML = 'pictures';
				vidButton = createEl('div', {}, switchBox);
				vidButton.innerHTML = 'video';
			}
			moviePlayer = createEl('div', {'id': 'flv-movie-div', 'style': 'visibility:hidden;'}, popDiv);
			flashLink = createEl('a', {'id': 'flv-movie', 'class': 'player', 'href': 'http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash'}, moviePlayer);
			flashLink.innerHTML = 'Get the Flash Plugin to see this video.';
			flashLink.style.display = 'none';
			movieFile = (playlist.length > 1) ? 'playlist.xml' : playlist[0].file;
			playlistSpot = (playlist.length > 1) ? 'right' : 'none';
			flashVars = {'file': movieFile, 'playlist': playlistSpot, 'id': 'flvMoviePlayer', 'stretching': 'uniform', 'backcolor': 'f9f9f9', 'frontcolor': '000000', 'lightcolor': '2665ad', 'screencolor': 'ffffff', 'plugins': 'gapro-1', 'gapro.accountid': 'UA-138028-1', 'gapro.trackstarts': 'true', 'gapro.trackpercentage': 'true', 'gapro.tracktime': 'true'};
			flashParams = {'allowscriptaccess': 'always', 'allowfullscreen': 'true'};
			flashAttributes = {'id': 'flvMoviePlayer', 'name': 'flvMoviePlayer'};
			addScriptToHead('http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js', '', 'js');
			window.setTimeout(embedFlash(), 50);
		}
		faderDiv = createEl('div', {'id': 'big-faded-box', 'class': 'hidden-object'}); // Creates div used to fade out rest of page
		if (document.getElementById('footer')) {
			document.getElementById('footer').appendChild(popDiv);
			document.getElementById('footer').appendChild(faderDiv);
		} else {
			document.getElementById('page-container').appendChild(popDiv);
			document.getElementById('page-container').appendChild(faderDiv);
		}
		window.setTimeout(centerPopDiv(), 200);
	}
}

function scrollRelatedProds() {
	var items, end, scrollProd, scrollIt, keepAtTop, oldTop, getScrollTop, pageScroll, counter = 0, getY, scrollInt, dist = 0, panelChanged = false, oldMain = 0,
	footer = document.getElementById('footer'),
	leftPanelBox = document.getElementById('left-panel-specials'),
	nextStop = 24,
	scrollPos = 24,
	start = 24,
	scrollable = false,
	next = document.createElement('div'),
	prev = document.createElement('div'),
	container = document.getElementById('left-panel-specials-scrollbox'),
	leftPanel = document.getElementById('left-panel'),
	mainPanel = document.getElementById('main-panel'),
	isMobile = mobile(navigator.userAgent||navigator.vendor||window.opera);
	
	getY = function (obj) {
		var curtop = 0;
		if (obj.offsetParent) {
			while (1) {
				curtop += obj.offsetTop;
				if (!obj.offsetParent) {
					break;
				}
				obj = obj.offsetParent;
			}
		}
		return curtop;
	};
	
	getScrollTop = function () {
		var scrollTop = document.body.scrollTop;
		if (scrollTop === 0) {
			if (window.pageYOffset) {
				scrollTop = window.pageYOffset;
			} else {
				scrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
			}
		}
		return scrollTop;
	};

	keepAtTop = function () {
		return function () {
			var scrollY = getScrollTop(),
			leftSize = leftPanel.offsetHeight + (leftPanelBox.className !== '' ? leftPanelBox.offsetHeight : 0);
			footerY = getY(footer);
			if (mainPanel.offsetHeight !== oldMain) {
				oldMain = mainPanel.offsetHeight;
				panelChanged = true;
			}
			if (mainPanel.offsetHeight > leftSize || panelChanged) {
				if (scrollY !== pageScroll || panelChanged) {
					panelChanged = false;
					pageScroll = scrollY;
					if (leftPanelBox.className === '' && oldTop !== leftPanelBox.offsetTop) {
						oldTop = leftPanelBox.offsetTop + 115;
					}
					if (pageScroll > oldTop) {
						if ((footerY - pageScroll) < (leftPanelBox.offsetHeight + 6)) {
							leftPanelBox.className = 'left-panel-absolute';
						} else if (leftPanelBox.className !== 'left-panel-static') {
							leftPanelBox.className = 'left-panel-static';
						}
					} else if (leftPanelBox.className !== '') {
						leftPanelBox.className = '';
					}
				}
			} else if (leftPanelBox.className !== '') {
				leftPanelBox.className = '';
				panelChanged = true;
			}
			if (scrollable) {
				if (counter === 50) {
					window.setTimeout(scrollProd(-200), 0);
				} else {
					counter++;
				}
			}
		};
	};
	
	scrollIt = function () {
		return function () {
			var diff = dist / 8;
			diff = Math.ceil(Math.abs(diff)) * Math.round(diff / Math.abs(diff));
			dist -= diff;
			scrollPos += diff;
			container.style.top = scrollPos + 'px';
			if (dist === 0) {
				next.onclick = scrollProd(-200);
				prev.onclick = scrollProd(200);
				window.clearInterval(scrollInt);
				counter = 0;
			}
		};
	};
	
	scrollProd = function (dir) {
		return function () {
			if (next.onclick !== null) {
				next.onclick = null;
				prev.onclick = null;
			}
			if (dir < 0) {
				if (nextStop === end) {
					nextStop = start;
					container.style.top = start + 'px';
					scrollPos = start;
				}
			} else {
				if (nextStop === start) {
					nextStop = end;
					container.style.top = end + 'px';
					scrollPos = end;
				}
			}
			counter = 0;
			nextStop += dir;
			dist = dir;
			scrollInt = window.setInterval(scrollIt(), 20);
		};
	};
	
	// init
	if (container && !isMobile) {
		items = getElementsByClassName(container, 'left-panel-specials-item', 'div');
		
		if (items.length > 1) {
			leftPanelBox.style.height = '424px';
			if (items.length > 2) {
				leftPanelBox.style.height = '624px';
				if (items.length > 3) {
					container.appendChild(items[0].cloneNode(true));
					container.appendChild(items[1].cloneNode(true));
					container.appendChild(items[2].cloneNode(true));
					end = (items.length * -200) + 24;
					container.style.height = (items.length + 3) * 200 + 'px';
					container.style.top = start + 'px';
					next.id = 'next-button';
					next.onclick = scrollProd(-200);
					container.parentNode.appendChild(next);
					prev.id = 'prev-button';
					prev.onclick = scrollProd(200);
					container.parentNode.appendChild(prev);
					scrollable = true;
				}
			}
		}
		oldTop = leftPanelBox.offsetTop + 115;
		pageScroll = getScrollTop();
		window.setInterval(keepAtTop(), 100);
	}
}

// makes tabs work
function Tabs(tabsContainerId, tabContainerClass, tabNameClass, resizeTabs, secondaryContainerId) {
	var i, tabs, tabsTwo, tabWidth, currentTab, active, thisWidth,
	tabsContainer = document.getElementById(tabsContainerId),
	tabsContainerTwo = document.getElementById(secondaryContainerId),
	ie = getIEVersion(),
	
	tabClickHandler = function (self) {
		return function () {
			currentTab.parentNode.className = 'tab-enabled';
			self.parentNode.className = 'tab-active';
			currentTab = self;
			return false;
		};
	},
	
	tabHoverHandler = function (hover) {
		return function () {
			this.className = tabNameClass + (hover ? ' tab-name-hover' : '');
		};
	};
	
	this.showTab = function (tabIndex) {
		if (tabs.length > tabIndex) {
			tabClickHandler(tabs[tabIndex])();
		}
	};
	
	if (tabsContainer) {
		tabsContainer.className = tabContainerClass;
		tabs = getElementsByClassName(tabsContainer, tabNameClass, 'div');
		if (tabs.length > 0) {
			if (resizeTabs) {
				tabWidth = 5;
				for (i = 0; i < tabs.length; i++) {
					if (tabs[i].parentNode.className === 'tab-active') {
						active = true;
					} else {
						active = false;
						tabs[i].parentNode.className = 'tab-active';
					}
					thisWidth = tabs[i].offsetWidth + 20;
					tabs[i].style.left = tabWidth + 'px';
					tabs[i].style.width = thisWidth + 'px';
					tabWidth += thisWidth;
					if (!active) {
						tabs[i].parentNode.className = 'tab-enabled';
					}
				}
			} else {
				tabs[tabs.length - 1].style.marginRight = '0';
			}
			for (i = 0; i < tabs.length; i++) {
				if (tabs[i].parentNode.className === 'tab-active') {
					currentTab = tabs[i];
				}
				if (tabs[i].parentNode.className !== 'tab-disabled') {
					if (!tabs[i].getElementsByTagName('a')[0]) {
						tabs[i].onclick = tabClickHandler(tabs[i]);
					}
					tabs[i].onmouseover = tabHoverHandler(true);
					tabs[i].onmouseout = tabHoverHandler(false);
				}
			}
			if (tabsContainerTwo) {
				tabsTwo = tabsContainerTwo.getElementsByTagName('a');
				for (i = 0; i < tabsTwo.length; i++) {
					tabsTwo[i].onclick = tabClickHandler(tabs[i]);
				}
			}
		}
	}
}

function BannerScroll(banners) {
	var scrollDiv, scrollMain, scrollCp, i, l, theLink = [], theLink2 = [], scrollLeft = 0, pauseButton, paused = false, whereToInsertCode, whereToInsert, nextButton, prevButton, smallScrollBox, imageLink, banTotal, lastWidth = 0, resizeInt, scrollContain, smallImg = [], thumbRight, scrollPosBox, scrollPosBox2, smallScrollLeft, scrollPosWidth, smallScrollLeft2, bannerHeight, smallBanHeight, counter = 39, currentBan = 0, scrollInt = null, dist = 0,
	isMobile = mobile(navigator.userAgent || navigator.vendor || window.opera),
	
	rand = function () {
		return Math.random() - 0.5;
	},
	
	runStop = function (isOver) {
		return function () {
			if (this.id === 'scroller-run-stop') {
				if (pauseButton.className === 'show-pause') {
					this.blur();
					pauseButton.className = 'show-play';
					paused = true;
					counter = 0;
				} else {
					this.blur();
					pauseButton.className = 'show-pause';
					paused = false;
					counter = 39;
				}
			} else {
				if (pauseButton.className === 'show-pause') {
					paused = (isOver) ? true : false;
					counter = 0;
				}
			}
		};
	},
	
	smallScroller = function () {
		smallScrollLeft = (scrollLeft / 9);
		if (-smallScrollLeft > smallScrollBox.offsetWidth) {
			smallScrollLeft = 0;
		}
		scrollPosBox.style.left = -smallScrollLeft + 'px';
		smallScrollLeft2 = -smallScrollLeft + scrollPosWidth;
		if (smallScrollLeft2 > smallScrollBox.offsetWidth) {
			smallScrollLeft2 = (smallScrollLeft2 - smallScrollBox.offsetWidth) - scrollPosWidth;
			scrollPosBox2.style.left = smallScrollLeft2 - 2 + 'px';
		} else {
			scrollPosBox2.style.left = -scrollPosWidth + 'px';
		}
	},
	
	disableEvents = function () {
		nextButton.onclick = prevButton.onclick = pauseButton.onclick = scrollDiv.onmouseover = scrollDiv.onmouseout = null;
		for (i = 0, l = theLink2.length; i < l; i++) {
			theLink2[i].onclick = null;
		}
	},
	
	enableEvents = function () {
		nextButton.onclick = goTo('next');
		prevButton.onclick = goTo('prev');
		pauseButton.onclick = runStop();
		scrollDiv.onmouseover = runStop(true);
		scrollDiv.onmouseout = runStop(false);
		for (i = 0, l = theLink2.length; i < l; i++) {
			theLink2[i].onclick = goTo(i);
		}
	},
	
	scrollMe = function () {
		return function () {
			var diff = dist / 8;
			diff = Math.ceil(Math.abs(diff)) * Math.round(diff / Math.abs(diff));
			dist -= diff;
			scrollLeft = scrollLeft - diff;
			if (dist > 0 && (scrollLeft < -banTotal || scrollLeft === -banTotal)) {
				scrollLeft += banTotal;
			} else if (scrollLeft > 0) {
				scrollLeft -= banTotal;
			}
			scrollDiv.style.left = scrollLeft + 'px';
			smallScroller();
			if (dist === 0) {
				enableEvents();
				window.clearInterval(scrollInt);
			}
		};
	},
	
	goTo = function (pos) {
		return function () {
			var left, right, direction;
			if (pos !== currentBan) {
				if (this.id && this.id.match('scroller')) {
					this.blur();
				}
				disableEvents();
				if (pos === 'next') {
					pos = (currentBan === banners.length - 1) ? 0 : currentBan + 1;
				} else if (pos === 'prev') {
					pos = (currentBan === 0) ? banners.length - 1 : currentBan - 1;
				}
				if (pos > currentBan) {
					right = pos - currentBan;
					left = currentBan + (banners.length - pos);
				} else {
					right = pos + (banners.length - currentBan);
					left = currentBan - pos;
				}
				direction = (left < right) ? -left : right;
				dist = direction * 186;
				currentBan = pos;
				scrollInt = window.setInterval(scrollMe(), 20);
				counter = 0;
			}
			return false;
		};
	},
	
	windowResize = function () {
		return function () {
			if (!paused) {
				if (counter === 40) {
					window.setTimeout(goTo('next'), 0);
					counter = 0;
				} else {
					counter++;
				}
			}
			if (lastWidth !== document.body.offsetWidth) {
				lastWidth = document.body.offsetWidth;
				scrollContain.style.width = scrollMain.offsetWidth + 'px';
				scrollPosWidth = scrollContain.offsetWidth / 9;
				scrollPosBox.style.width = scrollPosBox2.style.width = scrollPosWidth + 'px';
				smallScroller();
			}
		};
	},
	
	thumbOver = function (num) {
		return function () {
			smallImg[num].className = (smallImg[num].className === 'scroller-thumb') ? 'top-nav-hidden' : 'scroller-thumb';
		};
	};
	
	// init
	if (banners && !isMobile) {
		banners.sort(rand);
		bannerHeight = 326;
		smallBanHeight = 70;
		imageLink = php_layout_full_path + '/images/slides/';
		banTotal = banners.length * 186;
		
		scrollMain = createEl('div', {'id' : 'scroller-main-container'});
		scrollMain.style.height = bannerHeight + 30 + 'px';
		
		scrollContain = createEl('div', {'id' : 'scroller-banners-container'}, scrollMain);
		scrollContain.style.height = bannerHeight + 1 + 'px';
		
		scrollCp = createEl('div', {'id' : 'scroller-control-panel'}, scrollMain);
		pauseButton = createEl('div', {'id' : 'scroller-run-stop'}, scrollCp);
		pauseButton.className = 'show-pause';
		
		nextButton = createEl('div', {'id' : 'scroller-next-button'}, scrollCp);
		prevButton = createEl('div', {'id' : 'scroller-prev-button'}, scrollCp);
		
		smallScrollBox = createEl('div', {'id' : 'scroller-small-box'}, scrollCp);
		scrollPosBox = createEl('div', {'class' : 'scroller-position-box'}, smallScrollBox);
		scrollPosBox2 = createEl('div', {'class' : 'scroller-position-box'}, smallScrollBox);
		
		scrollDiv = createEl('div', {'id' : 'scroller-banners'}, scrollContain);
		scrollDiv.style.width = (banTotal * 2) + 'px';
		thumbRight = (banners.length * 20) + 20;
		for (i = 0, l = banners.length; i < l; i++) {
			theLink[i] = createEl('a', {'href' : banners[i].url}, scrollDiv);
			theLink[i].innerHTML = '<img src="' + imageLink + banners[i].imageId + '.jpg" alt="' + banners[i].alt + '" width="185" height="' + bannerHeight + '" style="display:inline;">';
			theLink2[i] = createEl('a', {'href' : '#', 'id' : ('scroller-thumb' + i)}, smallScrollBox);
			theLink2[i].innerHTML = i + 1;
			theLink2[i].onmouseover = theLink2[i].onmouseout = thumbOver(i);
			smallImg[i] = createEl('img', {'src' : imageLink + 'small/' + banners[i].imageId + '.jpg', 'alt' : banners[i].alt, 'class' : 'top-nav-hidden', 'width' : 40, 'height' : smallBanHeight}, scrollContain);
			smallImg[i].style.right = thumbRight + 'px';
			thumbRight -= 20;
		}
		for (i = 0, l = theLink.length; i < l; i++) {
			scrollDiv.appendChild(theLink[i].cloneNode(true));
		}
		if (document.getElementById('breadcrumbs')) {
			whereToInsertCode = document.getElementById('breadcrumbs').nextSibling;
			whereToInsert = whereToInsertCode.parentNode;
		} else {
			whereToInsert = document.getElementById('main-panel');
			whereToInsertCode = whereToInsert.firstChild;
		}
		if (whereToInsertCode) {
			whereToInsert.insertBefore(scrollMain, whereToInsertCode);
		} else if (whereToInsert) {
			whereToInsert.appendChild(scrollMain);
		}
		enableEvents();
		windowResize()();
		smallScroller();
		resizeInt = window.setInterval(windowResize(), 100);
	}
}

// Creates the tip boxes and handles the hiding and showing
function TipBox(tipParent, tipText, specialCase) {
	var tipBody, tipPointer, container, timer = null, showTip = false, x, y,
	parent = tipParent,
	text = tipText,
	
	hideShow = function () {
		return function () {
			if (showTip) {
				container.className = 'tip-container';
				x = (specialCase) ? x - 240 : x;
				container.style.top = y + 'px';
				container.style.left = x + 'px';
			} else {
				container.className = 'tip-container-hidden';
			}
			timer = null;
		};
	},
	
	// mouse over event
	eventOverOut = function () {
		return function (e) {
			if (container.className === 'tip-container-hidden') {
				if (timer === null) {
					if (!e) {
						e = window.event;
					}
					if (e.pageX || e.pageY) {
						x = e.pageX;
						y = e.pageY;
					} else if (e.clientX || e.clientY) {
						x = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
						y = e.clientY + document.body.scrollTop	+ document.documentElement.scrollTop;
					}
					x -= 30;
					y += 10;
					showTip = true;
					timer = window.setTimeout(hideShow(), 300);
				} else {
					showTip = false;
					window.clearTimeout(timer);
					timer = null;
				}
			} else {
				if (timer === null) {
					showTip = false;
					timer = window.setTimeout(hideShow(), 300);
				} else {
					showTip = false;
					window.clearTimeout(timer);
					timer = null;
				}
			}
		};
	},
	
	// Wrap a parent in a span for styling
	wrapParent = function () {
		var guts, tipSpan;
		guts = parent.innerHTML;
		tipSpan = document.createElement('span');
		tipSpan.className = 'tip';
		tipSpan.innerHTML = guts;
		parent.innerHTML = '';
		parent.appendChild(tipSpan);
	},
	
	// Creates tip
	createTip = function () {
		var footer = document.getElementById('footer');
		
		tipBody = document.createElement('div');
		tipBody.className = 'tip-body';
		tipBody.innerHTML = text;
	
		tipPointer = document.createElement('div');
		tipPointer.className = 'tip-pointer';
		if (specialCase) {
			tipPointer.style.left = '250px';
		}
		
		container = document.createElement('div');
		container.className = 'tip-container-hidden';
		container.appendChild(tipBody);
		container.appendChild(tipPointer);
		container.onmouseover = eventOverOut();
		container.onmouseout = eventOverOut();
		
		footer.appendChild(container);
		
		parent.onmouseover = eventOverOut();
		parent.onmouseout = eventOverOut();
	};
	
	this.resetTip = function (newParent) {
		parent = newParent;
		wrapParent();
		parent.onmouseover = eventOverOut();
		parent.onmouseout = eventOverOut();
	};
	
	// init
	if (parent && text) {
		wrapParent();
		createTip();
	}
}

function TimedHover(obj, normalClass, hoverClass, timeOver, timeOut) {
	var timer = null, show = false,
	
	hideShow = function () {
		return function () {
			obj.className = show ? hoverClass : normalClass;
			timer = null;
		};
	},
	
	eventOverOut = function () {
		return function () {
			if (obj.className === hoverClass) {
				if (timer === null) {
					show = false;
					timer = window.setTimeout(hideShow(), timeOut);
				} else {
					show = false;
					window.clearTimeout(timer);
					timer = null;
				}
			} else {
				if (timer === null) {
					show = true;
					timer = window.setTimeout(hideShow(), timeOver);
					obj.onmouseout = eventOverOut();
				} else {
					show = false;
					window.clearTimeout(timer);
					timer = null;
				}
			}
		};
	};
	
	this.closeMe = function () {
		obj.onmouseout = null;
		obj.className = normalClass;
		if (timer !== null) {
			window.clearTimeout(timer);
			timer = null;
		}
	};
	
	this.enable = function () {
		obj.onmouseover = obj.onmouseout = eventOverOut();
	};
}

function addTimedHovers() {
	var dealsObj, shipObj,
	cartDiv = document.getElementById('header-shopping-cart'),
	headerDeals = document.getElementById('header-dropdown-deals'),
	headerShipping = document.getElementById('header-dropdown-free-shipping'),
	headerContact = document.getElementById('header-contact'),
	headerCartClose = document.getElementById('cart-close-link'),
	
	closeIt = function () {
		return function () {
			cartHoverObj.closeMe();
			return false;
		};
	};
	
	// time delay on shopping cart (V. Nguyen)
	if (cartDiv) {
		cartHoverObj = new TimedHover(cartDiv, 'header-shopping-cart-link', 'header-shopping-cart-link-hover', 0, 800);
		if (headerContact) {
			headerContact.onmouseover = closeIt();
		}
		if (headerCartClose) {
			headerCartClose.onclick = closeIt();
		}
		if (!document.getElementById('header-cart-empty')) {
			cartHoverObj.enable();
		}
	}
	if (headerDeals) {
		dealsObj = new TimedHover(headerDeals, 'header-dropdown', 'header-dropdown-hover', 200, 0);
		dealsObj.enable();
	}
	if (headerShipping) {
		shipObj = new TimedHover(headerShipping, 'header-dropdown', 'header-dropdown-hover', 200, 0);
		shipObj.enable();
	}
}

function leftMenu() {
	var listItems, i, l, list = document.getElementById('left-panel-menu'), overList = false, timer = null, show = false, lastLi = -1, liBottom = [],
	
	hideShow = function (num) {
		return function () {
			if (show) {
				var div = listItems[num].getElementsByTagName('div')[0];
				overList = true;
				listItems[num].className = 'left-menu-hover';
				if (div.offsetHeight < liBottom[num]) {
					div.style.top = (liBottom[num] - div.offsetHeight) + 'px';
				}
				if (lastLi !== -1 && lastLi !== num) {
					listItems[lastLi].className = 'left-menu';
				}
				lastLi = num;
			} else {
				listItems[num].className = 'left-menu';
				lastLi = -1;
				overList = false;
			}
			timer = null;
		};
	},
	
	eventOver = function (num, over) {
		return function () {
			var time = over ? (overList ? 0 : 240) : 240;
			if (timer !== null) {
				window.clearTimeout(timer);
				timer = null;
			}
			show = over;
			timer = window.setTimeout(hideShow(num), time);
		};
	};
	
	if (list) {
		listItems = list.getElementsByTagName('li');
		for (i = 0, l = listItems.length; i < l; i++) {
			if (listItems[i].className === 'left-menu') {
				listItems[i].onmouseover = eventOver(i, true);
				listItems[i].onmouseout = eventOver(i, false);
				liBottom[i] = (listItems[i].offsetTop) + 26;
			}
		}
	}
}

function keepCartOnScreen() {
	var cart = document.getElementById('header-support-cart'), lastWidth = 0,
	
	resize = function () {
		return function () {
			var width = (window.innerWidth) ? window.innerWidth : document.documentElement.clientWidth + 16, right;
			if (lastWidth !== width) {
				lastWidth = width;
				if (lastWidth < 996) {
					right = 996 - lastWidth;
					if (right < 401) {
						cart.style.right = right + 'px';
					}
				} else {
					cart.style.right = '23px';
				}
			}
		};
	};
	
	// init
	if (cart) {
		window.setInterval(resize(), 20);
	}
}

// "subscribe to newsletter" (D. Naumov) (Optimized by M. Fayman)
function classNewsletter() {
	var blinkInterval, blinkCount = 0, blinkWhite = false,
	emailForm = document.getElementById('newsletterFrm'),
	emailSubmitButton = document.getElementById('email-submit-button'),
	errorMessage = document.getElementById('email-format-error'),
	successMessage = document.getElementById('subscribe-success'),
	emailInput = document.getElementById('newsletter-input'),
	enterMessage = document.getElementById('enter-email'),
	
	blinkError = function () {
		return function () {
			if (blinkCount < 4) {
				errorMessage.style.color = (blinkWhite) ? '#cc0000' : '#ffffff';
				blinkWhite = !blinkWhite;
				blinkCount++;
			} else {
				window.clearInterval(blinkInterval);
				blinkCount = 0;
			}
		};
	},
	
	// JSONP submit to phplist
	emailSubmit = function () {
		return function () {
			var query = 'http://enews.opticsplanet.com?p=subscribe&id=1&store=rangefinders&jsonp=',
			filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
			
			if (emailInput.value !== '' && emailInput.value !== 'your@email.com' && filter.test(emailInput.value)) {
				query += emailInput.value;
				addScriptToHead(query, '', 'js');
			} else {
				enterMessage.style.display = 'none';
				errorMessage.style.display = 'block';
				blinkInterval = window.setInterval(blinkError(), 100);
			}
			return false;
		}
	};
	
	// Subscription confirmation, JSONP response from phplist 
	this.emailResponse = function (status) {
		if (status === 'added') {
			errorMessage.style.display = emailForm.style.display = enterMessage.style.display = 'none';
			successMessage.style.display = 'block';
		} else if (status === 'error') {
			alert("subscription error");
		}
		return false;
	};

	// constructor
	if (emailForm) {
		emailForm.onsubmit = emailSubmit();
	}
} // end of classNewsletter

// feedback forms popup stuff (D. Naumov) (Optimized by M. Fayman)
function classFeedbackForm() {
	var formFrame,
	divLargeWrapper = createEl('div', {'id': 'help-large-wrapper'}),
	divSmallWrapper = createEl('div', {'id': 'help-small-wrapper'}, divLargeWrapper),
	helpWindow = createEl('div', {'id': 'help-window'}, divSmallWrapper),
	helpHeader = createEl('div', {'id': 'help-header'}, helpWindow),
	helpCloseButton = createEl('div', {'id': 'help-close-button'}, helpHeader),
	spanTitle = createEl('span', {'id': 'span-title'}, helpHeader),
	linkEmailThisPage = document.getElementById('email-icon'),
	linkRFQ = document.getElementById('icon-link-price_quote'),
	linkPriceMatch = document.getElementById('icon-link-best_price'),
	linkExpertAdvice = document.getElementById('icon-link-ask_an_expert'),
	linkDealNotification = document.getElementById('icon-link-deal_request'),
	linkCallToOrder = document.getElementById('call-to-order-button'),
	link2CallToOrder = document.getElementById('call-to-order-link'),
	productCode = document.getElementById('product-code'),
	feedbackData = {
		'rfq' : {'title' : 'RFQ'},
		'es' : {'title' : 'Email Support'},
		'pm' : {'title' : 'Price Match'},
		'ea' : {'title' : 'Expert Advice'},
		'dn' : {'title' : 'Deal Notification'},
		'etp' : {'title' : 'Email This Page'},
		'cto' : {'title' : 'Call To Order'}
	},
	
	openFormWindow = function (type) {
		return function () {
			var formFrame = document.getElementById('form-frame'),
			isIE6 = /msie|MSIE 6/.test(navigator.userAgent);
			if (isIE6) {
				window.scrollTo(0, 0);
			}
			if (spanTitle && formFrame) {
				spanTitle.innerHTML = feedbackData[type].title;
				formFrame.src = this.href.replace(/fullsize|window/, 'iframe');
				if (productCode) {
					formFrame.src = formFrame.src.replace(/~product-id.+~/i, '~' + productCode.innerHTML + '~');
				}
				formFrame.style.visibility = 'hidden';
				helpWindow.style.display = 'block';
			}
			return false;
		};
	},
	
	closeButton = function () {
		return function () {
			helpWindow.style.display = 'none';
			return false;
		};
	};
	
	this.closeFormWindow = function () {
		closeButton()();
		return false;
	};
	
	// constructor
	if (/msie|MSIE/.test(navigator.userAgent)) {
		formFrame = document.createElement('p');
		formFrame.innerHTML = '<iframe id="form-frame" width="650" height="1500" allowtransparency="true" frameborder="no" scrolling="no" onload="this.style.visibility = \'visible\';"></iframe>';
		helpWindow.appendChild(formFrame);
	} else {
		formFrame = createEl('iframe', {'id': 'form-frame', 'width': '650', 'height': '1500', 'allowtransparency': 'true', 'frameborder': 'no', 'scrolling': 'no', 'onload': 'this.style.visibility = "visible";'}, helpWindow);
	}
	helpCloseButton.onclick = closeButton();
	document.body.insertBefore(divLargeWrapper, document.body.firstChild);
	if (linkEmailThisPage) {
		linkEmailThisPage.onclick = openFormWindow('etp');
	}
	if (linkRFQ) {
		linkRFQ.onclick = openFormWindow('rfq');
	}
	if (linkPriceMatch) {
		linkPriceMatch.onclick = openFormWindow('pm');
	}
	if (linkExpertAdvice) {
		linkExpertAdvice.onclick = openFormWindow('ea');
	}
	if (linkDealNotification) {
		linkDealNotification.onclick = openFormWindow('dn');
	}
	if (linkCallToOrder) {
		linkCallToOrder.onclick = openFormWindow('cto');
	}
	if (link2CallToOrder) {
		link2CallToOrder.onclick = openFormWindow('cto');
	}
}; // end of classFeedbackForm

// function for resizing confirmation popup
function helperResizeForCloseScreen() {
	window.scrollTo(0, 0);
}

function printPage() {
	var printLink = document.getElementById('print-icon');
	if (printLink) {
		printLink.onclick = function () {
			return function () {
				window.print();
				return false;
			};
		};
	}
}

// Fade objects
function Fade(obj, maxOpac) {
	var timer = null, opac = 0,
	
	setOpacity = function (opacity) {
		opacity = '' + (opacity / 5);
		obj.style.opacity = opacity;		// For CSS 3 compliant browsers
		obj.style["-moz-opacity"] = opacity;	// For old FF
		obj.style.filter = 'alpha(opacity=' + opacity * 100 + ')';	// For IE
	},
	
	fade = function (fadeStop, show) {
		return function () {
			setOpacity(opac);
			if (opac === fadeStop) {
				window.clearInterval(timer);
				timer = null;
				if (!show) {
					obj.style.display = 'none';
				}
			} else {
				opac += show ? 1 : -1;
				if (show) {
					obj.style.display = 'block';
				}
			}
		};
	};
	
	this.show = function (show) {
		var stopAt = show ? maxOpac : 0;
		if (timer === null) {
			timer = window.setInterval(fade(stopAt, show), 50);
		}
	};
}

function setupTipBoxes() {
	var i, l, special,
	ctoTips = getElementsByClassName(document, 'cto-tip-me', 'span'),
	tooLowTips = getElementsByClassName(document, 'toolow', 'a');
	
	for (i = 0, l = ctoTips.length; i < l; i++) {
		special = (ctoTips[i].parentNode.parentNode.className !== 'left-panel-specials-item') ? true : false;
		TipBox(ctoTips[i], 'Please call our phone sales department toll free at 800-504-5994 or go to the product page and click the Call To Order button to fill out the form for more information on this item.', special);
	}
	for (i = 0, l = tooLowTips.length; i < l; i++) {
		special = (tooLowTips[i].parentNode.parentNode.className !== 'left-panel-specials-item') ? true : false;
		if (tooLowTips[i].getElementsByTagName('span').length < 1) {
			TipBox(tooLowTips[i], 'This indicates an additional discount is in effect. Due to MAP (Minimum Advertised Price) Policy we cannot display the discounted price here.', special);
		}
	}
}

// swap Departments link to below selectors and put Narrow By span in its place on search page when selectors exist
function addNarrowBy() {
	var narrowBySpan,
	selectors = document.getElementById('selectors-container'),
	deptLink = document.getElementById('header-link-departments');
	
	if (selectors && deptLink && deptLink.parentNode.id === 'header-left') {
		narrowBySpan = createEl('span', {'id' : 'header-link-narrowby'});
		narrowBySpan.innerHTML = 'Narrow by';
		deptLink.parentNode.insertBefore(narrowBySpan, deptLink);
		selectors.parentNode.insertBefore(deptLink, selectors.nextSibling);
	}
}

function copyPagination() {
	var i, l,
	fromNode = document.getElementById('pagination-top'),
	toNode = document.createElement('div');

	if (fromNode) {
		toNode.id = 'pagination-bottom';
		for (i = 0, l = fromNode.childNodes.length; i < l; i++) {
			toNode.appendChild(fromNode.childNodes[i].cloneNode(true));
		}
		fromNode.parentNode.appendChild(toNode);
	}
}

// collapsible multiple breadcrumbs (V. Nguyen)
function breadcrumbsHider(){	
	var i,
	container = document.getElementById('breadcrumbs'),
	toggleButton, div, clearFloat
	buttonClick = function (){
		return function () {
			if (!container.className.match(/show-breadcrumbs/)) {
				container.className += 'show-breadcrumbs';
			} else {
				container.className = container.className.replace('show-breadcrumbs', '');
			}
		}
	};
	if (container){
			div = container.getElementsByTagName('div');
			if (div.length > 2){
				for ( i = 2 ; i < div.length ; i++ ){
					div[i].className += ' hidable-breadcrumb';
				}
				container.className += 'breadcrumbs-with-js show-breadcrumbs';
				toggleButton = createEl('span', {'id': 'breadcrumbs-arrow'}, container);
				toggleButton.onclick = buttonClick();
			}
	}
	
	
	var i,
	container_bottom = document.getElementById('breadcrumbs_bottom'),
	toggleButton, div, clearFloat
	buttonClick = function (){
		return function () {
			if (!container_bottom.className.match(/show-breadcrumbs/)) {
				container_bottom.className += 'show-breadcrumbs';
			} else {
				container_bottom.className = container_bottom.className.replace('show-breadcrumbs', '');
			}
		}
	};
	if (container_bottom){
			div = container_bottom.getElementsByTagName('div');
			if (div.length > 2){
				for ( i = 2 ; i < div.length ; i++ ){
					div[i].className += ' hidable-breadcrumb';
				}
				container_bottom.className += 'breadcrumbs-with-js show-breadcrumbs';
				toggleButton = createEl('span', {'id': 'breadcrumbs-bottom-arrow'}, container_bottom);
				toggleButton.onclick = buttonClick();
			}
	}
}

function Selectors(listNum) {
	var subList, subListItems, collapse, numNonCollapse, localCollapseAfter, button, i, j, trimHeight, resize, tick, singleClick, eventClick, eventOverOut, subListParent, parentWidth, imageInSelectors, subListItem, mainList, flashButton = false, linkOverOut, 
	container = document.getElementById('object-list'),
	subLists = null, // contains the sublists
	totalWidths = 20, // contains total width of all sublists
	eachWidth = [], // contains orig widths of each sublist
	maxWidth = 0, // contains lagest single width of the sublists
	collapseAfter = 5, // number to start collapsing items after
	currentList = null, // list the mouse is over
	lastList = null, // last list mouse was over
	tickout = 0, // tick count
	reqTicks = 66, // must be even
	lastWidth = 0; // width of window to check if resize code should run
	mainList = getElementsByClassName(container, 'sub-page-selector', 'ul')[listNum];
	
	// handles resizing the height of unfilled selectors
	trimHeight = function (start, end) {
		var subListItems, length, newHeight, i;
		length = 0;
		for (i = start; i < end; i++) {
			subListItems = subLists[i].getElementsByTagName('li');
			length = (subListItems.length > length) ? subListItems.length : length;
		}
		if (length < 6) {
			for (i = start; i < end; i++) {
				newHeight = 19;
				newHeight += length * 20;
				subLists[i].parentNode.style.maxHeight = newHeight + 'px';
				subLists[i].parentNode.style.minHeight = newHeight + 'px';
				subLists[i].parentNode.style.height = (oldIE) ? newHeight + 'px' : '';
			}
		} else {
			for (i = start; i < end; i++) {
				subLists[i].parentNode.style.maxHeight = '';
				subLists[i].parentNode.style.minHeight = '';
				oldIE = 0;
				subLists[i].parentNode.style.height = (oldIE) ? '135px' : '';
			}
		}
	};
	
	// handles resizing selectors
	resize = function () {
		return function () {
			var subList, single, lastTop, i, j;
			if (lastWidth !== document.body.offsetWidth) {
				lastWidth = document.body.offsetWidth;
				if (subLists.length > 1) {
					lastTop = 0;
					j = 0;
					for (i = 0; i < subLists.length; i++) {
						subList = subLists[i];
						subListParent = subList.parentNode;
						single = (subListParent.className === 'single-selectors-more' || subListParent.className === 'single-selectors-less') ? true : false;
						
						if (totalWidths < container.offsetWidth) {
							if (document.all && (i + 1) === subList.length) {
								subListParent.style.marginRight = '1';
							}
							subListParent.style.width = eachWidth[i] + 'px';
							if (single) {
								subListParent.style.backgroundPosition = eachWidth[i] - 10 + 'px 9px';
							}
						} else {
							if (document.all && (i + 1) === subList.length) {
								subListParent.style.marginRight = '10';
							}
							subListParent.style.width = maxWidth + 'px';
							if (single) {
								subListParent.style.backgroundPosition = maxWidth - 10 + 'px 9px';
							}
						}
						
						if (!single) {
							if (lastTop > 0) {
								if (subListParent.offsetTop !== lastTop) {
									trimHeight(j, i);
									j = i;
									lastTop = subListParent.offsetTop;
									if (j === subLists.length - 1) {
										trimHeight(j, subLists.length);
									}
								} else if (subListParent.offsetTop === lastTop && j !== i) {
									trimHeight(j, i + 1);
								}
							} else {
								lastTop = subListParent.offsetTop;
							}
						}
					}
				} else {
					subLists[0].parentNode.style.width = eachWidth[0] + 'px';
					if (subLists[0].className !== 'single-selectors-more' || subLists[0].className !== 'single-selectors-less') {
						trimHeight(0, 1);
					}
				}
			}
		};
	};
	
	// selectors tickout stuff
	tick = function () {
		return function () {
			var subListItems, button;
			if (currentList !== null) {
				subListItems = currentList.getElementsByTagName('li');
				button = subListItems[subListItems.length - 1];
				
				if (tickout <= reqTicks) {
					tickout++;
					if (tickout >= 50) {
						flashButton = !flashButton;
						button.className = 'sps-button sps-button-hover' + (flashButton ? ' sps-button-flash' : '');
					}

				}
				if (tickout === reqTicks) {
					tickout = 0;
					button.className = 'sps-button sps-button-hover';
					flashButton = false;
				}
			} else {
				if (tickout > 0) {
					tickout = 0;
				}
			}
		};
	};
	
	// single liners click event
	singleClick = function () {
		return function (e) {
			var currentList = this.getElementsByTagName('ul');
			if (this.className === 'single-selectors-more') {
				this.className = 'single-selectors-less';
				currentList[0].className = 'sps-ul-expanded';
			} else {
				this.className = 'single-selectors-more';
				currentList[0].className = '';
			}
		};
	};
	
	// multi liners click event
	eventClick = function () {
		return function (e) {
			var subListItems = this.getElementsByTagName('li');
			button = subListItems[subListItems.length - 1];
			if (this.className === '') {
				currentList = this;
				currentList.className = 'sps-ul-expanded';
				button.innerHTML = '<span class=selectors-button-less>Less</span>';
				currentList = null;
				lastList = null;
			} else {
				subListItems[subListItems.length - 1].innerHTML = '<span class=selectors-button-more>' + (subListItems.length - 6) + ' More</span>';
				this.className = '';
			}
		};
	};
	
	// multi liners mouse over and out event
	eventOverOut = function (mouse) {
		return function (e) {
			var subListItems;
			if (mouse === 'over') {
				if (this.className === '') {
					if (lastList !== this) {
						if (lastList !== null) {
							subListItems = lastList.getElementsByTagName('li');
							subListItems[subListItems.length - 1].style.backgroundPosition = '-400px 0';
						}
						tickout = 0;
					}
					currentList = this;
				}
				subListItems = this.getElementsByTagName('li');
				subListItems[subListItems.length - 1].className = 'sps-button sps-button-hover';
			} else {
				lastList = currentList;
				currentList = null;
				subListItems = this.getElementsByTagName('li');
				subListItems[subListItems.length - 1].className = 'sps-button';
			}
		};
	};
	
	linkOverOut = function (isOver, type) {
		return function (e) {
			if (type === 'single') {
				this.parentNode.parentNode.parentNode.onclick = (isOver) ? null : singleClick();
			} else if (this.parentNode.className.match('sps-li')) {
				this.parentNode.parentNode.onclick = (isOver) ? null : eventClick();
			}
		};
	};
	
	// init
	subLists = mainList.getElementsByTagName('ul');
	if (subLists.length > 0) {
		for (i = 0; i < subLists.length; i++) {
			subList = subLists[i];
			subListParent = subList.parentNode;
			
			// checks for image in selectors and adjusts accordingly
			imageInSelectors = getElementsByClassName(subListParent, 'sort-by-key-image', 'a')[0];
			if (imageInSelectors) {
				subList.style.paddingLeft = '95px';
				imageInSelectors.style.display = 'block';
			}
			
			// expand to get correct widths then collapse again
			subList.className = 'sps-ul-expanded';
			parentWidth = subListParent.offsetWidth + ((subListParent.className === 'single-selectors-more') ? 10 : 0);
			subList.className = '';
			
			if (subListParent.className === 'single-selectors-more') {				// for single liners
				totalWidths += parentWidth + 23;
				eachWidth[i] = parentWidth;
				
				for (j = 0; (subListItem = subList.getElementsByTagName('li')[j]); j++) {
					subListItem.className = 'sps-li-collapsible';
					subListItem.getElementsByTagName('a')[0].onmouseover = linkOverOut(true, 'single');
					subListItem.getElementsByTagName('a')[0].onmouseout = linkOverOut(false, 'single');
				}
				
				subListParent.style.backgroundPosition = eachWidth[i] - 10 + 'px 9px';
				subListParent.onclick = singleClick();
			} else {																// for multi liners
				if (document.all) { // IE hates me
					totalWidths += parentWidth + 14;
					eachWidth[i] = parentWidth - 8;
				} else { // all other browsers
					totalWidths += parentWidth + 10;
					eachWidth[i] = parentWidth - 12;
				}
				
				subListItems = subList.getElementsByTagName('li');
				collapse = false;
				numNonCollapse = 0;
				localCollapseAfter = collapseAfter + ((collapseAfter + 1 === subListItems.length) ? 1 : 0); // don't collapse just one item
				
				// set which items should be able to collapse
				for (j = subListItems.length - 1 ; j >= 0; j--) {
					if (subListItems[j].className === 'sps-li-non-collapsible' && numNonCollapse < localCollapseAfter) {
						numNonCollapse++;
					} else {
						if (localCollapseAfter - numNonCollapse <= j) {
							subListItems[j].className = 'sps-li-collapsible';
							collapse = true;
						}
					}
				}
				
				if (collapse) {
					for (j = subListItems.length - 1 ; j >= 0; j--) {
						subListItems[j].getElementsByTagName('a')[0].onmouseover = linkOverOut(true);
						subListItems[j].getElementsByTagName('a')[0].onmouseout = linkOverOut(false);
					}
					button = document.createElement('li');
					button.className = 'sps-button';
					button.innerHTML = '<span class=selectors-button-more>' + (subListItems.length - 5) + ' More</span>';
					subList.appendChild(button);
					
					subList.onmouseover = eventOverOut('over');
					subList.onmouseout = eventOverOut('out');
					subList.onclick = eventClick();
				}
			}
			
			// find who has the largest width as we loop through sublists
			if (parentWidth > maxWidth) {
				maxWidth = parentWidth;
			}
		}
		resize();
		window.setInterval(resize(), 300);
		window.setInterval(tick(), 50);
	}
}

// HOLIDAY 2010 STUFF
function addHolidayBanners() {
	var container,
	footer = document.getElementById('footer');
	
	if (footer) {
		container = document.createElement('div')
		container.id = 'holiday-footer-banner';
		container.innerHTML = '<div id="holidar-footer-info"><div id="holiday-footer-return"><p>For orders placed between Nov. 1st and Dec. 24th, our Return Policy has been extended through Jan. 10, 2011 or up to 30 days after your order is received, whichever is later. <a href="http://www.rangefinders.com/return-policy.html">Details</a></p></div><div id="holiday-footer-shipping"><p>To receive delivery by Dec 24th for in stock items, you must order by...</p><div id="holiday-footer-shipping-date">Fri. Dec 17, 11 AM CST<br>Tue. Dec 21, 11 AM CST<br>Wed. Dec 22, 11 AM CST<br>Thu. Dec 23, 11 AM CST</div><div>FREE Standard Delivery*<br>3-Day Select Delivery**<br>2-Day Delivery**<br>Overnight Delivery**</div></div><div id="holiday-footer-details">* Free UPS ground shipping applies to most orders over $29.95. For complete details see our Free Shipping Policy.<br>** Additional charges apply.  Shipping deadlines exclude Out of Stock and personalized orders.</div></div><div id="holiday-footer-banner-box"></div>';
		footer.parentNode.insertBefore(container, footer);
	}
}

// checks if newsletter data is in url and adds cookie
function newsletterData() {
 var nlCookie = new Cookie('_opnld'), nldInput,
 data = window.location.search.match(/nldata=[a-z,0-9,\/]+/i);
 if (data) {
  data += '';
  data = data.split('=')[1];
  nlCookie.setValue(data, 168);
 }
 data = nlCookie.getValue();
 if (data && document.getElementById('addToCartForm')) {
  nldInput = document.createElement('input');
  nldInput.type = 'hidden';
  nldInput.name = 'OPNLD';
  nldInput.value = data;
  nldInput.id = 'op-nld';
  document.getElementById('addToCartForm').appendChild(nldInput);
 }
}


function initPage() {
	
	$(document).ready(function(){ 
		$("#main-menu-dropdown li").mouseover(function(){ 
			$(this).addClass("main-menu-active"); 
		}); 
		$("#main-menu-dropdown li").mouseout(function(){ 
			$(this).removeClass("main-menu-active"); 
		}); 
	});

	var ieVersion = getIEVersion();
	
	
	// setup selectors
	objList = document.getElementById('object-list');
	if (objList) {
		selectors = getElementsByClassName(objList, 'sub-page-selector', 'ul');
		for (i = 0; i < selectors.length; i++) {
			window.setTimeout("var selectorsInit" + i + " = new Selectors(" + i + ");", 0);
		}
	}

	
	if (document.domain.match('rangefinders.com') && !document.domain.match('feedback')) {
		// required for classFeedbackForm JS security permissions (D. Naumov)
		document.domain = 'rangefinders.com';
		
		// init feedback forms (D. Naumov)
		classFeedbackForm = new classFeedbackForm();
	}

	// init "subscribe to newsletter" stuff (D. Naumov)
	classNewsletter = new classNewsletter();
	
	// init collapsible multiple breadcrumbs (V. Nguyen)
	breadcrumbsHider();
	
	// start function to keep floating cart on screen with small width
	window.setTimeout('keepCartOnScreen();', 0);
	
	// setup bundles expand and collapse
	window.setTimeout('bundles();', 0);
	
	// fire up selectors event handling if any exist
	//window.setTimeout('selectors();', 0);
	
	// load up image gallery script for product pages
	window.setTimeout('ImageSwapper();', 0);
	
	if (ieVersion !== 6) {
		// load up scroller for left panel related products
		window.setTimeout('scrollRelatedProds();', 0);
	}
	
	// load Collapsible QnA script
	window.setTimeout('QNA();', 0);
	
	// load up left menu hover effects
	window.setTimeout('addTimedHovers();', 0);
	
	// left menu
	window.setTimeout('leftMenu();', 0);
	
	// setup tooltips
	window.setTimeout('setupTipBoxes();', 0);
	
	// setup js for printing page
	window.setTimeout('printPage();', 0);
	
	// check if we need to swap out dept link for narrow by
	window.setTimeout('addNarrowBy();', 0);
	
	// copy top pagination to bottom if its there
	window.setTimeout('copyPagination();', 0);
	
	//init holiday 2010
	// window.setTimeout('addHolidayBanners();', 1);
	
	// checks if newsletter data is in url and adds cookie
	window.setTimeout('newsletterData();', 0);
}
