/**
 * Javascript Functions for 1st-dream.de
 * $Author$
 * $Date$
 * $Rev$
 */

// Set some common attributes
document.observe('dom:loaded', function() {
	getFieldsAllFields();
});

function getFieldsAllFields() {
	$$('input.autoclean').each(function(f) {
		new emptyFormField(f);
	});
}

/**
 * Function to show big images in a container.
 */
function setPreviewImages() {
	
	// Hide the big images initially
	$$('ul#image_preview li').invoke('hide');
	$$('ul#image_preview li:first-child').invoke('show');
	
	$$('div.container ul li img').each(function(img) {
		img.observe('mouseover', function(e) {
			elm = Event.element(e);
			elm_big = elm.id.replace('_small', '_big');
			$$('ul#image_preview li').invoke('hide');
			$(elm_big).show();
		}.bind(this));
	})
}

/**
 * Class to empty fields if wanted
 * @param {Object} elm
 */
var emptyFormField = Class.create({
	
	initialize: function(elm) {

		this.elm = $(elm);
		this.oldValue = this.elm.value;
		
		this.elm.observe('click', function(e) {
			val = Event.element(e);
			if(val.value == this.oldValue) val.value='';
		}.bindAsEventListener(this));

		elm.observe('blur', function(e) {
			val = Event.element(e);
			if(val.value.length == 0) val.value=this.oldValue;
		}.bindAsEventListener(this));
	}
});