// Hide these elements until the flash is loaded.


var accordion_interval;
var accordion_speed = 4; //Smaller numbers are faster, 1 is instant

//document.write('<style rel="stylesheet" type="text/css" media="screen">#region_list ul {display:none;}</style>');

initAccordions = function() {

	var panels = getElementsBySelector(".item");

	
	for(var i=0; i<panels.length; i++){
		var panel = panels[i];
		
		var divs = panel.getElementsByTagName("div");
		var accordion;
		var toggle;
		var brief;
		
		for(var j=0; j<divs.length; j++){

			if(divs[j].className.indexOf("full") > -1)
				accordion = divs[j];
				
			if(divs[j].className.indexOf("toggle") > -1)
				toggle = divs[j];
				
			if(divs[j].className.indexOf("brief") > -1)
				brief = divs[j];
		}
				
		if(accordion){
			accordion.style.display = "block";
			accordion.collapsedHeight = 0;
			accordion.style.height = "auto"
			accordion.openHeight = accordion.offsetHeight;
			accordion.id = "accordion_" + i;
			
			accordion.style.height = accordion.collapsedHeight + "px";
			accordion.open = false;
						
			//var accordion_link = document.createElement("a");
			//accordion_link.className = "accordion_link";
			//accordion_link.innerHTML = "Show Details";
			//accordion_link.href = "javascript:void(0);";
			//accordion_link.accordion = accordion;
			//accordion_link.onclick = function(){this.blur();accordionShow(this.accordion)}
			//toggle.appendChild(accordion_link);
			accordion.toggle = toggle;
			//toggle.innerHTML = "Show Details";
			brief.accordion = accordion;
			brief.onclick = function(){this.blur();accordionShow(this.accordion)}
			brief.onmouseover = function(){this.className+=" hover";}
			brief.onmouseout=function() {
				this.className=this.className.replace("hover", "");			
				this.className=this.className.replace("  ", " ");				
			}
		}
	}
	/*content.collapsedHeight = content.offsetHeight;
	content.style.height = "auto";
	content.openHeight = content.offsetHeight;
	content.style.height = content.collapsedHeight + "px";
	
	var button_read_more = document.getElementById("button_read_more");
	
	button_read_more.onclick = function(){readMoreShow()};*/
}

function accordionShow(accordion){

	show = accordion.open = !accordion.open;
	
	if(show){
		accordion.targetHeight = accordion.openHeight;
		accordion.parentNode.className += " open";

		//accordion.toggle.innerHTML = "Hide Details";
		accordion.toggle.className = "toggle_open";
	}
	else{
		accordion.targetHeight = accordion.collapsedHeight;
		accordion.parentNode.className = accordion.parentNode.className.replace("open", "");	

		//accordion.toggle.innerHTML = "Show Details";
		accordion.toggle.className = "toggle";		
	}
	
	window.clearInterval(accordion.interval);
	accordion.interval = window.setInterval('accordionAnimate("' + accordion.id + '");', 10);


}


function accordionAnimate(accordion_id){
	var accordion;
	var newHeight;
	
	accordion = document.getElementById(accordion_id);
	
		
	var currentHeight = accordion.offsetHeight;
	var targetHeight = accordion.targetHeight;

	if(targetHeight > currentHeight)
		var newHeight = Math.ceil( currentHeight + (targetHeight - currentHeight) / accordion_speed );
	else
		var newHeight = Math.floor( currentHeight + (targetHeight - currentHeight) / accordion_speed );
	
	accordion.style.height = newHeight + "px";
	
	if(newHeight == targetHeight)
		window.clearInterval(accordion.interval);
}

//EventUtils.addEventListener(window,'load', initAccordions);

