
_	= $;
__	= $$;
_E	= $E;
_ES	= $ES;

// reset default Cookie vars
Cookie.options.duration	= 14;
Cookie.options.path	= '/';

// CustomLoad.js:
// script that handles window.domready and window.load in the correct order
// call via customLoad.dom.push(func) or customLoad.load.push(func)
var CustomLoad		= function() {
	var obj		= this;
	obj.done	= [];	// register which objs (DOM and load) are loaded
	obj.dom		= [];	// when DOM is loaded
	obj.load	= [];	// when all is loaded
	obj.unload	= [];	// when document is unloaded
	obj.exe		= function(kind) {
		if (kind=='load' && !obj.done['dom']) {obj.done[kind]=true}
		else {
			for (var i=0; i<obj[kind].length; i++) {if (obj[kind][i]()) break}
			obj.done[kind]	= true;
			if (kind=='dom' && obj.done['load']) {obj.exe('load')}
		}
	};
	window.addEvent('domready' ,	function() {obj.exe('dom')});
	window.addEvent('load' ,	function() {obj.exe('load')});
	window.addEvent('unload' ,	function() {obj.exe('unload')});
};
var customLoad = new CustomLoad();

// DocSel moet aangepast worden om correct op Safari en Opera te werken
// Zie: http://luke.breuer.com/tutorial/javascript-drag-and-drop-tutorial.aspx
customLoad.dom.push(function() {
	// only init if '/libs/js/mootools/HandleEventsByName/HandleEventsByName.js' is loaded
	if (window.addEventByName) {
		// Document Selection: DocSel.change(false) disables document selection (init value is false)
		DocSel	= new new Class({
			onOff:	true,
			func:	function (e) {if (!this.onOff) new Event(e).stop()},
			initialize: function() {
				this.change(this.onOff);

				__('html')[0].addEventByName(Window.ie ? 'selectstart':'mousedown' , 'docsel' , this.func.bind(this));
			},
			change:	function (onOff) {
				if (!(this.onOff = onOff!=undefined ? onOff:!this.onOff)) unselectAll()
			}
		});
	}
});

function unselectAll() {
	if	(document.selection && document.selection.empty) document.selection.empty()
	else if	(window.getSelection && (sel=window.getSelection())) {
		if	(sel.collapse)		sel.collapse(__('body')[0],0);
		else if	(sel.removeAllRanges)	sel.removeAllRanges();
	}
}

Element.extend({
	// rewrite Element.getText: otherwise it doesn't allways work on Safari
	getText: function() {
		return this.innerText || this.textContent || unescape(this.innerHTML.replace(/<[^>]+>/g , ''))
	},

	// rewrite Element.getProperty: IE8 does not like to approach attributes directly (http://www.chronoengine.com/forums/viewtopic.php?f=3&t=14184&p=35477#p35477)
	getProperty: function(property){
		var index = Element.Properties[property];
		if (index) return this[index];
		var flag = Element.PropertiesIFlag[property] || 0;

		// Commented old line
//		if (!window.ie || flag) return this.getAttribute(property, flag);

		// Two new lines: put MSIE version number in var msie and check if this is 8 or higher
		var msie = navigator.userAgent.toLowerCase().match(/msie\s+(\d)/);
		if (!window.ie || flag || msie && msie[1]>=8) return this.getAttribute(property, flag);

		var node = this.attributes[property];
		return (node) ? node.nodeValue : null;
	}
});

Garbage.destructor = new Element('div');
Element.extend({
	destroy: function(){
		this.injectInside(Garbage.destructor);
		Garbage.destructor.empty();
	}
});

var imageLoader	= loadImage = ImageLoader();
function ImageLoader() {
	var imgs = {};

	return function main(src , onload) {
		if (imgs[src]) {
			if (imgs[src].complete)	{if (onload) onload.delay(100 , imgs[src] , 2)}
			else			setTimeout(function() {main(src , onload)} , 1000)
		}
		else {
			imgs[src]		= new Image();
			imgs[src].onload	= function() {if (onload) onload.delay(100 , imgs[src] , 1)};
			imgs[src].src		= src;
		}
	}
}

var fx = new function() {
	var ta={};
	return function(id , arg) {
		if (arg) {
			if (arg=='remove') {
				if (ta[id]) {
					ta[id].stop().removeEvent();
					ta[id]=null;
					delete ta[id];
				}
			}
			else return ta[id]=arg
		}
		else return ta[id]
	}
}

