/*
 * TabbedPane.js v1.0.0 -- Dynamic AJAX Tabs for Prototype
 * Copyright (c) 2007-2008 Jesse Farmer <jesse@20bits.com>
 * Licensed under the MIT license.
 */
// Hash.prototype.toObject = Hash.prototype.toObject || function() { return Object.clone(this); };

var TabbedPane = function (pane, page_urls, args) {
	
	var args = Object.extend({asynchronous: true, method: 'get', evalScripts: true}, args || {});
	
	_load_page = function (page_id) {
		var timestamp = (new Date()).getTime();
		options = args;
		options.parameters = { ts: timestamp };
		new Ajax.Updater(pane, page_urls[page_id], options);
	};
	
	for (page_id in page_urls) {
		Event.observe(page_id, 'click', function (e) {
			Event.stop(e);
			if (typeof args.onClick == 'function') {
				args.onClick(e);
			}
			for (page_id in page_urls) {
				$(page_id).removeClassName('active');				
			}
			_load_page(Event.element(e).addClassName('active').id);
		}.bindAsEventListener(this));
		if ($(page_id).hasClassName('active')) { _load_page(page_id); }		
	}
};