Deck = function(id) {
	this.drawSelected = function(n, i) { };
	this.drawUnselected = function(n, i) { };
	this.instanceId = document.getElementById(id);
	this.selectedItem = 0;
	this.cards = [];
	var elementIndex = 0;
	if (this.instanceId)
		this.collectItems();
}
Deck.prototype.collectItems = function() {
	var elementIndex = 0;
	for (var i=0; i<this.instanceId.childNodes.length; i++) {
		var n = this.instanceId.childNodes.item(i);
		if (n.style) {
			this.cards.push(n);
			elementIndex++;
		}
	}
};
Deck.prototype.select = function(i) {
	if (i != this.selectedItem) {
		if (this.cards[this.selectedItem])
			this.drawUnselected(this.cards[this.selectedItem], this.selectedItem);
		if (this.cards[i])
			this.drawSelected(this.cards[i], i);
		this.selectedItem = i;
	}
};
Deck.prototype.init = function() {
	for (var i=0; i<this.cards.length; i++) {
		if (i == this.selectedItem)
			this.drawSelected(this.cards[i], i);
		else
			this.drawUnselected(this.cards[i], i);
	}
};

RadioButtonGroup = function(id) {
	this.instanceId = document.getElementById(id);
	this.selectedItem = 0;
	this.radioButtons = [];
	var elementIndex = 0;
	for (var i=0; i<this.instanceId.childNodes.length; i++) {
		var n = this.instanceId.childNodes.item(i);
		if (n.firstChild && n.firstChild.nodeName == "A") {
			//n.cardi = i;
			this.radioButtons.push(n);
			elementIndex++;
		}
	}
	this.setEventHandlers();
	//the following functions need to be overloaded differently on each page for proper behavior
	this.drawSelected = function(n, i) { };
	this.drawUnselected = function(n, i) { };
	this.drawHover = function(n, i) { };
	this.drawUnhover = function(n, i) { };
	this.drawSelected(this.selectedItem);
};
RadioButtonGroup.prototype.init = function() {
	for (var i=0; i<this.radioButtons.length; i++) {
		if (i == this.selectedItem)
			this.drawSelected(this.radioButtons[i], i);
		else
			this.drawUnselected(this.radioButtons[i], i);
	}
};

RadioButtonGroup.prototype.setEventHandlers = function() {
	var _this = this;
	for (var i=0; i<this.radioButtons.length; i++) {
		var instanceId = this.radioButtons[i];
		if (instanceId.addEventListener)
		 eval("instanceId.addEventListener('click', function() { _this.select("+i+") }, false);"); 
			//instanceId.addEventListener("click", eval("function() { _this.select("+i+"); }"), false);
		if (instanceId.attachEvent)
			eval("instanceId.attachEvent('onclick',function() { _this.select("+i+"); })"); // IE6 compatibility
		if (instanceId.addEventListener)
		eval("instanceId.addEventListener('mouseover', function() { _this.hover("+i+") }, false);");
			//instanceId.addEventListener("mouseover", eval("function() { _this.hover("+i+"); }"), false);
		if (instanceId.attachEvent)
			eval("instanceId.attachEvent('onmouseover',function() { _this.hover("+i+"); })"); // IE6 compatibility
		if (instanceId.addEventListener)
		eval("instanceId.addEventListener('mouseout', function() { _this.unhover("+i+") }, false);");
			//instanceId.addEventListener("mouseout", eval("function() { _this.unhover("+i+"); }"), false);
		if (instanceId.attachEvent)
			eval("instanceId.attachEvent('onmouseout',function() { _this.unhover("+i+"); })"); // IE6 compatibility
	}
};

//RadioButtonGroup.prototype.setEventHandlers = function() {    var _this = this;    for (var i=0; i<this.radioButtons.length; i++) {        var instanceId = this.radioButtons[i];        if (instanceId.addEventListener)            eval("instanceId.addEventListener('click', function() { _this.select("+i+") });");        if (instanceId.attachEvent)            eval("instanceId.attachEvent('onclick',function() { _this.select("+i+") });"); // IE6 compatibility        if (instanceId.addEventListener)            eval("instanceId.addEventListener('mouseover', function() { _this.hover("+i+") });");        if (instanceId.attachEvent)            eval("instanceId.attachEvent('onmouseover',function() { _this.hover("+i+") });"); // IE6 compatibility        if (instanceId.addEventListener)            eval("instanceId.addEventListener('mouseout', function() { _this.unhover("+i+") });");        if (instanceId.attachEvent)            eval("instanceId.attachEvent('onmouseout',function() { _this.unhover("+i+") });"); // IE6 compatibility    } }; 
 
RadioButtonGroup.prototype.select = function(i) {
	if (i != this.selectedItem) {
		this.drawUnselected(this.radioButtons[this.selectedItem]);
		this.drawSelected(this.radioButtons[i]);
		this.selectedItem = i;
		if (this.onselect)
			this.onselect(i);
	}
};
RadioButtonGroup.prototype.hover = function(i) {
	document.body.style.cursor = 'pointer';
	if (i != this.selectedItem) {
		this.drawHover(this.radioButtons[i]);
	}
};
RadioButtonGroup.prototype.unhover = function(i) {
	document.body.style.cursor = 'default';
	if (i != this.selectedItem) {
		this.drawUnhover(this.radioButtons[i]);
	}
};

