/*

	aWindow class for the windows used in the ELAL VA new website
	created by Itamar Arjuan , June 2007
	
*/
	g_priority = 12000;
	function aWindow(id,instanceName){
		this.id = id;
		this.instanceName = instanceName;
		this.isIE=document.all;
		this.isNN= !document.all && document.getElementById;
		this.isN4=document.layers;
		this.isHot=false;
		this.ddEnabled=false;
		this.exceedWindowLimits = false;
		
		this.windowState = "stopped";
		this.setWindow();
	}
	
	aWindow.prototype.ddInit = function(e){
		eval("var wThis=" + $(this.id).getAttribute("instanceName") + ";");
		
		ev = (document.all) ? event : e;
		
		var availableScreenX = (wThis.isIE) ? (document.body.clientWidth+54) : (window.innerWidth);
		var availableScreenY = (wThis.isIE) ? (document.body.clientHeight+15) : (window.innerHeight);
		wThis.maxX = availableScreenX - parseInt($(wThis.id).offsetWidth);
		wThis.maxY = availableScreenY - parseInt($(wThis.id).offsetHeight);
		
		wThis.topDog 	= "HTML";
		wThis.whichDog 	= document.getElementById(this.id);
		wThis.hotDog		= (document.all) ? event.srcElement : e.target;
		
		while (wThis.hotDog.id != this.id+"_titleBar" && wThis.hotDog.tagName != wThis.topDog){
			wThis.hotDog = wThis.hotDog.parentNode;
		}
		
		if (wThis.hotDog.id == this.id+"_titleBar"){
			wThis.offsetx = (document.all) ? event.clientX : e.clientX;
			wThis.offsety = (document.all) ? event.clientY : e.clientY;
			wThis.nowX = parseInt(wThis.whichDog.style.left);
			wThis.nowY = parseInt(wThis.whichDog.style.top);
			wThis.ddEnabled=true;
			eval("document.onmousemove=" + $(this.id).getAttribute("instanceName") + ".dd;");
			eval("document.onmouseup=function(){ if (o" + this.id + " != null){ " + $(this.id).getAttribute("instanceName") + ".ddEnabled=false; " + $(this.id).getAttribute("instanceName") + ".makeFullVisible(); } };");
			activeInstance = wThis;
		}
	};
	
	aWindow.prototype.setTitle = function(aTitle){
		eval("var wThis=" + $(this.id).getAttribute("instanceName") + ";");
		
		wThis.title.innerHTML = aTitle;
	};
	
	aWindow.prototype.makeLessVisible = function(){
		/*if (this.isIE){
			$(this.id).style.filter = "alpha(opacity=40);";
		} else {
			$(this.id).style.opacity = "0.4;";
		}*/
		return true;
	};
	
	aWindow.prototype.makeFullVisible = function(){
		/*if (this.isIE){
			$(this.id).style.filter = "alpha(opacity=100);";
		
		} else {
			$(this.id).style.opacity = "1.0;";
		}*/
		this.windowState = "stopped";
		return true;
	};
	
	aWindow.prototype.dd = function(e){
		wThis = activeInstance;
		wThis.whichDog.style.zIndex = g_priority;
		g_priority++;
		if (!wThis.ddEnabled) return;
		evt = (wThis.isIE) ? event : e;				
		var newY;
		var newX;
		
		newX = parseInt(wThis.nowX + evt.clientX - wThis.offsetx);
		newY = parseInt(wThis.nowY + evt.clientY - wThis.offsety);
		
		if ( wThis.exceedWindowLimits ){
			wThis.whichDog.style.left = (wThis.nowX + evt.clientX - wThis.offsetx) + "px";
			wThis.whichDog.style.top  = (wThis.nowY + evt.clientY - wThis.offsety) + "px";
		} else {
			
			if (wThis.windowState != "dragging"){
				wThis.windowState = "dragging";
				wThis.makeLessVisible();
			}
			
			if (newX >= 0 && newX <= wThis.maxX){
				// allow this x coordinate
				wThis.whichDog.style.left = (wThis.nowX + evt.clientX - wThis.offsetx) + "px";
			}
			if (newY >= 0 && newY <= wThis.maxY){
				//allow this y coordinate
				wThis.whichDog.style.top  = (wThis.nowY + evt.clientY - wThis.offsety) + "px";
			}
		}
		return false;
	};
	
	aWindow.prototype.ddN4 = function(whatDog){
	  if (!this.isN4) return;
	  N4=eval(whatDog);
	  N4.captureEvents(Event.MOUSEDOWN|Event.MOUSEUP);
	  N4.onmousedown=function(e){
		N4.captureEvents(Event.MOUSEMOVE);
		N4x=e.x;
		N4y=e.y;
	  }
	  N4.onmousemove=function(e){
		if (isHot){
		  N4.moveBy(e.x-N4x,e.y-N4y);
		  return false;
		}
	  }
	  N4.onmouseup=function(){
		N4.releaseEvents(Event.MOUSEMOVE);
	  }
	};
	
	aWindow.prototype.show = function(){
		$(this.id).style.visibility = "visible";
	};
	
	aWindow.prototype.hide = function(e){
		o = (document.all) ? event.srcElement : e.target;
		
		while (o.getAttribute("type") != "window")
			o = o.parentNode;
		o.style.visibility = "hidden";
		
		wThis = activeInstance;
		
		// Performing delegate hide method on the parent interface object , holding us
		var obj = getInstance("o" + wThis.id);		
		obj.hide();
		
		return true;
	};
	
	aWindow.prototype.setWindow = function(){
		$(this.id).setAttribute("instanceName",this.instanceName);
		$(this.id).onmousedown = this.ddInit;
		$(this.id+"_close").onclick = this.hide;
		this.title = $(this.id + "_title");
	};
