var doStop = 0;

function showFirst() {
	clearTimeout(timerDown);
/*
	$("div.section h3:first").nextAll().each(
		function(iCnt) {
			var tagName = $(this)[0].tagName;
			if ( (tagName!='H3') && (doStop==0) ){
				$(this).slideDown('',function(){
						footer();
				 });

			}
			if (tagName=='H3') {
				doStop = 1;
			}
		}
		footer();
	);
	$("div.section h3:first").addClass('open');
	$("div.section h3:first").removeClass('closed');
	*/
}


var timerDown = null;

function footerLocation(extraHeight){
	height = $("div.content").height() + extraHeight;
	aHeight = $("div.aside").height() + extraHeight;
	if (height>aHeight) {
		$('#footerWrapper').css({ position: "absolute",top:height, width:'100%' });
	} else {
		$('#footerWrapper').css({ position: "absolute",top:aHeight, width:'100%' });
	}
}


$(document).ready(function() {
	timerDown = setTimeout("showFirst()", 2000);
	$("div.section h3.open").addClass('closed');
	$("div.section > p").each(
		function(iCnt) {
			hasClass = $(this).hasClass('stay');
			if (!hasClass) {
				$(this).css('display','none');
			} else {
				$(this).css('display','block');
			}
		}
	);
	$("div.section >h4").each(
			function(iCnt) {
				hasClass = $(this).hasClass('stay');
				if (!hasClass) {
					$(this).css('display','none');
				} else {
					$(this).css('display','block');
				}
			}
		);
	$("div.section ul").each(
		function(iCnt) {
			hasClass = $(this).hasClass('stay');
			if (!hasClass) {
				$(this).css('display','none');
			} else {
				$(this).css('display','block');
			}
		}
	);
	
	$("div.section div.box").css('display','none');
	
	$("div.section h3.open").css('cursor','pointer');
	$("div.section h3.open").bind('click',function() {
		if ($(this).hasClass('open')) {
			doStop = 0;
			$(this).nextAll().each(
				function(iCnt) {
					var tagName = $(this)[0].tagName;
					if ( (tagName!='H3') && (doStop==0) ){
						$(this).css('display','none');
					}
					if (tagName=='H3') {
						doStop = 1;
					}
				}
			);
			footerLocation(400);
			$(this).addClass('closed');
			$(this).removeClass('open');
		} else {
			doStop = 0;
			$(this).nextAll().each(
				function(iCnt) {
					var tagName = $(this)[0].tagName;
					if ( (tagName!='H3') && (doStop==0) ){
						$(this).css('display','block');
					}
					if (tagName=='H3') {
						doStop = 1;
					}
				}	
			);
			footerLocation(400);
			$(this).addClass('open');
			$(this).removeClass('closed');
		}
	});
	$("div.section h3.open").removeClass('open');
	
});