/*
 * Unobtrusivelib 1.0
 *
 * Copyright (c) 2007 Pierre Bertet (pierrebertet.net)
 * Dual licensed under the MIT (MIT-LICENSE.txt)
 * and GPL (GPL-LICENSE.txt) licenses.
 *
 */

(function($j){
	$j.unobtrusivelib = function(enabled_modules){
		
		var modules = {
			popup: function(){
				$j("a[@rel^=popup]").click(function(){
					var dims = this.getAttribute('rel').match(/.*\[([0-9]+)-([0-9]+)\].*/);
					window.open(this.getAttribute('href'),'Info','width=' + dims[1] + ',height=' + dims[2] + ',resizable,scrollbars');
					return false;
				});
			},
			
			external: function(){
				$j("a[@rel=external]").click(function(){
					window.open(this.getAttribute('href'));
					return false;
				});
			},
			
			autoClearInput: function(){
				$j("input.autoclear:text, input.autoclear:password").focus(function(){
					if (this._defaultValue == this.value){
						this.value="";
					}
				})
				.each(function(){
					this._defaultValue = this.getAttribute("value");
				});
			},
			
			autoFocusInput: function(){
				var focusElmts = $j("input.autofocus");
				if (focusElmts.length != 0){
					 focusElmts.get(0).focus();
				}
			}
		};
		
		if (enabled_modules){
			$j.each(enabled_modules,function(i,n){
				if(modules[n]){
					modules[n]();
				}
			});
		}
		else {
			$j.each(modules,function(i,n){n();});
		}
		
	};
})(jQuery);
