function showTab(tabname) {
	if (document.getElementById) {
		elem=document.getElementById('tab'+tabname);
		if (elem)
			elem.style.display='block';
	}
	return false;
}
function hideTab(tabname) {
	if (document.getElementById) {
		elem=document.getElementById('tab'+tabname);
		if (elem)
			elem.style.display='none';
	}
	return false;
}

function makeFacilitiesLinks(facilities) {
	if (document.getElementById) {
		
		if (facilities.length==0) {
			var tabfacilities=document.getElementById('tabfacilities');
			var facilitiesTab=document.getElementById('facilitiesTab');
			if (tabfacilities)
				tabfacilities.style.display='none';
			if (facilitiesTab)
				facilitiesTab.style.display='none';
		}
			
		for (var i=0;i<facilities.length;i++) {
			var prevName=facilities[i-1];
			var prevElem=document.getElementById('prev'+facilities[i]);
			var nextElem=document.getElementById('next'+facilities[i]);
			var nextName=facilities[i+1];
			if (prevName) { // do prev link
				var prevLink = document.createElement('a');
				onclick='';
				for (var j=0;j<facilities.length;j++) {
					if (facilities[j]==prevName)
						onclick+="showTab('"+facilities[j]+"');";
					else 
						onclick+="hideTab('"+facilities[j]+"');";
				}
				onclick+='void(0)';
				prevLink.setAttribute('href','javascript:'+onclick);
				var prevLinkText=document.createTextNode(entity('&laquo;') + " previous");
				prevLink.appendChild(prevLinkText);
				prevElem.appendChild(prevLink);
			}
			if (nextName) { // do next link
				var nextLink = document.createElement('a');
				onclick='';
				for (var j=0;j<facilities.length;j++) {
					if (facilities[j]==nextName)
						onclick+="showTab('"+facilities[j]+"');";
					else 
						onclick+="hideTab('"+facilities[j]+"');";
				}
				onclick+='void(0)';
				nextLink.setAttribute('href','javascript:'+onclick);
				var nextLinkText=document.createTextNode("next " +  entity('&raquo;'));
				nextLink.appendChild(nextLinkText);
				nextElem.appendChild(nextLink);
			}
		}
	}
}
//
//						<img src="/images/maraephoto1.jpg" alt="Marae" />
//						<a class="fleft" href="#">&laquo; previous</a><div class="tag">Displaying photo 2  of 3</div><a class="fright" href="#">next &raquo;</a>

function makePhotoDivs(photos) {
	if (document.getElementById) {
		var photoContainer=document.getElementById('photocontainer');
		var allPhotos=document.getElementById('allphotos');
		if (allPhotos) {
			allPhotos.style.display='none';
		}
		var count=photos.length
		for (var i=0;i<count;i++) {
			var prevSrc=photos[i-1];
			var thisSrc=photos[i];
			var nextSrc=photos[i+1];
			var prevID=prevSrc;
			var thisID=thisSrc;
			var nextID=nextSrc;
			if (prevID) {
				prevID=prevID.substr(prevID.lastIndexOf('/')+1);
				prevID=prevID.substr(0,prevID.lastIndexOf('.'));
			}
			if (thisID) {
				thisID=thisID.substr(thisID.lastIndexOf('/')+1);
				thisID=thisID.substr(0,thisID.lastIndexOf('.'));
			}
			if (nextID) {
				nextID=nextID.substr(nextID.lastIndexOf('/')+1);
				nextID=nextID.substr(0,nextID.lastIndexOf('.'));
			}
			//alert('prevSrc: '+prevSrc+' '+prevID+"\n"+'thisSrc: '+thisSrc+' '+thisID+"\n"+'nextSrc: '+nextSrc+' '+nextID);
			var thisDiv = document.createElement('div');
			thisDiv.setAttribute('id','tab_img_'+thisID);
			thisDiv.setAttribute('class','hidden clear image');
			thisDiv.setAttribute('className','hidden clear image');

			var thisImg = document.createElement('img');
			thisImg.setAttribute('src','/images/phpThumb/phpThumb.php?src='+thisSrc+'&w=340&h=300');
			thisDiv.appendChild(thisImg);
			br1 = document.createElement('br');
			br1.setAttribute('className','clear');
			thisDiv.appendChild(br1);
			if (prevID) {
				var prevLink = document.createElement('a');
				onclick='';
				for (var j=0;j<count;j++) {
					linkID=photos[j];
					linkID=linkID.substr(linkID.lastIndexOf('/')+1);
					linkID=linkID.substr(0,linkID.lastIndexOf('.'));
					if (photos[j]==prevSrc)
						onclick+="showTab('_img_"+linkID+"');";
					else 
						onclick+="hideTab('_img_"+linkID+"');";
				}
				onclick+='void(0)';
				prevLink.setAttribute('href','javascript:'+onclick);
				prevLink.setAttribute('class','fleft');
				prevLink.setAttribute('className','fleft');
				var prevLinkText = document.createTextNode( entity('&laquo;') + " previous");
				prevLink.appendChild(prevLinkText);
				thisDiv.appendChild(prevLink);
			}
			tagDiv = document.createElement('div');
			tagDiv.setAttribute('class','tag');
			tagDiv.setAttribute('className','tag');
			tagText = document.createTextNode("Displaying photo "+(i+1)+" of "+count);
			tagDiv.appendChild(tagText);
			thisDiv.appendChild(tagDiv);

			if (nextID) {
				var nextLink = document.createElement('a');
				onclick='';
				for (var j=0;j<count;j++) {
					linkID=photos[j];
					linkID=linkID.substr(linkID.lastIndexOf('/')+1);
					linkID=linkID.substr(0,linkID.lastIndexOf('.'));
					if (photos[j]==nextSrc)
						onclick+="showTab('_img_"+linkID+"');";
					else 
						onclick+="hideTab('_img_"+linkID+"');";
				}
				onclick+='void(0)';
				nextLink.setAttribute('href','javascript:'+onclick);
				nextLink.setAttribute('class','fright');
				nextLink.setAttribute('className','fright');
				var nextLinkText = document.createTextNode("next " + entity('&raquo;'));
				nextLink.appendChild(nextLinkText);
				thisDiv.appendChild(nextLink);
			}
			br2 = document.createElement('br');
			br2.setAttribute('className','clear');
			thisDiv.appendChild(br2);
			photoContainer.appendChild(thisDiv);
		}
		var firstSrc=photos[0];
		if (firstSrc) {
			firstID=firstSrc.substr(firstSrc.lastIndexOf('/')+1);
			firstID=firstID.substr(0,firstID.lastIndexOf('.'));
			showTab('_img_'+firstID);
		}


	}
	
}

function entity(str, mode) {
	str = (str) ? str : "";
	mode = (mode) ? mode : "string";

	var e = document.createElement("div");
	e.innerHTML = str;

	if (mode == "numeric") {
		return "&#" + e.innerHTML.charCodeAt(0) + ";";
	}
	else if (mode == "utf16") {
		var un = e.innerHTML.charCodeAt(0).toString(16);
		while (un.length < 4) un = "0" + un;
		return "\\u" + un;
	}
	else return e.innerHTML;
}