/* ================================================================ 
This copyright notice must be untouched at all times.

The original version of this stylesheet and the associated (x)html
is available at http://www.stunicholls.com/menu/pro_concertinaslide_3.html
Copyright (c) 2005-2008 Stu Nicholls. All rights reserved.
This script and the associated (x)html may be modified in any 
way to fit your requirements.
=================================================================== */
var getdd = document.getElementById('slide').getElementsByTagName("DD");
var getdt = document.getElementById('slide').getElementsByTagName("DT");
var getMenu = document.getElementById('menuOuter').getElementsByTagName("DT");
	



	for (var x=0; x<getMenu.length; x++) {
		getMenu[x].onclick=function() {
			
		if (this.id == "menu1" && document.getElementById('smenu').className=='')
		{
			expand (0,document.getElementById('slide').offsetHeight,'smenu')
			document.getElementById('smenu').className = "clicked";
			this.className="expand";
		}else{
			for (var q=0; q<getdd.length; q++)
			{
				eNext = getdd[q].firstChild;
				while (eNext.nodeType!=1) {eNext = eNext.nextSibling;}
				ulHeight = eNext.offsetHeight;
				if (getdd[q].offsetHeight > 0)
				{
					getdd[q].className='';
					getdt[q+1].className='';
					contract (ulHeight,0,getdd[q].id)
				}
			}
			document.getElementById('slide').style.position = "absolute";
			document.getElementById('smenu').style.overflow = "hidden";
			contract (document.getElementById('slide').offsetHeight,0,'smenu')
			document.getElementById('smenu').className = '';
			this.className='';
		}
	}
}
	

	//document.getElementById('sitem1').style.height = 140 +"px";
	
for (var i=0; i<getdt.length; i++) {	
		;
	getdt[i].onclick=function() {
		//document.getElementById('slide').style.position = "relative";
		document.getElementById('smenu').style.overflow = "visible";
		
		if (this.id.indexOf('item') != -1) {
			for (var z=0; z<getdd.length; z++) {
				if (getdd[z].id.indexOf(this.id) !=-1 && getdd[z].className=='') {
					eNext = getdd[z].firstChild;
					while (eNext.nodeType!=1) {eNext = eNext.nextSibling;}
					eNext = eNext.firstChild;
					while (eNext.nodeType!=1) {eNext = eNext.nextSibling;}
					ulHeight = eNext.offsetHeight;
					ulWidth = eNext.offsetWidth;			
					ddHeight = document.getElementById(getdd[z].id).offsetHeight;
//					alert('id1= ' + getdd[z].id);	
					if(ulHeight<200){// 200 is the maxHeight in px
						eNext.style.width = 132+'px';
					}	
					if(ddHeight>0){
//						alert('contract ' + getdd[z].id);
						contract (ulHeight,0,getdd[z].id);
					}else{
//						alert('expand ' + getdd[z].id);
						expand (0,ulHeight,getdd[z].id);
//						expand = 'on';
					}
				}else {
					eNext = getdd[z].firstChild;
					while (eNext.nodeType!=1) {eNext = eNext.nextSibling;}
					eNext = eNext.firstChild;
					while (eNext.nodeType!=1) {eNext = eNext.nextSibling;}
					ulHeight = eNext.offsetHeight;
					ulWidth = eNext.offsetWidth;			
					ddHeight = document.getElementById(getdd[z].id).offsetHeight;

//					alert('id2= ' + getdd[z].id);	
					if (ddHeight > 0) {
//						alert('contract ' + getdd[z].id);	
						contract (ulHeight,0,getdd[z].id)
					}
//					if(ddHeight < 1 && ){
//						alert('expand ' + getdd[z].id);
//						expand (0,ulHeight,getdd[z].id);
//					}
				}
				if (getdd[z].id.indexOf(this.id) !=-1 && getdd[z].className=='') {
					getdd[z].className='selected'; 
					this.className='slide';
				}
				else {
					getdd[z].className='';
					ePrevious = getdd[z].previousSibling;
					while (ePrevious.nodeType!=1) {ePrevious = ePrevious.previousSibling;}
					ePrevious .className='';
				}
			}
		}
	}
}
setFirstHeight('sitem1');
function expand (cY, fY, subY, firstRun) {


	
//	if(cY < 5)
//		alert(cY+" "+fY+" "+subY);

	var maxHeight =  200;
	// IMPORTANT - When you change the maxHeight, you must change the hight (.scrollArea) in the css file.
	cY=cY+2;
	//alert(fY);
	var number = subY.split("sitem");
	if (cY <= fY && cY <= maxHeight) {
		document.getElementById(subY).style.height = cY + "px";
		setTimeout ("expand("+cY+","+fY+",'"+subY+"')", 10);
	}
	
	if (fY < maxHeight) {
		document.getElementById("scrollArea"+number[1]).style.width = 132 + "px";
	}else{
		document.getElementById("scrollArea"+number[1]).style.width = 122 + "px";
	}
	
	
	if(firstRun == 'firstRun'){		
		document.getElementById(subY).style.height = fY + "px";
		firstRun = '';
		return false;
	}
//	if (fY <= maxHeight+20) {
//		document.getElementById("scrollbar"+number[1]).style.display = "none";
//	}else{
//		document.getElementById("scrollArea"+number[1]).style.height = maxHeight + "px";
//	}
//	document.getElementById("scrollArea"+number[1]).style.height = fY + "px";

}
	
function contract (cZ, fZ, subZ) {
	var maxHeight =  200;
	if (cZ > maxHeight){
		cZ= cZ - (cZ-maxHeight) -2;
	}else{
		cZ=cZ-2;
	}
	if (cZ >= fZ ) {
		document.getElementById(subZ).style.height = cZ + "px";
		setTimeout ("contract("+cZ+","+fZ+",'"+subZ+"')", 10);
	}else{
		document.getElementById(subZ).style.height = 0 + "px";
	}
}

function setFirstHeight(id){
	for (var z=0; z<1; z++) {
			eNext = $(id).firstChild;
			while (eNext.nodeType!=1) {eNext = eNext.nextSibling;}
			eNext = eNext.firstChild;
			while (eNext.nodeType!=1) {eNext = eNext.nextSibling;}
			ulHeight = eNext.offsetHeight;
			ulWidth = eNext.offsetWidth;	
			if(ulHeight<200){// 200 is the maxHeight in px
				eNext.style.width = 132+'px';
			}		
			ulHeight = eNext.offsetHeight;
			
			expand (ulHeight,ulHeight,$(id).id, 'firstRun')
	}
}

