// console
if (! window.console) {
	console = {};
	console.log = function(){}
}

/// mootools extensions
Element.Properties.storage = {
	set: function (obj) {
		for (key in obj) {
			this.store(key, obj[key]);
		}
	},
	get: function (key) {
		return this.retrieve(key);
	},
	erase: function (key) {
		return this.eliminate(key);
	}
};

Fx.implement({
	isRunning: function () {
		return this.timer? true : false;
	}
});

Element.implement({
	isVisible: function(){
		var el = this;
		while (el) {
			if (
					(el.offsetWidth == 0 && el.offsetHeight == 0)
					|| el.getStyle('display') == 'none' 
					|| el.getStyle('visibility') == 'hidden' 
					|| el.getStyle('opacity') == 0 
			) {
				return false;
			}
			el = el.getParent();
		}
		return true;
	}
});






/// root unibasel class
UB = new Class({
	Implements: [Options, Events, Chain],
	
	options: {
		sys_lang_uid: 0, 
		ajax: {
			url: 'typo3conf/ext/unibasel_prog/res/ajax_service.php',
			paramsKey: '_ubajax'
		}
	},
	
	initialize: function (options) {
		this.setOptions(options);
		UB.config = this.options;
	},
	
	/**
	* Get url prepared for ajax request
	* Auto generate url with prepared internal (method, language) and user params
	*/
	ajaxUrl: function (method, params) {
		var qsp = $H({});
		// method and lang
		qsp[this.options.ajax.paramsKey] = {
			'method': method,
			'lang': this.options.sys_lang_uid
		};
		// user params
		qs = qsp.toQueryString();
		switch ($type(params)) {
			case 'object':
				qs += '&' + Hash.toQueryString(params);
				break;
			case 'string':
				qs += '&' + params;
				break;
		}
		// append to script url
		return this.options.ajax.url + (qs? ('?' + qs) : '');
	},
	
	/**
	* Get prepared for send mootools request object
	*/
	ajaxRequest: function (method, params, onLoad, addOptions, dontSend) {
		var options = {
			url: this.ajaxUrl(method, params),
			method: 'get',
			link: 'cancel'
		};
		if (onLoad) {
			options.onSuccess = onLoad;
		}
		if (addOptions) {
			options = $H(options).extend(addOptions).getClean();
		};
		var req = new Request.JSON(options);
		if (! dontSend) {
			req.send();
		}
	},
	
	
	lambda: function () {
		
	}
});
// static
UB.extend({
	instances: {},
	sys_lang_uid: 0,
	config: null
});


