// =======
// COMCODE
// =======

function flip_page(to,pass_id,sections)
{
	var i,current_pos=0,section;

	if (typeof to=='number')
	{
		for (i=0;i<sections.length;i++)
		{
			section=document.getElementById(pass_id+'_section_'+sections[i]);
			if (section.style.display=='block')
			{
				current_pos=i;
				break;
			}
		}

		current_pos+=to;
	} else
	{
		for (i=0;i<sections.length;i++)
		{
			if (sections[i]==to)
			{
				current_pos=i;
				break;
			}
		}
	}

	var x;
	x=document.getElementById(pass_id+'_has_next_yes');
	if (x) x.style.display=(current_pos==sections.length-1)?'none':'inline';
	x=document.getElementById(pass_id+'_has_next_no');
	if (x) x.style.display=(current_pos==sections.length-1)?'inline':'none';
	x=document.getElementById(pass_id+'_has_previous_yes');
	if (x) x.style.display=(current_pos==0)?'none':'inline';
	x=document.getElementById(pass_id+'_has_previous_no');
	if (x) x.style.display=(current_pos==0)?'inline':'none';
	for (i=0;i<sections.length;i++)
	{
		x=document.getElementById(pass_id+'_goto_'+sections[i]);
		if (x) x.style.display=(i==current_pos)?'none':'inline';
		x=document.getElementById(pass_id+'_isat_'+sections[i]);
		if (x) x.style.display=(i==current_pos)?'inline':'none';
		x=document.getElementById(pass_id+'_section_'+sections[i]);
		if (x) x.style.display=(i==current_pos)?'block':'none';
	}

	return false;
}

var tick_pos=[];
function ticker_tick(id,width)
{
	if (!window.focused) return;
	
	var e=document.getElementById(id);
	if (!e) return;
	if (e.mouseisover) return;
	e.style.textIndent=tick_pos[id]+'px';
	tick_pos[id]--;
	if (tick_pos[id]<-1.2*getInnerHTML(e).length) tick_pos[id]=width;
}

var jumper_pos=[],jumper_parts=[];
function jumper_tick(id)
{
	if (jumper_pos[id]==jumper_parts[id].length-1) jumper_pos[id]=0;
	var e=document.getElementById(id);
	if (!e) return;
	setInnerHTML(e,jumper_parts[id][jumper_pos[id]]);
	jumper_pos[id]++;
}

function crazy_tick()
{
	if (!window.mouseX) return;
	if (!window.mouseY) return;

	var e,i,s_width,biasx,biasy;
	for (i=0;i<window.crazy_criters.length;i++)
	{
		e=document.getElementById(window.crazy_criters[i]);
		s_width=e.clientWidth;

		biasx=window.mouseX-e.offsetLeft;
		if (biasx>0) biasx=2; else biasx=-1;
		if (Math.random()*4<1) biasx=0;
		biasy=window.mouseY-e.offsetTop;
		if (biasy>0) biasy=2; else biasy=-1;
		if (Math.random()*4<1) biasy=0;

		if (s_width<100)
			e.style.width=(s_width+1)+'px';
		e.style.left=(e.offsetLeft+(Math.random()*2-1+biasx)*30)+"px";
		e.style.top=(e.offsetTop+(Math.random()*2-1+biasy)*30)+"px";
		e.style.position='absolute';
	}
}

