// www.airmedia.pl / licencja CC
var mld=document;
var mlbg,mlpg,mlct,mlim;
var okpr,elem;
var ms6=false;
/*@cc_on @*/
/*@if(@_jscript_version>=5 && @_jscript_version<=5.6) ms6=true;
@end @*/
AttachEvent(window,'load',initml,false);
function initml() {
 for(var i=0;i<mld.links.length;i++)
  if(mld.links[i].rel && mld.links[i].rel.match(/(^|\s)mlbox($|\[|\s)/) && mld.links[i].onclick==null) mld.links[i].onclick=mlbox;
 mlpg=mld.createElement("IMG");
 mlpg.src='img/ml_load.gif';
 mlpg.style.position='absolute';
 mlpg.style.backgroundColor='white';
 mlpg.style.display='none';
 mlpg.style.zIndex='998';
 mld.getElementsByTagName("BODY")[0].appendChild(mlpg);
 mlpg.onclick=mldie;
}

function mlbox() {
 if(elem) return!1;
 var bd=mld.getElementsByTagName("BODY")[0];
 if(ms6) {
  var s=mld.getElementsByTagName("SELECT");
  for(var i=0;i<s.length;i++) s[i].style.visibility='hidden';
 }
 elem=this;

 var mh=DocumentHeight();
 if(WindowHeight()>mh) mh=WindowHeight();
 mlbg=mld.createElement("DIV");
 mlbg.style.top='0';
 mlbg.style.left='0';
 mlbg.style.position='absolute';
 mlbg.style.width=DocumentWidth()+'px';
 mlbg.style.height=mh+'px';
 mlbg.style.backgroundColor='black';
 mlbg.style.opacity='0.7';
 mlbg.style.filter='alpha(opacity=70)';
 mlbg.style.zIndex='997';
 bd.insertBefore(mlbg, mlpg);
 mlbg.onclick=mldie;

 mlpg.style.top=(Math.round((WindowHeight()-mlpg.height-40)/2)+ScrollTop())+'px';
 mlpg.style.left=(Math.round((WindowWidth()-mlpg.width-40)/2)+ScrollLeft())+'px';
 mlpg.style.padding='20px';
 mlpg.style.display='block';

 mlim=mld.createElement("IMG");
 mlim.onload=mlshow;
 mlim.src=this.href;
 return!1;
}

function mlshow()
{
 if(elem && mlim)
 {	 
  mlct=mld.createElement("DIV");
  mlct.style.position='absolute';
  mlct.style.backgroundColor='white';
  mlct.style.padding='20px';
  mlct.style.visibility='hidden';
  mlct.style.zIndex='999';
  mld.getElementsByTagName("BODY")[0].insertBefore(mlct, mlpg);
  mlim.style.cursor='pointer';
  mlct.appendChild(mlim);
  mlim.onclick=mldie;
  var tmx=(Math.round((WindowHeight()-mlim.height-40)/2)+ScrollTop());
  if(tmx<0) tmx=0;
  mlct.style.top=tmx+'px';
  mlct.style.left=(Math.round((WindowWidth()-mlim.width-40)/2)+ScrollLeft())+'px';

  if(elem.getAttribute('title') && elem.getAttribute('title').length>0) {
   var o=mld.createElement("P");
   o.style.margin='0';
   o.style.padding='10px 0 0 0';
   o.style.color='black';
   o.style.lineHeight='135%';
   o.innerHTML=elem.getAttribute('title');
   mlct.style.paddingBottom='10px';
   mlct.appendChild(o);
  }

  var s=mld.createElement("IMG");
  s.style.display='block';
  s.style.position='absolute';
  s.style.top='1px';
  s.style.right='1px';
  s.style.width='16px';
  s.style.height='16px';
  s.style.cursor='pointer';
  s.setAttribute('src', 'img/ml_close.gif');
  s.setAttribute('alt', 'Klawisz Z zamyka okno');
  s.onclick=function() { mldie(); }
  mlct.appendChild(s);

  mlct.style.visibility='';
  mlpg.style.display='none';
  okpr=mld.onkeypress;
  mld.onkeypress=function(e) { if(!e) keycode=event.keyCode; else keycode=e.which;
   if(String.fromCharCode(keycode).toLowerCase()=='z') mldie(); }

  if(elem.rel.indexOf('[')!=-1 && elem.rel.indexOf(']')!=-1) {
   var g=elem.rel.replace(/^(.*)\[/,'').replace(/\](.*)?$/,'');
   var prev_obj=null;
   var next_obj=null;
   var tmp=false;
   var nxt=false;
   var reg=new RegExp('(^|\\s)mlbox\\['+g+'\\]($|\\s)','');
   for(var i=0;i<mld.links.length;i++)
    if(mld.links[i].rel && mld.links[i].rel.match(reg))
    {
     if(prev_obj!=null) nxt=true;
	 if(mld.links[i]==elem && prev_obj==null) prev_obj=tmp;
	 tmp=mld.links[i];
	 if(nxt && mld.links[i]!=elem) { next_obj=mld.links[i]; break; }
    }
   if(prev_obj!=false && prev_obj!=null) {
    var s=mld.createElement("DIV");
    s.style.position='absolute';
    s.style.top='20px';
    s.style.left='20px';
	s.style.width=Math.round(mlim.offsetWidth/2-10)+'px';
    s.style.height=mlim.offsetHeight+'px';
	s.style.backgroundImage='url(img/ml_prev.gif)';
	s.style.backgroundRepeat='no-repeat';
	s.style.backgroundPosition='-1000px -1000px';
    s.style.cursor='pointer';
	s.onmouseover=function() { this.style.backgroundPosition='center left'; }
	s.onmouseout=function() { this.style.backgroundPosition='-1000px -1000px'; }
    s.onclick=function() { mlchg(prev_obj); }
    mlct.appendChild(s);
   }
   if(next_obj!=null) {
    var s=mld.createElement("DIV");
    s.style.position='absolute';
    s.style.top='20px';
    s.style.right='20px';
    s.style.width=Math.round(mlim.offsetWidth/2-10)+'px';
    s.style.height=mlim.offsetHeight+'px';
	s.style.backgroundImage='url(img/ml_next.gif)';
	s.style.backgroundRepeat='no-repeat';
	s.style.backgroundPosition='-1000px -1000px';
    s.style.cursor='pointer';
	s.onmouseover=function() { this.style.backgroundPosition='center right'; }
	s.onmouseout=function() { this.style.backgroundPosition='-1000px -1000px'; }
    s.onclick=function() { mlchg(next_obj); }
    mlct.appendChild(s);
   }
   if((prev_obj!=false && prev_obj!=null) || (next_obj!=null)) {
    mlim.onclick=null;
    mlim.style.cursor='default';
   }
  }

 }
 return!1;
}

function mlchg(obj) {
 var bd=mld.getElementsByTagName("BODY")[0];
 if(mlct) { bd.removeChild(mlct); mlct=null; mlim=null; }
 if(mlim) { bd.removeChild(mlim); mlim=null; } 
 elem=obj;
 mlpg.style.top=(Math.round((WindowHeight()-mlpg.height-40)/2)+ScrollTop())+'px';
 mlpg.style.left=(Math.round((WindowWidth()-mlpg.width-40)/2)+ScrollLeft())+'px';
 mlpg.style.padding='20px';
 mlpg.style.display='block';
 mlim=mld.createElement("IMG");
 mlim.onload=mlshow;
 mlim.src=obj.href;
 return!1;
}

function mldie() {
 if(mlbg) {
  var bd=mld.getElementsByTagName("BODY")[0];
  bd.removeChild(mlbg);
  mlbg=null;
  if(mlct) { bd.removeChild(mlct); mlct=null; mlim=null; }
  if(mlim) { bd.removeChild(mlim); mlim=null; }
  if(ms6) {
   var s=mld.getElementsByTagName("SELECT");
   for(var i=0; i<s.length; i++) s[i].style.visibility='';
  }
  mlpg.style.display='none';
  elem=null;
 }
}

function WindowHeight() {
 var z;
 if(mld.compatMode.toLowerCase().indexOf('back')==-1)
  z=mld.documentElement.clientHeight;
   else z=mld.body.clientHeight;
 return z;
}
function WindowWidth() {
 var z;
 if(mld.compatMode.toLowerCase().indexOf('back')==-1)
  z=mld.documentElement.clientWidth;
   else z=mld.body.clientWidth;
 return z;
}
function ScrollTop() {
 var z;
 if(self.pageYOffset) z=self.pageYOffset;
  else if(mld.documentElement && mld.documentElement.scrollTop) z=mld.documentElement.scrollTop;
   else if(mld.body) z=mld.body.scrollTop;
 return z;
}
function ScrollLeft() {
 var z;
 if(self.pageXOffset) z=self.pageXOffset;
  else if(mld.documentElement && mld.documentElement.scrollLeft) z=mld.documentElement.scrollLeft;
   else if(mld.body) z=mld.body.scrollLeft;
 return z;
}
function DocumentHeight() {
 var z;
 if(mld.compatMode.toLowerCase().indexOf('back')==-1)
  z=mld.documentElement.scrollHeight;
   else z=mld.body.scrollHeight;
 return z;
}
function DocumentWidth() {
 var z;
 if(mld.compatMode.toLowerCase().indexOf('back')==-1)
  z=mld.documentElement.scrollWidth;
  else z=mld.body.scrollWidth;
 return z;
}
function AttachEvent(obj,evt,fnc,useCapture) {
 if(!useCapture) useCapture=false;
 if(obj.addEventListener) {
  obj.addEventListener(evt,fnc,useCapture);
  return true;
 } else if(obj.attachEvent) return obj.attachEvent("on"+evt,fnc);
  else{
   MyAttachEvent(obj,evt,fnc);
   obj['on'+evt]=function() { MyFireEvent(obj,evt) };
  }
 return true;
}
function MyAttachEvent(obj,evt,fnc) {
 if(!obj.myEvents) obj.myEvents={};
 if(!obj.myEvents[evt]) obj.myEvents[evt]=[];
 var evts = obj.myEvents[evt];
 evts[evts.length]=fnc;
}
function MyFireEvent(obj,evt) {
 if(!obj || !obj.myEvents || !obj.myEvents[evt]) return;
 var evts=obj.myEvents[evt];
 for(var i=0,len=evts.length;i<len;i++) evts[i]();
}