// MooTools Plus, <http://www.tobymiller.com/plus>. Copyright (c) 2008 Toby Miller, MIT Style License.

/*
Script: Debug.js
	Output debug messages.

Usage:
	Debug.enable(); // call once
	Debug.log('your message');
		or
	Debug.enable('http://www.yourdomain.com/debug.php'); // call once
	Debug.log('your message');

	Note: If you opt to use your own remote logger it should accept a query
	like this: http://www.yourdomain.com/debug.php?key=yourdomain&msg=hello

License:
	MIT-style license
*/
var Debug = {
	enable: function(){
		if (!this.enabled){
			this.enabled = true;
			this.ready = false;
			this.remote = (arguments.length > 0) ? arguments[0] : null;
			this.idx = 0;
			this.dmsg = [];
			this.dimg = [];
		}
	},

	disable: function(){
		if (this.enabled){
			this.enabled = false;
			this.remote = null;
		}
	},

	log: function(msg){
		if (typeof this.enabled == 'undefined') this.enable();
		this.dmsg[this.dmsg.length] = msg;
		this.process();
	},

	process: function(){
		if (this.enabled){
			if (this.dmsg[this.idx]){
				this.ready = true;
				if (window.console){
					window.console.log(this.dmsg[this.idx]);
					this.idx++;
					this.process();
				} else if (this.remote != null){
					var ts = new Date().getTime();
					var h = new Hash({'key': window.location.hostname, 'msg': this.dmsg[this.idx]});
					var q = this.remote+'?ts='+ts+'&'+h.toQueryString();
					this.dimg.push(new Asset.image(q));
					this.idx++;
					this.process();
				}
			}
		}
	}
};

/*
Script: EnhancedElement.js
	Define additional class names, styles, events, attributes, and properties to
	apply to html elements whenever JavaScript is enabled. These definitions
	are written into a JavaScript object inside an html comment block within the
	particular html element(s) being enhanced.

	Note: Since these instructions are ignored by search engines and screen
	readers they should never contain content or anything else that would
	prevent the current page from being contextually understandable.

	Usage:
	<tag>
		tag content
		<!--{
			'styles': {
				'color': '#f00',
				'background-color': '#000'
			},
			'class': 'harry',
			'className': 'monkey',
			'classes': ['harry', 'monkey', 'fever'],
			'attributes': {
				'checked': 'checked',
				'temperature': '99.7'
			},
			'property1': 'hello',
			'property2': ['hello', 'world'],
			'property3': {
				'key1': 'hello',
				'key2': 'there',
				'key3': 'world'
			},
			'events': {
				'mouseover': function(){ this.set('src', 'on.gif') }
				'mouseover': function(){ this.set('src', 'off.gif') }
			}
		}-->
	</tag>

License:
	MIT-style license
*/
var EnhancedElement = {
	enhance: function(){
		var selector = (arguments.length > 0) ? arguments[0] : ['address','a','big','blockquote','body','b','caption','center','cite','code','dd','dfn','dir','div','dl','dt','em','form','h1','h2','h3','h4','h5','h6','i','kbd','li','menu','ol','option','param','pre','p','samp','select','small','strike','strong','sub','sup','table','td','th','title','tr','tt','ul','u','var'];
		$$(selector).each(function(el){
			var html = el.innerHTML;
			el.getChildren().each(function(child){ html = html.replace(child.innerHTML, '') });
			html = html.replace(/[\n\r]*/g, '');
			var match = html.match(/^.*<!--\s*\{(.*)\}\s*-->.*$/);
			if (match){
				var enhanced = eval('({' + match[1] + '})');
				for (var name in enhanced){
					switch(name){
						case 'class':
						case 'className':
							el.addClass(enhanced[name]);
							break;
						case 'classes':
							for (var i = 0; i < enhanced[name].length; i++) el.addClass(enhanced[name][i]);
						case 'styles':
							for (var n in enhanced[name]) el.setStyle(n, enhanced[name][n]);
							break;
						case 'events':
							for (var n in enhanced[name]) el.addEvent(n, enhanced[name][n]);
							break;
						case 'attributes':
							for (var n in enhanced[name]) el.setAttribute(n, enhanced[name][n]);
							break;
						default:
							if (name.length > 0) el.setProperty(name, enhanced[name]);
							break;
					}
				}
			}
		});
	}
};
window.addEvent('domready', function(){ EnhancedElement.enhance() });


/*if (Browser.Plugins.Flash.version > 0){
	if (Browser.Plugins.Flash.version >= 9) new Asset.css('/css/flash.css');
	else new Asset.css('/css/upgradeflash.css');
}*/
