   var sirka = 348;
	var vyska = 335;
	var pozicia_zlava = 64;
	var pozicia_odvrchu = 100;
		
	sirka+=4;vyska+=40;
	var wins_list = function() {}; //zasobnik pro vytvorena okna 
   var active_win = null; //objekt pro hodnoty aktualniho okna
   
   var win_id_prefix = "bbwin_";
   var win_title_prefix = win_id_prefix + "title_";
   var win_min_prefix = win_id_prefix + "min_";
   var win_close_prefix = win_id_prefix + "close_";
   var win_status_prefix = win_id_prefix + "status_";
   var win_resize_prefix = win_id_prefix + "resize_";
   
   var win_moving = false, win_resizing = false;
   
   function BBWin() {
     this.position = {x:pozicia_zlava, y:pozicia_odvrchu};
     this.size = {width: sirka, height: vyska};
     this.mouse_offset = {x:0, y:0};
     this.win     = null;
     this.title   = null;
     this.name    = null;
     this.content = null;
     this.bottom  = null;
     this.status  = null;
     this.minimalized = false;
   } 
   
   BBWin.prototype.setPosition = function(x, y) {
     this.position.x = x;
     this.position.y = y;
     this.win.style.left = x + "px";
     this.win.style.top = y + "px";
   }
   
   BBWin.prototype.setSize = function (width, height) {
     this.size.width = width;
     this.size.height = height;
     this.win.style.width = width + "px";
     this.win.style.height = height + "px";
   }
   
   function cancelEvent() {
   	return (!win_moving && !win_resizing) ? true : false;
   }
   
   function bbWinMove(e) {
   	if(document.all) e = event;
   
     if(win_moving) {
       active_win.setPosition(e.clientX - active_win.mouse_offset.x, e.clientY - active_win.mouse_offset.y);
   		return false;
   	}
   	if(win_resizing) {
   	  var width = e.clientX - parseInt(active_win.win.style.left) + active_win.mouse_offset.x;
   	  var height = e.clientY - parseInt(active_win.win.style.top) + active_win.mouse_offset.y;
   	  if( width < 20 ) width = 20;
   	  if( height < 20 ) height = 20;
   	  active_win.setSize(width, height);
   	  return false;
   	}
   	
   	if(!document.all) return false;  
   }
   
   function bbWinMoveStop(e) {
     win_moving = false;
     win_resizing = false;
	  active_win.title.style.cursor = "";  
   }
   
   function bbWinMoveStart(e) {
     if(document.all) e = event;
     var id = this.id.substr( win_title_prefix.length );
     active_win = wins_list[ win_id_prefix + id ];
     active_win.mouse_offset.x = e.clientX - active_win.win.offsetLeft; 
     active_win.mouse_offset.y = e.clientY - active_win.win.offsetTop;
     active_win.title.style.cursor = "move";
     if( typeof active_win == "object" ) win_moving = true;
   }
   
   function bbWinResizeStart(e) {
     if(document.all) e = event;
     var id = this.id.substr( win_resize_prefix.length );
     active_win = wins_list[ win_id_prefix + id ];
     if( !parseInt(active_win.win.style.width) ) active_win.win.style.width = sirka+"px";
     if( !parseInt(active_win.win.style.height) ) active_win.win.style.height = vyska+"px";
     active_win.mouse_offset.x = parseInt(active_win.win.style.width) - (e.clientX - active_win.win.offsetLeft); 
     active_win.mouse_offset.y = parseInt(active_win.win.style.height) - (e.clientY - active_win.win.offsetTop);
     if( typeof active_win == "object" ) win_resizing = true;
   }
   
   function bbWinResizeStop(e) {
     win_resizing = false;
   }
   
   function bbWinMinimalize() {
     var id = this.id.substr( win_min_prefix.length );
     active_win = wins_list[ win_id_prefix + id ];
   
     if( active_win.minimalized ) {
       active_win.win.style.height = active_win.size.height;
       
       active_win.content.style.display = "";
       active_win.bottom.style.display = "";
       this.src = "min.gif";
       active_win.minimalized = false;
     } else {
       active_win.win.style.height = "20px";
   
       active_win.content.style.display = "none";
       active_win.bottom.style.display = "none";
       this.src = "max.gif";
       active_win.minimalized = true;
     } 
   }
   
   function bbWinClose() {
     var id = this.id.substr( win_close_prefix.length );
     active_win = wins_list[ win_id_prefix + id ];
     var prnt=active_win.win.parentNode;
     if(prnt) {
       var old=prnt.removeChild(active_win.win);
       delete wins_list[ win_id_prefix + id ];
     }  
   }
   
   function init() {
     var tables = document.getElementsByTagName("table");
     if(!tables) return;
     
     var win_id = 1;
     
     var chld, chld1;
     var button;
   
     for(var i=0; i<tables.length; i++) {
       if( !tables[i].className ||  tables[i].className != "bbwin" ) continue;     
       
       tables[i].id = win_id_prefix + win_id;
       chld = tables[i].getElementsByTagName("tr"); 
       var win = new BBWin();
       win.win = tables[i];
   
       win.setPosition(pozicia_zlava,pozicia_odvrchu);
       win.setSize(sirka,vyska);
   
       if(chld) {
       
         //window title 
         if( chld.length > 0 ) {
           win.title = chld[0];
           chld[0].id = win_title_prefix + win_id;
           chld[0].onmousedown = bbWinMoveStart;
           chld[0].onmouseup = bbWinMoveStop;
   
           chld1 = chld[0].getElementsByTagName("td");
           if(chld1) {
             if(chld1.length > 0) win.name = chld1[0];
             if(chld1.length > 1) {
               chld1 = chld1[1].getElementsByTagName("img");
               if(chld1) {
                 if(chld1.length > 0) {
                   chld1[0].id = win_min_prefix + win_id;
                   chld1[0].onclick = bbWinMinimalize;
                 }   
                 if(chld1.length > 1) {
                   chld1[1].id = win_close_prefix + win_id;
                   chld1[1].onclick = bbWinClose;
                 }   
               }
             }
           } 
         }
   
         //window content
         if(chld.length > 1) win.content = chld[1];
   
         //window bottom
         if(chld.length > 2) {
           win.bottom = chld[2];
           chld1 = chld[2].getElementsByTagName("td");
           if(chld1) {
             if( chld1.length > 0 ) win.status = chld1[0];
             if( chld1.length > 1 ) {
               chld1 = chld1[1].getElementsByTagName("img");
               if( chld1 && chld1.length > 0 ) {         
                 chld1[0].id = win_resize_prefix + win_id;
                 chld1[0].onmousedown = bbWinResizeStart;
                 chld1[0].onmouseup = bbWinResizeStop;              
               }
             } 
           }        
         }       
       }
       
       wins_list[ win_id_prefix + win_id ] = win;
       win_id++;
     }  
   
   	document.body.onmousemove = bbWinMove;
   	document.body.onmouseup = bbWinMoveStop;
     document.body.ondragstart = cancelEvent;
   	document.body.onselectstart = cancelEvent;	
   }
   
   window.onload = init;
