function initializeCardFrames() {
	map(function(frame) {
		frame.cards = [];
		frame.show = function(card) {
			var showCardIndex = parseInt(card);
			if (isNaN(showCardIndex)) {
				showCardIndex = card.index;
			}
			for (var i = 0; i < this.cards.length; i++) {
				if (this.cards[i].index == showCardIndex) {
					if (!isNull(this.selectedCard)) {
						signal(this.selectedCard, 'onflipblur');
					}
					this.selectedCard = this.cards[i];
					removeElementClass(this.cards[i], "hidden");
					signal(this.cards[i], 'onflipfocus');
				} else {
					addElementClass(this.cards[i], "hidden");
				}
			}
			signal(this, 'onflip');
		};
		frame.flip = function () {
			if (isNull(this.selectedCard)) {
				this.show(0);
			} else {
				this.show((this.selectedCard.index + 1) % this.cards.length);
			}
		};
		frame.selectedCard = null;
		for (var i = 0; i < frame.childNodes.length; i++) {
			nodeWalk(frame.childNodes[i], function(node) {
				if (node.nodeType == 1) {
					if (hasElementClass(node, 'card_frame')) {
						return null;
					} else if (hasElementClass(node, 'card')) {
						node.frame = frame;
						node.enabled = true;
						node.show = function() {
							this.frame.show(this);
						};
						node.index = frame.cards.length;
						frame.cards.push(node);
						if (!hasElementClass(node, "hidden")) {
							frame.selectedCard = node;
						}
						return node.childNodes;
					} else {
						return node.childNodes;
					}
				}
				return null;
			});
		}
	}, getElementsByTagAndClassName(null, 'card_frame'));
}
addLoadEvent(initializeCardFrames);