//get url parameter value by name
function getParam(paramName)
{
  var regexS = "[\\?&]"+ paramName +"=([^&#]*)";
  var regex = new RegExp( regexS );
  var tmpURL = window.location.href;
  var results = regex.exec( tmpURL );
  if( results == null )
    return "";
  else
    return results[1];
}

// in photo gallery, sets initally selected thumbnail
function setSelected() {
	try {
		photoID = getParam("photoID");
		document.getElementById(photoID).className = "selected";
	} catch(err) {document.getElementById("ambient1").className = "selected";}
}

// in photo gallery and room photo switchers
function changeMainImage(name) {
	top.document.getElementById("mainGalleryImage").src = "images/"+name+"_lg.jpg";
	allTables = document.getElementsByTagName("table");
		
	for(i=0; i<allTables.length; i++) {
		if(/\bdwlThumbs\b/.test(allTables[i].className)) {
			tdArray = allTables[i].getElementsByTagName("td");
			
			for(j=0; j<tdArray.length; j++) {
				tdArray[j].className = "";
			}
		}
	}
	
	document.getElementById(name).className = "selected";
}

// this function runs the room info switcher
function roomInfoSwitcher(name) {
		
	try {
		changeMainImage(name);
	
		roomInfoArray = document.getElementById("roomInfoContainer").getElementsByTagName("div");
		
		for(i=0; i<roomInfoArray.length; i++) {
			roomInfoArray[i].className = "";
		}
		
		document.getElementById(name+"_room_info").className = "activeRoomInfo";
	
	} catch(err) {}
}


/*********************************************************/
//				 PRODUCTS TO USE UTILITY				 //
/*********************************************************/

// this function display, hides, or grays out the bulbs and fixtures on the 'Products to Use' tab
function activateProductsToUse(lightTrait) {
	// grab the thumbnail links
	bulbsByLinks = document.getElementById("bulbsByTable").getElementsByTagName("a");
	
	// cycle through bulbsByLinks
	for(i = 0; i < bulbsByLinks.length; i++) {
		
		key = dwlMainArray[tabRoomName+"_"+lightTrait][i];
		
		
		// strip classes when not showing a thumb
		if(key == -1) {
			bulbsByLinks[i].className = "";
		}
		
		
		// set class of 'showGray' and remove href		
		if(key == 0) {
			bulbsByLinks[i].removeAttribute('href');
			bulbsByLinks[i].className = "showGray";
		}
		
		
		// set class of 'show' and set href
		if(key > 0) {
			bulbsByLinks[i].href = urlArray[key];
			bulbsByLinks[i].className = "show";
		}
	}
}