

function s(a,pageslug) {
	manualhash=false;
    var e = document.getElementById('block'+a);
	if(e == null || e == undefined) return;
	progress(pageslug + "/" + a);
    if (e.style.display != "block") {
        smoothexpand(e);
		window.location.hash = "/" + pageslug + "/" + a;
		textmark(pageslug + "/" + a);
		
		narrate(pageslug + "/" + a);
		oldhash = a;
    }
    else {
		smoothcollapse(e);
		
		window.location.hash = thishash;
		textmark( pageslug + "/" + a);
		
		if(currentaudio == pageslug + "/" + a) { silence(); }
		bullet_swap(a);
    }
}

function narrate(src)
{
	if(getCookie('audio') != 1){return false}
	wimpyButtonPause();
	wimpyButtonPlay('audio/'+src);
	currentaudio = src;

}

function silence()
{
	wimpyButtonPause();
}

function smoothexpand(e,child,gchld)
{
	var ggpexists = 0;
	ggp = e.parentNode.parentNode.parentNode;
	if(ggp.getAttribute("class") == 'textcontainer' || ggp.getAttribute("className") == 'textcontainer') { ggpexists = 1;  }
	if (ggpexists == 1 && ggp.style.display != "block")
	{
		smoothexpand(ggp,e,child);
		return;
	}
	e.style.display 	=	"inline-block";
	var divHeight = e.clientHeight;
	var incr = 5;
	var tmpheight = 0;
	e.style.display 	=	"block";
	e.style.overflow	=	"hidden";
	e.style.height 		=	"0px";
	i=0;
	
	var pageRect = getPageRect();
	var bullet = document.getElementById('bullet'+stripAlphaChars(e.id))
	var elementRect = getElementRect(bullet);
	var visible = rectsIntersect(pageRect,elementRect);
	if(!visible)
	{
		bullet.parentNode.scrollIntoView(true);
		window.scrollBy(0,-100);
	}
	if(ggpexists == 1)
	{
		ggp.style.height = 'auto';
	}
	
	
	
	bullet_swap(stripAlphaChars(e.id));
		
	for (tmpheight=0;tmpheight<=divHeight+1;tmpheight=tmpheight+incr)
	{
		setTimeout('stretch_div("'+e.id+'","'+tmpheight+'")',i);
		i=i+10;
	}
	setTimeout(function timeout(){e.style.height = 'auto';},i);
	if (child != undefined)
	{
	setTimeout(function chld(){smoothexpand(child,gchld);  },i);
	}
}

function smoothcollapse(e)
{
	e.style.display 	=	"inline-block";
	var divHeight = e.clientHeight;
	var incr = 5;
	var tmpheight = divHeight;
	e.style.display 	=	"block";
	e.style.overflow	=	"hidden";
	i=0;
	for (tmpheight=divHeight;tmpheight>0;tmpheight=tmpheight-incr)
	{
		setTimeout('stretch_div("'+e.id+'","'+tmpheight+'")',i);
		if(ggp.getAttribute("class") == 'textcontainer' || ggp.getAttribute("className") == 'textcontainer')
		{
			setTimeout(function ggxp(){ggp.style.height = 'auto';},i);
		}	
		i=i+10;
	}
	setTimeout('hide_div("'+e.id+'")',i);
}

function stretch_div(eid,tmpheight)
{
	document.getElementById(eid).style.height = tmpheight+"px";
}

function hide_div(eid)
{
	document.getElementById(eid).style.height 	=	"auto";
	document.getElementById(eid).style.display =	"none";
}

function bullet_swap(a)
{
	var img = document.getElementById('bullet'+a);
	var stem = "http://"+window.location.hostname+'/interface/';
	if(img != null && img != undefined)
	{
		if(img.src == stem+'triangle0' || img.src == stem+'triangle0h')
		{
			img.src = stem+'triangle22';
			setTimeout("swapdelay('"+a+"','triangle45');",33);
			setTimeout("swapdelay('"+a+"','triangle67');",66);
			setTimeout("swapdelay('"+a+"','triangle90');",100);
		}
		else if(img.src == stem+'triangle90' || img.src == stem+'triangle90h')
		{
			img.src = stem+'triangle67';
			setTimeout("swapdelay('"+a+"','triangle45');",33);
			setTimeout("swapdelay('"+a+"','triangle22');",66);
			setTimeout("swapdelay('"+a+"','triangle0');",100);
		}
	}
}

function swapdelay(a,png)
{
	var img = document.getElementById('bullet'+a);
	png = "http://"+window.location.hostname+'/interface/'+png;
	img.src = png;
}

function scrollSection(eID,openblock,pageslug) {
	manualhash=false;
	autoscroll = true;
    var destination = elmYPosition(eID)-20;
	
	var frame = 10;
	var step = 20;
	var position = 0;
	
	for (var i = 0; position<destination; i=i+frame) 
	{
		setTimeout("window.scrollTo(0, " + position + ")", i);
		position = position+step;
	}
	
	setTimeout("window.scrollTo(0, " + destination + ")", i);
	setTimeout("autoscroll = false", i+500);
	setTimeout("s(" + openblock + ",'" + pageslug + "')", i+700);
	
	
	if(supplement != '')
	{
		setTimeout("supplink('" + supplement + "')", i+700);
	}
	
}


























