//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// CLASS
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

var zxBaseClass = new Class(
{
	///////////////////////////////////////////////////////////////////////////////////////////////
	// PUBLIC
	///////////////////////////////////////////////////////////////////////////////////////////////

	initialize: function()
	{
		zxBaseClass.implement( new Events );
	},
	
	setDefaultOptions: function( options )
	{
		this.$defaultOptions = options;		
	},
	
	setDefaultCustomOptions: function( options )
	{
		this.$defaultCustomOptions = options;
	},

	getOption: function( key, customOptions )
	{
		var data = null;
		
		if ( customOptions != null )
		{
			data = this._getOptionFromOptions( customOptions, key );
		}
		
		if ( (data == null) && this.$defaultCustomOptions != null )
		{
			data = this._getOptionFromOptions( this.$defaultCustomOptions, key );
		}

		if ( (data == null) && this.$defaultOptions != null )
		{
			data = this._getOptionFromOptions( this.$defaultOptions, key );
		}
		
		return data;
	},

	setOption: function( key, value, customOptions )
	{
		if ( customOptions == null )
		{
			customOptions = new Object();
		}
			
		customOptions[key] = value;
		
		return customOptions;
	},
	
	getFirstChildByTag: function( tagName, baseNode )
	{
		if ( tagName == null ) return null;
		if ( baseNode == null ) return null;
		
		var result = null;
		
		// search in all direct childrens
		baseNode.getChildren().each( function(child)
		{
			// for node with given tag name
			if ( (result == null) && (child.getTag() == tagName.toLowerCase()) ) result = child;
		});
		
		return result;
	},

	getChildrenByTag: function( tagName, baseNode )
	{
		if ( tagName == null ) return null;
		if ( baseNode == null ) return null;

		var results = new Array();			
		
		// search in all direct childrens
		baseNode.getChildren().each( function(child)
		{
			// for node with given tag name
			if ( child.getTag() == tagName.toLowerCase() ) 
			{
				results.push( child );
			}
		});
		
		return results;
	},

	getNodeText: function ( node )
	{
		if ( node == null ) return '';
	
		if ( (typeof node == 'string') || (typeof node == 'undefined') ) return el;
		
		// get simple innerText
		if ( node.innerText != null ) return node.innerText;
		
		var text = '';
		
		// get all text data from all td child nodes (this is the default way to get the sort data) 
		for ( var i = node.firstChild; i; i = i.nextSibling)
		{
			switch ( i.nodeType )
			{
				case 3: text += i.nodeValue;						// text node
				case 1: text += this.getNodeText( i );				// element node
			}
		};
		
		return text.trim();
    },
	
	getPageSizeInfos : function()
	{
		//taken from lightbox by Lokesh Dhakar - http://www.huddletogether.com
		var xScroll, yScroll;
		
		if ( window.innerHeight && window.scrollMaxY ) 
		{
			xScroll = document.body.scrollWidth;
			yScroll = window.innerHeight + window.scrollMaxY;
		} 
		else if ( document.body.scrollHeight > document.body.offsetHeight )
		{ 
			// all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} 
		else
		{ 
			// Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
		
		var windowWidth, windowHeight;

		if ( self.innerHeight )
		{	
			// all except Explorer
			windowWidth = window.getWidth();
			windowHeight = self.innerHeight;
		} 
		else if ( document.documentElement && document.documentElement.clientHeight ) 
		{  	
			// Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} 
		else if ( document.body ) 
		{  	
			// other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}
		
		// for small pages with total height less then height of the viewport
		if ( yScroll < windowHeight )
		{
			pageHeight = windowHeight;
		} 
		else
		{
			pageHeight = yScroll;
		}
		
		// for small pages with total width less then width of the viewport
		if ( xScroll < windowWidth )
		{
			pageWidth = windowWidth;
		}
		else
		{
			pageWidth = xScroll;
		}
		
		var sizes = new Object();
		
		sizes.pageWidth = pageWidth;
		sizes.pageHeight = pageHeight;
		sizes.windowWidth = windowWidth;
		sizes.windowHeight = windowHeight;
		sizes.xScroll = xScroll;
		sizes.yScroll = yScroll;
		
		return sizes;
	},

	
	///////////////////////////////////////////////////////////////////////////////////////////////
	// PRIVATE
	///////////////////////////////////////////////////////////////////////////////////////////////
	
	_getOptionFromOptions: function( options, key )
	{
		if ( options[key] != null ) 
		{
			return options[key];
		}
	}	
	
});

