// Banner object
function Banner(objName){
	this.obj = objName;
	this.aNodes = [];
	this.horizontal = true;
	this.shuffle = false;
};

// Node object
function Node(name, bannerTitle, bannerPath, hyperlink, bannerTarget) {
	this.name = name;
	this.bannerTitle = bannerTitle;
	this.hyperlink = hyperlink;
	this.bannerPath = bannerPath;
	this.bannerTarget = bannerTarget;
};

// set shuffle mode
Banner.prototype.setShuffle = function(mode) {
	this.shuffle = (mode == true);
}

// set display style
Banner.prototype.setDisplay = function(mode) {
	this.horizontal = (mode == true);
}

// set horizontal display style
Banner.prototype.setHorizontal = function() {
	this.setDisplay(true);
}

// set vertical display style
Banner.prototype.setVertical = function() {
	this.setDisplay(false);
}

// add new banner
Banner.prototype.add = function(bannerTitle, bannerPath, hyperlink, bannerTarget) {
	this.aNodes[this.aNodes.length] = new Node(this.obj + '_' + this.aNodes.length, bannerTitle, bannerPath, hyperlink, bannerTarget);
};

// Outputs the banner to the page
Banner.prototype.toString = function() {
	var str = '';
	var indices = new Array(this.aNodes.length);
	for (var i = 0; i < this.aNodes.length; i++) indices[i] = i;
	if (this.shuffle) {
		var s1, s2, stmp;
		for (var i = 0; i < this.aNodes.length * 2; i++) {
			s1 = Math.floor(Math.random() * this.aNodes.length);
			s2 = Math.floor(Math.random() * this.aNodes.length);
			tmp = indices[s1];
			indices[s1] = indices[s2];
			indices[s2] = tmp;
		}
	}
	var code = 0;
	for (var iCtr = 0; iCtr < this.aNodes.length; iCtr++) {
		code = indices[iCtr];
		str += (this.horizontal ? '<span': '<div');
		str += ' name="' + this.aNodes[code].name + '"';
		str += ' id="' + this.aNodes[code].name + '"';
		str += ' align="center"';
		str += ' valign="top">' + "\n";
		if (this.aNodes[code].hyperlink != '') {
			str += '<a href="'+this.aNodes[code].hyperlink + '"';
			if (this.aNodes[code].bannerTarget) str += ' target="' + this.aNodes[code].bannerTarget + '"';
			str += '>';
		}
		str += '<img border="0" src="' + this.aNodes[code].bannerPath + '"';
		if (this.aNodes[code].bannerTitle != '') str += ' alt="' + this.aNodes[code].bannerTitle + '"';
		str += '></img>';
		if (this.aNodes[code].hyperlink != "") str += '</a>';
		str += (this.horizontal ? '</span> &nbsp; ': '</div><div style="margin:0px;font-size:4px;"> &nbsp; </div>');
	}
	return str;
};