
lastzIndex = 1;
var mWindow = new Class({
initialize: function(titleText,t,l,w,h){
	this.container = new Element('div');
	this.container.className = 'window';	
			
	this.containerContent = new Element('div');		
	this.containerContent.className = 'windowLayer';
	this.container.adopt(this.containerContent);
	this.frameContainer = new Element('div');	
	this.frameContainer.className = 'windowFrameContainer';	
	this.frameContent = new Element('iframe');	
	this.frameContent.className = 'windowFrameContent';	
	this.frameContainer.adopt(this.frameContent);	
	this.containerContent.adopt(this.frameContainer);
		
	if(t){
		this.container.setStyle("top",t);
	}
	if(l){
		this.container.setStyle("left",l);
	}
	if(w){
		this.container.setStyle("width",w);
		this.containerContent.setStyle("width",w);
	}
	else{
		this.container.setStyle("width",200);
		this.containerContent.setStyle("width",200);
	}
	if(h){
		this.container.setStyle("height",h);
		this.containerContent.setStyle("height",h);
	}
			
	// Defining title bar
	this.titleButtons = new Element('span');
	this.closeButton = new Element('img',{src: calcTemplate+'close.gif', style: 'margin-top: 2px;margin-right: 2px;'});
	this.closeButton.setStyle('cursor','default');
	this.closeButton.addEvent('click', this.close.bind(this));
	this.slideButton =  new Element('img',{src: calcTemplate+'slide.gif', style: 'margin-top: 2px;margin-right: 2px;'});
	this.slideButton.setStyle('cursor','default');
	this.slideButton.addEvent('click', this.slide.bind(this));
	this.slideButton.inject(this.titleButtons);
	this.closeButton.inject(this.titleButtons);
	this.title = new Element('div');
	this.title.className = 'windowTitle';

	this.titleButtons.inject(this.title);
	this.titleButtons.setStyle("float","right");
	this.title.appendText(titleText);
	this.container.adopt(this.title);
	new Drag.Move(this.container,{
		handle: this.title
	});
	
	// Defining content block
	this.content = new Element('div');	
	this.content.className = 'windowContent';
	this.container.adopt(this.content);
		
	// Defining status bar
	this.statusBar = new Element('div');	
	this.statusBar.className = 'windowStatus';
	
	/*
	this.resizeButton = new Element('img',{src: calcTemplate+'resize.gif', style: 'margin-bottom: 2px;margin-right: 2px;'});
	this.resizeButton.setStyle('cursor','se-resize');
	this.resizeButton.setStyle("float","right");
	
	this.statusBar.adopt(this.resizeButton);
	this.container.makeResizable({
		handle: this.resizeButton,
		limit:{
			        x:[100, 800],
			        y:[50, 600]
			    }							
		
		});
	*/
	this.container.adopt(this.statusBar);
	this.fx = new Fx.Style(this.container, 'opacity', {duration: 250, wait: false}).set(0);	
	
	this.container.addEvent('mousedown',this.bringToTop.bind(this));
	this.title.addEvent('mousedown',this.bringToTop.bind(this));
	this.container.inject($(document.body));
},

setContent: function(content){
		this.content.setHTML(content);
},
slide: function(){
		if(this.content.getStyle('display')=='block'){
			this.content.setStyle('display','none');
			this.containerContent.setStyle('display','none');
		}
		else{
			this.content.setStyle('display','block');
			this.containerContent.setStyle('display','block');
		}
},
close: function(){
	this.fx.start(0);
	//this.container.setStyle('display','none');
},
show: function(){
	this.container.setStyle('display','block');
	this.fx.start(1);
	
	if(this.content.getStyle('display')!='block') this.slide();
},
setPosition: function(t, l){
	if(t)
		this.container.setStyle("top",t);
	if(l)
		this.container.setStyle("left",l);
},
bringToTop: function(){
	lastzIndex++;
	this.container.setStyle('z-index',lastzIndex);
}

});
