/*
 * Javascript Functions
 *
 * Copyright (c) CLICKSPORTS
 * $Rev$
 * $Author$
 * $Date$
 *
 */

// Set some common attributes
document.observe('dom:loaded', function() {
	setImageFlash();
	getFieldsAllFields();
});

/**
 * Clean all fields with class of autoclean automatically
 */
function getFieldsAllFields() {
	$$('input.autoempty').each(function(f) {
		new emptyFormField(f);
	});
}

/**
 * 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));
	}
});


function setImageFlash() {
	fadeTime = 4.0;
	elm = $('image_teaser');
	imgs = elm.select('img');
	counter = imgs.length;

	if (counter > 1) {
		imgs.invoke('hide');
		imgs[0].show();
		i = 0;
		setInterval("imageFlash(counter, imgs)", 4000);
	}
}

function imageFlash(end, Slides) {
	new Effect.Fade(Slides[i], { duration: 2.0 });
	if (i == end-1) i = 0;
	else i++;
	new Effect.Appear(Slides[i], { duration: 2.0 });
}
