﻿window.fast = new (function() {   
   
    var $ = function() {
		var o = document.getElementById( arguments[0] );
		return o ? extend( o ) : null;
	};
	window.$ = $;
	
	var extendedFunctionList = new Array();
	this.register = function( name, func ) {
		extendedFunctionList[extendedFunctionList.length]={ name : name, func : func };
	}
	
	function extend( o ) {
		if( !o ) return null;
		for( var i = 0; i < extendedFunctionList.length; i++ ) {
			if( !o[extendedFunctionList[i].name] ) {
				o[extendedFunctionList[i].name] = extendedFunctionList[i].func;
			};
		}
		return o;		
	};
		
	this.register("hide", function() {
		this.style._display = this.style.display;
		this.style.display = "none"; 
	});
	
	this.register("show", function() {
		this.style.display = this.style._display ? this.style._display : "block"; 
	});
		
	this.register("setClass", function( cn ) {
		this.className = cn;
	});
		
	this.register("removeClass", function( cn ) {
	    var l = new String(this.className).split(" ");
	    l.splice(l.indexOf(cn),1);
		this.className = l.join(" ");
	});
		
	this.register("addClass", function( cn ) {
	    var l = new String(this.className).split(" ");
	    if( l.indexOf(cn) == -1 ) {
	        l.push(cn);
	    };
		this.className = l.join(" ");
	});
	
	this.register("setContent", function( data ) {
		this.innerHTML = data;
	});
	
	this.register("setOpacity", function( data ) {
		this.style.opacity = data > 0 ? data/100 : 0;	
		this.style.filter = "alpha(opacity="+data+")";
	});
	


		
	this.extend = extend;
	
});

if (!Array.prototype.indexOf){
	Array.prototype.indexOf = function(elt /*, from*/) {
		var len = this.length;
		var from = Number(arguments[1]) || 0;
		from = (from < 0)	
			? Math.ceil(from)
			: Math.floor(from);
		if (from < 0) {
			from += len;
		};
		for (; from < len; from++) {
			if (from in this && this[from] === elt)
				return from;
		};
		return -1;
	};
};

if( !String.prototype.trim ) {
	String.prototype.trim = function() {
		return this.replace(/^\s*/,'').replace(/\s*$/,'');
	};
};