//-- -------------------------------------------
//-- NAME: DOM SCRIPTS TO GENERATE ROLLOVERS AND VISIBILITY TOGGLE
//-- PROJECT: REFLEX::PROGEN
//-- CLIENT: NIXON McINNES
//-- DATE: 16/11/2005
//-- -------------------------------------------


window.onload = init;


function init() {
	if (!document.getElementById) return;
	navRollovers();
	showHide();
}


function navRollovers() {
	var aPreLoad = new Array();
	aPreLoad[0] = new Image();
	aPreLoad[0].src = 'images/bgMainNav.gif';

	var aLinks = document.getElementsByTagName('a');

	for (var i = 0; i < aLinks.length; i++) {

		if(aLinks[i].id == 'navHome') {

			aPreLoad[1] = new Image();
			aPreLoad[1].src = 'images/bgMainNavHome.gif';

			aLinks[i].onmouseover = function() {
				document.getElementById('mainNav').style.background = "url('images/bgMainNavHome.gif')";
			}
		}


		if(aLinks[i].id == 'navInfo') {

			aPreLoad[2] = new Image();
			aPreLoad[2].src = 'images/bgMainNavInfo.gif';

			aLinks[i].onmouseover = function() {
				document.getElementById('mainNav').style.background = "url('images/bgMainNavInfo.gif')";
			}
		}

		if(aLinks[i].id == 'navStory') {

			aPreLoad[3] = new Image();
			aPreLoad[3].src = 'images/bgMainNavStory.gif';

			aLinks[i].onmouseover = function() {
				document.getElementById('mainNav').style.background = "url('images/bgMainNavStory.gif')";
			}
		}


		if(aLinks[i].id == 'navQuestions') {

			aPreLoad[3] = new Image();
			aPreLoad[3].src = 'images/bgMainNavQuestions.gif';

			aLinks[i].onmouseover = function() {
				document.getElementById('mainNav').style.background = "url('images/bgMainNavQuestions.gif')";
			}
		}


		if(aLinks[i].id == 'buynowButton') {

			aPreLoad[4] = new Image();
			aPreLoad[4].src = 'images/bgMainNavBuyNow.gif';

			aLinks[i].onmouseover = function() {
				document.getElementById('mainNav').style.background = "url('images/bgMainNavBuyNow.gif')";
			}

		}

		// Generic "Free Sample button" image swap
		if(aLinks[i].className == 'orderFreeSampleButton') {
			var imgObject = aLinks[i].getElementsByTagName('img');
			var offState = imgObject[0].getAttribute('src');
			var ftype = offState.substring(offState.lastIndexOf('.'), offState.length);
			var overState = offState.replace(ftype, '_over'+ftype);

			aPreLoad[5] = new Image();
			aPreLoad[5].src = overState;

			aLinks[i].onmouseover = function() {
				imgObject[0].setAttribute('src', overState);
			}

		}


		aLinks[i].onmouseout = function() {
			document.getElementById('mainNav').style.background = "url('images/bgMainNav.gif')";

			// Swap the "free sample button" back to the off state
			imgObject[0].setAttribute('src', offState);
		}
	}
}





function showHide() {

	if (document.getElementById('nutritionDataTable')) {

		var openPanel = false;

		var tableObject = document.getElementById('nutritionDataTable');
		var tableObjectRows = tableObject.getElementsByTagName('tr');
		for (var i = 0; i < tableObjectRows.length; i++) {
			if (tableObjectRows[i].className == 'activeClosed' || tableObjectRows[i].className == 'activeOpen') {

				tableObjectRows[i].onmouseover = function() {
					var tableObjectRowCols = this.getElementsByTagName('td');

					if (this.className == 'activeClosed') {
						tableObjectRowCols[0].style.background = "#E1E1E1 url('images/bgNutritionArrowOff.gif') no-repeat right";
						tableObjectRowCols[1].style.background = "#C8DCEB";
						tableObjectRowCols[2].style.background = "#D3E1EB";
						tableObjectRowCols[3].style.background = "#DCE3EC";
					}
				}

				tableObjectRows[i].onmouseout = function() {
					var tableObjectRowCols = this.getElementsByTagName('td');

					if (this.className == 'activeClosed') {
						tableObjectRowCols[0].style.background = "#F1F1F1 url('images/bgNutritionArrowOff.gif') no-repeat right";
						tableObjectRowCols[1].style.background = "#E0EBF5";
						tableObjectRowCols[2].style.background = "#E8F0F7";
						tableObjectRowCols[3].style.background = "#EFF5FA";
					}
				}

				tableObjectRows[i].onclick = function() {
					var tableObjectRowCols = this.getElementsByTagName('td');

					var thisID = this.id;
					var thisData = thisID + 'Data';
					var thisDataObject = document.getElementById(thisData);

					// If the data panel is currently hidden, make it visible
					if (thisDataObject.className == 'hide') {

						// First close any other open panel
						if(openPanel != false) {
							var openPanelID = openPanel.id;
							var openPanelData = openPanelID + 'Data';
							var openPanelDataObject = document.getElementById(openPanelData);
							openPanelDataObject.className = 'hide';
							openPanel.className = 'activeClosed';

							var openPanelCols = openPanel.getElementsByTagName('td');
							openPanelCols[0].style.background = "#F1F1F1 url('images/bgNutritionArrowOff.gif') no-repeat right";
							openPanelCols[1].style.background = "#E0EBF5";
							openPanelCols[2].style.background = "#E8F0F7";
							openPanelCols[3].style.background = "#EFF5FA";
						}

						tableObjectRowCols[0].style.background = "#E1E1E1 url('images/bgNutritionArrowOn.gif') no-repeat right";
						this.className = 'activeOpen';
						thisDataObject.className = 'showRow';
						openPanel = this;
					}
					else {
						tableObjectRowCols[0].style.background = "#F1F1F1 url('images/bgNutritionArrowOff.gif') no-repeat right";
						tableObjectRowCols[1].style.background = "#E0EBF5";
						tableObjectRowCols[2].style.background = "#E8F0F7";
						tableObjectRowCols[3].style.background = "#EFF5FA";
						this.className = 'activeClosed';
						thisDataObject.className = 'hide';
						openPanel = false;
					}
				}
			}
		}
	}
}