// ITRepublic ViViD.js by Gabor Gludovatz (C) 2009
// Web: www,itrepublic.ca
// Mail: gabor.gludovatz #AT# gmail.com

var ITRepublicVidid =
{
	hideDefault:
	{
		init: function(target) {
			var newObj = {};

			newObj.target = target;
			newObj.origValue = target.value;
			newObj.changed = false;
			newObj.focused = false;
			newObj.base = this;

			target.style.color = '#999';

			Event.observe(target, 'focus', this.focus.bind(newObj));
			Event.observe(target, 'blur', this.blur.bind(newObj));
			Event.observe(target, 'mouseover', this.mouseEnter.bind(newObj));
			Event.observe(target, 'mouseout', this.mouseOut.bind(newObj));
			Event.observe(target, 'keydown', this.onItemChanged.bind(newObj));
			//Event.observe(element, 'changed', function() { this.changed = true; });
		},

		hideValue: function(newObj) {
			if (!newObj.changed)
				newObj.target.value = '';
		},

		resetDefaultValue: function(newObj) {
			if (!newObj.changed && !newObj.focused)
				newObj.target.value = newObj.origValue;
		},

		resetDefaultValueSlowly: function(newObj) {
			if (!newObj.changed)
				setTimeout(function() { newObj.base.resetDefaultValue(newObj); }, 600);
		},

		focus: function(event) {
			this.focused = true;

			this.base.hideValue(this);
		},

		blur: function(event) {
			this.focused = false;

			this.base.resetDefaultValueSlowly(this);
		},

		mouseEnter: function(event) {
			if (!this.focused)
				this.base.hideValue(this);
		},

		mouseOut: function(event) {
			if (!this.focused)
				this.base.resetDefaultValueSlowly(this);
		},

		onItemChanged: function(event) {
			this.changed = true;

			this.target.style.color = '#333';
			this.target.style.textAlign = 'left';

			Event.stopObserving(this.target, 'focus', this.base.focus.bind(this));
			Event.stopObserving(this.target, 'blur', this.base.blur.bind(this));
			Event.stopObserving(this.target, 'mouseover', this.base.mouseEnter.bind(this));
			Event.stopObserving(this.target, 'mouseout', this.base.mouseOut.bind(this));
			Event.stopObserving(this.target, 'keydown', this.base.onItemChanged.bind(this));
		}
	},

	init: function() {
		this.hideDefault.init($('stayintouch_name'));
		this.hideDefault.init($('stayintouch_email'));
	}
};

/*
var ITRepublicVidid =
{
	hideDefault:
	{
		target: false,
		changed: false,
		origValue: '',

		init: function(target) {
			this.target = target;
			this.origValue = target.value;

			this.target.style.color = '#88B';



			Event.observe(target, 'focus', this.hideValue.bind(this));
			Event.observe(target, 'blur', this.resetDefaultValue.bind(this));
			Event.observe(target, 'change', this.onItemChanged.bind(this));
			//Event.observe(element, 'changed', function() { this.changed = true; });
		},

		hideValue: function(event) {
			if (!this.changed)
				this.target.value = '';
		},

		resetDefaultValue: function(event) {
			if (!this.changed)
				this.target.value = this.origValue;
		},

		onItemChanged: function(event) {
			this.changed = true;

			this.target.style.color = '#333';

			Event.stopObserving(this.target, 'focus', this.hideValue.bind(this));
			Event.stopObserving(this.target, 'blur', this.resetDefaultValue.bind(this));
			Event.stopObserving(this.target, 'change', this.onItemChanged.bind(this));
		}
	},

	init: function() {
		//this.hideDefault.init($('stayintouch_name'));
		this.hideDefault.init($('stayintouch_email'));
	}
};
*/
Event.observe(window, 'load', function() {
	ITRepublicVidid.init()
});
