/*======================================================================*\
|| #################################################################### ||
|| # > H-Php v1.0 final                                               # ||
|| # ---------------------------------------------------------------- # ||
|| # > Author: Kid08												  # ||
|| # > Date started: 8th September 2005								  # ||
|| # > http://www.h-php.net                                           # ||
|| #################################################################### ||
\*======================================================================*/

function HimWindow()
{
	this.WindowInfo = new Array();
	this.WindowTabHeight = new Array();
	this.ListWindow = new Array();
	this.CurWindow = null;
	this.checkTitle = new Array();
	this.windowNumber = 0;
	this.windowCount = 0;
	this.windowTab = new Array();
	this.faded = 0;
	
	this.BuildWindow = function(title, mes, width, height, zindex)
	{
		if (this.checkTitle[title] != true) {
			this.windowNumber++;
			
			var windowID = "window_"+this.windowNumber;
			
			this.ListWindow[windowID] = true;
			this.WindowInfo[windowID] = new Array();
			this.WindowInfo[windowID]['title'] = title;
			this.checkTitle[title] = true;
			
			var NewWindow = document.createElement('div');
			NewWindow.setAttribute('id',windowID);
			NewWindow.setAttribute('class',"window");
						
			var WindowContent = '	<div class="clearfix" style="width:'+width+'px">';
			WindowContent += '			<div class="window_top_left"></div>';
			WindowContent += '			<div class="window_top_center" style="width:'+(width-12)+'px">';
			WindowContent += '				<div class="window_navi clearfix" style="width:100%">';
			WindowContent += '					<div class="window_top_center_left" style="width:'+(width-37)+'px" onclick="HimWindow.selectWindow(\''+windowID+'\')">&nbsp;&nbsp;'+(Base64.decode(title))+'</div>';
			WindowContent += '					<div class="window_top_center_right">';
			WindowContent += '						<div class="window_buttons clearfix">';
			WindowContent += '							<div class="window_button" style="background-position:0px 0px" onclick="HimWindow.closeWindow(\''+windowID+'\')"><img src="'+rootDomain+'/images/space.gif" /></div>';
			WindowContent += '						</div>';
			WindowContent += '					</div>';
			WindowContent += '				</div>';
			WindowContent += '			</div>';
			WindowContent += '			<div class="window_top_right"></div>';
			WindowContent += '		</div>';
			
			// End Tab
			WindowContent += '		<div class="window_content" style="width:'+(width-8)+'px;height:'+(height-33)+'px" onclick="HimWindow.selectWindow(\''+windowID+'\')">'+mes+'</div>';
			
			document.body.appendChild(NewWindow);
			// Set Attribute to Window Drag
			getObjId(windowID).style.width = width+"px";
			getObjId(windowID).style.height = height+"px";
			getObjId(windowID).style.position = "absolute";
			WindowContent = WindowContent.replace(/&quotdon;/g,"'");
			WindowContent = WindowContent.replace(/&quotkep;/g,'"');
			getObjId(windowID).innerHTML = WindowContent;
			// Set Window Drag to middle
			setMiddlePage(windowID);
			
			this.setWindowPos(windowID);
			
			this.selectWindow(windowID);
			
			if (this.windowCount!=0 || this.faded==0) { this.fade('fade'); }
			this.windowCount++;
		}
	};
	
	this.fade = function(state) {
		if (state=='fade') {
			changeOpac(3, 'body_page');
			this.faded = 1;
		} else {
			changeOpac(15, 'body_page');
			this.faded = 0;
		}
	};
	
	this.setWindowPos = function(obj) {
		if (this.CurWindow!=null && obj!=this.CurWindow)
		{
			if (parseInt(getObjId(this.CurWindow).style.left)+15+getObjId(obj).offsetWidth<viewportwidth && parseInt(getObjId(this.CurWindow).style.top)+15+getObjId(obj).offsetHeight<viewportheight) {
				getObjId(obj).style.top = parseInt(getObjId(this.CurWindow).style.top)+15+'px';
				getObjId(obj).style.left = parseInt(getObjId(this.CurWindow).style.left)+15+'px';
			} else {
				getObjId(obj).style.top = getObjId(obj).style.left = '0px';
			}
		}
	}
	
	this.selectWindow = function(obj, zindex)
	{
		if (getObjId(this.CurWindow) && obj!=this.CurWindow)
		{
			// Set Style Attribute for Last Window
			getObjId(this.CurWindow).style.zIndex = 9;
		}
		
		if (!is_ie) {
			for (windowID in this.ListWindow) {
				if (windowID!=obj) {
					changeOpac(10, windowID);
				} else {
					changeOpac(15, windowID);
				}
			}
		}
		// Set Current Window
		this.CurWindow = obj;
	}
	
	this.closeWindow = function(obj)
	{
		RemoveObj(obj);
		this.ListWindow[obj] = null;
		this.checkTitle[this.WindowInfo[obj]['title']] = null;
		this.WindowInfo[obj] = null;
		this.CurWindow = null;
		this.windowCount--;
		
		this.curWindow = null;
		
		if (this.windowCount==0) { this.fade('none'); } 
	}
}

var HimWindow = new HimWindow();
