	function fade_quote() {
		new_quote = (current_quote == max_quote ? 1 : current_quote + 1);
		Effect.Fade('quote' + current_quote, {duration: 0.95});
		Effect.Appear('quote' + new_quote, {duration: 0.95});
		current_quote = new_quote;
		setTimeout('fade_quote()', 7000);
	}
	
	/* Start */
	
/* --- Additional Methods --- */

Element.addMethods({
	findClassName: function(element, className) {
	  if (!(element = $(element))) return;
		if (typeof className == 'string') className = new RegExp(className);
		return element.classNames().detect(function(c){ return (className.exec(c)?true:false) });
	},
	cancelClick: function(element) {
		if (!(element = $(element))) return;
		element.onclick = element.onmousedown = function() {return false};
		return element;
	}
});



/* --- Object Classes ---*/

// This class adds .methods to all nodes of type (input,checkbox,textarea)
var FormElement = Class.create({
	initialize : function(elm){
		this.elm = elm = $(elm);
		this.elm.Methods = this;

		if (elm.readAttribute('name')) elm.addClassName(elm.readAttribute('name'));
		if (elm.readAttribute('type')) elm.addClassName('type'+elm.readAttribute('type').capitalize());

		elm.observe('focus',		function() { elm.addClassName('focus') });
		elm.observe('blur',			function() { elm.removeClassName('focus') });
		elm.observe('mouseover',function() { elm.addClassName('hover')} );
		elm.observe('mouseout',	function() { elm.removeClassName('hover')} );

 	},
	formElements: function(value) { return Form.getInputs(this.elm.form) },
	previousElement: function() {
		var elms = this.formElements();
		return elms[( elms.indexOf(this.elm) - 1)];
	},
	nextElement: function() {
		var elms = this.formElements();
		return elms[( elms.indexOf(this.elm) + 1)];
	},
	focusPreviousElement: function() {
		var pe = this.previousElement();
		if (typeof pe == 'undefined') return false;
		if (!pe.Methods.autoTab) return false;
		pe.focus();
		pe.Methods.setSelectionRange(pe.value.length,pe.value.length);
	},
	focusNextElement: function() {
		var ne = this.nextElement();
		if (typeof ne == 'undefined') return false;
		ne.focus();
	},
	removeTypeClass: function() {
		this.elm.classNames().findAll(function(s) { return s.match(/type.*/)	}).each(function(className) { this.elm.removeClassName(className) }.bind(this));
	},
	disablePaste: function(){
		
		var stopPast = function(event) {
			if ((event.keyCode == 86 && event.ctrlKey) || event.metaKey) event.stop();
		}.bindAsEventListener(this)
		
		this.elm.observe('keydown', stopPast).observe('keypress', stopPast);
		
		return this;
	}
});

// This class adds additional .Methods to all input nodes of type text or password
var TextInput = Class.create(FormElement, {
	initialize : function($super, elm){
		$super(elm);
		
		if(! elm.findClassName(/^ibi-/)) elm.addClassName('ibi-'+elm.readAttribute('name')); 
		this.backgroundImageURL = 'images/'+'inputBg-'+elm.findClassName(/^ibi-/).replace(/^ibi-/,'')+'.gif';
		elm.setStyle({'backgroundImage': 'url('+this.backgroundImageURL+')'})
		
		this.storeState();
		
		elm.observe('focus', function() { 
			this.updateClassNames();
			if (this.autoTab) this.setSelectionRange(0,this.elm.value.length);
		}.bind(this));

		elm.observe('blur', this.updateClassNames.bind(this));
		elm.observe('keydown', this.storeState.bind(this));
		elm.observe('keyup', function(e) {
			this.updateClassNames();
			if (e.keyCode != 9 & this.autoTab){
				try{ if ([8,16,37,38,39,40,46].indexOf(e.keyCode) == -1 & this.elm.value.length >= this.elm.maxLength & this.nextElement().Methods.autoTab) this.focusNextElement(); }catch(e){}
				if (
					[8].indexOf(e.keyCode) != -1 & 
					this.elm.lastSelection.length == 0 & 
					this.elm.value.length == 0
				) this.focusPreviousElement();
				// this.elm.lastValue.length <= 1 &
			}
		}.bind(this));
		
		this.updateClassNames();
		elm.onkeypress = this.onKeyPress.bindAsEventListener(this);
		return this;
 	},
	selection: function() {
			if (typeof this.selectionStart != 'undefined' & typeof this.selectionEnd != 'undefined') return	{
				start: this.selectionStart,
				end: this.selectionEnd,
				length: (this.selectionEnd - this.selectionStart)
			};
			if (this.createTextRange) return {
				start: 0,
				end: 0,
				length: this.createTextRange().text.length
			};
			return{start:0,end:0,length:0}
	},

	setSelectionRange: function(start,end) {
		if (typeof this.elm.setSelectionRange == 'function') return this.elm.setSelectionRange(start,end);
		start = (start||0);
		end = (end||0)
		var range = this.elm.createTextRange();
		range.collapse(true);
		range.moveStart('character', start);
		range.moveEnd('character', end);
		range.select();
	},

	storeState: function() {
		this.elm.lastValue = this.elm.value;
		this.elm.lastSelection = this.selection();
	},
	// validCharactor: optional function to validate input field's charactors before they are allowed
	onKeyPress: function(e) {
		var keyCode = (window.event)? window.event.keyCode : e.which;
		var charactor = String.fromCharCode(keyCode);
		return (typeof this.validCharactor == 'function')? this.validCharactor(e, keyCode, charactor) : true;
	},
	updateClassNames: function() {
		if (this.elm.value == ''){
			this.elm.addClassName('empty');
			this.elm.removeClassName('notEmpty');
		}else{
			this.elm.removeClassName('empty');
			this.elm.addClassName('notEmpty');
		}
		return this;
	}
});


/*
 	ON LOAD.....
*/


Event.observe(window,'load',function() {

	//Setting up forms
	$$('input,textarea,select').each(function(formElement){
		formElement = $(formElement);
		if (formElement.readAttribute('jstyle') != null && formElement.readAttribute('jstyle').match(/no/i)) return;		

		switch(formElement.nodeName.toLowerCase()){
			case 'input':
				switch(formElement.readAttribute('type').toLowerCase()){
					case 'text': case 'password': new TextInput(formElement); break;    
				}
				
			break;    
		}
	});

	document.fire('afterCommonLoad');
});















