var extensibleArea = Class.create({
	element: null,
	openHandlers: [],
	closeHandlers: [],
	
	initialize: function(areaName) {
		var that = this;
		this.element = $(areaName);
		if (this.element) {
			var controls = $$('.extensibleAreaControl');
			if (controls) {
				controls.each(function(element) {
					if (element.hasClassName('open_' + areaName)) {
						element.extensibleAreaBinding = that;
						element.onclick = that.openHandler;
						that.openHandlers.push(element);
					}
					if (element.hasClassName('close_' + areaName)) {
						element.extensibleAreaBinding = that;
						element.onclick = that.closeHandler;
						that.closeHandlers.push(element);
						element.hide();
					}
				});
			}
			this.element.hide();
		}
	},
	show: function(visible) {
		if (visible) {
			this.element.show();
			this.openHandlers.each(function(element) {
				element.hide();
			});
			this.closeHandlers.each(function(element) {
				element.show();
			});
		} else {
			this.element.hide();
			this.openHandlers.each(function(element) {
				element.show();
			});
			this.closeHandlers.each(function(element) {
				element.hide();
			});
		}
	},
	openHandler: function() {
		this.extensibleAreaBinding.show(true);
	},
	closeHandler: function() {
		this.extensibleAreaBinding.show(false);
	}
});

var rewardPrint = {
	printViewer: null,
	code: null,
	
	initialize: function(code) {
		new extensibleArea('rewardDetails'+code);
		this.code = code;		
		this.initEasyViewer(code);
		this.initPrintButton(code);
	},
	
	initEasyViewer: function(code) {
		this.printViewer = new easyViewer('Print'+code);
	},
	
	initPrintButton: function(code) {
		var printButton = $('evPrint'+code+'PrintButton');
		if (printButton) {
			printButton.onclick = this.printClickHandler;
		} 
	},
	
	printClickHandler: function() {
		window.print();
		return false;
	}
};

document.observe('dom:loaded', function() {
	if(window.rewardsArray && rewardsArray) {
		for(var i=0;i<rewardsArray.length;i++) {
			rewardPrint.initialize(rewardsArray[i]);
		}
	}
});
