var $activepane;

$(document).ready(function() {
	
	//browser fix for bullets (does not align with border in section header in Internet Explorer)
	if ($.browser.msie) {
		$("ul").css("padding-left","35px");
		$("li").css("padding-left","2px");
	}
	
	activatePanes();
	info();
});

function activatePanes() {
	/*$("h1").each(function(i) {
		$("<span style='color:" + $(this).attr("color") + ";font-weight:bold;'>&raquo;&nbsp;</span>").prependTo($(this));
	});*/
	
	var targeth;
	location.href.indexOf("#") > -1 ? targeth = unescape(location.href.substr(location.href.indexOf("#")+1)) : targeth = null;
	
	$activepane = $("h1:first");
	
	$("body,html").css("background-color",$activepane.attr("color"));
	
	$("h1 + div").hide();
	
	$("h1").css("cursor","pointer");
	
	$("h1").click(function() {
		
		$("#foldout").hide(300);
		
		var $trigger = $(this);		
		
		location.hash = "#" + escape($trigger.text());
		
		if ($trigger.attr("color")) {
			var newcolor = $trigger.attr("color");
			$("body").animate({backgroundColor:newcolor},1000);
			$("html").animate({backgroundColor:newcolor},1000);
		}
		
		$activepane.next().slideUp(300, function() {
			$trigger.next().slideDown(300);				
		});
		
		$activepane = $trigger;
	});
	
	if (targeth) {
		$("h1:contains('" + targeth + "')").trigger('click');
	} else {
		$("h1:first").trigger('click');
	}
	
	$("li").css('color','#AD8B32');
	
	$("li").each(function(i) {
		var textinside = $(this).html();
		$(this).empty();
		var spaninside = $("<span></span>").appendTo($(this));
		spaninside.html(textinside);
	});
}

function info() {
	$("<div id='foldout-button'></div>").appendTo("body");
	
	/*$("#foldout-button").html("i");*/
	$("#foldout-button").html("<img src='envelope.jpg'/>");
	
	$("#foldout-button").css("cursor","pointer");
	
	$("#foldout-button").click(function() {
		$("#foldout").toggle(300);
	});
	
	$(".killifjs").hide();
}
