// (c) 1999, Andrew Danylchenko 
// e-mail  : anry@bigfoot.com
// homepage: www.bigfoot.com/~anry

function Item(anID, aTitle) {
	this.ID    = anID;
	this.Title = aTitle || "";
}

function ItemsIterator_findItem(anID) {
	for(i=0; i < this.items.length; i++) {
		if(this.items[i].ID == anID) {
			loadItem(this.items[this.currItem = i]);
			return;
		}
	}
	loadItem(this.items[this.currItem = 0]);
}

function ItemsIterator_nextItem() {
	this.currItem = (this.currItem >= this.items.length - 1) ? 0 : this.currItem + 1;
	loadItem(this.items[this.currItem]);
}

function ItemsIterator_prevItem() {
	this.currItem = (this.currItem <= 0) ? this.items.length -1 : this.currItem - 1;
	loadItem(this.items[this.currItem]);
}

function ItemsIterator(anItemsArray, aLoadItemFunction) {
	this.items    = anItemsArray;
	this.currItem = 0;
	this.loadItem = aLoadItemFunction;

	this.findItem = ItemsIterator_findItem;
	this.nextItem = ItemsIterator_nextItem;
	this.prevItem = ItemsIterator_prevItem;
}

function RollOver_onMouseOut() {
	var image;

	if(image = document.images[this.imageName]) image.src = this.outImage.src;
	this.overFlag = false;
}

function RollOver_onMouseOver() {
	var image;

	if(this.overFlag) {
		return;
	} else {
		if(image = document.images[this.imageName]) image.src = this.overImage.src;
		this.overFlag = true;		
	}
		
}                              

function RollOver(anImageName, anOutImage, anOverImage) {
	this.imageName = anImageName;

	this.outImage  = anOutImage;
	this.overImage = anOverImage;

	this.overFlag  = false;

	this.onMouseOut  = RollOver_onMouseOut;
	this.onMouseOver = RollOver_onMouseOver;
}

function cacheImage(anImageFileName) {
	var image = new Image();
	image.src = anImageFileName;

	return image;
}

function debug(mess) {
	window.status = mess;
}

function MapRollOver_onMouseOut(stateNumb) {
	image = document.images[this.imgName];
	filed = this.defaultImg;

	if(image && filed) image.src = filed.src;

	this.overFlag = false;
}

function MapRollOver_onMouseOver(stateNumb) {
	if(this.overFlag) {
		return;
	} else {
		image = document.images[this.imgName];
		filed = this.stateImgs[stateNumb];

		if(image && filed) image.src = filed.src;

		this.overFlag = true;		
	}
		
}                              

function MapRollOver(imgName, defaultSrc, stateSrcs) {
	this.overFlag = false;

	this.imgName = imgName;

	this.defaultImg = cacheImage(defaultSrc);

	this.stateImgs = new Array();
	for(i = 0; i < stateSrcs.length; i++) {
		this.stateImgs[i] = cacheImage(stateSrcs[i]);
	}

	this.onMouseOut  = MapRollOver_onMouseOut;
	this.onMouseOver = MapRollOver_onMouseOver;
}

function popup(name, file, width, height, scrolling) {
	window.name = "main";

   	width = Math.min(width, screen.width-40);
	height = Math.min(height, screen.height-60);

	wleft = (screen.width - width) / 2;
	wtop  = (screen.height - height) / 2 - 20;

	win = window.open(file, name, "width=" + width + ",height=" + height + ",left=" + wleft + ",top=" + wtop + ",location=no,menubar=no,resizable=no,scrollbars=" + ((scrolling)?'yes':'no') + ",status=no,toolbar=no");
	win.focus();
}
