// helpful utilities written by blue
// any questions? contact me:
// http://blue.ovh.org/kontakt/

// DOMready thanks to Dean Edwards, Matthias Miller & John Resig
DOMready = new function(){
	var m=this,funkcje=[],odpalone;
	function dodaj(fn){
		funkcje[funkcje.length] = fn;
	}
	dodaj.zrzut = function(){return funkcje}
	function init(){
		if(odpalone)return;
		odpalone=!0;
		funkcje.each(function(n,v){v()})
	}

	if(document.addEventListener&&!/webkit/i.test(navigator.userAgent)) document.addEventListener("DOMContentLoaded",init,false);
	else if(document.all&&!window.opera){
		document.write('<script id="__ie_domload" defer="true" src="javascript:\'/*[]*/\'"><\/script>');
		var ieDom = document.getElementById('__ie_domload');
		if(ieDom){
			ieDom.onreadystatechange = function(){
				if(this.readyState == "complete"){
					init();
					this.onreadyStateChange = null;
					this.parentNode.removeChild(this);
				}
			}
		}
	}
	else if(/webkit/i.test(navigator.userAgent)){
		var safariInterval = setInterval(function(){
			if(/(complete|loaded)/i.test(document.readyState)){
				init();
				safariInterval = clearInterval(safariInterval);
			}
		},10);
	}
	else window.onload = init;
	return dodaj;
}


// These are entirely mine
function getElement(x){
	x=document.getElementById(x);
	if(x)x.gebtn=x.getElementsByTagName;
	return x}
function Alert(x){getElement('alert').innerHTML+=x+'<br />'}
function dump(x,glab,wciecie){
	var y='',nawiasy=[['{','}'],['[',']']],n;
	wciecie=wciecie||'';
	if(glab===0)return wciecie+'[za głęboko]\n';
	glab=glab==undefined?5:glab-1;
	for(var i in x){
		if(x[i]&&typeof x[i]=='object'){
			n=+(x[i].constructor===Array);
			y+=wciecie+i+': '+nawiasy[n][0]+'\n'+dump(x[i],glab,wciecie+"\t")+wciecie+nawiasy[n][1]+',\n';
		} else if(x.constructor===Array&&i=='each') {
			continue;
		} else {
			y+=wciecie+i+': '+x[i]+',\n';
		}
	}
	return y;
}

utils={
	offset: function(x,w,l,t){
		l = x.offsetLeft; t = x.offsetTop;
		while(x=x.offsetParent){
			if(x==w)break;
			l += x.offsetLeft;
			t += x.offsetTop;
		}
		return {'l':l,'t':t}
	},
	pozMyszy: function(e,d,b,E){
		d=document;b=d.body;E=d.documentElement;
		return {
			'l':(e||event).clientX+(E.scrollLeft||b.scrollLeft),
			't':(e||event).clientY+(E.scrollTop||b.scrollTop)
		}
	},
	cookie: function(n,v,t){
		if(v||t)document.cookie=n+'='+escape(v)+(t?';expires='+new Date(+new Date()+t).toGMTString():'')
		if(n=(document.cookie+';').match(new RegExp('(^|\\s)'+n+'=[^;]*')))return n[0].split('=')[1]
	},
	addClass: function(o,c){return o.className=(o.className?o.className+' ':'')+c;},
	remClass: function(o,c){return o.className=o.className?o.className.replace(new RegExp('(^|\\s)'+c+'(?=\\s|$)','g'),'').trim():''}
}
Number.prototype.round=
String.prototype.round=function(p){return Math.round(this*(p=+('1e'+p)))/p}
String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,'')}
Array.prototype.each=function(fn,i,l){for(i=i||0,l=l||this.length-1;i<=l;i++)if(fn.apply(this,[i,this[i]])===false)break;return this}
