/*
 * EasyGUI XP 1.0.293
 * Copyright(c) 2006-2008 Gaetan Lauff <glauff@plansoft.de>.
 * 
 * This code is licensed under BSD license. Use it as you wish, 
 * but keep the copyright intact.
 * 
 * ========================================================
 * 
 * Prototype JavaScript framework, version 1.6.0.2
 * (c) 2005-2008 Sam Stephenson
 * 
 * ========================================================
 * 
 * script.aculo.us scriptaculous.js v1.8.1
 * Copyright (c) 2005-2008 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
 * 
 * ========================================================
 */

/**
 * @fileoverview EasyGUI Table Column Header Class
 *
 * @author	Gaetan Lauff	<glauff@plansoft.de>
 * @package	js.widgets.table
 *
 * @version	$Id: class.tableheader.js 288 2008-01-15 17:40:20Z glauff $
 */
var EasyGUI_TableHeader = Class.create();

/**
 * Base Class for Table Headers
 *
 * @class EasyGUI_TableColumnHeader
 * @constructor
 * @param	{object}	table	Table Object
 * @private
 */ 
EasyGUI_TableHeader.prototype =
{
	id: null,
	header: null,
	headerTable: null,
	element: null,
	container: null,
	zIndex: 200,
	fl: 0,
	fc: 0,
	height: 0,
	width: 0,
	
	/**
	 * Initializes the Header
	 * @param	table	table object
	 * @returns	void
	 * @private
	 */
	initialize: function( table ) 
	{
		this.id 			= table.id;
		this.element 		= table.element;
		this.container 		= table.container;
		
		this.fl				= table.fixedLines;
		this.fc				= table.fixedColumns;
		
		this.header 		= table.container.cloneNode( true );
		
		this.header.style.overflow 	= 'hidden';
		
		this.headerTable 	= Element.getFirstChildByTagName( this.header, 'TABLE' );
		this.headerTable.id = this.header.id + '_TABLE';
		
		this.headerTable.style.position = 'absolute';
		
		Element.setPosition( this.headerTable, '0px', '0px');
		
		this.headerTable.style.width = this.container.clientWidth + 'px';
		
		this.removeHeaderInputs();
		
		this.setHeight();
		this.setWidth();
		
		this.render();
		
		this.header.style.zIndex 	= this.zIndex;
	},
	
	/**
	 * @private
	 */
	removeHeaderInputs: function()
	{
		for ( var i=0; i < this.fl; i++ ) {
			var nodes = $(this.element.rows[i]).getElementsBySelector('select');
			var element = this.element;
			
			['select','input','textarea'].each( function(name,index) {
				var nodes = $(element.rows[i]).getElementsBySelector(name);
				
				nodes.each( function(node, idx ) {
					node.id += '_EK_REMOVED';
					node.name += '_EK_REMOVED';
					node.style.visibility = "hidden";
				});
			});
				
			
		}
	},

	/**
	 * @private
	 */
	setIframe: function() {
		if (is.ie5up) {
			this.header.iframeEl = this.header.parentNode.insertBefore( Util.getIframe(), this.header);
			
			Element.setPosition( this.header.iframeEl, this.header.offsetTop, this.header.offsetLeft );
			
			Element.show( this.header.iframeEl );
			//Element.setStyle( this.header.iframeEl, { 'position': 'absolute', 'z-index': this.zIndex - 1 } );
			
			this.header.iframeEl.style.position = 'absolute';
			this.header.iframeEl.zIndex = this.zIndex - 1;
			
			Element.setDimension(this.header.iframeEl, this.container.clientWidth, this.height);
		}
	},
	
	/**
	 * @private
	 */
	setWidth: function() {
		for (var i=0; i < this.fl; i++)
			this.width += parseInt(this.element.rows[0].cells[i].offsetWidth);
	},
	
	/**
	 * @private
	 */
	setHeight: function() {
		for (var i=0; i < this.fl; i++)
			this.height += parseInt(this.element.rows[i].offsetHeight);
			
		var tableBorderTop = parseInt( Element.getStyle( this.element, 'border-top-width' ) );
		
		if ( isNaN( tableBorderTop ) )
			tableBorderTop = 0;
			
		this.height += tableBorderTop;
	}
};