pressed=false;
my=0;
mx=0;
PosY=0;
PosX=0;


function mcs_wnd(indeks,canvas,left,top,width,height,tlo,fromtop) {

this.indeks=indeks; 
this.canvas=canvas;
this.width=width;
this.height=height;
this.left=left;
this.top=top;
this.tlo=tlo;
this.fromtop=fromtop;

   

this.show=show; //metoda
this.hide=hide; //metoda
this.page=page; //metoda

document.write('<div id="'+this.indeks+
'" style="left:'+this.left+
'px;top:'+this.top+
'px;width:'+this.width
+'px;height:'+this.height+
'px;padding:6px;padding-top:'+this.fromtop+
'px;background-color:white;background-image:url('+this.tlo+');background-repeat:no-repeat;position:absolute;"><div id="'+this.indeks+'_main" style="overflow: auto;width:100%; height:100%;"></div></div>');

// ustawienie zdarzenia
var handle = document.getElementById(this.indeks);

handle.onmousedown= function (e){ 

	pressed = true;

	 
	x = 0;
	y = 0;
	a = document.getElementById(indeks);
	x = a.offsetLeft;
	y = a.offsetTop;
           
	var isIE = navigator.appName;
          
	if (isIE == "Microsoft Internet Explorer")
	{
	my = window.event.clientY+document.body.scrollTop-y;
	mx = window.event.clientX+document.body.scrollLeft-x;
	}else{
	mx = e.clientX+window.pageXOffset-x;
	my = e.clientY+window.pageYOffset-y;
	}
                                  
	if ((mx > 2)&& (mx<width) && (my >2) && (my<fromtop) ){
	pressed = true;
	}else{ 
	pressed = false;																	     
	}
//	if ((mx > 603)&& (mx<618) && (my >8) && (my<19) ){
//	hide();
//	}

}
//koniec zdarzenia

handle.onmousemove=function(e)
{
	if (pressed){

	PosX = 0;
	PosY = 0;
	x = 0;
	y = 0;
	a = document.getElementById(indeks);


	  var isIE = navigator.appName;
    
	 if (isIE == "Microsoft Internet Explorer")
	 {
	    PosY=window.event.clientY+document.body.scrollTop-my;
	    PosX=window.event.clientX+document.body.scrollLeft-mx;
	 }else{
	    PosY=e.clientY+window.pageYOffset-my;
 	   PosX=e.clientX+window.pageXOffset-mx;
	 }
 
	 var mm = document.getElementById(indeks);

	 with(mm.style){
	 top = PosY + 'px';
	 left = PosX + 'px';
	 }
 }
}

handle.onmouseup = function (e)
{                                           
pressed = false;
a = document.getElementById(indeks);
a.blur();
a.focus();
}

var handle_canvas = document.getElementById(this.canvas);

handle_canvas.onmousemove= function (e){ 
 
if (pressed){

 var isIE = navigator.appName;
 
 if (isIE == "Microsoft Internet Explorer")
 {
    PosY=window.event.clientY+document.body.scrollTop-my;
    PosX=window.event.clientX+document.body.scrollLeft-mx;
 }else{
    PosY=e.clientY+window.pageYOffset-my;
    PosX=e.clientX+window.pageXOffset-mx;
 }
  
 var mm = document.getElementById(indeks);

 with(mm.style){
 top = PosY + 'px';
 left = PosX + 'px';
 }

}
}

handle_canvas.onmouseup = function (e)
{
pressed = false;
a = document.getElementById(indeks);
a.blur();
a.focus();
}

/////////////////////////////////////////////////
//
//koniec konstruktora
//
////////////////////////////////////////////////
}

function page(tresc, zrodlo ) {
var handle = document.getElementById(this.indeks+"_main");
handle.style.display = 'block';

if (tresc == 'tekst'){
handle.innerHTML = zrodlo;
}

if (tresc == 'strona'){

//ajax

	var Obj = false;
	if (window.XMLHttpRequest){
	Obj= new XMLHttpRequest();
	}else if (window.ActiveXObject){
	Obj = new ActiveXObject("Microsoft.XMLHTTP");
	}

	if (Obj) {
	 
	 Obj.open("GET","./"+zrodlo);
	 //Obj.setRequestHeader('Content-Type', 'text/html; charset=iso-8859-2');
	 Obj.onreadystatechange = function()
	 {
	  if (Obj.readyState == 4 && Obj.status == 200){
	  var str = Obj.responseText;
	  handle.innerHTML = str;
	  init_images();     
	  }
		 }             
	 Obj.send(null);
	 }
}

//ajax
}


function show() {
var handle = document.getElementById(this.indeks);
handle.style.display = 'block';
}

function hide() {
var handle = document.getElementById(this.indeks);
handle.style.display = 'none';
}
