/**
 * SEVENSPIRE JS-UTILITIES
 * (c) 2008 by Peter Wallner | peter@helic.net
 */


function Sevenspire()
{
	var that = this;
	this.cnt = 0;

	this.$ = function(id)
	{
		return document.getElementById(id); 
	}
	
	this.$v = function(id)
	{
		return document.getElementById(id).value; 
	}

	this.changeBgColor = function(id, color)
	{
		this.$(id).style.backgroundColor = color;
	}
	
	this.changeBorderColor = function(id, color)
	{
		this.$(id).style.borderColor = color;
	}

	this.validateForm = function(elements)
	{
		var ret_val = true;
		var elements = elements.split(" ");

		for(i=0;i<=(elements.length-1);i++)
		{
			var e = elements[i];
			if(!this.$v(e))
			{
				this.highlightFormElement(e);
			
				ret_val = false;
			}
		}

		return ret_val;
	}

	this.highlightFormElement = function(id, options)
	{
		if(!options) options = new Array();
	
		if(!options[0]) options[0] = "white";
		if(!options[1]) options[1] = "#eee";
		
		if(!this.$v(id))
		{
			this.changeBgColor(id, options[1]);
		}
		else
		{
			this.changeBgColor(id, options[0]);
		}
	}
	
	this.rotateNews = function(cnt, duration, init)
	{
		if(!init)
		{
			var current = this.cnt;
			this.cnt = (this.cnt>=(cnt-1) ? 0 : this.cnt+1);

			$("news-"+current).style.display = "none";
			new Effect.BlindDown($("news-"+this.cnt), {duration:0.25});
		}

		setTimeout(function(){s.rotateNews(cnt, duration, false);}, duration);
	}
	
}


//create object
var s = new Sevenspire;
