var base = {
	instances : [],
	storeInstance : null,
	uniqid: 0,
		  
	offX : 0,
	offY : 0,
	posX : 0,
	posY : 0,
		  
	init: function() {
		var n = navigator, ua = n.userAgent;
	
	    base.isOpera = window.opera && opera.buildNumber;
	    base.isWebKit = /WebKit/.test(ua);
	    base.isOldWebKit = base.isWebKit && !window.getSelection().getRangeAt;
	    base.isIE = !base.isWebKit && !base.isOpera && (/MSIE/gi).test(ua) && (/Explorer/gi).test(n.appName);
	    base.isIE6 = base.isIE && (/MSIE 6./).test(ua);
	    base.isIE7 = base.isIE && (/MSIE 7./).test(n.appVersion);
	    base.isGecko = !base.isWebKit && /Gecko/.test(ua);
	    //admin.isGecko3 = admin.isGecko && /(Firefox|Minefield)\/[3-9]/.test(ua);
	    base.isMac = ua.indexOf('Mac') != -1;
	    
	    if(typeof loader != 'undefined')
	    	loader.init();
	    
	    //base.createInstance({title: 'Zkušební okno2', width: 800, height: 600, tabs: [{title: 'První', name: 'prvni', url: 'http://localhost'}, {title: 'Druhý', name: 'druhy', url: 'http://localhost/rsj'}]});
	    
	    //vytvoreni uvodniho panelu
	    //base.createPanel();
	    
	    dom.aE(window, 'keydown', base.adminStart, false);
	    
	    dom.aE(window, "scroll", base._windowRefresh, false);
	    dom.aE(window, "resize", base._windowRefresh, false);
	},
	adminStart: function(e) {
		var ev = dom.fE(e), keynum;
		
		if(window.event) // IE
			keynum = ev.keyCode;
		else if(e.which) // Netscape/Firefox/Opera
			keynum = ev.which;
		
		//alert(keynum);
		if(keynum == 119) {
			base.createInstance(
				{
					title: 'Nastavení',
					width: 845,
					height: 480, 
					tabs: [
						{
							title: 'Vlastnosti webu',
							name: 'vlastnosti_webu',
							url: './window.php?id=global_setings&globalSetting'
						},
					    {
					    	title: 'Přehled modulů',
					    	name: 'prehled_modulu',
					    	url: './window.php?id=system_settings&cat=modules_overview'
					    },
					    {
					    	title: 'Přehled míst (url)',
					    	name: 'prehled_mist',
					    	url: 'window.php?id=system_settings&cat=urls_overview'
					    },
					    {
					    	title: 'Místa/moduly',
					    	name: 'mista_moduly',
					    	url: 'window.php?id=system_settings&cat=urls_modules'
					    },
					    {
					    	title: 'Menu',
					    	name: 'menu',
					    	url: 'window.php?id=system_settings&cat=menu_settings'
					    },
					    {
					    	title: 'Souborový manažer',
					    	name: 'souborovy_manager',
					    	url: 'window.php?fileManagerV2'
					    }
					]
				}
			);
		}
	},
	getScreen : function () {
	    return {
	    	x : window.pageXOffset || window.document.body.scrollLeft,
	      	y : window.pageYOffset || window.document.body.scrollTop,
	      	w : base.isIE ? document.documentElement.clientWidth || document.body.offsetWidth : window.innerWidth || window.document.body.clientWidth,
	    	h : base.isIE ? document.documentElement.clientHeight || document.body.offsetHeight : window.innerHeight || window.document.body.clientHeight
	    };
	},
	uniqueID : function () {
	    return base.uniqid++;
	},
	scrollingDetector: function (){
		if (navigator.appName == "Microsoft Internet Explorer") {
			alert("You've scrolled to " + document.body.scrollTop + " pixels.");
		}
		else
			alert ("You've scrolled to " + window.pageYOffset + " pixels.");
	},
	createPanel : function() {
		var tpanel = dom.cE('div');
		tpanel.id = 'panelInstance';
		tpanel.className = 'panelInstance';
		
		var tsettings = dom.cE('a');
		tsettings.innerHTML = 'shit';
		dom.aE(tsettings, 'click', function(e) {
			base.createInstance(
				{
					title: 'Nastavení',
					width: 800,
					height: 470, 
					tabs: [
						{
							title: 'Vlastnosti webu',
							name: 'vlastnosti_webu',
							url: './window.php?id=global_setings&globalSetting'
						},
					    {
					    	title: 'Přehled modulů',
					    	name: 'prehled_modulu',
					    	url: './window.php?id=system_settings&cat=modules_overview'
					    },
					    {
					    	title: 'Přehled míst (url)',
					    	name: 'prehled_mist',
					    	url: 'window.php?id=system_settings&cat=urls_overview'
					    },
					    {
					    	title: 'Místa/moduly',
					    	name: 'mista_moduly',
					    	url: 'window.php?id=system_settings&cat=urls_modules'
					    },
					    {
					    	title: 'Menu',
					    	name: 'menu',
					    	url: 'window.php?id=system_settings&cat=menu_settings'
					    }/*,
					    {
					    	title: 'Nastavení menu',
					    	name: 'menu_preset',
					    	url: 'window.php?id=system_settings&cat=menu_preset'
					    }*/
					]
				}
			);
		}, false);
		dom.aC(tpanel, tsettings);
		
	    dom.aC(document.body, tpanel);
	},
	createInstanceTabs: function (id, prefix, name, text, form) {
	    var ve = vertexElement, p = prefix, n = name, t = text, f = form, sf, fc, tab, a, panel, inp, lab;

	    var form = dom.cE('form');
	    form.action = '#';
	    
	    var tabs = dom.cE('div');
	    tabs.className = 'tabs';
	    
	    var ul = dom.cE('ul');
	    ul.tabs = name.length;
	    dom.aC(tabs, ul);
	    
	    var box = dom.cE('div');
	    box.className = 'box';
	    
	    form.onsubmit = function() {
	      return false;
	    };
	    
	    dom.aE(form, "submit", function() {return false;}, false);
	    
	    for(var i = 0; i < n.length; i++) {
	      sf = f[i];
	      fc = sf.fields;
	      tab = dom.cE('li');
	      tab.id = p + '_' + n[i] + '_tab';
	      tab.tab = n[i];
	      dom.aE(tab, "mousedown", ve.alterInstanceTab, false);
	      if(i == 0) tab.className = 'current';
	      dom.aC(ul, tab);
	      span = dom.cE('span');
	      dom.aC(tab, span);
	      a = dom.cE('a');
	      a.href = '#';
	      a.innerHTML = t[i];
	      a.onclick = function() {
	        return false;
	      };
	      dom.aE(a, "click", function() {return false;}, false);
	      dom.aC(span, a);
	      panel = dom.cE('div');
	      panel.id = p + '_' + n[i] + '_panel';
	      panel.className = 'panel';
	      if(typeof sf.fields != 'undefined') for(var j = 0; j < fc.length; j++) {
	        if(fc[j].nodeType != fc[j].undefined) dom.aC(panel, fc[j]);
	      }
	      if(i == 0) panel.className = 'panel current';
	      dom.aC(box, panel);
	    }
	    dom.aC(form, tabs);
	    dom.aC(form, box);
	    
	    form.ch = f;
	    
	    dom.aC(id, form);
	  },
	  alterInstanceTab: function(e) {
	    ev = dom.fE(e);
	    var n = base.getInstance(ev).id, ul = base.getTabs(ev).childNodes, li = base.getTab(ev), p, val, ifr;
	    
	    for(var i = 0; i<ul.length; i++) {
	      if(ul[i].className == 'current') ul[i].className = '';
	      val = n + '_' + ul[i].tab + '_panel';
	      p = dom.gI(val);
	      p.className = 'panel';
	      //p.style.display = 'none';
	    }
	    
	    li.className = 'current';
	    p = dom.gI(n + '_' + li.tab + '_panel');
	    p.className = 'panel current';
	    ifr = dom.gI(n + '_' + li.tab + '_frame');
	    //ifr.location.reload(true);
	    //alert(ifr);
	    //if(ifr.src == '')
	    	ifr.src = ifr.presrc;
	    /*else
	    	ifr.location.reload(true);*/
	    //p.style.display = 'block';
	    
	    base.instanceAutoSizer(n);
	    
	    return false;
	  },
	  getElement: function (event) {
		  var target = (window.event) ? ev.srcElement : ev.target;
		  return target;
	  },
	  getInstance: function (event) {
		  var target = base.getElement(event);
		  var done = false;
		    
		  //alert(target.inby);
		    
		  while(done == false) {
			  if(typeof target.inby == 'undefined') {
				  if(target.parentNode)
					  target = target.parentNode;
				  else{
					  done = true;
					  return false;
				  }
			  }else{
				  if(target.className == 'windowInstance') {
			          //alert(target.id);
			          done = true;
			          return target;
				  }
			  }
		  }
	  },
	  getTabs: function (event) {
		  var target = base.getElement(event);
		  var done = false;
			    
		  while(done == false) {
			  if(typeof target.tabs == 'undefined') {
				  if(target.parentNode)
					  target = target.parentNode;
			      else{
			    	  done = true;
			    	  return false;
			      }
			  }else return target;
		 }
	},
	getTab: function (event) {
		var target = base.getElement(event);
		var done = false;
			    
		while(done == false) {
			if(typeof target.tab == 'undefined') {
				 if(target.parentNode)
					 target = target.parentNode;
			     else{
			         done = true;
			         return false;
			     }
			}else return target;
		}
	},
	instanceAutoSizer: function(ids) {
		var i, j, id = ids, pan, pa;
		
		i = dom.gI(id + '_body');
		pan = i.childNodes;
		
		for(j = 0; j < pan.length; j++) {
			if(pan[j].className == 'panels')
				pa = pan[j];
		}
		
		if(typeof pa != 'undefined')
			pa.style.height = i.clientHeight - 30 + 'px';
		//alert(i.clientHeight);
	},
	createInstance: function(properties) {
	    var i = base.instances, p = properties, uid = base.uniqueID(), w, h;
	    
	    for(var j = 0; j < i.length; j++) {
	      if(i[j].ids == p.ids) return;
	    }
	    
	    var zLevel = i.length + 10;
	    var gR = base.getScreen();
	    
	    //top
	    var top = dom.cE('div');
	    top.className = 'top';
	    
	    var tleft = dom.cE('div');
	    tleft.className = 'left';
	    dom.aC(top, tleft);
	    
	    var tcenter = dom.cE('div');
	    tcenter.className = 'center';
	    dom.aC(top, tcenter);
	    
	    var tright = dom.cE('div');
	    tright.className = 'right';
	    dom.aC(top, tright);
	    
	    var title = dom.cE('span');
	    title.id = 'windowInstance' + uid + '_title';
	    title.style.position = 'absolute';
	    title.style.color = '#FFFFFF';
	    title.innerHTML = p.title;
	    //title.style.zIndex = zLevel;
	    title.style.textAlign = 'center';
	    //title.style.width = '100%';
	    title.unselectable = "on";
	    dom.aC(top, title);
	    
	    top.style.cursor = 'move';
	    dom.aE(top, 'mousedown', base._moveBoxStart, false);
	    
	    //middle
	    var middle = dom.cE('div');
	    middle.className = 'middle';
	    
	    var mleft = dom.cE('div');
	    mleft.className = 'left';
	    dom.aC(middle, mleft);
	    
	    var mcenter = dom.cE('div');
	    mcenter.id = 'windowInstance' + uid + '_body';
	    mcenter.className = 'center';
	    
	    //t/tuuuuuuuuu
	    if(p.tabs) {
		    var tdiv = dom.cE('div');
		    tdiv.className = 'tabs';
		    
		    var tul = dom.cE('ul');
		    tul.tabs = p.tabs.length;
		    dom.aC(tdiv, tul);
		    
		    var box = dom.cE('div');
		    box.className = 'panels';
		    
		    var tab, panel, a, span, tframe;
		    var tn = p.tabs;
		    
		    for(var n = 0; n < tn.length; n++) {
		      tab = dom.cE('li');
		      tab.id = 'windowInstance' + uid + '_' + tn[n].name + '_tab';
		      tab.tab = tn[n].name;
		      dom.aE(tab, "mousedown", base.alterInstanceTab, false);
		      if(n == 0) tab.className = 'current';
		      span = dom.cE('span');
		      dom.aC(tab, span);
		      a = dom.cE('a');
		      a.href = '#';
		      a.innerHTML = tn[n].title;
		      a.onclick = function() {
		        return false;
		      };
		      dom.aE(a, "click", function() {return false;}, false);
		      dom.aC(span, a);
		      dom.aC(tul, tab);
		      panel = dom.cE('div');
		      panel.id = 'windowInstance' + uid + '_' + tn[n].name + '_panel';
		      panel.className = 'panel';
		      //panel.style.position = 'absolute';
			  //dom.sS(panel, 'width', '100%');
			  //dom.sS(panel, 'height', '100%');
			  dom.sS(panel, 'background', '#ffffff url(./shared/img/loader.gif) no-repeat center center');
			  //dom.sS(panel, 'textAlign', 'center');
			  //dom.sS(panel, 'paddingTop', '53%');
			  //panel.innerHTML = 'Prosím čekejte ...';
		      //panel.style.display = 'block';
		      /*if(typeof sf.fields != 'undefined')
		    	  for(var j = 0; j < fc.length; j++) {
		    		  if(fc[j].nodeType != fc[j].undefined) dom.aC(panel, fc[j]);
		    	  }*/
		      
		      tframe = dom.cE('iframe');
		      
		      if(n == 0) {
		    	  tframe.src = tn[n].url;
		    	  tframe.presrc = tn[n].url;
		      }else
		    	  tframe.presrc = tn[n].url;
		      
		      tframe.id = 'windowInstance' + uid + '_' + tn[n].name + '_frame';
		      tframe.name = 'windowInstance' + uid + '_' + tn[n].name + '_frame';
		      tframe.className = 'windowFrame';
		      //tframe.style.position = 'absolute';
		      //tframe.style.top = '0px';
		      //tframe.style.left = '0px';
		      tframe.style.width = '100%';
		      tframe.style.height = '100%';
		      tframe.style.border = 'none';
		        
		      dom.aC(panel, tframe);
		      
		      if(n == 0) //{
		    	  panel.className = 'panel current';
		    	  /*panel.style.display = 'block';
		      }else
		    	  panel.style.display = 'none';*/
		      
		      dom.aC(box, panel);
		    }
		    dom.aC(mcenter, tdiv);
		    dom.aC(mcenter, box);
	    }
	    ///////////
	    
	    if(base.isIE) {
	      mcenter.id = 'windowInstanceCenter' + uid;
	      mcenter.style.height = p.height - 49;
	    }
	    
	    var mright = dom.cE('div');
	    mright.className = 'right';
	    dom.aC(middle, mright);
	    
	    //bottom
	    var bottom = dom.cE('div');
	    bottom.className = 'bottom';
	    
	    var bleft = dom.cE('div');
	    bleft.className = 'left';
	    dom.aC(bottom, bleft);
	    
	    var bcenter = dom.cE('div');
	    bcenter.className = 'center';
	    dom.aC(bottom, bcenter);
	    
	    var bright = dom.cE('div');
	    bright.className = 'right';
	    dom.aC(bottom, bright);
	    
	    switch(p.type) {
	      case 'message':
	        var fram = dom.cE('div');
	        fram.className = 'framBox';
	        
	        var icon = dom.cE('div');
	        icon.className = 'icon';
	    
	        var text = dom.cE('span');
	        text.className = 'messageBox';
	        
	        text.innerHTML = p.message;
	        icon.style.backgroundImage = 'url(shared/img/message.png)';
	        break;
	      case 'confirm':
	        var fram = dom.cE('div');
	        fram.className = 'framBox';
	        
	        var icon = dom.cE('div');
	        icon.className = 'icon';
	    
	        var text = dom.cE('span');
	        text.className = 'messageBox';
	        
	        text.innerHTML = p.confirm;
	        icon.style.backgroundImage = 'url(shared/img/confirm.png)';
	        break;
	      default:
	        w = p.width;
	        h = p.height;
	        
	        //alert(p.forms);
	        if(p.url) {
	        	dom.sS(mcenter, 'background', '#ffffff url(./shared/img/loader.gif) no-repeat center center');
	        	
		        var frame = dom.cE('iframe');
		        frame.src = p.url;
		        frame.id = 'windowFrame' + uid;
		        frame.name = 'windowFrame' + uid;
		        frame.className = 'windowFrame';
		        frame.style.width = '100%';
		        frame.style.height = '100%';
		        frame.style.border = 'none';
		        
		        dom.aC(mcenter, frame);
		        
		        //ve.createInstanceTabs(mcenter, p.id ? p.id : uid, p.tnames, p.tabs, p.forms);
	        }
	        
	        break;
	    }
	    
	    var scr_top = base.isIE ? document.body.scrollTop || document.documentElement.scrollTop : window.pageYOffset;
	    
	    var inst = dom.cE('div');
	    inst.className = p.classname ? p.classname : 'windowInstance';
	    inst.id = p.id ? p.id : 'windowInstance' + uid;
	    inst.style.position = 'absolute';
	    //inst.style.margin = '0 auto';
	    inst.style.left = gR.w/2 - w/2 + 'px';
	    inst.style.top = scr_top + (gR.h/2 - h/2) + 'px';
	    inst.style.width = w + 'px';
	    inst.style.height = h + 'px';
	    inst.style.zIndex = zLevel;
	    //inst.style.backgroundColor = 'blue';
	    
	    dom.aC(inst, top);
	    dom.aC(inst, middle);
	    dom.aC(middle, mcenter);
	    
	    if(p.type == 'message' || p.type == 'confirm') {
	      dom.aC(fram, icon);
	      dom.aC(fram, text);
	      dom.aC(mcenter, fram);
	    }
	    if(p.buttons) {
	      var buttons = dom.cE('div');
	      buttons.className = 'buttons';
	      
	      if(p.buttons.length < 5)
	        var bmax = p.buttons.length;
	      else
	        var bmax = 4;
	      
	      for(var b = 0; b < bmax; b++) {
	        var button = dom.cE('a');
	        button.className = 'button';
	        button.href = '#';
	        button.innerHTML = p.buttons[b].title ? p.buttons[b].title : 'Zpráva';
	        button.onclick = function() {
	          return false;
	        };
	        //dom.aE(button, 'click', function() {return false;}, false);
	        dom.aE(button, p.buttons[b].evt ? p.buttons[b].evt : 'mouseup', p.buttons[b].act ? p.buttons[b].act : function(e) {return false;}, false);
	        dom.aC(buttons, button);
	      }
	      
	      dom.aC(mcenter, buttons);
	    }
	    dom.aC(inst, bottom);
	    
	    if(p.type != 'loader') {
	      /*var bC = dom.cE('div');
	      bC.style.position = 'absolute';
	      bC.style.top = '4px';
	      bC.style.right = '5px';
	      bC.style.width = '34px';
	      bC.style.height = '17px';
	      bC.style.zIndex = '10020';
	      bC.style.background = 'transparent url(shared/img/button-minimalize-normal.png) no-repeat';
	      
	      dom.aE(bC, 'mouseover', base._instanceCloseButtonOver, false);
	      dom.aE(bC, 'mouseout', base._instanceCloseButtonOut, false);
	      dom.aE(bC, 'mousedown', base._instanceCloseButtonDown, false);
	      
	      dom.aC(inst, bC);*/
	      
	      var bC = dom.cE('div');
	      bC.style.position = 'absolute';
	      bC.style.top = '3px';
	      bC.style.right = '5px';
	      bC.style.width = '33px';
	      bC.style.height = '19px';
	      bC.style.zIndex = '10021';
	      bC.style.background = 'transparent url(shared/img/button-close.png) no-repeat';
	      
	      dom.aE(bC, 'mouseover', base._instanceCloseButtonOver, false);
	      dom.aE(bC, 'mouseout', base._instanceCloseButtonOut, false);
	      dom.aE(bC, 'mousedown', base._instanceCloseButtonDown, false);
	      
	      dom.aC(inst, bC);
	      
	      var bMax = dom.cE('div');
	      bMax.style.position = 'absolute';
	      bMax.style.top = '3px';
	      bMax.style.right = '38px';
	      bMax.style.width = '27px';
	      bMax.style.height = '19px';
	      bMax.style.zIndex = '10021';
	      bMax.style.background = 'transparent url(shared/img/button-max.png) no-repeat';
	      
	      dom.aE(bMax, 'mouseover', base._instanceMaximizeButtonOver, false);
	      dom.aE(bMax, 'mouseout', base._instanceMaximizeButtonOut, false);
	      dom.aE(bMax, 'mousedown', base._instanceMaximizeButtonDown, false);
	      
	      dom.aC(inst, bMax);
	      
	      var bMin = dom.cE('div');
	      bMin.style.position = 'absolute';
	      bMin.style.top = '3px';
	      bMin.style.right = '65px';
	      bMin.style.width = '27px';
	      bMin.style.height = '19px';
	      bMin.style.zIndex = '10021';
	      bMin.style.background = 'transparent url(shared/img/button-minimalize.png) no-repeat';
	      
	      dom.aE(bMin, 'mouseover', base._instanceMinimalizeButtonOver, false);
	      dom.aE(bMin, 'mouseout', base._instanceMinimalizeButtonOut, false);
	      dom.aE(bMin, 'mousedown', base._instanceMinimalizeButtonDown, false);
	      
	      dom.aC(inst, bMin);
	    }
	    
	    var res = ['nw','n','w','ne','sw','s','e','se'];
			
		for(var k = 0; k < res.length; k++) {
			var r = dom.cE('div');
			r.style.position = 'absolute';
			r.className = 'resize resize-' + res[k];
			r.style.overflow = 'hidden';
			r.style.cursor = res[k] +'-resize';
			r.direction = res[k];
				
			dom.aE(r, 'mousedown', base._resizeBoxStart, false);
				
			dom.aC(inst,r);
		}
			
	    dom.aC(document.body, inst);
	    
	    base.instances.push(inst);
	    inst.inby = base.instances.length - 1;
	    
	    inst.ids = p.ids ? p.ids : 'windowInstance' + uid;
	    
	    base.instanceAutoSizer('windowInstance' + uid);
	    
	    //if(p.init) p.init(p);
	  },
	  instancePush : function (ev) {
	    var i = dom.gW(ev), ins = base.instances, store = [];
	    
	    if(typeof i == 'undefined') return;

	    for(var j = 0; j < ins.length; j++) {
	      if(ins[j].id != i.id) store.push(ins[j]);
	    }
	    store.push(i);
	    
	    for(var k = 0; k < store.length; k++) {
	      store[k].style.zIndex = k + 10;
	    }
	    
	    base.instances = [];
	    base.instances = store;
	    
	    return false;
	  },
	  instanceClose : function (ev) {
	    var i = (ev.className != 'windowInstance') ? dom.gW(ev) : ev, ins = base.instances, store = [];

	    for(var j = 0; j < ins.length; j++) {
	      if(ins[j].id != i.id) store.push(ins[j]);
	    }
	    
	    base.instances = [];
	    base.instances = store;
	    
	    document.body.removeChild(i);
	    
	    return false;
	  },
	  instanceChange : function (i) {
	    var is = i.style, iid = parseInt(i.id), newH = parseInt(is.height) - 49, c = dom.gI('windowInstanceCenter' + iid);
	    c.style.height = newH + 'px';
	  },
	  eventBlocker : function (nis, mode) {
	    var gR = base.getScreen(), x = nis.left, y = nis.top, w = nis.width, h = nis.height, eB, pH;
	    
	    if(parseInt(x) < 0) x = '0px';
	    if(parseInt(y) < 0) y = '0px';
	    
	    gR.w -= 2;
	    gR.h -= 2;
	    
	    if(base.isGecko) {
	      gR.w -= 16;
	      gR.h -= 16;
	    }
	    
	    eB = dom.cE('div');
	    eB.id = 'eventBlocker';
	    eB.className = 'eventBlocker';
	    eB.style.position = 'absolute';
	    eB.style.zIndex = 10000;
	    eB.style.left = '0px';
	    eB.style.top = '0px';
	    eB.style.width = gR.w + 'px';
	    eB.style.height = gR.h + 'px';
	    //eB.style.border = '1px solid black';
			//eB.style.backgroundColor = 'blue';
			
			pH = dom.cE('div');
			pH.id = 'placeHolder';
			pH.classMame = 'placeHolder';
			pH.style.position = 'absolute';
	    pH.style.zIndex = 10001;
	    pH.style.left = x;
	    pH.style.top = y;
	    pH.style.width = w;
	    pH.style.height = h;
	    pH.style.backgroundColor = '#868686';
	    pH.style.borderStyle = nis.borderStyle;
	    pH.style.borderWidth = nis.borderWidth;
	    pH.style.borderColor = nis.borderColor;
	    pH.style.padding = nis.padding;
	    pH.style.margin = nis.margin;
	    pH.style.opacity = '0.4';
	    pH.style.filter = 'alpha(opacity=40)';
	    
	    switch(mode) {
	      case 'move':
	        pH.style.cursor = 'move';
	        dom.aE(document, 'mousemove', base._moveBoxMove, false);
	        dom.aE(document, 'mouseup', base._moveBoxEnd, false);
	        break;
	      case 'resize':
	        dom.aE(document, 'mousemove', base._resizeBoxResize, false);
	        dom.aE(document, 'mouseup', base._resizeBoxEnd, false);
	        break;
	    }
	    
	    dom.aC(eB, pH);
	    dom.aC(document.body, eB);
	    
	    return false;
	  },
	  instanceMaximalize: function(ev) {
		  var i = (ev.className != 'windowInstance') ? dom.gW(ev) : ev, is = i.style, gs;
		  
		  gs = base.getScreen();
		  
		  i.maxX = is.left;
		  i.maxY = is.top;
		  i.maxW = is.width;
		  i.maxH = is.height;
		  i.maximalize = true;
		  
		  is.width = gs.w - 16 + 'px';
		  is.height = gs.h + 'px';
		  is.left = '0px';
		  is.top = '0px';
	  },
	  instanceFMNormalize: function(ev) {
		  var i = (ev.className != 'windowInstance') ? dom.gW(ev) : ev, is = i.style;
		  
		  is.left = i.maxX;
		  is.top = i.maxY;
		  is.width = i.maxW;
		  is.height = i.maxH;
		  i.maximalize = false;
	  },
	  instanceMinimalize: function(ev) {
		  var i = (ev.className != 'windowInstance') ? dom.gW(ev) : ev, is = i.style, ib, it, gs;
		  
		  ib = dom.gI(i.id + '_body');
		  it = dom.gI(i.id + '_title');
		  gs = base.getScreen();
		  
		  ib.style.display = 'none';
		  
		  i.minX = is.left;
		  i.minY = is.top;
		  i.minW = is.width;
		  i.minH = is.height;
		  i.minimalize = true;
		  
		  is.width = '200px';
		  is.height = '25px';
		  is.left = '0px';
		  is.top = gs.y + gs.h - 25 + 'px';
		  
		  it.style.marginLeft = '10px';
		  it.style.textAlign = 'left';
	  },
	  instanceNormalize: function(ev) {
		  var i = (ev.className != 'windowInstance') ? dom.gW(ev) : ev, is = i.style, ib, it;
		  
		  ib = dom.gI(i.id + '_body');
		  it = dom.gI(i.id + '_title');
		  
		  ib.style.display = 'block';
		  
		  is.left = i.minX;
		  is.top = i.minY;
		  is.width = i.minW;
		  is.height = i.minH;
		  i.minimalize = false;
		  
		  it.style.marginLeft = '0px';
		  it.style.textAlign = 'center';
	  },
	  _windowRefresh: function(e) {
		  var i, ins, is, gs = base.getScreen();
		  
		  for(i = 0; i < base.instances.length; i++) {
			  ins = base.instances[i];
			  
			  if(ins.minimalize == true) {
				  is = ins.style;
				  it = dom.gI(ins.id + '_title');
				  
				  is.left = '0px';
				  is.top = gs.y + gs.h - 25 + 'px';
			  }
		  }
	  },
	  _moveBoxStart : function (e) {
	    var ev = dom.fE(e), i = dom.gW(ev), is = i.style, nis, mX, mY;
	    
	    base.instancePush(ev);
	    
	    nis = {
	      style: {
	        left: is.left,
	        top: is.top,
	        width: is.width,
	        height: is.height,
	        border: is.border,
	        margin: is.margin,
	        padding: is.padding
	      }
	    };
	    
	    mX = ev.clientX;
			mY = ev.clientY;
	    
	    base.storeInstance = i;

	    base.offY = parseInt(is.top) - mY;
			base.offX = parseInt(is.left) - mX;
			
			if((base.isIE && ev.button == 1) || (base.isGecko && ev.button == 0) || (base.isOpera && ev.button == 0))
	      base.eventBlocker(is, 'move');
	    
	    return false;
	  },
	  _moveBoxMove : function (e) {
	    var ev = dom.fE(e), gR = base.getScreen(), pH = dom.gI('placeHolder'), eB = dom.gI('eventBlocker'), newX, newY, maxX, maxY;
	        
	    newX = ev.clientX + base.offX;
		newY = ev.clientY + base.offY;
	    
	    maxX = parseInt(pH.style.left) + parseInt(pH.style.width);
	    maxY = parseInt(pH.style.top) + parseInt(pH.style.height);
	    
	    if(newX < 0) newX = 0;
	    if(newY < 0) newY = 0;
	    if(newX > (parseInt(eB.style.width) - parseInt(pH.style.width))) newX = parseInt(eB.style.width) - parseInt(pH.style.width);
	    if(newY > (parseInt(eB.style.height) - parseInt(pH.style.height))) newY = parseInt(eB.style.height) - parseInt(pH.style.height);
	    
	    base.posX = newX;
		base.posY = newY;
		pH.style.top = newY + 'px';
		pH.style.left = newX + 'px';
	    
	    return false;
	  },
	  _moveBoxEnd : function (e) {
	    var ev = dom.fE(e), i = base.storeInstance, is = i.style, pH, eB, newX, newY;

	    pH = dom.gI('placeHolder');
	    newX = parseInt(pH.style.left) + 'px';
	    newY = parseInt(pH.style.top) + 'px';
	    
	    eB = dom.gI('eventBlocker');
	    dom.rE(document, 'mousemove', base._moveBoxMove, false);
		dom.rE(document, 'mouseup', base._moveBoxEnd, false);
			
	    document.body.removeChild(eB);
	    
	    is.left = newX;
	    is.top = newY;
			
		return false;
	  },
	  _resizeBoxStart : function (e) {
	    var ev = dom.fE(e), i = dom.gW(ev), is = i.style, target;
	    
	    base.instancePush(ev);
	    
	    ev.cancelBubble = true;
	    if(ev.stopPropagation) ev.stopPropagation();
	    
	    base.storeInstance = i;
	    base.eventBlocker(is, 'resize');
	    
	    i.mposX = ev.clientX;
	    i.mposY = ev.clientY;
	    i.oldW = parseInt(is.width);
	    i.oldH = parseInt(is.height);
	    i.oldX = parseInt(is.left);
	    i.oldY = parseInt(is.top);
	    
	    target = (window.event) ? ev.srcElement : ev.target;
	    i.opt = target.direction;
	    
	    return false;
	  },
	  _resizeBoxResize : function (e) {
	    var ev = dom.fE(e), i = base.storeInstance, is = i.style, eB, pH , pHs, mouseX, mouseY, dW, dH, newX, newY, newW, newH, minW, minH, minX, minY;
	    eB = dom.gI('eventBlocker');
	    pH = dom.gI('placeHolder');
	    pHs = pH.style;
	    
	    mouseX = ev.clientX;
	    mouseY = ev.clientY;
	    
	    dW = i.mposX - mouseX;
	    dH = i.mposY - mouseY;
	    newX = i.oldX;
	    newY = i.oldY;
	    newW = i.oldW;
	    newH = i.oldH;
	    
	    minW = 70;
	    minH = 50;
	    minX = i.oldX + newW - minW;
	    minY = i.oldY + newH - minH;
	    
	    switch(i.opt) {
	      case 'n':
	        newH = i.oldH + dH;
	        if(newH > minH) newY = i.oldY - dH; else newY = minY;
	        break;
	      case 'ne':
	        newW = i.oldW - dW;
	        newH = i.oldH + dH;
	        if(newH > minH) newY = i.oldY - dH; else newY = minY;
	        break;
	      case 'e':
	        newW = i.oldW - dW;
	        break;
	      case 'se':
	        newW = i.oldW - dW;
	        newH = i.oldH - dH;
	        break;
	      case 's':
	        newH = i.oldH - dH;
	        break;
	      case 'sw':
	        newW = i.oldW + dW;
	        newH = i.oldH - dH;
	        if(newW > minW) newX = i.oldX - dW; else newX = minX;
	        break;
	      case 'w':
	        newW = i.oldW + dW;
	        if(newW > minW) newX = i.oldX - dW; else newX = minX;
	        break;
	      case 'nw':
	        newW = i.oldW + dW;
	        newH = i.oldH + dH;
	        if(newW > minW) newX = i.oldX - dW; else newX = minX;
	        if(newH > minH) newY = i.oldY - dH; else newY = minY;
	        break;
	    }
	    
	    if(minW > newW) newW = minW;
	    if(minH > newH) newH = minH;

	    if(newX < 0) newX = 0;
	    if(newY < 0) newY = 0;
	    
	    pHs.left =  newX + 'px';
	    pHs.top = newY + 'px';
	    pHs.width =  newW + 'px';
	    pHs.height = newH + 'px';
	    
	    return false;
	  },
	  _resizeBoxEnd : function (e) {
	    var ev = dom.fE(e), i = base.storeInstance, is = i.style, pH, eB;
	    
	    pH = dom.gI('placeHolder');
	    eB = dom.gI('eventBlocker');
			
	    document.body.removeChild(eB);
	    
	    is.left = pH.style.left;
	    is.top = pH.style.top;
	    is.width = pH.style.width;
	    is.height = pH.style.height;
	    
	    dom.rE(document, 'mousemove', base._resizeBoxResize, false);
	    dom.rE(document, 'mouseup', base._resizeBoxEnd, false);
	    
	    if(base.isIE) 
	      base.instanceChange(i);
	  
	    return false;
	  },
	  /*_instanceCloseButtonOver : function(e) {
	    var ev = dom.fE(e), bC = dom.gE(ev);
	    
	    bC.style.backgroundImage = 'url(shared/img/button-minimalize-hovered.png)';

	    return false;
	  },
	  _instanceCloseButtonOut : function(e) {
	    var ev = dom.fE(e), bC = dom.gE(ev);
	    
	    bC.style.backgroundImage = 'url(shared/img/button-minimalize-normal.png)';

	    return false;
	  },
	  _instanceCloseButtonDown : function(e) {
	    var ev = dom.fE(e), bC = dom.gE(ev);
	    
	    bC.style.backgroundImage = 'url(shared/img/button-minimalize-down.png)';
	    dom.aE(bC, 'mouseup', base._instanceCloseButtonUp, false);
	    
	    return false;
	  },
	  _instanceCloseButtonUp : function (e) {
	    var ev = dom.fE(e), bC = dom.gE(ev);
	    
	    bC.style.backgroundImage = 'url(img/button-minimalize-normal.png)';
	    
	    base.instanceClose(ev);
	    
	    return false;
	  },*/
	  _instanceCloseButtonOver : function(e) {
		  var ev = dom.fE(e), bC = dom.gE(ev);
		    
		  bC.style.backgroundImage = 'url(shared/img/button-close-over.png)';

		  return false;
	  },
	  _instanceCloseButtonOut : function(e) {
		  var ev = dom.fE(e), bC = dom.gE(ev);
		    
		  bC.style.backgroundImage = 'url(shared/img/button-close.png)';

		  return false;
	  },
	  _instanceCloseButtonDown : function(e) {
		  var ev = dom.fE(e), bC = dom.gE(ev);
		    
		  //bC.style.backgroundImage = 'url(shared/img/button-minimalize-down.png)';
		  dom.aE(bC, 'mouseup', base._instanceCloseButtonUp, false);
		    
		  return false;
	  },
	  _instanceCloseButtonUp : function (e) {
		  var ev = dom.fE(e), bC = dom.gE(ev);
		    
		  //bC.style.backgroundImage = 'url(img/button-minimalize-normal.png)';
		    
		  base.instanceClose(ev);
		    
		  return false;
	  },
	  _instanceMaximizeButtonOver : function(e) {
		  var ev = dom.fE(e), bC = dom.gE(ev);
		    
		  bC.style.backgroundImage = 'url(shared/img/button-max-over.png)';

		  return false;
	  },
	  _instanceMaximizeButtonOut : function(e) {
		  var ev = dom.fE(e), bC = dom.gE(ev);
		    
		  bC.style.backgroundImage = 'url(shared/img/button-max.png)';

		  return false;
	  },
	  _instanceMaximizeButtonDown : function(e) {
		  var ev = dom.fE(e), bC = dom.gE(ev);
		    
		  dom.aE(bC, 'mouseup', base._instanceMaximizeButtonUp, false);
		    
		  return false;
	  },
	  _instanceMaximizeButtonUp : function (e) {
		  var ev = dom.fE(e), bC = dom.gE(ev), i = (ev.className != 'windowInstance') ? dom.gW(ev) : ev;
		  
		  if(i.maximalize == false || typeof i.maximalize == 'undefined')
			  base.instanceMaximalize(ev);
		  else
			  base.instanceFMNormalize(ev);
		  
		  return false;
	  },
	  _instanceMinimalizeButtonOver : function(e) {
		  var ev = dom.fE(e), bC = dom.gE(ev);
		    
		  bC.style.backgroundImage = 'url(shared/img/button-minimalize-over.png)';

		  return false;
	  },
	  _instanceMinimalizeButtonOut : function(e) {
		  var ev = dom.fE(e), bC = dom.gE(ev);
		    
		  bC.style.backgroundImage = 'url(shared/img/button-minimalize.png)';

		  return false;
	  },
	  _instanceMinimalizeButtonDown : function(e) {
		  var ev = dom.fE(e), bC = dom.gE(ev);
		    
		  //bC.style.backgroundImage = 'url(shared/img/button-minimalize-down.png)';
		  dom.aE(bC, 'mouseup', base._instanceMinimalizeButtonUp, false);
		    
		  return false;
	  },
	  _instanceMinimalizeButtonUp : function (e) {
		  var ev = dom.fE(e), bC = dom.gE(ev), i = (ev.className != 'windowInstance') ? dom.gW(ev) : ev;
		    
		  //bC.style.backgroundImage = 'url(img/button-minimalize-normal.png)';
		  if(i.minimalize == false || typeof i.minimalize == 'undefined')
			  base.instanceMinimalize(ev);
		  else
			  base.instanceNormalize(ev);
		    
		  return false;
	  },
	  withoutAccent : function (src, to) {
	    var urlt = src.value.toLowerCase();
	    var sdiak = "áäčďéěíĺľňóôőöŕšťúůűüýřž ,.:;!?*+-/_<>()[]{}\"'";
	    var bdiak = "aacdeeillnoooorstuuuuyrz----------------------";
	    var newtext = '';
	    
	    // /\b[^\w/][-]*\b/gi //na zakladni
	    /// /[^/\w:][-]*//gi nak onec
	      
	    for(var j = 0; j < urlt.length; j++) {
	      if(sdiak.indexOf(urlt.charAt(j)) != -1)
	        newtext += bdiak.charAt(sdiak.indexOf(urlt.charAt(j)));
	      else
	        newtext += urlt.charAt(j);
	    }
	    
	    newtext = newtext.replace(/\b[^\w/][-]*\b/gi, '-');
	    newtext = newtext.replace(/[-]*$/, '');
	    
	    to.value = newtext;
	  }
}
