var	tools = {
	randomString: function() {
		var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
		var string_length = 8;
		var randomstring = '';
		for (var i=0; i<string_length; i++) {
			var rnum = Math.floor(Math.random() * chars.length);
			randomstring += chars.substring(rnum,rnum+1);
		}
		return randomstring;
	},

	getUniqueId: function() {
		return dynamicComponents.options.uniqueIdStr + dynamicComponents.options.uniqueId++;
	}		
};

var dynamicComponents = {
	
	options: {
		growDelayInc: 300,
		growDelayCurrent: 1000,
		uniqueIdStr: tools.randomString(),
		uniqueId: 0
	},
	
	".grow-delay": function(el) {
		setTimeout(function() {Effect.Grow(el, {
			direction: "top-left",
			duration: 0.2
		})}, dynamicComponents.options.growDelayCurrent);
		dynamicComponents.options.growDelayCurrent += dynamicComponents.options.growDelayInc;
	},
	
	".high": function(el) {
//		el.observe("mouseover", function() {
//			if (!el.highlighted) {
//				console.log("mouseover");
//				el.highlighted = true;
//				new Effect.Highlight(el, {endcolor: '#fffde4'});
//			}
//		});
//		el.onmouseout = function(ev) { 
//			e = ev || window.event; 
//			onMouseOutWrapper(el, e, function() {
//				el.highlighted = false;
//			});
//		};
	}
	
};

function scanComponents() {
	for (cmp in dynamicComponents)
		$$(cmp).each(function(el) {
			dynamicComponents[cmp](el);
		});
};

function onMouseOutWrapper(element, event, handler) {
	if (!Position.within(element, Event.pointerX(event), Event.pointerY(event)))
		handler(element, event);
}

document.observe('dom:loaded', function () { scanComponents(); });
