// Hide these elements until the flash is loaded.

draw_accordions = function(){

	var accordion_interval;
	var accordion_speed = 4; //Smaller numbers are faster, 1 is instant
	var counter = 0;

	var init = function() {
		$(".game").each(setupPanel);
	}
	
	var setupPanel = function(){
			var panel = this;
			
			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 && brief.className.indexOf("bye") == -1){
				accordion.style.display = "block";
				accordion.collapsedHeight = 0;
				accordion.style.height = "auto"
				accordion.openHeight = accordion.offsetHeight;
				accordion.id = "accordion_" + ++counter;
				
				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()};*/
	}
	
	var accordionShow = function (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('draw_accordions.accordionAnimate("' + accordion.id + '");', 10);
	
	
	}
	
	
	var accordionAnimate = function(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);
	}

	return {
	/* Public API
	*/
	init: init,
	accordionAnimate: accordionAnimate
	}	
	
}();

//EventUtils.addEventListener(window,'load', initAccordions);
$(document).ready(draw_accordions.init);
