//var DHTML = ( document.getElementById || document.all || document.layers );

function getById( id ) {
    var ret = new Object();

    if ( document.getElementById ) {
	ret.obj   = document.getElementById(id);
	if ( ret.obj && ret.obj.style ) {
	    ret.style = document.getElementById(id).style;
	}
    }
    else if ( document.all ) {
	ret.obj   = document.all[id];
	ret.style = document.all[id].style;
    }
    else if ( document.layers ) {
	ret.obj   = document.layers[id];
	ret.style = document.layers[id];
    }

    if ( ret.obj ) {
	return ret;
    }
    else {
	return false;
    }
}

/**
 * Given object will have the magic powers to
 * modify it's classes in a nice way.
 * 
 *
 * Usage: 
 *
 * obj = getElementById( 'someHtmlId');
 * makeClassHandler( obj );
 * // now the obj has the following functions:
 * 
 * if ( obj.hasClass( 'someClass' ) ) {
 *     // do something
 * }
 *
 * obj.addClass( 'anotherClass' );
 *
 * obj.dropClass( 'anotherClass' );
 */

function makeClassHandler( obj )
{

    if ( obj.className.length > 0 ) {
	obj.classes = obj.className.split( ' ' );
    }
    else {
	obj.classes = new Array();
    }

    obj.addClass = function( c ) {
	for ( var i = 0 ; i < this.classes.length; i++ ) {
	    if ( this.classes[i] == c ) {
		return true;
	    }
	}
	this.classes.push( c );
	this.updateClassName();
	return true;
    }

    obj.dropClass = function( c ) {
	for ( var i = 0 ; i < this.classes.length; i++ ) {
	    if ( this.classes[i] == c ) {
//		this.classes[i] = null;
		this.classes.splice( i, 1 );
		this.updateClassName();
		return true;
	    }
	}
	return false;
    }

    obj.hasClass = function( c ) {
	for ( var i = 0 ; i < this.classes.length; i++ ) {
	    if ( this.classes[i] == c ) {
		return true;
	    }
	}
	return false;
    }
    
    obj.updateClassName = function(){
	this.className = this.classes.join( ' ' );
    }

}


function getPageHeight()
{
    if (window.innerHeight)
    {
	return window.innerHeight;
    }
    else if (document.documentElement && document.documentElement.clientHeight)
    {
	return document.documentElement.clientHeight;
    }
    else if (document.body)
    {
	return document.body.clientHeight;
    }
}

function getPageOffsetX()
{
    var ox;
    if (self.pageYOffset) // all except Explorer
    {
	ox = self.pageXOffset;
    }
    else if (document.documentElement && document.documentElement.scrollTop) // Explorer 6 Strict
    {
	ox = document.documentElement.scrollLeft;
    }
    else if (document.body) // all other Explorers
    {
	ox = document.body.scrollLeft;
    }

    return ox;
}

function getPageOffsetY()
{
    var oy;
    if (self.pageYOffset) // all except Explorer
    {
	oy = self.pageYOffset;
    }
    else if (document.documentElement && document.documentElement.scrollTop) // Explorer 6 Strict
    {
	oy = document.documentElement.scrollTop;
    }
    else if (document.body) // all other Explorers
    {
	oy = document.body.scrollTop;
    }

    return oy;
}

function getPageWidth()
{
    if (window.innerWidth)
    {
	return window.innerWidth;
    }
    else if (document.documentElement && document.documentElement.clientWidth)
    {
	return document.documentElement.clientWidth;
    }
    else if (document.body)
    {
	return document.body.clientWidth;
    }
}


