/*
 * JavaScript News Article Database
 *
 * (c) 2001-2003 by FeLIX@discoverymountain.de
 *
 */

var ArticleList = new Array();

//
function Article(nr, title, text, date, source, location, pics)
{
	// Member variables
	this.nr       = nr;
	this.title    = title;
	this.text     = text;
	this.date     = date;
	this.source   = source;
	this.location = location;
	this.pics     = pics;

	// Member functions
	this.show     = ShowArticle;
}

//
function mydate(dat)
{
	var month = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" );
	var d = dat.split(".");

	var thedate = d[0] + ". " + month[d[1]-1] + " " + d[2];

	return thedate;
}

//
function ShowArticle()
{
	if (this.pics) {
		pictures = this.pics.split(" ");
		
		for (i=0; i<pictures.length; i++) {
			if (pictures[i].indexOf("_") == 0) {
				document.write("<IMG src=\"pics/");
				document.write(pictures[i]);
				document.writeln("\" border=0 alt=\"\" align=LEFT hspace=10>");
			} else {
//				document.write("<A href=\"pics/" + pictures[i] + "\"><IMG src=\"pics/");
				document.write("<A href=\"javascript:OpenPicWin('pics/" + pictures[i] + "','Space Mountain');\"><IMG src=\"pics/");
				document.write(pictures[i].replace(/[.]/,"_."));
				document.writeln("\" border=0 alt=\"\" align=LEFT hspace=10></A>");
			}
		}
	}
	
	document.writeln("<DIV class=\"heading\">" + this.title + "</DIV>");

	document.writeln("<DIV class=\"text\">" + this.text + "</DIV>");

	document.write("<DIV class=\"source\">Reported by " + this.source);
	if (this.location) {
		document.write(" at " + this.location);
	}
	document.writeln(", " + mydate(this.date) + "</DIV>");

	document.writeln("<BR clear=all><BR>");
}

//
function ShowItemList(itemlist)
{
	for (j=0; j<itemlist.length; j++) {
		ShowItem(itemlist[j]);
	}
}

//
function ShowItem(item)
{
	var art = Find(item);
	if (art) {
		art.show();
	}
}

//
function Add(nr, title, text, date, source, location, pics)
{
	ArticleList = ArticleList.concat(new Array(new Article(nr, title, text, date, source, location, pics)));
}

function AddAndShow(nr, title, text, date, source, location, pics)
{
	var a = new Article(nr, title, text, date, source, location, pics);
	ArticleList = ArticleList.concat(new Array(a));
	a.show();
}

//
function Find(nr)
{
	for (i=0; i<ArticleList.length; i++) {
		if (nr == ArticleList[i].nr) {
			return ArticleList[i];
		}
	}
	return 0;
}

//
function OpenPicWin(filename, title)
{
	var win=window.open("", "","width=400,height=300,scrollbars=no,toolbar=no,menubar=no,location=no,resizable=no,status=no,marginwidth=0,dependent=yes");
	with (win) {
		document.open();
		document.writeln("<HTML><HEAD><TITLE>" + title + "</TITLE></HEAD>");
		document.writeln("<BODY onLoad=\"window.resizeTo(document.pic.width + 20, document.pic.height + 20);\">");
		document.writeln("<DIV style=\"position:absolute; left:0; top:0\">");
		document.writeln("<A href=javascript:window.close();><IMG src=\"" + filename + "\" name=\"pic\" border=0></A>");
		document.writeln("</DIV>");
		document.writeln("</BODY></HTML>");
		document.close();

		focus();
		//resizeTo(document.pic.width, document.pic.height);
		//alert(document.pic.height);
		//window.Width = document.pic.width;
		//window.Height = document.pic.height;
	}
}

