
/************************************************************************
 *																		*
 *		element.js														*
 *																		*
 *			Contains the ELEMENT class.									*
 *																		*
 *			ELEMENT Class contains various functions for elements.		*
 *																		*
 *																		*
 *		Copyright © 2009 by Josef Guenther								*
 *			All rights reserved.										*
 *																		*
 *			Contact me at:												*
 *			josefguenther@gmail.com										*
 *																		*
 *																		*
 ************************************************************************/



// -------------------------------------------------------------------------------- //
//																					//
//								ELEMENT Class										//
//																					//
// -------------------------------------------------------------------------------- //

//
// element Class
//
var element = ({
	
	//
	// Functions
	//
	
	
	//
	// id() - Returns the document id for element
	//
	id: function (id)
	{
		return document.getElementById(id);
	},
	
	//
	// show() - Displays the element
	//
	show: function (id)
	{
		this.id(id).style.display = '';
	},
	
	//
	// hide() - Hides the element
	//
	hide: function (id)
	{
		this.id(id).style.display = 'none';
	},
	
	//
	// fade() - Fades element in or out
	//
	fade: function (id, opacStart, opacEnd, millisec)
	{
		var stepSize, i, speed, timer;
		
		if (isIE6) {
			this.changeOpacity(id, opacEnd);
			return;
		}
		
		// speed for each frame
		speed = Math.round(millisec / 100);
		timer = 0;
		
		// determine the direction for the blending, if start and end are the same nothing happens
		if (opacStart > opacEnd) {
			stepSize = Math.round((opacStart - opacEnd) / (isIE ? 4 : 20));
			for (i = opacStart; i > opacEnd; ) {
				i -= stepSize;
				if (i < opacEnd) { i = opacEnd; }
				setTimeout("element.changeOpacity('" + id + "'," + i + ")",(timer * speed));
				timer += stepSize;
			}
		} else if (opacStart < opacEnd) {
			stepSize = Math.round((opacEnd - opacStart) / (isIE ? 4 : 20));
			for(i = opacStart; i < opacEnd; ) {
				i += stepSize;
				if (i > opacEnd) { i = opacEnd; }
				setTimeout("element.changeOpacity('" + id + "'," + i + ")",(timer * speed));
				timer += stepSize;
			}
		}
	},
	
	//
	// changeOpacity() - Changes element opacity (cross browser)
	//
	changeOpacity: function (id, opacity)
	{
		var object = this.id(id).style;
		object.opacity = (opacity / 100);
		object.MozOpacity = (opacity / 100);
		object.KhtmlOpacity = (opacity / 100);
		object.filter = "alpha(opacity=" + opacity + ")";
		//
		if (!opacity) {
			object.display = "none";
		} else if (object.display == "none") {
			object.display = "";
		}
	}
	
	
});

