function common () {this.init();}

common.prototype = {

	init : function () {
		// Init array for fading elements
		this.fadeElems = []
		this.aLen = 0;
	},
	
	
	/**
	* $ - Prototype $ function. Accepts element ID's (strings) and HTML objects as arguments. Returns an array of objects.      
	* 
	* Usage: common.$("someID", "someID2", aDivElement, aImgElement); 
	*
	* Author - Prototype library
	*/
	$ : function() {
	
		var elements = new Array();
		
		for (var i = 0; i < arguments.length; i++) {
		
			var element = arguments[i];
		
			if (typeof element == 'string') element = document.getElementById(element);
		
			if (arguments.length == 1) return element;
			
			elements.push(element);
		}
		return elements;
	},

	/**
	* fade - Fades an element. Changes CSS opacity over time.
	*
	* @obj - Element to apply fade to
	* @fadeType - The type of fade, "in", "out", "blink"
	* @fadeSpeed - Time in milliseconds for fade duration, this time is doubled for the blink type fade
	*/
	fade : function (obj, fadeType, fadeSpeed, callback) {
	
		var speed = fadeSpeed / 10;
		
		this.fadeCallback = callback;
		
		// Store all fading elements in array, if over 100 start again.
		if (this.aLen >= 100) {
			this.aLen = 0;
		} else {
			this.aLen++;		
		}
		
		this.fadeElems[this.aLen] = obj;
		
		if (fadeType == "out") {
			for (var i=0;i<11;i++) setTimeout('common.fadeReturn("out", '+this.aLen+', '+(10-i)+', common.fadeCallback )', speed*i);
		}
		
		if (fadeType == "in") {
			for (var i=1;i<11;i++) setTimeout('common.fadeReturn("in", '+this.aLen+', '+i+', common.fadeCallback )', speed*i);
		}
		
		return false;
	},
	
	fadeReturn : function (direction, obj, opacity, callback) {
		common.setOpacity(common.fadeElems[obj], opacity);
		if (direction == "out") {
			if (common.getOpacity(common.fadeElems[obj]) == 0) {
				eval(callback);
			}
		} else if (direction == "in") {
			if (common.getOpacity(common.fadeElems[obj]) == 10) {
				eval(callback);
			}
		}
	},
	
	/**
	* setOpacity - Sets an elements opacity style
	*
	* @obj - Element to apply style rules to
	* @val - Opacity range from 0 - 10
	*
	* NB: In IE the opacity filter can only be applied to elements that have been styled with a width, height or position css attribute.
	*/
	setOpacity : function(obj, val) {
		
		obj.style.opacity = val / 10;
		obj.style.filter = "alpha(opacity="+val*10+")";
	},
	
	getOpacity : function(obj) {
		
		return (obj.style.opacity * 10);
	}
}


/* Add Array push and Pop methods, because some browsers like IE 5 don't have them */

Array.prototype.push = function() {
    var n = this.length >>> 0;
    for (var i = 0; i < arguments.length; i++) {
        this[n] = arguments[i];
        n = n + 1 >>> 0;
    }
    this.length = n;
    return n;
};

Array.prototype.pop = function() {
    var n = this.length >>> 0, value;
    if (n) {
        value = this[--n];
        delete this[n];
    }
    this.length = n;
    return value;
};

common = new common();
