function LGImageHolderChildNode(HTMLElement,x,y){
	this.HTMLElement = HTMLElement;
	this.HTMLElement.style.position = "absolute";
	this.x = x;
	this.y = y;
	this.getWidth = function(){
		return parseInt(this.HTMLElement.style.width.substr(0,this.HTMLElement.style.width.length-2));
	}
}

function LGImageHolder(id, owner, title, IMGurl, action){
	//create - init - deaclre
	this.id=id;
	this.IMGurl = IMGurl;
	this.action = action;
	this.HTMLElement = document.createElement('div');
	this.HTMLElement.style.position = "absolute";
	this.childElements = new Array();
	owner.frame.appendChild(this.HTMLElement);
	this.owner = owner;
	this.HTMLElement.style.display = "none";
	this.HTMLElement.style.zIndex = 0;
	this.IMGObject = null;
	this.ready = false;
	this.title = title;
	var _this = this;
	
	this.addChildNode = function(HTMLElement,x,y){
		var newElement = new LGImageHolderChildNode(HTMLElement,x,y);
		this.childElements.push(newElement);
		this.HTMLElement.appendChild(newElement.HTMLElement);
	}
	
	//betöltés
	this.loadIMG = function() {
		this.IMGObject = new Image();
		this.IMGObject.onload = function () { _this.readyToUse()}
		this.IMGObject.src = this.IMGurl;
		this.HTMLElement.style.backgroundImage = 'url("'+this.IMGurl+'")';
	}
	
	this.readyToUse = function(){
		this.HTMLElement.style.width = this.IMGObject.width+"px";
		this.HTMLElement.style.height = this.IMGObject.height+"px";
		this.HTMLElement.style.backgroundRepeat = "no-repeat";
		var messageObj = new function() {
			this.message = "imgLoaded";
			this.sender = _this;
		}
		_this.owner.controller.receveMessage(messageObj);
	}
	
	//megjelenés
	this.setVisible = function (bool){
		if (bool) {
			this.HTMLElement.style.display = "block";
		} else {
			this.HTMLElement.style.display = "none";
		}
	}
	this.isVisible = function (){
		return this.HTMLElement.style.display != "none";
	}
	
	this.positionX = 0.0;
	this.positionY = 0.0;
	this.bgRelPositionX = 0;
	this.bgRelPositionY = 0;
	
	this.setPositionX = function(x){
		this.positionX = x;
		if (this.ready){
			var xout = x;
			var bgpx = 0;
			if (this.positionX < -this.getWidth()){
				this.setVisible(false);
			} else {
				if (this.positionX < this.owner.getWidth()) {
					var locwidth = this.getWidth();
					if ( this.positionX < 0){
						locwidth = (this.getWidth()+this.positionX);
						bgpx = this.positionX;
						xout = 0;
						if ( (this.positionX + this.getWidth() ) > this.owner.getWidth() ) {
							locwidth = this.owner.getWidth();
						}

					} else {
						if ( (this.owner.getWidth() - this.getWidth() ) < this.positionX ) {
							locwidth = (this.owner.getWidth()-this.positionX);
						}
					}
					this.HTMLElement.style.left = xout+'px';
					this.HTMLElement.style.backgroundPosition = bgpx+this.bgRelPositionX+"px "+this.bgRelPositionY+"px";
					this.HTMLElement.style.width = locwidth+'px';
					for (i=0;i<this.childElements.length;i++){
					
						this.childElements[i].HTMLElement.style.left = this.childElements[i].x + bgpx +"px";	
						var opa = 1;
						var isVisible = true;
						if (bgpx < 0) {
							if (-bgpx > (this.childElements[i].x)){
								if ( (-bgpx < (this.childElements[i].x + this.childElements[i].getWidth())) && NotIE ){
										opa = 1-(-bgpx - this.childElements[i].x)/this.childElements[i].getWidth();
								} else {
									isVisible = false;
								}
							}
						} else {
							if (locwidth < (this.childElements[i].x+this.childElements[i].getWidth())){
								if ( (locwidth > (this.childElements[i].x)) && NotIE ){
									opa = (locwidth-this.childElements[i].x)/this.childElements[i].getWidth();
								} else {
									isVisible = false;
								}
							}
						}
						
						if (NotIE) this.childElements[i].HTMLElement.style.opacity = opa;
						
						if (isVisible){
							this.childElements[i].HTMLElement.style.display= "block";
						} else {
							this.childElements[i].HTMLElement.style.display= "none";
						}
						
						
						/*
						var maxOpa = true;
						if (bgpx !=0){
							maxopa = false;
							var opa = 1-(bgpx/this.getWidth())*(bgpx/this.getWidth());
							if (NotIE){
								this.childElements[i].HTMLElement.style.opacity = opa;
							} else {
								this.childElements[i].HTMLElement.style.filter = "alpha(opacity="+Math.round(opa*100)+")";
							}
						}
						
						if (locwidth != this.getWidth()){
							maxOpa = false;
							var opa = (locwidth/this.getWidth())*(locwidth/this.getWidth())
							if (NotIE){
								this.childElements[i].HTMLElement.style.opacity = opa;
							} else {
								this.childElements[i].HTMLElement.style.filter = "alpha(opacity="+Math.round(opa*100)+")";
							}
						}
						
						if (maxOpa){
							if (NotIE){
								this.childElements[i].HTMLElement.style.opacity = 1;
							} else {
								this.childElements[i].HTMLElement.style.filter = "alpha(opacity=100)";
							}
						}*/
					}
					
					if (((this.owner.getWidth()/2-this.getPositionX())>0) && ((this.owner.getWidth()/2-this.getPositionX()) < this.getWidth())){
						var messageObj = new function(){
							this.message = "inCenter";
							this.sender = _this;
						}
						this.owner.controller.receveMessage(messageObj);
					}
					this.setVisible(true);
				} else {
					this.setVisible(false);
				}
			}
		}
	}
	
	this.setRelativeBackgroundPositionX = function(x){
		this.bgRelPositionX = x;
	}
	
	this.setRelativeBackgroundPositionY = function(y){
		this.bgRelPositionY = y;
	}
	
	this.setPositionY = function(y){
		this.positionY = y;
		this.HTMLElement.style.top = Math.round(y)+'px';
	}
	
	this.getPositionX = function(){
		return this.positionX;
	}
	
	this.getPositionY = function(){
		return this.positionY;
	}
	
	this.getWidth = function() {
		return this.IMGObject.width;
	}
	
	this.getHeight = function() {
		return this.IMGObject.height;
	}
	
	//eseménykezelők
	this.active = false;
	this.HTMLElement.onmousedown = function(event) {
		_this.active=true;
		var messageObj = new function(){
			this.message="mousedown";
			this.sender = _this;
			this.event = (NotIE) ? event : window.event;
		}
		_this.owner.controller.receveMessage(messageObj);
	}
	
	this.HTMLElement.onmouseup = function(event) {
		_this.owner.setAllImageHolderInactive();
		var messageObj = new function(){
			this.message="mouseup";
			this.sender = _this;
			this.event = (NotIE) ? event : window.event;
		}
		_this.owner.controller.receveMessage(messageObj);
	}
	
	this.HTMLElement.onmousemove = function(event) {
		var messageObj;
		if (_this.active){
			messageObj = new function(){
				this.message = "mousedrag";
				this.sender = _this;
				this.event = (NotIE) ? event : window.event;
			}
		} else {
			messageObj = new function(){
				this.message = "mousemove";
				this.sender = _this;
				this.event = (NotIE) ? event : window.event;
			}
		}
		_this.owner.controller.receveMessage(messageObj);
	}
	
	this.HTMLElement.onmouseover = function(event) {
		var messageObj = new function(){
			this.message="mouseover";
			this.sender = _this;
			this.event = (NotIE) ? event : window.event;
		}
		_this.owner.controller.receveMessage(messageObj);
	}
	
	this.HTMLElement.onmouseout = function(event) {
		var messageObj = new function(){
			this.message="mouseout";
			this.sender = _this;
			this.event = (NotIE) ? event : window.event;
		}
		_this.owner.controller.receveMessage(messageObj);
	}
	
	this.HTMLElement.ondblclick = function(event) {
		eval(_this.action);
	}
}
