﻿ 

function id( el ){
	if( typeof (el) == 'string' ) return document.getElementById( el );
	else if( typeof (el) == 'object' ) return el; 
}



//change the opacity for different browsers
function changeOpac( opacity , el ) {
	if( !id(el) ) return;
    var objectStyle = id(el).style;
    objectStyle.opacity = (opacity / 100);
    objectStyle.MozOpacity = (opacity / 100);
    objectStyle.KhtmlOpacity = (opacity / 100);
    objectStyle.filter = 'alpha(opacity=' + opacity + ')';
}



/*
Fades an HTML element

el			:	string/object	the HTML element to fade
opacStart	:	integer			startvalue opacity
opacEnd		:	integer			endvalue opacity
delay		:	integer			number of milliseconds the script waits to start fade the next opacity %

NOTE: 	Since the setTimeout statement has to evaluate a string (the function to execute when it runs out)
		the HTML-element argument 'el' has to be a string as well.
		Which means we should write the objects ID down for this argument,
		which means the HTML element HAS TO CONTAIN and ID, also when this function is called with the THIS-keyword (e.g. fade(this, 100, 50, 2); )
*/
function fade( el , opacStart , opacEnd , delay ){
	var ob = id(el);
	var opac;
		
	if( !ob ) return;
	
	// If the object is still fading, stop the 'old' fading
	try{clearTimeout(ob.fadingTimeOut);}
	catch(e){}
	
	// determine the direction for the blending, if start and end are the same we're done; return
	if(opacStart > opacEnd) {
		opac = opacStart - 1;
	} else if(opacStart < opacEnd) {
		opac = opacStart + 1;
	} else {
		return;
	}

	changeOpac( opac , ob.id );
	ob.fadingTimeOut = setTimeout('fade( "' + ob.id + '" , ' + opac + ' , ' + opacEnd + ' , ' + delay + ' )',(delay));
}









function getStyle(el,styleProp)
{
	var obj = Tangora.DOM.EnsureElement(el);
	if (obj.currentStyle)
		var y = obj.currentStyle[styleProp];
	else if (window.getComputedStyle)
		var y = document.defaultView.getComputedStyle(obj,null).getPropertyValue(styleProp);
	return y;
}

// Get the actual height (using the computed CSS) of an element
function getHeight( elem ) {
	// Gets the computed CSS value and parses out a usable number
	return parseInt( getStyle( elem, 'height' ) );
}

// Get the actual width (using the computed CSS) of an element
function getWidth( elem ) {
	// Gets the computed CSS value and parses out a usable number
	return parseInt( getStyle( elem, 'width' ) );
}