function _addEvent(obj, evType, fn){
	if (obj.addEventListener){
		obj.addEventListener(evType, fn, false);
		return true;
	} else if (obj.attachEvent){
		var r = obj.attachEvent("on"+evType, fn);
		return r;
	} else {
		return false;
	}
}

function _findTabs(){

	var divs = document.getElementsByTagName('DIV');



	for(i=0; i< divs.length; i++){
		if(_hasClassOf(divs[i],"park-data-tab")){
			_createTabs(divs[i]);
		}
	}
}

function _hasClassOf(oObj,sClass){

	if(!oObj){return false;}
	
	var aClasses = oObj.className.split(" ");

	for(var j=0;j<aClasses.length;j++){
		if(aClasses[j] == sClass){
			return true;
		}
	}

	return false;
}

function _createTabs(oObj){

	var iTabWidth = 150;
	var oFirst;
	// Set the height and width of the tab

	oObj.style.width 		= "910px";
	oObj.style.height 		= "600px";
	oObj.style.overflow 	= "hidden";
	oObj.style.position 	= "relative";
	oObj.style.display 		= "none";

   	var count = 0;

	for( var x = 0; oObj.childNodes[x]; x++ ){
	
   		//alert(oObj.childNodes[x].tagName);

   		if(oObj.childNodes[x].tagName == "H2"){
			oObj.childNodes[x].style.width 		= iTabWidth+"px";
			oObj.childNodes[x].style.height 	= "30px";
			oObj.childNodes[x].style.overflow 	= "hidden";
			oObj.childNodes[x].style.position 	= "absolute";
			oObj.childNodes[x].style.top 		= "0px";
			oObj.childNodes[x].style.left		= (iTabWidth*count)+"px";
			oObj.childNodes[x].style.display 	= "block";
			oObj.childNodes[x].style.textAlign 	= "center";
			oObj.childNodes[x].style.color 		= "#FFF";
			oObj.childNodes[x].style.lineHeight	= "30px";
			oObj.childNodes[x].style.fontSize	= "16px";
			oObj.childNodes[x].style.backgroundImage= "url(http://www.breakfreeholidays.co.uk/images/tab_unselect.gif)";
			oObj.childNodes[x].style.backgroundRepeat = "no-repeat";
			oObj.childNodes[x].style.cursor		= "pointer";
			oObj.childNodes[x].onclick = _showTab;
			count++;
	
			if(!oFirst){
				oFirst = oObj.childNodes[x];
			}

			var nextSibling = oObj.childNodes[x].nextSibling;
			while(nextSibling && nextSibling.nodeType != 1) {
			    nextSibling = nextSibling.nextSibling
			}

			if(nextSibling.tagName == "DIV"){
				nextSibling.style.width 		= "896px";
				nextSibling.style.height 		= "556px";
				nextSibling.style.overflow 		= "auto";
				nextSibling.style.position 		= "absolute";
				nextSibling.style.top 			= "30px";
				nextSibling.style.left			= "0px";
				nextSibling.style.display 		= "block";
				nextSibling.style.borderTop 		= "1px solid #446AB8";
				nextSibling.style.padding		= "5px";
				nextSibling.style.display		= "none";
				nextSibling.style.backgroundColor= "#FFF";
			}
		}
    }

	_setCurrent(oFirst);

	oObj.style.display		= "block";
}

function _showTab(){
	
	for( var x = 0; this.parentNode.childNodes[x]; x++ ){
		if(this.parentNode.childNodes[x].tagName == "H2"){
			this.parentNode.childNodes[x].style.backgroundImage= "url(http://www.breakfreeholidays.co.uk/images/tab_unselect.gif)";
	
			var nextSibling = this.parentNode.childNodes[x].nextSibling;
			while(nextSibling && nextSibling.nodeType != 1) {
			    nextSibling = nextSibling.nextSibling
			}

			if(nextSibling.tagName == "DIV"){
				nextSibling.style.display		= "none";
			}
		}
	}
	_setCurrent(this);
}

function _setCurrent(oObj){
	oObj.style.backgroundImage = "url(http://www.breakfreeholidays.co.uk/images/tab_select.gif)";

	var nextSibling = oObj.nextSibling;
	while(nextSibling && nextSibling.nodeType != 1) {
	    nextSibling = nextSibling.nextSibling
	}
 	if(nextSibling.tagName == "DIV"){
		nextSibling.style.display		= "block";
	}
}

_addEvent(window, 'load', _findTabs);

