function o(a){return document.getElementById(a)}
if (!Array.prototype.forEach)Array.prototype.forEach = function(fun /*, thisp*/){var len = this.length >>> 0,thisp = arguments[1]; for (var i = 0; i < len; i++)if (i in this)fun.call(thisp, this[i], i, this);};
function byClass(c,tag){var ls=(this!=window?this:document).getElementsByTagName((tag?tag:'*')),r=[];for(var i=0,l=ls.length;i<l;i++)if(hasClass(ls[i],c))r.push(ls[i]);return r;}
function addClass(obj,c){if(!hasClass(obj,c))obj.className+=' '+c;}
function remClass(obj,c){var a= (obj.className+'').split(/\s+/);for(l=a.length,i=0,s=[];i<l;i++)if(a[i]!=c)s[s.length]=a[i];obj.className=s.join(' ');}
function hasClass(obj,c){return (obj.className+'').indexOf(c)==0||(obj.className+'').indexOf(' '+c)>0}
function togClass(obj,c){if(hasClass(obj,c))remClass(obj,c);else addClass(obj,c);}
function target(e) {var targ;if (!e) var e = window.event;if (e.target) targ = e.target;else if (e.srcElement) targ = e.srcElement;if (targ.nodeType == 3)targ = targ.parentNode;return targ;	}
function index(obj){var ls=obj.parentNode.childNodes;for(var i=0,l=ls.length;i<l;i++)if(ls[i]==obj)return i;return -1;}
function scrollTop(){return document.body.scrollTop+ document.documentElement.scrollTop;}
function alpha(obj,value) {obj.style.opacity = value/100;obj.style.filter = 'alpha(opacity=' + value + ')';};

function ajax(params){
var xmlHttp;
  try{xmlHttp=new XMLHttpRequest();}catch (e){
    try{xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");}catch (e){
      try{xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}catch (e){
        alert("Your browser does not support AJAX!");
        return false;
        }
      }
    }
    xmlHttp.onreadystatechange=function()
    {
       if(xmlHttp.readyState==4)
       {
        if(params.obj)
          params.ready.call(params.obj,xmlHttp.responseText,xmlHttp.responseXML,params.data,xmlHttp)	 ;
        else	 
          params.ready(xmlHttp.responseText,xmlHttp.responseXML,params.data,xmlHttp);
       }
     };
	if(params.method.toLowerCase()!="post"){xmlHttp.open(params.method,params.url,true);xmlHttp.send(null);}
	if(params.method.toLowerCase()=="post"){
	var par=(params.params?params.params:{});
	var i,p=[];
	for(i in par)
	p.push(i+'='+escape(par[i]));
	p=p.join('&');
	xmlHttp.open(params.method,params.url,true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", p.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(p);
	}
	return xmlHttp;
}



var i=new Image();
i.src='/static/gfx/6-0.gif';
var overlay={
	bg:'#000',
	obj:null,
	show:function(url,type,w,h,obj){
		this.obj=obj;
		this.node=document.createElement('div');
		this.node.onclick=function(){
		overlay.close();
		}
		this.cont=document.createElement('div')
		this.cont.id="over"
		this.cont.innerHTML='<img id="load" src="/static/gfx/6-0.gif"/>'
		var s=this.node.style
		s.background=this.bg;
		s.zIndex=20;
		s.position='absolute';
		s.left='0';	s.top='0';
		s.width=this.winSize()[0]+'px'
		s.height=this.winSize()[1]+'px'
		alpha(this.node,50);
		document.body.appendChild(this.node);
		document.body.appendChild(this.cont);
		if(url){
			this[type](url,w,h,obj)
		}
		this.center();
		
	},
	close:function(){
		document.body.removeChild(this.node)
		document.body.removeChild(this.cont)
	
	},
	center:function(){
		//setTimeout('overlay.center()',1)
		var s=this.winSize()
		//window.status=this.cont.offsetWidth+'x'+this.cont.offsetHeight+' , '+this.image.width
		
		
		this.cont.style.left=(s[0]- this.cont.offsetWidth)/2 + 'px'
		this.cont.style.top=(s[1]- this.cont.offsetHeight)/2 + 'px'
	},
	winSize:function(){
	var h=document.getElementsByTagName('html')[0];
	return [h.offsetWidth-(document.all?21:0),h.offsetHeight];
	},
	img:function(url,w,h,obj){
		
		//this.image = new Image();
		var img = document.createElement('img')
		img.style.position='absolute'
		img.style.top='-1000px';
		img.style.left='-1000px';
		img.style.visibility='hidden'
		img.src=url;
		
		
		this.cont.insertBefore(img,this.cont.firstChild)
		
		img.onload=function(){
			this.style.position='static'
			this.style.visibility='visible'
			//console.log(this.width+'x'+this.height)
			overlay.cont.style.width=this.width+'px'
			overlay.cont.style.height=this.height+'px'
			overlay.cont.removeChild(o('load'))
			overlay.center()
			overlay.cont.innerHTML+='<a href="#" id="close" onClick="overlay.close();return false;" class="btn2">zamknij</a>	<a href="#" id="overlay_nxt" onClick="overlay.nextimg();return false;">Następne &#9658;</a> <a href="#" id="overlay_pre" onClick="overlay.previmg();return false;">&#9668; Poprzednie</a>'
		}
		//this.image.src=url;
		
		
		
	   
		this.center();
	},
	nextimg:function(){
		var n=this.obj.nextSibling;
		while(n&&n.nodeType!=1)n=n.nextSibling;
		this.close();
		if(n)
		this.show(n.href,'img',0,0,n);
	
	},
	previmg:function(){
		var n=this.obj.previousSibling;
		while(n&&n.nodeType!=1)n=n.previousSibling;
		this.close();
		if(n)
		this.show(n.href,'img',0,0,n);
	
	},
	html:function(url,w,h){
	
		ajax({
		url:url,
		method:'GET',
		ready:function(s){
		overlay.cont.innerHTML=s;
		overlay.center();
		}
		})
	}



}





 
function main(){

	var lst=document.getElementsByTagName('a')
	for(var i=0,l=lst.length;i<l;i++){
		if(lst[i].getAttribute('rel')=='lbox'){
			
			lst[i].onclick=function(){
			
			overlay.show(this.href,'img',0,0,this);
			
			return false;
			}
		}
	}

}
