/*
Copyright (c) 2006 Lukasz Szajkowski <http://www.szajkowski.com/>

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
*/


/** A GenericDiv class is a div conteiner */
function GenericDiv(name) {
	//alert('GenericDiv' + name);
	
	this.className = 'GenericDiv';
	
	/** Default construtor
	 *
	 * name - div name
	 */
	{	
		this.name = name;
		
		if (NS4) {
			this.obj = Zorya.divFactory().getDivForN4(document,name);
			this.style = this.obj;
			this.width = parseInt(this.obj.width);
			this.x = parseInt(this.style.left);
			this.y = parseInt(this.style.top);
		} else if (IE4) {
			this.obj = document.getElementById(name);
			this.style = document.getElementById(name).style;	
			this.width = parseInt(this.style.pixelWidth);
			this.x = parseInt(this.style.pixelLeft);
			this.y = parseInt(this.style.pixelTop);	
		} else if (NS6) {
			this.obj = document.getElementById(name);
			this.style = document.getElementById(name).style;	
			this.x = parseInt(this.style.left);
			this.y = parseInt(this.style.top);
		} else {
			alert('Browser not supported');
		} 
		/*else if (document.all)
			this.obj = document.all[name];
			this.style = document.all[name].style;	
			this.x = parseInt(this.style.left);
			this.y = parseInt(this.style.top);
		  }*/
	}
		
	/** Template like function declaration where browser type 
	 * is like class type
	 */
	if (NS4) {
		/** The method returns y field */
		this.getX = function(){
			return parseInt(this.style.left);
		}	
		/** The method returns y field */
		this.getY = function(){
			return parseInt(this.style.top);
		}

		/** The method returns width field */
		this.getWidth = function(){
			return parseInt(this.obj.offsetWidth);
		}

		/** The method returns height field */
		this.getHeight = function(){
			return parseInt(this.obj.offsetHeight);
		}		
	} else if (IE4) {
		/** The method returns y field */
		this.getX = function(){
			return parseInt(this.style.pixelLeft);
		}	
		/** The method returns y field */
		this.getY = function(){
			return parseInt(this.style.pixelTop);
		}

		/** The method returns width field */
		this.getWidth = function(){
			return parseInt(this.obj.offsetWidth);
		}

		/** The method returns height field */
		this.getHeight = function(){
			return parseInt(this.obj.offsetHeight);
		}		
	} else if (NS6) {
		//alert('declare getX');
		/** The method returns y field */
		this.getX = function(){
			return parseInt(this.style.left);
		}	
		/** The method returns y field */
		this.getY = function(){
			return parseInt(this.style.top);
		}

		/** The method returns y field */
		this.getY = function(){
			return parseInt(this.style.top);
		}

		/** The method returns width field */
		this.getWidth = function(){
			return parseInt(this.obj.offsetWidth);
		}

		/** The method returns height field */
		this.getHeight = function(){
			return parseInt(this.obj.offsetHeight);
		}
	} 	
	
	/** The method returns y field */
	this.getCenterX = function(){
		return this.getX() + this.getWidth()/2;
	}
	
	/** The method returns y field */
	this.getCenterY = function(){
		return this.getY() + this.getHeight()/2;
	}
			
	this.paint = function(content){

	}

	/** 
	 * The method append to the div content
	 * TODO if the method is coled many times refactor
	 * to template like implementation
	 */
	this.appendContent = function(content) {
		Zorya.divFactory().appendToDiv(content, this.name);
	}
	
	//alert('[' + this.name + ']');
}
