/* 
 * domTab.js 
 * version 2.2
 * written by Chris Heilmann
 * more info: http://www.onlinetools.org/tools/domtab.php
*/

// Hide all elements - added by Darren Ansley
if (document.getElementById && document.getElementsByTagName && document.createElement) {
	document.write('<style type="text/css">#pix div {display:none}</style>');
	if (document.styleSheets) {
		document.write('<style type="text/css">#pix div#pic1 {display:block;}</style>');
	}
}

// Global variables
var currentTab, currentLink;

// Change if you want to use another class for highlighting
var tabHighlightClass='pixon'; 

function initTabs() {
	if(!(document.getElementById && document.createTextNode)) return false;

	// change if you have another main navigation ids for tabbed or normal element id
	var navElement='pixnav';
	var navElementTabbedId='pix';
	var n,as,id,i,cid,re;

	// extract "#anchor" from end of URL
	cid = window.location.toString().match(/#(\w.+)/);
	if (cid && cid[1]) cid = cid[1];

	var n = $(navElement);
	if(!n) return false;
	var as = n.getElementsByTagName('a');

	var re = new RegExp('\\b'+tabHighlightClass+'\\b');
	for (i=0;i<as.length;i++) {	
		as[i].onclick = function() { showTab(this); return false }
		as[i].hideFocus = true;
		id = as[i].href.match(/#(\w.+)/)[1];
		displayVal = "none";
		if( (!cid && i==0) || (id==cid) ) {
			currentTab = id;
			currentLink = as[i];
			displayVal = "block";
		}
		p = $(id);
		if(p) p.style.display=displayVal;
		if(currentLink && !re.test(currentLink.className)) currentLink.className += ' ' + tabHighlightClass;
	}
	if(!currentLink) showTab(as[0]);
}	

function showTab(o) {
	var id = o.href.match(/#(\w.+)/)[1];
	if (id == currentTab) return false;
	ct = $(currentTab);
	if(ct) ct.style.display = 'none'
	if(currentLink) currentLink.className = currentLink.className.replace(tabHighlightClass,'');
	currentTab = id;
	currentLink = o;
	tab = $(currentTab);
	if(tab) tab.style.display='block';
	var re = new RegExp('\\b'+tabHighlightClass+'\\b');
	if(!re.test(o.className)) o.className += ' ' + tabHighlightClass;
}

// If you need to call other scripts onload, change this call
addEvent(window,'load',initTabs);		
