//-----------------------------------\\
//        PROJECT BlueStorm          \\
//        version 1.0                \\
//-----------------------------------\\

var BlueStorm = {
	Name: "Project BlueStorm",
	Version: "1.0",
	Comment: "Beta"
}

//---------------------------------------------------------------[ SKROTY DO POPULARNYCH RZECZY ]
function $(){
	if (arguments.length==1){ return document.getElementById(arguments[0]); }
	else {
		var outp = new Array();
		for (i=0;i<arguments.length;i++){	
			outp.unshift(document.getElementById(arguments[i]));
		}
		return outp;
	}
}

function $byTag(){
	var outp = new Array();
	for (i=0;i<arguments.length;i++){
		var items = document.getElementsByTagName(arguments[i]);
		for (k=0;k<items.length;k++){
			outp.unshift(items[k]);
		}
	}
	return outp;
}

function $byCSS(){
	var outp = new Array();
	var tags = $byTag('*');
	for (i=0;i<tags.length;i++){
		for (k=0;k<arguments.length;k++){
			if (tags[i].className==arguments[k]){ outp.unshift(tags[i]); }
		}
	}
	return outp;
}

function $byName(){
	var outp = new Array();
	var tags = $byTag('*');
	for (i=0;i<tags.length;i++){
		for (k=0;k<arguments.length;k++){
			if (tags[i].name==arguments[k]){ outp.unshift(tags[i]); }
		}
	}
	return outp;
}

function $byParams(){
	var outp = new Array();
	var tags = $byTag('*');
	for (i=0;i<tags.length;i++){
		for (k=0;k<arguments.length;k++){
			var matchcnt = 0;
			var thisargs = arguments[k].split(";");
			for (l=0;l<thisargs.length;l++){
				thisarg = thisargs[l].split("=");
				if (tags[i][thisarg[0]]==thisarg[1]){ matchcnt++; }
			}	
			if (matchcnt==thisargs.length){ outp.unshift(tags[i]); }
		}
	}
	return outp;
}

function $fValue(){
	var outp = new Array();
	for(i=0;i<arguments.length;i++){
		var obj = $(arguments[i]);
		if (!obj.type=='checkbox'){	outp.unshift(obj.value); } else if (obj.checked==true){ outp.unshift(obj.value); }
	}
	if (outp.length==1){ outp = outp[0]; }
	return outp;
}

function $fExtVal(id,expby){
	$(id).value = $(id).value+expby;
}

function $IHExt(id,expby){
	$(id).innerHTML = $(id).innerHTML+expby;
}

function $cookie(){
	var outp = new Array();
	for (i=0;i<arguments.length;i++){
		outp.unshift(document.CookiesCollection.getCookieByName(arguments[i]));
	}
	if ($outp.length==1){ outp = outp[0]; }
	return $outp;
}

function $_COOKIES(){ return $cookie(arguments); }

function $CSSClass(id){
         var found = '';
         for (i=0;i<document.styleSheets.length;i++){
             var cssDoc = document.styleSheets[i];
             var cssDocRules;
             if (document.all){ cssDocRules = cssDoc.rules; } else { cssDocRules = cssDoc.cssRules; }
             for (k=0;k<cssDocRules.length;k++){
                 var cssRule = cssDocRules[k];
                 if (cssRule.selectorText==id){ return cssRule; }
             }
         }
         return null;	
}

//---------------------------------------------------------------[ PRZYDATNE FUNKCJE ]
function tryThese(){
	var outp;
	for (i=0;i<arguments.length;i++){
		var testnow = arguments[i];
		try { outp = testnow();	break; } 
		catch (e) {}
	}
	return outp;
}

function toArray(obj){
	var outp = new Array();
	for (p in obj){
		outp[p] = obj[p];
	}
	return outp;
}


function findPosX(obj){
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}


function findPosY(obj){
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function ClassToStyle(cssclass,obj,classoverstyle){
	var forbidden = new Array('length','cssText','cssText','parentRule','accelerator','prototype');
	var outp = '';
	for (s in cssclass.style){
		if (cssclass.style[s] && !cssclass.style[s].isFunction() && parseInt(s)!=s){
				if (!forbidden.inArray(s)){
					if (classoverstyle==true || !obj.style[s]){
						obj.style[s] = cssclass.style[s];
					}
				}
		}
	}
}


function ApplyCSSStyle(style,obj){
	var forbidden = new Array('length','cssText','cssText','parentRule','accelerator','prototype');
	var evalcode = '';
	for (s in style){
		if (style[s] && !style[s].isFunction() && parseInt(s)!=s){
			if (!forbidden.inArray(s)){
				evalcode += 'obj.style.'+s+' = "'+style[s]+'";';
			}
		}
	}
	eval (evalcode);
}


function SetAlpha(obj,val){
	if (document.all){ obj.style.filter="alpha(style=0, opacity='"+val+"')"; }
	else { obj.style.MozOpacity = val / 100; }
}

//---------------------------------------------------------------[ OBIEKTY :: KLASY ]
function Class(){ return function(){}; }
function ExtendPrototype(target,src){	for (property in src){ target[property] = src[property]; } }


//---------------------------------------------------------------[ OBIEKTY :: COOKIE ]
var Cookie = new Class;
	Cookie.prototype.name = '';
	Cookie.prototype.value = '';
	Cookie.prototype.time = new Class;
	Cookie.prototype.time.value = 0;
	Cookie.prototype.time.set = function(v){ this.value = v * this.secmultiply; }
	Cookie.prototype.time.increase = function(v){ this.value = this.value + v; }
	Cookie.prototype.time.decrease = function(v){ this.value = this.value - v; }
	Cookie.prototype.time.secmultiply = 1;
	Cookie.prototype.time.as = function(m){ if (m=='sec' || m=='s' || m=='seconds'){ this.secmultipy = 1; } if (m=='min' || m=='m' || m=='minutes'){ this.secmultiply = 60; } if (m=='hou' || m=='h' || m=='hours'){ this.secmultiply = 60*60; } if (m=='day' || m=='d' || m=='days'){ this.secmultiply = 60*60*24; } if (m=='wee' || m=='w' || m=='weeks'){ this.secmultiply = 60*60*24*7; } if (m=='mon' || m=='mn' || m=='months'){ this.secmultiply = 60*60*24*7*31; } if (m=='yea' || m=='y' || m=='years'){ this.secmultiply = 60*60*24*7*31*365; } }
	Cookie.prototype.path = '';
	Cookie.prototype.prepare = function(n,v,t,p){ this.name = n; this.value = v; this.time.set(t); this.path = p; }
	Cookie.prototype.set = function(){ 
										var ttl = ''; 
										var cookiestr = '';
										if (this.time.value){ var nowdate = new Date(); nowdate.setTime(nowdate.getTime()+(this.time.value)); ttl = '; expires='+nowdate.toGMTString(); }  
										cookiestr = this.name+'='+this.value+ttl;
										if (this.path){ cookiestr = cookiestr+'; path='+this.path; }
										document.cookie = cookiestr;
									 }
	Cookie.prototype.setNow = function(n,v,t,p){ this.prepare(n,v,t,p); this.set(); }
	Cookie.prototype.unSet = function(){ var nowdate = new Date(); nowdate.setTime(nowdate.getTime()-3600); document.cookie = this.name+'=EMPTY; expires='+nowdate.toGMTString(); }
	Cookie.prototype.isSet = function(name){ if (!name || name==''){ name = this.name; } var str = document.cookie; return (str.match(new RegExp(name+"=[^;]*"))?true:false); }
	Cookie.prototype.read = function(name){ 
											if (!name || name==''){ name = this.name; }
											var str = document.cookie; str = str.split(";");   
											for (i=0;i<str.length;i++){
												if (str[i] && str[i]!=''){
													var nowcookie = str[i]; nowcookie = nowcookie.split("=");
													var nowid = nowcookie[0]; while (nowid.charAt(0)==' '){ nowid = nowid.substring(1,nowid.length); }
													if (nowid==name){ this.name = nowid; this.value = nowcookie[1]; break; return; }
												}
											}
										  }



//---------------------------------------------------------------[ OBIEKTY :: COOKIESCOLLECTION ]
var CookiesCollection = new Class;
	CookiesCollection.prototype.cookies = new Array();
	CookiesCollection.prototype.add = function(obj){ this.cookies[this.cookies.length] = obj; }
	CookiesCollection.prototype.clear = function(){
													for (i=0;i<this.cookies.length;i++){
														this.cookies[i].unSet();
													}
												}
	CookiesCollection.prototype.unSetAll = CookiesCollection.prototype.clear;
	CookiesCollection.prototype.refresh = function(){
														this.cookies = new Array();
														var str = document.cookie;
														str = str.split(';');
														for (i=0;i<str.length;i++){
															var nowcookie = str[i];
															if (nowcookie && nowcookie!=''){ 
																nowcookie = nowcookie.split('='); 
																var nowid = nowcookie[0];
																if (nowid){
																	while (nowid.charAt(0)==' '){ nowid = nowid.substring(1,nowid.length); }
																	var tmp = new Cookie;
																	tmp.read(nowid);
																	this.add(tmp);
																}
															}
														}
													}
	CookiesCollection.prototype.readAll = CookiesCollection.prototype.refresh;
	CookiesCollection.prototype.increaseTTLs = function(v){	for (i=0;i<this.cookies.length;i++){ this.cookies[i].time.increase(v); } }
	CookiesCollection.prototype.decreaseTTLs = function(v){	for (i=0;i<this.cookies.length;i++){ this.cookies[i].time.decrease(v); } }
	CookiesCollection.prototype.getCookieByName = function(n){ for (i=0;i<this.cookies.length;i++){ if (this.cookies[i].name==n){ return this.cookies[i]; } } }
	CookiesCollection.prototype.getCookieByNr = function(n){ return this.cookies[n]; }


//---------------------------------------------------------------[ OBIEKTY :: ENUM ]
var Enum = new Class;
	Enum.prototype.indexOf = function(key,withfunctions){
											var i = 0;
											for (p in this){
												if (this[p].isFunction()==false || withfunctions==true){
													if (this[p]==key){ return i; }												
													i++;
												}
											}
											return null;
										}
	Enum.prototype.contains = function(){
											for (i=0;i<arguments.length;i++){
												var arg = arguments[i];
												if (this.forAny(function(v,i){return v==arg;},true)){ return true; }
											}
											return false;
										}
										
	Enum.prototype.containsAll = function(){
											var cnt = 0;
											for (i=0;i<arguments.length;i++){
												var arg = arguments[i];
												if (this.any(function(v,i){return v==arg;},true)){ cnt++; }
											}
											if (cnt==arguments.length){ return true; } else { return false; }
										}
										
	Enum.prototype.containsWF = function(){
											for (i=0;i<arguments.length;i++){
												var arg = arguments[i];
												if (this.any(function(v,i){ return v==arg;},true,true)){ return true; }
											}
											return false;
										}
										
	Enum.prototype.containsWFAll = function(){
											var cnt = 0;
											for (i=0;i<arguments.length;i++){
												var arg = arguments[i];
												if (this.any(function(v,i){return v==arg;},true,true)){ cnt++; }
											}
											if (cnt==arguments.length){ return true; } else { return false; }
										}
										
	Enum.prototype.without = function(){ 
											var outp = new Array();
											for (p in this){
												if (this[p].isFunction()==false){
													var within = false;
													for (i=0;i<arguments.length;i++){
														if (p==arguments[i]){ within = true; }
													}
													if (within==false){ outp[p] = this[p]; }
												}
											}
											return outp;
									   }
									   
	Enum.prototype.execOn = function(obj,withfunctions,rubystyle){ 
							for (p in this){ 
								var now = this[p];
								if (now){
									if (now.isFunction()==false || withfunctions==true){
										if (rubystyle){ try {var ret = obj(p,now);} catch(e){} } else { try {var ret = obj(now,p);} catch(e){} }
										this[p] = ret;
									}
								}
							}
						  }
						  
	Enum.prototype.execOnEach = Enum.prototype.execOn;
				  
	Enum.prototype.walk = function(obj,withfunctions,rubystyle){
															for (p in this){
																var now = this[p];
																if (now){
																	if (now.isFunction()==false || withfunctions==true){
																		try { if (rubystyle) { obj(p,now); } else { obj (now,p); } } catch(e){}
																	}
																}
															}
														}
						  
	Enum.prototype.forEach = function(obj,withfunctions,rubystyle){ this.walk(obj,withfunctions,rubystyle); }

	Enum.prototype.inject = function(initial,obj,withfunctions,rubystyle){
										for (p in this){
											var now = this[p];
											if (now.isFunction()==false || withfunctions==true){
												if (rubystyle){ try { initial = obj(initial,p,now); } catch(e){} } else { try { initial = obj(initial,now,p); } catch (e){} }
											}
										}
										return initial;
							}
	
	Enum.prototype.forAll = function(obj,inreturn,withfunctions,rubystyle){
														var hits = 0;
														for (p in this){
															var now = this[p];
															if (now.isFunction()==false || withfunctions){
																if (rubystyle){ try {var ret = obj(p,now);} catch(e){} } else { try {var ret = obj(now,p);} catch(e){} }
																if (ret==inreturn){ hits++; }
															}
														}
														if (hits==this.length){ return true; } else { return false; }
													}
	Enum.prototype.forAny = function(obj,inreturn,withfunctions,rubystyle){
														var hits = 0;
														for (p in this){
															var now = this[p];
															if (now.isFunction()==false || withfunctions){
																if (rubystyle){ try {var ret = obj(p,now);} catch(e){} } else { try {var ret = obj(now,p);} catch(e){} }
																if (ret==inreturn){ hits++; }
															}
														}
														if (hits>0){ return true; } else { return false; }
													}												
												
	Enum.prototype.collect = function(obj,withfunctions,rubystyle){
														var outp = new Array();
														for (p in this){ 
															var now = this[p];
															if (now.isFunction()==false || withfunctions==true){
																if (rubystyle){ try {var ret = obj(p,now);} catch(e){} } else { try {var ret = obj(now,p);} catch(e){} }
																if (ret){
																	if (ret.isArray()==true){ outp[ret[0]] = ret[1]; }
																	else { outp.push(ret); }
																}
															}
														}
														return outp;
													  }																			

													  
	Enum.prototype.keys = function(withfunctions){
													outp = new Array();
													for (p in this){
														if (this[p].isFunction()==false || withfunctions){
															outp.push(p);
														}
													}
													return outp;
												}											


//---------------------------------------------------------------[ OBIEKTY :: AJAX ]
var AJAX = new Class;
	AJAX.prototype.URL = '';
	AJAX.prototype.method = 'POST';
	AJAX.prototype.query = '';
	AJAX.prototype.async = true;
	AJAX.prototype.headers = new Array();
	AJAX.prototype.headers['Content-Type'] = "application/x-www-form-urlencoded; charset=UTF-8";
	AJAX.prototype.mimeType = 'text/xml';
	AJAX.prototype.id = '';
	AJAX.prototype.onStart = null;
	AJAX.prototype.onEnd = null;
	AJAX.prototype.onSuccess = null;
	AJAX.prototype.onFailure = null;
	AJAX.prototype.onStateChange = null;
	AJAX.prototype.fireEvent = function(nr,arg1,arg2,arg3){ 
											if (nr==0 && this.onStart){ this.onStart(arg1); } 
											if (nr==1 && this.onEnd){ this.onEnd(arg1,arg2); }
											if (nr==2 && this.onSuccess){ this.onSuccess(arg1); }
											if (nr==3 && this.onFailure){ this.onFailure(arg1,arg2,arg3); }
											if (nr==4 && this.onStateChange){ this.onStateChange(arg1,arg2); }
											}
	AJAX.prototype.createResponse = function(XMLReq,stime){
										var etime = new Date();	etime = etime.getTime();
										
										outp = new AJAXResponse;
										outp.source = XMLReq.responseText;
										outp.XML = XMLReq.responseXML;
										outp.executionTime = etime - stime;
										return outp;
									}
	AJAX.prototype.setOptions = function(u,m,q,a,id){ this.URL = u; this.method = m; this.query = q; this.async = a; this.id = id; }
	AJAX.prototype.setEvents = function(s,e,su,fa,sc){ this.onStart = s; this.onEnd = e; this.onSuccess = su; this.onFailure = fa; this.onStateChange = sc; }
	AJAX.prototype.fire = function(encodequery){
										var XMLReq = null;
										var THIS = this; // ZMIENNA POTRZEBNA, ZEBY TEN OBIEKT BYL WIDZIANY W FUNKCJACH PODRZEDNYCH
										if (THIS.method=='GET'){ THIS.URL = THIS.URL+'?'+THIS.query; }
										
										XMLReq = tryThese( function() {return new XMLHttpRequest()}, function() {return new ActiveXObject('Msxml2.XMLHTTP')}, function() {return new ActiveXObject('Microsoft.XMLHTTP')} );
										if (XMLReq){
											var stime = new Date(); stime = stime.getTime();
										
											THIS.fireEvent(0,THIS.id); // EVENT:START
											if (XMLReq.overrideMimeType){ XMLReq.overrideMimeType(THIS.mimeType); }

											XMLReq.onreadystatechange = function(){
												THIS.fireEvent(4,XMLReq.readyState,stime);
												if (XMLReq.readyState==4){
													THIS.fireEvent(1,THIS.id); // EVENT:END
													if (XMLReq.status==200){ THIS.fireEvent(2,THIS.createResponse(XMLReq,stime)); }
													else { THIS.fireEvent(3,THIS.id,XMLReq.status,XMLReq.statusText); } // EVENT:FAILURE
												}
											}
											
											XMLReq.open(THIS.method,THIS.URL,THIS.async);
											THIS.headers.forEach( function(v,i){ XMLReq.setRequestHeader(i,v); } );
											if (THIS.method=='GET'){ XMLReq.send(null); } else { XMLReq.send(THIS.query); }
											
										} else { THIS.fireEvent(3,THIS.id,-1); } // EVENT:FAILURE
									}
	AJAX.prototype.start = AJAX.prototype.fire;
	AJAX.prototype.setAndFire = function(u,m,q,a,id,s,e,su,fa,se){ this.setOptions(u,m,q,a,id); this.setEvents(s,e,su,fa,se); this.fire(); }
	AJAX.prototype.setAndStart = AJAX.prototype.setAndFire;	
	
//---------------------------------------------------------------[ OBIEKTY :: AJAXRESPONSE ]
var AJAXResponse = new Class;
	AJAXResponse.prototype.source = '';
	AJAXResponse.prototype.XML = '';
	AJAXResponse.prototype.executionTime = 0;
	
	
//---------------------------------------------------------------[ OBIEKTY :: TIMERUN ]
var TimeRun = new Class;
	TimeRun.prototype.delay = 0;
	TimeRun.prototype.decay = 0;
	TimeRun.prototype.times = -1; // JESLI -1 - NIESKONCZONOSC
	TimeRun.prototype.nowPass = 0;
	TimeRun.prototype.func = null;
	TimeRun.prototype.wid = null;
	TimeRun.prototype.paused = false;
	TimeRun.prototype.doStop = false;
	TimeRun.prototype.onEvery = null; // DODATKOWA FUNKCJA, KTORA ZOSTANIE WYKONANA PRZY KAZDYM POWTORZENIU
	TimeRun.prototype.onPass = new Array(); // TABLICA FUNKCJI, FUNKCJA onPass[X] ZOSTANIE WYKONANA PRZY POWTORZENIU NUMER X
	TimeRun.prototype.onEveryX = new Array(); // TABLICA FUNKCJI, FUNKCJA onEveryX[X] ZOSTANIE WYKONANA CO X POWTORZEN
	TimeRun.prototype.onEveryXFromLast = new Array(); // TABLICA POMOCNICZA
	TimeRun.prototype.fire = function(){ 
									  		if (!this.doStop){
										  		if (this.times==-1 || this.nowPass<this.times){
										  			var THIS = this;
										  			this.wid = window.setInterval( function(){ if (!THIS.paused){ THIS.func(); } THIS.widclear(); THIS.fire(); }, (THIS.delay+(THIS.decay*THIS.nowPass)));
										  		}
										  		if (!this.paused){
										  			if (this.onPass[this.nowPass]){ this.onPass[this.nowPass](); }
										  			var THIS = this;
										  			if (this.onEveryX[this.nowPass] && !this.onEveryXFromLast[this.nowPass]){ this.onEveryXFromLast[this.nowPass] = this.nowPass-1; }
										  			this.onEveryXFromLast.execOn( function(v,i){ v++; if (v==i){ THIS.onEveryX[v](); v = 0; } return v; } );
										  			if (this.onEvery){ this.onEvery(); }
										  			this.nowPass++;
									  			}
									  		}
									  		else { this.reset(); }
										}
	TimeRun.prototype.widclear = function(){ window.clearInterval(this.wid); }
	TimeRun.prototype.start = TimeRun.prototype.fire;
	TimeRun.prototype.set = function(delay,func,decay,times){ this.delay = delay; if (decay){ this.decay = decay; } if (times){ this.times = times; } this.func = func; }
	TimeRun.prototype.setAndFire = function(delay,func,decay,times){ this.set(delay,func,decay,times); this.fire(); }
	TimeRun.prototype.setAndStart = TimeRun.prototype.setAndFire;
	TimeRun.prototype.pause = function(tf){ this.paused = tf; }
	TimeRun.prototype.togglePause = function(){ (this.paused==true?this.paused=false:this.paused=true); }
	TimeRun.prototype.reset = function(){ this.nowPass = 0; this.doStop = false; }
	TimeRun.prototype.stop = function(){ this.doStop = true; }


//---------------------------------------------------------------[ OBIEKTY :: HTMLObject ]
var HTMLObject = function(obj){ this.object = obj; };
	HTMLObject.prototype.assign = function(obj){ this.object = obj; }
	HTMLObject.prototype.grab = HTMLObject.prototype.assign;
	
	HTMLObject.prototype.object = null;	

	// WZGLEDNE WYMIARY
	HTMLObject.prototype._x = function(n){ if (n){ this.object.style.left = n; } return (parseInt(this.object.style.left) || 0); }
	HTMLObject.prototype._y = function(n){ if (n){ this.object.style.top = n; } return (parseInt(this.object.style.top) || 0); }
	HTMLObject.prototype._w = function(n){ if (n){ this.object.style.width = n; } return (parseInt(this.object.style.width) || 0); }
	HTMLObject.prototype._h = function(n){ if (n){ this.object.style.height = n; } return (parseInt(this.object.style.height) || 0); }
	HTMLObject.prototype._x2 = function(){ return (this._x()+this._w()); }
	HTMLObject.prototype._y2 = function(){ return (this._y()+this._h()); }
	HTMLObject.prototype._d = function(n){ if (n){ this.object.style.zIndex = n; } return (parseInt(this.object.style.zIndex) || 0); }
	HTMLObject.prototype._rect = function(x,y,w,h){ return [this._x(x), this._y(y), this._w(w), this._h(h)]; }
	
	// ABSOLUTNE WYMIARY
	HTMLObject.prototype._ax = function(){ return findPosX(this.object); }
	HTMLObject.prototype._ay = function(){ return findPosY(this.object); }
	HTMLObject.prototype._aw = function(){ return (parseInt(this.object.offsetWidth) || 0); }
	HTMLObject.prototype._ah = function(){ return (parseInt(this.object.offsetHeight) || 0); }
	HTMLObject.prototype._ax2 = function(){ return (this._ax()+this._aw()); }
	HTMLObject.prototype._ay2 = function(){ return (this._ay()+this._ah()); }
	HTMLObject.prototype._arect = function(){ return [this._ax(),this._ay(),this._aw(),this._ah()] }

	// WIDOCZNOSC
	HTMLObject.prototype.hide = function(){ this.object.style.display = 'none'; }
	HTMLObject.prototype.show = function(){ this.object.style.display = ''; }
	HTMLObject.prototype.toggleVis = function(){ (this.object.style.display==''?this.hide():this.show()); }
	
	// PRZECIAGANIE OBIEKTU
	HTMLObject.prototype.drag = new Class;
	HTMLObject.prototype.drag.prototype.now = false;

	HTMLObject.prototype.dragDuplicate = false;
	HTMLObject.prototype.dragNow = false;
	HTMLObject.prototype.dragTrigger = null;
	HTMLObject.prototype.dragCatchPos = new Array(0,0);
	HTMLObject.prototype.dragDropTargets = new Array();
	HTMLObject.prototype.dragAddDropTarget = function(obj){ this.dragDropTargets.push(obj); }
	HTMLObject.prototype.dragLastStates = new Array();
	HTMLObject.prototype.dragLastStateRevert = function(){ 
															this.object.style.position = this.dragLastStates['position'];  
															this.object.style.left = this.dragLastStates['left'];  
															this.object.style.top = this.dragLastStates['top'];  
															}
																												
	HTMLObject.prototype.dragModeStart = function(trigger){ 
											var THIS = this;
											this.dragTrigger = trigger; 
											
											// ZAPAMIETYWANIE OSTATNICH PARAMETROW
											this.dragLastStates['position'] = this.object.style.position;
											this.dragLastStates['left'] = this.object.style.left;
											this.dragLastStates['top'] = this.object.style.top;
											
											trigger.onmousedown = function(e){ 
																				THIS.object.style.position = 'absolute';
																				THIS.dragNow = true; 
																				THIS.dragCatchPos[0] = document.eventMouseX(e)-THIS._ax(); 
																				THIS.dragCatchPos[1] = document.eventMouseY(e)-THIS._ay(); 
																				if (THIS.onDragStart){ THIS.onDragStart(THIS.dragCatchPos[0],THIS.dragCatchPos[1]); }
																			}
											trigger.onmouseup = function(e){ 
																				THIS.dragNow = false; 
																				var x = document.eventMouseX(e); var y = document.eventMouseY(e);
																				if (THIS.onDragEnd){ THIS.onDragEnd(x,y); }
																				var targetHit = false;
																				for (i=0;i<THIS.dragDropTargets.length;i++){
																					var nowTarget = new HTMLObject($(THIS.dragDropTargets[i]));
																					if (x>=nowTarget._ax() && x<=nowTarget._ax()+nowTarget._aw() && y>=nowTarget._ay() && y<=nowTarget._ay()+nowTarget._ah() ){ 
																						if (THIS.onDragDropOnTarget){ THIS.onDragDropOnTarget(nowTarget.object.id,THIS.dragCatchPos[0],THIS.dragCatchPos[1]); }
																						targetHit = true;  
																					}
																				}
																				if (!targetHit && THIS.onDragDropOffTarget){ THIS.onDragDropOffTarget(THIS.dragCatchPos[0],THIS.dragCatchPos[1]); }
																			}
																									
											document.onmousemove = function(e){ THIS.dragDo(e); }
																
										  }
	HTMLObject.prototype.dragModeStop = function(){  
													this.dragTrigger.onmousedown = null;
													this.dragTrigger.onmouseup = null;
													document.onmousemove = null;
													this.dragTrigger = null;
												 }
	HTMLObject.prototype.dragDo = function(e){ 
												if (this.dragNow){
													if (document.selection){ document.selection.empty(); }
													var dx = document.eventMouseX(e);
													var dy = document.eventMouseY(e);
													this._x(dx - this.dragCatchPos[0]+2);
													this._y(dy - this.dragCatchPos[1]+2);
													if (this.onDragNow){ this.onDragNow(dx,dy); }
													}
												}
												
	// ROZCIAGANIE OBIEKTU
											 
	// ZMIANA RODZICA
	HTMLObject.prototype.parentChange = function(newParent){ 
											newParent = $(newParent);
											newParent.appendChild(this.object);
										 }
											 
	// DODATKOWE EVENTY
	HTMLObject.prototype.onDragStart = null;
	HTMLObject.prototype.onDragDropOnTarget = null;
	HTMLObject.prototype.onDragDropOffTarget = null;
	HTMLObject.prototype.onDragEnd = null;
	HTMLObject.prototype.onDragNow = null;
													
//---------------------------------------------------------------[ ROZSZERZENIA :: DOCUMENT ]
document.CookiesCollection = new CookiesCollection;
document.CookiesCollection.refresh();

document.includeJS = function(url){  
	var tmp = document.createElement("script");
		tmp.type = "text/javascript"; 
		tmp.language = "JavaScript";
		tmp.src = url;
		$byTag('head')[0].appendChild(tmp);
}

document.excludeJS = function(url){
	var tmp = $byParams("src="+url+";type=text/javascript")[0];
	if (tmp){
		$byTag('head')[0].removeChild(tmp);
	}
}

document.includeCSS = function(url){ 
	var tmp = document.createElement("link");
		tmp.rel = "stylesheet";
		tmp.type = "text/css";
		tmp.href = url;
		$byTag('head')[0].appendChild(tmp);
}

document.excludeCSS = function(url){
	var tmp = $byParams("href="+url+";type=text/css")[0];
	if (tmp){
		$byTag('head')[0].removeChild(tmp);
	}
}


document.scrollX = function(){
	var outp = 0;
	if (typeof(window.pageXOffset)=='number'){ outp = window.pageXOffset; } 
	else if (document.body.scrollLeft) { outp = document.body.scrollLeft; }
	else if (document.documentElement.scrollLeft){ outp = document.documentElement.scrollTop; }
	return outp;
}
	
	
document.scrollY = function(){
	var outp = 0;
	if (typeof(window.pageYOffset)=='number'){ outp = window.pageYOffset; } 
	else if (document.body.scrollTop) { outp = document.body.scrollTop; }
	else if (document.documentElement.scrollTop){ outp = document.documentElement.scrollTop; }
	return outp;
}


document.scroll = function(){
	return [document.scrollX(),document.scrollY()]
}

document.eventMouseX = function(e){ if (document.all){ return event.clientX + document.scrollX(); } else { return e.pageX; } }
document.eventMouseY = function(e){ if (document.all){ return event.clientY + document.scrollY(); } else { return e.pageY; } }


//---------------------------------------------------------------[ ROZSZERZENIA :: ARRAY ]
ExtendPrototype(Array.prototype,Enum.prototype);
Array.prototype.clear = function(){ this.length = 0; return this; }
Array.prototype.first = function(){ return this[0]; }
Array.prototype.last = function(){ return this[this.length-1]; }
Array.prototype.stackAdd = function(v){ this.unshift(v); }
Array.prototype.stackGet = function(){ return this.shift(); }
Array.prototype.queryAdd = function(v){ this.push(v); }
Array.prototype.queryGet = function(){ return this.shift(); }
Array.prototype.fill = function(){ for(i=0;i<arguments.length;i=i+2){ this[arguments[i]] = arguments[i+1]; } }
Array.prototype.toURLQuery = function(mode){
											if (mode==2){
												var tmp = this.collect( function(v,i){ return encodeURIComponent(i)+'='+encodeURIComponent(v);  } );
											} else {var tmp = this.collect( function(v,i){ return i+'='+v;  } );}
											if (mode==1 || mode==2){ return tmp.join('&amp;'); } else { return tmp.join('&'); }
											}
Array.prototype.flip = function(){	
								 	var outp = new Array();
								 	for (p in this){
								 		if (this[p].isFunction()==false){
								 			outp[this[p]] = p;
								 		}
								 	}
								 	return outp;
								 }

Array.prototype.inArray = Array.prototype.contains;
Array.prototype.allInArray = Array.prototype.containsAll;
Array.prototype.search = function(){
									var outp = new Array();
										for (i=0;i<arguments.length;i++){
											var arg = arguments[i];
											var tmp = this.collect(function(v,i){ if (v==arg){ return i; } else { return null; } });
											if (tmp){ outp = outp.concat(tmp); }
										}
										return outp;
									}
									
Array.prototype.grep = function(){
									var outp = new Array();
										for (i=0;i<arguments.length;i++){
											var arg = new RegExp(arguments[i].toString());
											var tmp = this.collect(function(v,i){ v=v.toString(); if (v.match(arg)){ return i; } else { return null; } });
											if (tmp){ outp = outp.concat(tmp); }
										}
										return outp;
									}
Array.prototype.sum = function(){ 
									var outp = 0;
									for (p in this){
										if (this[p].isFunction()==false){
											outp = outp+parseInt(this[p]);
										}
									}
									return outp;
								 }

Array.prototype.multiply = function(){ 
									var outp = 1;
									for (p in this){
										if (this[p].isFunction()==false){
											outp = outp*parseInt(this[p]);
										}
									}
									return outp;
								 }
								 
Array.prototype.max = function(){
									var outp = 0;
									for (p in this){
										if (this[p]>outp){ outp = this[p]; }
									}
									return outp;
								}
								
Array.prototype.min = function(){
									var outp = 9999999999;
									for (p in this){
										if (this[p]<outp){ outp = this[p]; }
									}
									return outp;
								}
								
Array.prototype.next = function(val){
									var prev = false;
									for (p in this){
										if (p && this[p]){
											if (prev==true){ return [p,this[p]] }
											if (p==val){ prev = true; }
										}
									}
}



//---------------------------------------------------------------[ ROZSZERZENIA :: OBJECT ]
ExtendPrototype(Object.prototype,Enum.prototype);
Object.prototype.isObject = function(){ return ((this && typeof this =='object') || this.isFunction()); }
Object.prototype.isJustObject = function(){ return (this && typeof this =='object'); }
Object.prototype.isJustAnObject = Object.prototype.isJustObject;
Object.prototype.isFunction = function(){ return typeof this == 'function'; }
Object.prototype.isArray = function(){ return (this.isObject && this.constructor == Array); }
Object.prototype.isNull = function(){ return this === null; }
Object.prototype.isUndefined = function(){ return this == 'undefined'; }
Object.prototype.isNil = function(){ return (this.isNull() || this.isUndefined()); }
Object.prototype.isUnknown = function(){ return (this.isObject() && typeof this.constructor != 'function'); }
Object.prototype.isCookie = function(){ return (this.isObject() && this.constructor == Cookie); }
Object.prototype.isAJAX = function(){ return (this.isObject() && this.constructor == AJAX); }
Object.prototype.isAJAXResponse = function(){ return (this.isObject() && this.constructor == AJAXResponse); }
Object.prototype.isRegExp = function(){ return (this.constructor.match(/function RegExp\(\)(.*)/)?true:false) }
Object.prototype.isTypeOf = function(typename){ return (this.isObject() && typeof this == typename); }
Object.prototype.ifFormObject = function(){ var t = this.tagName; alert (t); }
Object.prototype.isConstructorTypeOf = function(typename){ return (this.isObject() && typeof this.constructor == typename); }
Object.prototype.ExtendBy = function(src){	for (property in src){ this[property] = src[property]; } }
Object.prototype.Extends = function(target){ for (property in this){ target[property] = this[property];	} }
Object.prototype.toArray = function(obj) {  var outp = new Array(); for (i=0;i<this.length;i++){ outp.push(this[i]); } return outp; }

// WRZUCONE DLA EWENTUALNEJ KOMPATYBILNOSCI - NIE DZIALAJA PONIEWAZ PONIZSZE TYPY NIE SA OBIEKTAMI
Object.prototype.isNumber = function(){ return typeof this == 'number'; }
Object.prototype.isInteger = Object.prototype.isNumber;
Object.prototype.isString = function(){ return typeof this == 'string'; }
Object.prototype.isBoolean = function(){ return typeof this == 'boolean'; }

//---------------------------------------------------------------[ DODATKOWE FUNKCJE SPRAWDZAJACE ]

isNumber = function(obj){ return typeof obj == 'number'; }
isInteger = isNumber;
isString = function(obj){ return typeof obj == 'string'; }
isBoolean = function(obj){ return typeof obj == 'boolean'; }

//---------------------------------------------------------------[ ROZSZERZENIA :: REGEXP ]
RegExp.prototype.templates = new Class;
RegExp.prototype.templates.HTMLTags = /(<\/?[^>]+>)/gim;
RegExp.prototype.templates.HTMLScripts = /(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)/gim;
RegExp.prototype.templates.HTMLDocType = /<!DOCTYPE HTML PUBLIC "([^"]+)">/gim;
RegExp.prototype.templates.BBCode = /(\[[^\]]*\])/gim;
RegExp.fromTemplate = function(tmp){ return RegExp.prototype.templates[tmp]; }
RegExp.registerTemplate = function(name,rexp){ RegExp.prototype.templates[name] = rexp; }
RegExp.listTemplates = function(){ return RegExp.prototype.templates.collect(function(v,i){ if (v.isRegExp){ return i; } else { return null; } }); }
RegExp.hasTemplates = function(){ var cnt=0; for(i=0;i<arguments.length;i++){ if (RegExp.prototype.templates[arguments[i]]){ cnt++; } } if (cnt>0){ return true; } else { return false; } }
RegExp.hasAllTemplates = function(){ var cnt=0; for(i=0;i<arguments.length;i++){ if (RegExp.prototype.templates[arguments[i]]){ cnt++; } } if (cnt==arguments.length){ return true; } else { return false; } }


//---------------------------------------------------------------[ ROZSZERZENIA :: STRING ]
String.prototype.stripTags = function(){ return this.replace(RegExp.prototype.templates.HTMLTags, ''); }
String.prototype.stripJS = function(){ return this.replace(RegExp.prototype.templates.HTMLScripts,''); }
String.prototype.stripBBCode = function(){ return this.replace(RegExp.prototype.templates.BBCode,''); }
String.prototype.extractScripts = function(){ var tmp = this.match(RegExp.prototype.templates.HTMLScripts,''); if (tmp){ tmp.execOn(function(v,i){ return v.toString().replace(/<script[^>]+>|<\/script>/gim,''); }); return tmp; } else { return null; } }
String.prototype.runScripts = function(){ scripts = this.extractScripts(); if (scripts){ return scripts.forEach(eval); } }
String.prototype.evalScripts = String.prototype.runScripts;
String.prototype.encode = function(){ return encodeURIComponent(this); }
String.prototype.decode = function(){ return decodeURIComponent(this); }
String.prototype.escape = function(){ var container = document.createElement('div');  var tNode = document.createTextNode(this); container.appendChild(tNode); var tmp = container.innerHTML; container.removeChild(tNode); return tmp;}
String.prototype.unEscape = function(){ var container = document.createElement('div'); container.innerHTML = this.stripTags(); if (container.childNodes[0]){ return container.childNodes[0].nodeValue; } else { return ''; } }
String.prototype.unescape = String.prototype.unEscape;
String.prototype.toURLQueryArray = function(mode){ if (mode==1 || mode==2){ var tmp = this.split("&amp;"); } else { var tmp = this.split("&"); } if (mode==2){ return tmp.collect(function(v,i){ v = v.toString().split("="); return [decodeURIComponent(v[0]),decodeURIComponent(v[1])]}); } else { return tmp.collect(function(v,i){ v = v.toString().split("="); return [v[0],v[1]]}); } }
String.prototype.toCamel = function(){
									 	var outp = this;
									 	while (outp.indexOf('-')>-1){
									 		pos = outp.indexOf('-');
									 		outp = outp.substring(0,pos)+outp.charAt(pos+1).toUpperCase()+outp.substring(pos+2,outp.length);
									 	}
									 	return outp;		 	
									 }
String.prototype.toCamelCase = String.prototype.toCamel;
String.prototype.toHyphen = function(){ var outp = this; outp = outp.replace(/([^\ ])([A-Z])/gm,'$1-$2'); return outp.toLowerCase(); }
String.prototype.fromCamel = String.prototype.toHyphen;
String.prototype.fromCamelCase = String.prototype.toHyphen;
String.prototype.reverse = function(){ var outp = ''; for (i=this.length;i>=0;i--){ outp = outp+this.charAt(i); } return outp; }
String.prototype.baseConvert = function(s,t){ // S == THIS_BASE; T = TARGET_BASE
											 var tmp = new Array("0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","R","S","T","U","V","W","X","Y","Z");
											 var str = this.reverse(); if (!s || s<2){ s = 16; } if (!t || t<2){ t = 10; }
											 var outp = 0;
											 	for (i=0;i<str.length;i++){	outp = outp+(s.pow(i)*tmp.indexOf(str.charAt(i))); }
											 if (t==10){ return outp; } else { return outp.baseConvert(t); }
											}
											
String.prototype.insertAfter = function(afterstr,toinsert,startfrom){
	if (!startfrom){ startfrom = 0; }
	var pos = this.indexOf(afterstr,startfrom)+afterstr.length;
	return this.left(pos)+toinsert+this.right(pos);		
}

String.prototype.insertBefore = function(beforestr,toinsert,startfrom){
	if (!startfrom){ startfrom = 0; }
	var pos = this.indexOf(beforestr,startfrom);
	return this.left(pos)+toinsert+this.right(pos);
}

String.prototype.left = function(pos){ return this.substring(0,pos); }
String.prototype.right = function(pos){ return this.substring(pos,this.length); }
String.prototype.mid = String.prototype.substring;
String.prototype.extractFileName = function(woext){ 
													var p1 = this.lastIndexOf('/')+1;
													if (woext){ var p2 = this.lastIndexOf('.'); } else { p2 = this.length; }
													return this.substring(p1,p2);
												 }
												 

//---------------------------------------------------------------[ ROZSZERZENIA :: NUMBER ]
Number.prototype.times = function(c){ for (i=0;i<this;i++){c(i);} }
Number.prototype.baseConvert = function(t){ // T == BASE
											
											var tab = new Array("0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","R","S","T","U","V","W","X","Y","Z");
											var tmp = this; var outp = '';
											t = parseInt(t); if (!t || t<2){ t=16; }
											while (tmp>=t){
												outp = tab[(tmp%t)]+outp;
												tmp = Math.floor(tmp/t);
											}
											outp = tab[tmp]+outp;
											return outp;
										  }
Number.prototype.baseConvertStr = function(s,t){ return this.toString().baseConvert(s,t); }								  
Number.prototype.pow = function(n){ return Math.pow(this,n); }


//---------------------------------------------------------------[ ROZSZERZENIA :: FUNCTION ]
Function.prototype.expand = function(f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13,f14,f15,f16,f17,f18,f19,f20,f21,f22,f23,f24,f25) {
  var THIS = this;
  return function() {	
    THIS.apply(THIS, arguments.toArray());
    if (f1){ f1.apply(THIS, arguments.toArray()); }
    if (f2){ f2.apply(THIS, arguments.toArray()); }
    if (f3){ f3.apply(THIS, arguments.toArray()); }
    if (f4){ f4.apply(THIS, arguments.toArray()); }
    if (f5){ f5.apply(THIS, arguments.toArray()); }
    if (f6){ f6.apply(THIS, arguments.toArray()); }
    if (f7){ f7.apply(THIS, arguments.toArray()); }
    if (f8){ f8.apply(THIS, arguments.toArray()); }
    if (f9){ f9.apply(THIS, arguments.toArray()); }
    if (f10){ f10.apply(THIS, arguments.toArray()); }
    if (f11){ f11.apply(THIS, arguments.toArray()); }
    if (f12){ f12.apply(THIS, arguments.toArray()); }
    if (f13){ f13.apply(THIS, arguments.toArray()); }
    if (f14){ f14.apply(THIS, arguments.toArray()); }
    if (f15){ f15.apply(THIS, arguments.toArray()); }
    if (f16){ f16.apply(THIS, arguments.toArray()); }
    if (f17){ f17.apply(THIS, arguments.toArray()); }
    if (f18){ f18.apply(THIS, arguments.toArray()); }
    if (f19){ f19.apply(THIS, arguments.toArray()); }
    if (f20){ f20.apply(THIS, arguments.toArray()); }
    if (f21){ f21.apply(THIS, arguments.toArray()); }
    if (f22){ f22.apply(THIS, arguments.toArray()); }
    if (f23){ f23.apply(THIS, arguments.toArray()); }
    if (f24){ f24.apply(THIS, arguments.toArray()); }
    if (f25){ f25.apply(THIS, arguments.toArray()); }
  }
}
Function.prototype.bind = Function.prototype.expand;
