var ajaxBox = Class.create();

ajaxBox.prototype = {

	initialize : function(name, aUrl){

		this.name = name;
		this.id = 'box_'+(Math.floor(Math.random () * Math.random () * 10000));
		this.conteinerId = this.id+'Cont';
		this.ajaxUrl = '/etc/'+aUrl;
		this.box = '';
		this.cssClass = 'dialog';
		this.topPadding = 50;
		this.width = 500;
		this.page = '';

		window[name] = this;
	},

	Create: function(){
		
		template = 
			'<div style="width: '+this.width+'px;" class="popContainer">'
				+'<div id="'+this.conteinerId+'" class="popContent">'
					+'&nbsp;'
				+'</div>'
			+'</div>'
		;
		
		var divTag = document.createElement("div");
		divTag.setAttribute("id",this.id);
		divTag.setAttribute("class",this.cssClass);
		divTag.setAttribute("className",this.cssClass);

		divTag.innerHTML = template;

		document.body.appendChild(divTag);
		
		this.box = $(this.id);
		
		var pageY;
	    if(typeof(window.pageYOffset)=='number') {
	       pageY=window.pageYOffset;
	    }else {
	       pageY=document.documentElement.scrollTop;
	    }
		this.box.style.top = (pageY + this.topPadding)+'px';

		this.conteiner = $(this.conteinerId); 
	},
	
	Remove: function(){

		document.body.removeChild(this.box);
		this.box = false;
		this.page = '';
	},
	
	Load: function(mdkey, page){
		
		if(this.page != page){
			
			if( false == this.box ){
				this.Create();	
			}
			this.box.style.display = 'block';
			//this.conteiner.innerHTML = 'zarejdam!!';
			pars = 'mdkey='+mdkey+'&page='+page+'&fname='+this.name;
	
			new Ajax.Updater(this.conteinerId,this.ajaxUrl,{
				method: 'post',
				parameters: pars
			});
			
			this.page = page;
		}
	},
	
	LoadTpl: function(tpl){
		
		if( false == this.box ){
			this.Create();	
		}
		this.box.style.display = 'block';
		
		this.conteiner.innerHTML = tpl;
	}
};
