
function addToPulldown(elements)
{
	elements.remove().appendTo("#pulldown").hide();
	var height = 0;
	elements.each(function() {
		if (location.hash != "#" + this.id) return;
		openPulldown($(this), "instant");
	});
}

function openPulldown(child, speed, callback)
{
	child.show();
	$("#pulldown").css({
		"height": "" + child.height() + "px",
		"marginTop": "-" + child.height() + "px"
	});
	scrollTo(0, 0);
	if (speed == "instant") {
		$("#pulldown").css("marginTop", "0");
		if (callback) callback();
	} else {
		$("#pulldown").animate({
			"marginTop": "0"
		}, speed, callback);
	}
}

function closePulldown(speed, callback)
{
	if (navigator.userAgent.indexOf("MSIE 6") != -1) {
		$("#pulldown").css("height", "0px");
		//$("#pulldown").children().hide();
		if (callback) callback();
	}
	if (speed == "instant") {
		$("#pulldown").css("marginTop", "-" + $("#pulldown > :visible").height() + "px");
		$("#pulldown").children().hide();
		if (callback) callback();
	} else {
		$("#pulldown").animate({
			"marginTop": "-" + $("#pulldown > :visible").height() + "px"
		}, speed, function() {
			$("#pulldown").children().hide();
			if (callback) callback();
		});
	}
}

function switchPulldownFocus(speed, child)
{
	closePulldown(speed, function() {
		openPulldown(child);
	});
}

$(document).ready(function() {

	if ($("#pulldown").children().length > 0) {
		openPulldown($("#pulldown > *:first-child"), "instant");
	}
	
});
