/**
 * mozliwosc zdefiniowania wielkosci poopupa aby wycentrowani
 * jego było odpowiednie względem całego okna domyslna wartosc to -> wysokoscOkna:450
 * 
 * okreslenie czy mpopup ma byc przesuwane czy nie  to ->  przesuwajOkno tak
 * 
 * przykład implementacji:
function open_okno()
{	
	var okno	    = new TOkno( {przesuwajOkno:"tak"} );
	var crt = _c('div');
	crt.innerHTML = '<p>coś</p>';
	okno.zmien_tytul('Tytuł');
	okno.wstaw( crt );
	okno.pokaz();
}  	 
*/
TOkno = function()
{  
	var param =
	{
		id				: 'tokno',
		className		: 'xwindow',
		autoclose		: false,
		autoclose_time	: 6,	// sekund;
		przesuwajOkno	: 'tak',
		_delay			: undefined,
		unSelectable	: true,
		loop			: false,
		test_speed		: false,
		outHandle		: 'content',
		outHandleRes	: 'strona'
	};
	for (var i in arguments[0]) if (typeof(arguments[0][i]!= 'function')) param[i]=arguments[0][i];
		
	//--- tylko 1 okno;
	var test = _get(param['id']);
	if ( test != undefined) test.zamknij();
	
	this.obj = new TAnimKontener(param);
	this.obj.rysuj = function( dane )
	{
		this.tytul		= _c('div',{parent:this, id:'okno_tytul', className:'okno_tytul'});
		this.text		= _c('h3',{parent:this,className:'okno_title'});
		this.icon_close = _c('a',{parent:this,title:'zamknij okno',className:'close_ico'});
		this.body		= _c('div',{parent:this, id: 'okno_body', className:'okno_body'});
		this.bottom		= _c('div',{parent:this, id:'okno_bottom', className:'okno_bottom'});
		
		this.icon_close.onclick = function(){ this.parent.zamknij(); }

		var content	= _c('div',{className:'inner'});
		//this.opak		= _c('div',{className:'xokienko'});
		this.topleft	= _c('div',{className:'xtop-left'});
		this.corner1	= _c('div',{className:'xcorner1'});
		this.corner2	= _c('div',{className:'xcorner2'});
		this.topright	= _c('div',{className:'xtop-right'});
		this.bottomleft	= _c('div',{className:'xbottom-left'});
		this.bottomright	= _c('div',{className:'xbottom-right'});
		this.top		= _c('div',{className:'xtop'});
		this.left		= _c('div',{className:'xleft'});
		this.top		= _c('div',{className:'xtop'});
		this.right		= _c('div',{className:'xright'});
		this.inner		= _c('div',{className:'xinner'});
		this.corner3	= _c('div',{className:'xcorner3'});
		this.cornert4	= _c('div',{className:'xcorner4'});
		this.bottoms	= _c('div',{className:'xbottoms'});
		
		this.inner.apC( content );
		this.right.apC(this.inner);
		this.left.apC(this.right);
		this.bottomright.apC(this.top);
		this.bottomright.apC(this.left);
		this.topright.apC(this.bottomleft);
		this.bottomright.apC(this.corner3);
		this.bottomright.apC(this.cornert4);
		this.bottomright.apC(this.bottoms);

		this.bottomleft.apC(this.bottomright);
		this.topleft.apC(this.corner1);
		this.topleft.apC(this.corner2);
		this.topleft.apC(this.topright);

		this.apC(this.topleft);
		
		this.tytul.apC( this.text);
		this.tytul.apC( this.icon_close );
		content.apC( this.tytul );
		content.apC( this.body );
		content.apC( this.bottom );
	}

	this.obj.wstaw = function(o)
	{
		this.body.innerHTML = '';
		o.handle = this;
		this.body.apC( o );
	}
	this.obj.add			= function( o ){ o.handle = this; }
	this.obj.wstaw_tytul	= function(o){	}
	this.obj.clear  		= function(){ this.body.innerHTML = ''; }
	this.obj.zmien_tytul	= function(tytul){ this.text.innerHTML = tytul; }
	this.obj.getScrollTop	= function()
	{
		var scrollTop = document.body.scrollTop;
		if (scrollTop == 0) scrollTop = document.documentElement.scrollTop;
		return scrollTop;		
	}
	this.obj.getTop	= function()
	{
		var a_top = this.style['top']
		if (a_top == undefined) a_top = '';
		a_top = a_top.replace('px','');
		return parseInt(a_top);		
	}
		
	this.obj.odswiezWysokosc = function(){ this.zmien_polozenie(); }
	this.obj.zmien_polozenie = function()
	{ 
		var wspolrzednaY	= parseInt(this.getScrollTop() + this.stop_poz);
		var a_top = this.getTop();
		
		if (a_top == wspolrzednaY) return true;
		a_top = a_top + parseInt( (wspolrzednaY - a_top) * 0.7);
		//-- 
		this.style.position	= "absolute";
  	    this.style.top		= a_top + 'px'; 
	}
		
	this.obj.pokaz =  function()
	{
		if (this.autoclose) this.delay_close();

		this.h = _c('div');
		this.h.style.position = 'absolute';
		this.h.style.width	= "1px";
		this.h.style.height	= "1px";
		this.h.style.top	= "0";
		this.h.style.left	= "0";
		this.h.apC( this );
		
		if (_get(this.outHandle) != undefined)
			_get(this.outHandle).appendChild(this.h);
		
		this.anim_show(); 
		this.show();
	}
	this.obj.anim_show	 = function()
	{
		this.start_poz	= -100;
		this.stop_poz	= 120 + this.getScrollTop();
		this.klatek		= 20;
		this.interval	= 40;
		this.transform('top');
	}
	
	this.obj.onTransformEnd = function()
	{
		this.stop_poz	= 120;
		if( this.przesuwajOkno =='tak')
			this.zegar_zmien_polozenie = setInterval("_get('"+this.id+"').odswiezWysokosc()",80);
	}
	
	this.obj.setAutoClose	= function(){ this.autoclose = true; }
	this.obj.delay_close	= function(){ this._delay = setTimeout("_get('"+this.id+"').zamknij()",this.autoclose_time * 1000); }

	this.obj.zamknij =  function()
	{
		try { clearInterval( this.zegar['transform']) }catch(e){}
		try { clearInterval( this.zegar_zmien_polozenie ) } catch(e){}
		try { clearTimeout( this._delay ) } catch(e){}

		this.hide();
		if (_get(this.outHandle) != undefined)
			if (this.h != undefined)
			{
				_get(this.outHandle).removeChild( this.h );
				this.h.removeChild( this );
			}
	}
	this.obj.ukryj = function(){ this.zamknij(); }
	 
	this.obj.rysuj();
	return this.obj;	 
} 


