gnuru.js 1.95 KB
gnuru   = new Image ();
gnuru_t = new Image ();

gnuru.src   = "images/gnuru.png"
gnuru_t.src = "images/gnuru-trans.png"

/* Klasse die Weisheiten aufnehmen kann. */
function GnuruWisdom (ti, te, so)
{
	var title  = ti;
	var text   = te;
	var source = so;

	this.setTitle = function (ti)
	{
		title = ti;
	}

	this.setText = function (te)
	{
		text = te;
	}

	this.setSource = function (so)
	{
		source = so;
	}

	this.getTitle = function ()
	{
		return title;
	}

	this.getText = function ()
	{
		return text;
	}

	this.getSource = function ()
	{
		return source;
	}
}

/* an array with all weisheiten (will be filled through php in gnuru.tpl) */
var gnuruWisArray = new Array ()

/* Eventhandler */
function gnuruWake ()
{
	document.getElementById ('GNURU_IMG').src = gnuru.src;
}

function gnuruMeditate ()
{
	document.getElementById ('GNURU_IMG').src = gnuru_t.src;
}

function gnuruAsk ()
{
	divShow ('GNURU_BUBBLE', 2);
}

function gnuruAskEnd ()
{
	divHide ('GNURU_BUBBLE', 2);
}

var wisIndex;
var lastWisIndex;

function gnuruSais ()
{
	gnuruAskEnd ();

	/* create the index for the wisdom that should be displayed, but ensure
	   not to create the same index twice */
	while (wisIndex == lastWisIndex)
		wisIndex = Math.round (Math.random () * 100) % gnuruWisArray.length;
	lastWisIndex = wisIndex;

	/* The following clears all childdata from title, text and source ...*/
	/* ... and then refills it with our own data */
	node  = document.getElementById('GNURU_WIS_TITLE');
	pnode = node.parentNode;
	pnode.replaceChild (gnuruWisArray[wisIndex].getTitle (), node);

	node  = document.getElementById('GNURU_WIS_TEXT')
	pnode = node.parentNode;
	pnode.replaceChild (gnuruWisArray[wisIndex].getText (), node);

	node  = document.getElementById('GNURU_WIS_SOURCE')
	pnode = node.parentNode;
	pnode.replaceChild (gnuruWisArray[wisIndex].getSource (), node);

	/* and finally display the whole stuff */
	divShow ('GNURU_SAIS', 3);
}

function gnuruSilence ()
{
	divHide ('GNURU_SAIS', 3);
}