/* Javascript - Agefiph */
var anchor = document.location.hash.substring(1);

// 10 - Accordion
function aBuilder(o){
	// Global
	o.deployed = null;
	o.transition = false;
	o.synch = 0;
	// Items
	$(".item",o).each(function(){
		this.head = $(".head",this).get(0);
		this.head.anchor = $(".anchor",this).get(0).name;
		this.head.content = $(".text",this).get(0);
		this.head.content.anchor = this.head.anchor;
		this.head.content.restore = this.head.content.offsetHeight;
		this.head.content.parent = o;
		this.head.content.head = this.head;
		// Check default
		if(this.head.anchor == anchor){
			o.deployed = this.head;
			aDeploy(this.head.content)
		} else {
			o.transition = true;
			aFold(this.head.content)
		}
		// Events
		this.head.style.cursor = "pointer";
		this.head.onclick = aEvent;
	});
}
function aEvent(){
	if(!this.content.parent.transition && this.content.parent.deployed != this){
		aDeploy(this.content);
		if(this.content.parent.deployed != null){
			aFold(this.content.parent.deployed.content);
		}
		this.content.parent.transition = true;
		this.content.parent.deployed = this;
	}
}
function aDeploy(o){
	$(o).delay(500).animate({height:o.restore},500,function(){
		this.parent.transition = false;
		$(this.parentNode).addClass("deployed");
		//var s = o.parent.scrollTop;
		//document.location = "#"+o.anchor;
		//$(o.parent).scrollTop(0);
	});
}
function aFold(o){
	$(o).animate({height:0},500,function(){
		this.parent.transition = false;
		$(this.parentNode).removeClass("deployed");
		$(o.parent).scrollTop(0);
	});
}

// 99 - Load
$(document).ready(function(){
	
	// 10 - Accordion
	if(hasstyle){
		$(".accordion").each(function(){
			aBuilder(this);
		});
	}
	
});