/////////////////////////////////////////////////////////////////////////////
// rootmoves.js -- support script for HROCH.NET root page
// Version 1.0 Signed by Sid Paral @ MORTICIA on 2008/04/07 21:32:58 GMT-0700
// Authentication (do not edit) $x0Ww3n$
// Copyright (c) 1997-2008 by Sid Paral. All rights reserved.
/////////////////////////////////////////////////////////////////////////////

var			g_ie			=	document.all ? true : false;
var			g_bReVisit		=	false;

var			g_accX			=	0.08;
var			g_accY			=	0.08;
var			g_dampX			=	0.1;
var			g_dampY			=	0.1;
var			g_maxVX			=	30;
var			g_maxVY			=	30;

var			g_oFloaters		=	new Array();
var			g_iFloaters		=	0;

var			g_Xrnd			=	0;
var			g_Yrnd			=	0;

var			g_delay			=	0;
var			g_onSteady		=	"";
var			g_onDelay		=	"";
var			g_onMOTitle		=	"waveTitle();";

var			g_sJournalLink	=	"journal/index(cz).html";

function onLoad()
{
	// var skip			=	getCookie("hroch_net_skip_intro_on_entry");
	var skip			=	1;
	var visits			=	getCookie("hroch_net_visited");
	if (!visits)
	{
		g_bReVisit		=	skip && (skip == 1);
		visits			=	1;
	}
	else
	{
		g_bReVisit		=	true;
		visits = parseInt(visits) + 1;
	}
	setCookie("hroch_net_visited", visits);

	reset_floaters (false);

	setInterval ("global_onInterval()", 20);

	var JourLan = getCookie("JournalLanguage");
	if (!JourLan)
	{
		var	now	= new Date();
		fixDate(now);
		now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
		setCookie ("JournalLanguage", "CZ", now, "/");
	}
	else
	{
		if (JourLan == "EN")
			g_sJournalLink	=	"journal/index.html";
	}
}

function randomX()
{
	return (Math.random() - 0.5) * 1600;
}

function randomY()
{
	return (Math.random() - 0.5) * 1200;
}

function randomVX()
{
	return Math.random() * 60 - 30;
}

function randomVY()
{
	return Math.random() * 40 - 20;
}

function ex_randomX()
{
	var	ex_radius		=	300;
	g_Xrnd				=	randomX();
	g_Yrnd				=	randomY();
	if (g_Xrnd == 0)
		g_Yrnd			=	ex_radius;
	else
	{
		var	angle		=	Math.atan(g_Yrnd/g_Xrnd);
		if (g_Xrnd < 0)
			angle		+=	Math.PI;
		g_Xrnd			=	ex_radius * Math.sin(angle);
		g_Yrnd			=	ex_radius * Math.cos(angle);
	}
	return g_Xrnd;
}

function ex_randomY()
{
	return g_Yrnd;
}

function floater_onDump (sContext)
{
	alert (sContext + "\nfloater #" + this.m_index
			+ '\nFID = "' + this.m_sFID + '"'
			+ '\nGroup = "' + this.m_sGroup + '"'
			+ '\nclass = "' + this.m_sClass + '"'
			+ '\nSize = ' + this.m_sizeX + ', ' + this.m_sizeY
			+ '\nGrav = ' + this.m_gravX + ', ' + this.m_gravY);
}

function floater_onMouseOver ()
{
	// this.m_onDump ("floater_onMouseOver()");

	if ((this.m_sGroup == "jface") ||
		(this.m_sGroup == "face"))
	{
		this.m_velY			=	2;
		this.m_suspension	=	0;
		this.m_active		=	true;
		activateCaption (this.m_sFID, true);
	}
	else if (this.m_sGroup == "title")
	{
		activateCaption (this.m_sFID, true);
		waveTitle ();
	}
}

function floater_onMouseOut ()
{
	// this.m_onDump ("floater_onMouseOut()");

	if ((this.m_sGroup == "jface") ||
		(this.m_sGroup == "face") ||
		(this.m_sGroup == "title"))
	{
		activateCaption (this.m_sFID, false);
	}
}

function floater_onClick ()
{
	// this.m_onDump ("floater_onClick()");
	// return false;

	if (this.m_sFID == "Jface")
	{
		// alert ("Loading " + g_sJournalLink);
		window.location = g_sJournalLink;
		return false;
	}
	if (this.m_sFID == "title")
		return false;
	return true;
}

function floater_onUpdate ()
{
	if (!this.m_active)
		return false;

	if (this.m_suspension > 0)
	{
		--this.m_suspension;
		return true;
	}

	var		distX		=	(this.m_gravX - this.m_posX);
	var		distY		=	(this.m_gravY - this.m_posY);

	var		lockX		=	false;
	var		lockY		=	false;

	this.m_velX			-=	this.m_velX * this.m_dampX;
	this.m_velY			-=	this.m_velY * this.m_dampY;

	this.m_velX			+=	this.m_accX * distX;
	this.m_velY			+=	this.m_accY * distY;

	if (this.m_velX < -this.m_maxVX)
		this.m_velX = -this.m_maxVX;
	if (this.m_velX > this.m_maxVX)
		this.m_velX = this.m_maxVX;

	if (this.m_velY < -this.m_maxVY)
		this.m_velY = -this.m_maxVY;
	if (this.m_velY > this.m_maxVY)
		this.m_velY = this.m_maxVY;

	if ((Math.abs(distX) < 1) && (Math.abs(this.m_velX) < 0.25))
	{
		lockX			=	true;
		this.m_posX		=	this.m_gravX;
	}
	else
	{
		this.m_posX		+=	this.m_velX;
	}
	if ((Math.abs(distY) < 1) && (Math.abs(this.m_velY) < 0.25))
	{
		lockY			=	true;
		this.m_posY		=	this.m_gravY;
	}
	else
	{
		this.m_posY		+=	this.m_velY;
	}

	var		newLeft		=	this.m_posX - this.m_sizeX / 2;
	var		newTop		=	this.m_posY - this.m_sizeY / 2;

	this.m_objectStyle.left			=	newLeft + 'px';
	this.m_objectStyle.top			=	newTop + 'px';

	if (lockX && lockY)
		this.m_active	=	false;

	return true;
}

function floater_onReset (bRepeat)
{
	this.m_suspension	=	(bRepeat || g_bReVisit) ? 0 : getFloaterInitSuspension (this);

	this.m_accX			=	g_accX;
	this.m_accY			=	g_accY;
	this.m_dampX		=	g_dampX;
	this.m_dampY		=	g_dampY;
	this.m_maxVX		=	g_maxVX;
	this.m_maxVY		=	g_maxVY;

	this.m_gravX		=	getFloaterGravX (this);
	this.m_gravY		=	getFloaterGravY (this);

	if ((this.m_sGroup == "jface") ||
		(this.m_sGroup == "jface_sh") ||
		(this.m_sGroup == "face") ||
		(this.m_sGroup == "face_sh"))
	{
		this.m_velX		=	0;
		this.m_velY		=	0;
		this.m_posX		=	g_bReVisit ? this.m_gravX : getFloaterInitPosX (this);
		this.m_posY		=	g_bReVisit ? this.m_gravY : getFloaterInitPosY (this);
	}
	else if (!bRepeat)
	{
		this.m_velX		=	g_bReVisit ? 0 : randomVX();
		this.m_velY		=	g_bReVisit ? 0 : randomVY();
		this.m_posX		=	g_bReVisit ? this.m_gravX : getFloaterInitPosX (this);
		this.m_posY		=	g_bReVisit ? this.m_gravY : getFloaterInitPosY (this);
	}

	this.m_active		=	true;
}

function getFloaterSizeX (oFlt)
{
	if ((oFlt.m_sGroup == "letter") || (oFlt.m_sGroup == "shadow"))
		return 70;
	if ((oFlt.m_sGroup == "hln") || (oFlt.m_sGroup == "hln_sh"))
		return 580;
	if ((oFlt.m_sGroup == "jface") || (oFlt.m_sGroup == "jface_sh"))
		return 580;
	if ((oFlt.m_sGroup == "face") || (oFlt.m_sGroup == "face_sh"))
		return 130;
	if (oFlt.m_sGroup == "title")
		return 580;
	if (oFlt.m_sClass == "caption")
		return 15;
	alert ('getFloaterSizeX invalid group = "' + oFlt.m_sGroup + '"');
	return 100;
}

function getFloaterSizeY (oFlt)
{
	if ((oFlt.m_sGroup == "letter") || (oFlt.m_sGroup == "shadow"))
		return 70;
	if ((oFlt.m_sGroup == "hln") || (oFlt.m_sGroup == "hln_sh"))
		return 2;
	if ((oFlt.m_sGroup == "jface") || (oFlt.m_sGroup == "jface_sh"))
		return 128;
	if ((oFlt.m_sGroup == "face") || (oFlt.m_sGroup == "face_sh"))
		return 168;
	if (oFlt.m_sGroup == "title")
		return 80;
	if (oFlt.m_sClass == "caption")
		return 20;
	alert ('getFloaterSizeY invalid group = "' + oFlt.m_sGroup + '"');
	return 100;
}

function getFloaterGravX (oFlt)
{
	if (oFlt.m_sGroup == "letter")
		return (oFlt.m_baseX - 4) * 67;
	if (oFlt.m_sGroup == "shadow")
		return (oFlt.m_baseX - 4) * 67 + 3;
	if (oFlt.m_sGroup == "hln")
		return 0;
	if (oFlt.m_sGroup == "hln_sh")
		return 3;
	if (oFlt.m_sGroup == "jface")
		return 0;
	if (oFlt.m_sGroup == "jface_sh")
		return 3;
	if (oFlt.m_sGroup == "face")
		return 75+ (oFlt.m_baseX - 2) * 150;
	if (oFlt.m_sGroup == "face_sh")
		return 75+ (oFlt.m_baseX - 2) * 150 + 3;
	if (oFlt.m_sGroup == "hcaption")
		return -1000;//0;
	if (oFlt.m_sGroup == "jcaption")
		return -1000;//0;
	if (oFlt.m_sGroup == "ccaption")
		return -1000;//-150;
	if (oFlt.m_sGroup == "tcaption")
		return -1000;//0;
	if (oFlt.m_sGroup == "lcaption")
		return -1000;//0;
	if (oFlt.m_sGroup == "scaption")
		return -1000;//+150;
	return 0;
}

function getFloaterGravY (oFlt)
{
	if (oFlt.m_sGroup == "title")
		return -55 + 20;
	if (oFlt.m_sGroup == "letter")
		return -55;
	if (oFlt.m_sGroup == "shadow")
		return -55 + 3;
	if (oFlt.m_sGroup == "hln")
		return -1000;
	if (oFlt.m_sGroup == "hln_sh")
		return -1000 + 3;
	if (oFlt.m_sGroup == "jface")
		return -180;
	if (oFlt.m_sGroup == "jface_sh")
		return -180 + 3;
	if (oFlt.m_sGroup == "face")
		return 110;
	if (oFlt.m_sGroup == "face_sh")
		return 110 + 3;
	if (oFlt.m_sGroup == "hcaption")
		return 240;//-60;
	if (oFlt.m_sGroup == "jcaption")
		return 240;//-60;
	if (oFlt.m_sGroup == "ccaption")
		return 240;//110;
	if (oFlt.m_sGroup == "tcaption")
		return 240;//110;
	if (oFlt.m_sGroup == "lcaption")
		return 240;//110;
	if (oFlt.m_sGroup == "scaption")
		return 240;//110;
	return 0;
}

function getFloaterInitSuspension (oFlt)
{
	if ((oFlt.m_sGroup == "jface") ||
		(oFlt.m_sGroup == "face"))
		return (100 + 20 * oFlt.m_baseX - 10 * oFlt.m_baseY);
	if ((oFlt.m_sGroup == "jface_sh") ||
		(oFlt.m_sGroup == "face_sh"))
		return 200 - 10 * (oFlt.m_baseY * 3 + oFlt.m_baseX);
	return 0;
}

function getFloaterInitPosX (oFlt)
{
	if (oFlt.m_sGroup == "jface_sh")
		return -1000;
	if (oFlt.m_sGroup == "face_sh")
		return -2000;
	return oFlt.m_gravX;
}

function getFloaterInitPosY (oFlt)
{
	if (oFlt.m_sGroup == "jface")
		return -1000;
	if (oFlt.m_sGroup == "face")
		return -1000;
	return oFlt.m_gravY;
}

function floater (index, sFID, sGroup, sClass, baseX, baseY, baseG)
{
	this.m_index		=	index;
	this.m_sFID			=	sFID;
	this.m_sGroup		=	sGroup;
	this.m_sClass		=	sClass;
	this.m_baseX		=	baseX;
	this.m_baseY		=	baseY;
	this.m_baseG		=	baseG;

	this.m_active		=	false;
	this.m_suspension	=	getFloaterInitSuspension (this);
	this.m_sizeX		=	getFloaterSizeX (this);
	this.m_sizeY		=	getFloaterSizeY (this);

	this.m_accX			=	g_accX;
	this.m_accY			=	g_accY;
	this.m_dampX		=	g_dampX;
	this.m_dampY		=	g_dampY;
	this.m_maxVX		=	g_maxVX;
	this.m_maxVY		=	g_maxVY;

	this.m_gravX		=	getFloaterGravX (this);
	this.m_gravY		=	getFloaterGravY (this);

	this.m_velX			=	0;
	this.m_velY			=	0;
	this.m_posX			=	getFloaterInitPosX (this);
	this.m_posY			=	getFloaterInitPosY (this);

	this.m_objectStyle	=	findDOM ("floater" + this.m_index, 1);

	this.m_onReset		=	floater_onReset;
	this.m_onUpdate		=	floater_onUpdate;
	this.m_onMouseOver	=	floater_onMouseOver;
	this.m_onMouseOut	=	floater_onMouseOut;
	this.m_onClick		=	floater_onClick;
	this.m_onDump		=	floater_onDump;
}

function create_new_floater (sFID, sGroup, sClass, baseX, baseY, baseG, sContents)
{
	// alert ("create_new_floater #" + g_iFloaters);

	var		index		=	0;

	if ((index = locate_floater_by_FID (sFID)) >= 0)
		g_oFloaters[index].m_onDump ("new floater #" + g_iFloaters + " has Duplicate FID with");

	// this section defines the document object the floater creator refers to

	document.write ('<DIV ID="floater' + g_iFloaters + '" CLASS="' + sClass + '">');
	document.write (sContents);
	document.writeln ('</DIV>');

	// only now the floater may define its object, as is did not exist before above document.writing

	g_oFloaters[g_iFloaters]			=	new floater (g_iFloaters, sFID, sGroup, sClass, baseX, baseY, baseG);
	// g_oFloaters[g_iFloaters].m_onDump ("created");

	++g_iFloaters;

	// alert ("so far " + g_iFloaters + " floater(s)");
}

function create_new_floater_string (sFIDBase, sGroup, sClass, baseY, sSplash)
{
	var		index		=	0;
	var		len			=	sSplash.length;
	var		cc			=	"";
	var		sAcc		=	"";
	var		bEscape		=	false;
	var		baseX		=	0;

	for (index = 0; index < len; ++index)
	{
		cc				=	sSplash.substr(index, 1);
		sAcc			+=	cc;
		if (bEscape)
		{
			if (cc == ";")
				bEscape	=	false;
		}
		else
		{
			if (cc == "&")
				bEscape	=	true;
		}

		if (!bEscape)
		{
			create_new_floater (sFIDBase + "_inst" + index,
								sGroup,
								sClass,
								baseX,
								baseY,
								len,
								sAcc);
			sAcc		=	"";
			++baseX;
		}
	}

	if (sAcc != "")
		alert ("Invalid splash string \"" + sSplash + "\"");
}

function reset_floaters (bRepeat)
{
	g_onSteady					=	"";
	// g_onClickTitle				=	"round_letters()";
	// g_onClickTitle				=	"scatter_letters()";
	g_onDelay					=	"";

	var		index;

	for (index = 0; index < g_iFloaters; ++index)
	{
		g_oFloaters[index].m_onReset (bRepeat);
	}
}

function scatter_letters ()
{
	var 	index				=	0;
	var		oFlt;

	for (index = 0; index < g_iFloaters; ++index)
	{
		oFlt					=	g_oFloaters[index];
		if ((oFlt.m_sGroup == "letter") ||
			(oFlt.m_sGroup == "shadow"))
		{
			oFlt.m_accX			=	g_accX;
			oFlt.m_accY			=	g_accY;
			oFlt.m_dampX		=	g_dampX;
			oFlt.m_dampY		=	g_dampY;
			oFlt.m_maxVX		=	g_maxVX;
			oFlt.m_maxVY		=	g_maxVY;
			oFlt.m_gravX		=	ex_randomX();
			oFlt.m_gravY		=	ex_randomY();
			oFlt.m_suspension	=	0;
			oFlt.m_active		=	true;
		}
	}
	g_onSteady					=	"circulate_letters()";
	g_onSteady					=	"round_letters()";
	g_onClickTitle				=	"reset_floaters(true)";
	g_onDelay					=	"";
}

function round_letters ()
{
	var		acc					=	0.01;
	var		damp				=	0.1;
	var 	index				=	0;
	var		angle				=	0;
	var		oFlt;

	for (index = 0; index < g_iFloaters; ++index)
	{
		oFlt					=	g_oFloaters[index];
		if (oFlt.m_sGroup == "letter")
		{
			angle 				=	Math.PI * (oFlt.m_baseX - 4) / 20;
			oFlt.m_accX			=	acc;
			oFlt.m_accY			=	acc;
			oFlt.m_dampX		=	damp;
			oFlt.m_dampY		=	damp;
			oFlt.m_gravX		=	320 * Math.cos(angle);
			oFlt.m_gravY		=	329 * Math.sin(angle);
			oFlt.m_suspension	=	0;
			oFlt.m_active		=	true;
		}
		else if (oFlt.m_sGroup == "shadow")
		{
			angle 				=	Math.PI * (oFlt.m_baseX - 4) / 20;
			oFlt.m_accX			=	acc;
			oFlt.m_accY			=	acc;
			oFlt.m_dampX		=	damp;
			oFlt.m_dampY		=	damp;
			oFlt.m_gravX		=	320 * -Math.cos(angle);
			oFlt.m_gravY		=	320 * Math.sin(angle);
			oFlt.m_suspension	=	0;
			oFlt.m_active		=	true;
		}
	}
	g_onSteady					=	"circulate_letters()";
	g_onClickTitle				=	"reset_floaters(true)";
	g_onDelay					=	"";
}

function circulate_letters ()
{
	var		acc					=	0.003;
	var		damp				=	0.0001;
	var		maxV				=	100;
	var 	index				=	0;
	var		oFlt;

	for (index = 0; index < g_iFloaters; ++index)
	{
		oFlt					=	g_oFloaters[index];
		if (oFlt.m_sGroup == "letter")
		{
			oFlt.m_accX			=	acc;
			oFlt.m_accY			=	acc;
			oFlt.m_dampX		=	damp;
			oFlt.m_dampY		=	damp;
			oFlt.m_gravX		=	0;
			oFlt.m_gravY		=	0;
			oFlt.m_velX			=	+0.05 * oFlt.m_posY;
			oFlt.m_velY			=	-0.05 * oFlt.m_posX;
			oFlt.m_maxVX		=	maxV;
			oFlt.m_maxVY		=	maxV;
			oFlt.m_suspension	=	0;
			oFlt.m_active		=	true;
		}
		else if (oFlt.m_sGroup == "shadow")
		{
			oFlt.m_accX			=	acc;
			oFlt.m_accY			=	acc;
			oFlt.m_dampX		=	damp;
			oFlt.m_dampY		=	damp;
			oFlt.m_gravX		=	0;
			oFlt.m_gravY		=	0;
			oFlt.m_velX			=	-0.05 * oFlt.m_posY;
			oFlt.m_velY			=	+0.05 * oFlt.m_posX;
			oFlt.m_maxVX		=	maxV;
			oFlt.m_maxVY		=	maxV;
			oFlt.m_suspension	=	0;
			oFlt.m_active		=	true;
		}
	}
	g_onSteady					=	"reset_floaters(true)";
	g_onClickTitle				=	"reset_floaters(true)";
	g_onDelay					=	"reset_floaters(true)";
	g_delay						=	500;
}

function waveTitle ()
{
	var 	index				=	0;
	var		oFlt;

	for (index = 0; index < g_iFloaters; ++index)
	{
		oFlt					=	g_oFloaters[index];
		if ((oFlt.m_sGroup == "letter") || (oFlt.m_sGroup == "shadow"))
		{
			if (!oFlt.m_active)
			{
				oFlt.m_velY			=	-3;
				oFlt.m_suspension	=	2 * oFlt.m_baseX + 10 * oFlt.m_baseY;
				oFlt.m_active		=	1;
			}
		}
	}
}

function activateCaption (sCallerFID, bActivate)
{
	var 	index				=	0;
	var		oFlt;
	var		sGroup				=	""

	if (sCallerFID == "title")
		sGroup					=	"hcaption";
	else if (sCallerFID == "Jface")
		sGroup					=	"jcaption";
	else if (sCallerFID == "Cface")
		sGroup					=	"ccaption";
	else if (sCallerFID == "Tface")
		sGroup					=	"tcaption";
	else if (sCallerFID == "Lface")
		sGroup					=	"lcaption";
	else if (sCallerFID == "Sface")
		sGroup					=	"scaption";
	else
	{
		alert ("invalid activateCaption(\"" + sCallerFID + "\", " + bActivate + ")");
		return;
	}

	for (index = 0; index < g_iFloaters; ++index)
	{
		oFlt					=	g_oFloaters[index];
		if (oFlt.m_sGroup == sGroup)
		{
			// oFlt.m_gravY			=	bActivate ? 240 : getFloaterGravY(oFlt);
			oFlt.m_gravY			=	getFloaterGravY(oFlt);
			oFlt.m_gravX			=	bActivate ? ((-0.5 * oFlt.m_baseG + oFlt.m_baseX + 0.5) * oFlt.m_sizeX) : getFloaterGravX(oFlt);
			if (!oFlt.m_active)
			{
				// oFlt.m_velY			=	0;
				// oFlt.m_suspension	=	bActivate ? oFlt.m_baseX : 0;
				oFlt.m_suspension	=	0;
				oFlt.m_active		=	1;
			}
		}
	}
}

function locate_floater_by_FID (sFID)
{
	var		index;
	for (index = 0; index < g_iFloaters; ++index)
	{
		if (g_oFloaters[index].m_sFID == sFID)
			return index;
	}
	return -1;
}

function global_onInterval()
{
	var		index		=	0;
	var		bUpdating	=	false;

	for (index = 0; index < g_iFloaters; ++index)
	{
		bUpdating		|=	g_oFloaters[index].m_onUpdate();
	}
	if (!bUpdating && (g_onSteady != ""))
	{
		setTimeout (g_onSteady, 10);
		g_onSteady		=	"";
	}
	else if (g_delay > 0)
	{
		if ((--g_delay <= 0) && (g_onDelay != ""))
		{
			setTimeout (g_onDelay, 10);
			g_onDelay		=	"";
		}
	}
}
