// Hide these elements until the flash is loaded.


var accordion_interval;
var accordion_speed = 10; //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("#region_list li");
	
	for(var i=0; i<panels.length; i++){
		var panel = panels[i];
		if(panel.getElementsByTagName("UL").length > 0){
			var accordion = panel.getElementsByTagName("UL")[0];
			accordion.style.display = "block";
			accordion.collapsedHeight = 0;
			accordion.style.height = "auto"
			accordion.openHeight = accordion.offsetHeight;
			accordion.id = "accordion_" + i;
			
			//Check for selected items
			var items = accordion.getElementsByTagName("LI");
			var item_selected = false;

			for(var j=0; j<items.length; j++){
				if(items[j].className.indexOf("selected") > -1)
					item_selected = true;
			}
			
			if(item_selected){
				accordion.style.height = accordion.openHeight + "px";
				accordion.open = true;
			}else{
				accordion.style.height = accordion.collapsedHeight + "px";
				accordion.open = false;
			}

			
			var strong = panel.getElementsByTagName("STRONG")[0];
			var accordion_link = document.createElement("a");
			
			accordion_link.className = "accordion_link";
			accordion_link.innerHTML = strong.innerHTML;
			accordion_link.href = "javascript:void(0);";
			accordion_link.accordion = accordion;
			accordion_link.onclick = function(){accordionShow(this.accordion)}
			
			strong.parentNode.insertBefore(accordion_link, strong);
			strong.parentNode.removeChild(strong);
		}
	}
	/*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;
	else
		accordion.targetHeight = accordion.collapsedHeight;
	
	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);
}


function pageLoad(){
	initAccordions();
	doHeadingReplace();
	initFormFocus();	
}

