m.Registry=[];
m.aniLen=250;
m.hideDelay=1000;
m.minCPUResolution=10;

function m(id,_2,_3,_4,_5,_6,pid) {
    this.ie=document.all?1:0;
    this.ns4=document.layers?1:0;
    this.dom=document.getElementById?1:0;
    this.css="";
    if(this.ie||this.ns4||this.dom) {
        this.id=id;
        this.pid=pid||false;
        this.dir=_2;
        this.orientation=_2=="left"||_2=="right"?"h":"v";
        this.dirType=_2=="right"||_2=="down"?"-":"+";
        this.dim=this.orientation=="h"?_5:_6;
        this.hideTimer=false;
        this.aniTimer=false;
        this.open=false;
        this.over=false;
        this.startTime=0;
        this.gRef="m_"+id;
        eval(this.gRef+"=this");
        m.Registry[id]=this;
        var d=document;        
        this.load();
    }
}
;
m.prototype.load=function() {
    var d=document;
    var _10=this.id+"Container";
    var _11=this.id+"Content";
    var _12=this.dom?d.getElementById(_10):this.ie?d.all[_10]:d.layers[_10];
    if(_12) {
        var _13=this.ns4?_12.layers[_11]:this.ie?d.all[_11]:d.getElementById(_11);
    }
    var _14;
    if(!_12||!_13) {
        window.setTimeout(this.gRef+".load()",100);
    }
    else {
        this.container=_12;
        this.menu=_13;
        this.style=this.ns4?this.menu:this.menu.style;
        this.homePos=eval("0"+this.dirType+this.dim);
        this.outPos=0;
        this.accelConst=(this.outPos-this.homePos)/m.aniLen/m.aniLen;
        if(this.ns4) {
            this.menu.captureEvents(Event.MOUSEOVER|Event.MOUSEOUT);
        }
        this.menu.onmouseover=new Function("m.showMenu('"+this.id+"')");
        this.menu.onmouseout=new Function("m.hideMenu('"+this.id+"')");
        this.endSlide();
    }
}
;
m.showMenu=function(id) {
    var reg=m.Registry;
    var obj=m.Registry[id];
    if(obj.container) {
        obj.over=true;
        for(menu in reg) {
            if(id!=menu) {
                m.hide(menu);
            }
        }
        if(obj.hideTimer) {
            reg[id].hideTimer=window.clearTimeout(reg[id].hideTimer);
        }
        if(!obj.open&&!obj.aniTimer) {
            reg[id].startSlide(true);
        }
    }
}
;
m.hideMenu=function(id) {
    var obj=m.Registry[id];
    if(obj.container) {
        if(obj.hideTimer) {
            window.clearTimeout(obj.hideTimer);
        }
        obj.hideTimer=window.setTimeout("m.hide('"+id+"')",m.hideDelay);
    }
}
;
m.hideAll=function() {
    var reg=m.Registry;
    for(menu in reg) {
        m.hide(menu);
        if(menu.hideTimer) {
            window.clearTimeout(menu.hideTimer);
        }
    }
}
;
m.hide=function(id) {
    var obj=m.Registry[id];
    obj.over=false;
    if(obj.hideTimer) {
        window.clearTimeout(obj.hideTimer);
    }
    obj.hideTimer=0;
    if(obj.open&&!obj.aniTimer) {
        obj.startSlide(false);
    }
}
;
m.adjMenu=function(){
	var menu_bar = getElementLeft('menu_bar');
	for(var id in m.Registry) {
        m.Registry[id]._left=getElementLeft(id)-menu_bar;
		  getObject(id+'Container').style.left=m.Registry[id]._left+"px";
    };
}
;
m.prototype.startSlide=function(_21) {
    this[_21?"onactivate":"ondeactivate"]();
    this.open=_21;
    if(_21) {
        this.setVisibility(true);
    }
    this.startTime=(new Date()).getTime();
    this.aniTimer=window.setInterval(this.gRef+".slide()",m.minCPUResolution);
}
;
m.prototype.slide=function() {
    var _22=(new Date()).getTime()-this.startTime;
    if(_22>m.aniLen) {
        this.endSlide();
    }
    else {
        var d=Math.round(Math.pow(m.aniLen-_22,2)*this.accelConst);
        if(this.open&&this.dirType=="-") {
            d=-d;
        }
        else {
            if(this.open&&this.dirType=="+") {
                d=-d;
            }
            else {
                if(!this.open&&this.dirType=="-") {
                    d=-this.dim+d;
                }
                else {
                    d=this.dim+d;
                }
            }
        }
        this.moveTo(d);
    }
}
;
m.prototype.endSlide=function() {
    this.aniTimer=window.clearTimeout(this.aniTimer);
    this.moveTo(this.open?this.outPos:this.homePos);
    if(!this.open) {
        this.setVisibility(false);
    }
    if((this.open&&!this.over)||(!this.open&&this.over)) {
        this.startSlide(this.over);
    }
}
;
m.prototype.setVisibility=function(_24) {
    var s=this.ns4?this.container:this.container.style;
    s.visibility=_24?"visible":"hidden";
}
;
m.prototype.moveTo=function(p) {
    this.style[this.orientation=="h"?"left":"top"]=this.ns4?p:p+"px";
}
;
m.prototype.getPos=function(c) {
    return parseInt(this.style[c]);
}
;
m.prototype.onactivate=function() {
}
;
m.prototype.ondeactivate=function() {
}
;
function getObjNN4(obj,name)
{
	var x = obj.layers;
	var foundLayer;
	for (var i=0;i<x.length;i++)
	{
		if (x[i].id == name)
		 	foundLayer = x[i];
		else if (x[i].layers.length)
			var tmp = getObjNN4(x[i],name);
		if (tmp) foundLayer = tmp;
	}
	return foundLayer;
}
;

function getElementLeft(Elem) {
	if (document.layers) {
		var elem = getObjNN4(document, Elem);
		return elem.pageX;
	} else {
		var elem;
		if(document.getElementById) {
			var elem = document.getElementById(Elem);
		} else if (document.all){
			var elem = document.all[Elem];
		}
		xPos = elem.offsetLeft;
		tempEl = elem.offsetParent;
  		while (tempEl != null) {
  			xPos += tempEl.offsetLeft;
	  		tempEl = tempEl.offsetParent;
  		}
		return xPos;
	}
};
function getObject(obj) {
    var o;
    if(document.getElementById) o = document.getElementById(obj);
    else if(document.all) o = document.all.obj;
    return o;
};

function Popup(img,szer,wys) {
  tytul="Sport Factory";
  var szer1 = parseInt(szer) + 20;
  var wys1 = parseInt(wys) + 22;
  szer1 = (szer1 < screen.availWidth) ? szer1 : screen.availWidth;
  wys1 = (wys1 < screen.availHeight) ? wys1 : screen.availHeight;
  var winl = (screen.availWidth - szer1) / 2;
  var wint = (screen.availHeight - wys1) / 2; 
  w=window.open("","","width="+szer1+",height="+wys1+",top="+wint+",left="+winl+",toolbar=no,scrollbars=no,resizable=no,status=no,location=no,menubar=no,");	
  w.document.write("<HTML><HEAD><meta http-equiv='content-type' content='text/html;  charset=utf-8' /><TITLE>"+tytul+"</TITLE>");
  w.document.write("<style><!-- table { background: url(/img/waiting.gif) 50% 50% no-repeat white; margin: 0; padding: 0;color: #aaaaaa; font-family: verdana, sans-serif; font-size: 8pt; } body {margin:0; padding: 0; background-color:#FFFFFF;} //--> </style></head><body scroll='no'><table cellspacing='0' cellpadding='0' align='center' valign='middle' width='100%' height='100%'><tr><td class='img' width='100%' height='100%' align='center' valign='middle'><div style='border-top: 1px solid #cccccc; border-bottom: 1px solid #cccccc; margin: auto;' ><a href=\"javascript:self.close();\"><img	style='cursor: pointer; cursor: hand; border: 10px solid white;' galleryimg='no' src='"+ img +"' alt=\"click to close\" /></a></div></td></tr></table>");
  w.document.write("</BODY></HTML>");
  w.document.close();
		};
		
var req;
var d = new Date();
var curr_year = d.getFullYear();

function navigate(month,year,evt) {
	setFade(0);
	var url = "/calendar/super_calendar.php?month="+month+"&year="+year+"&event="+evt;
	if(window.XMLHttpRequest) {
		req = new XMLHttpRequest();
	} else if(window.ActiveXObject) {
		req = new ActiveXObject("Microsoft.XMLHTTP");
	}
	req.open("GET", url, true);
	req.onreadystatechange = callback;
	req.send(null);
};

function callback() {	
	if(req.readyState == 4) {
		var response = req.responseXML;	
		var resp = response.getElementsByTagName("response");
		getObject("calendar").innerHTML = resp[0].getElementsByTagName("content")[0].childNodes[0].nodeValue;
		fade(70);
	}
};

function fade(amt) {
	if(amt <= 100) {
		setFade(amt);
		amt += 10;
		setTimeout("fade("+amt+")", 5);
    }
};

function setFade(amt) {
	var obj = getObject("calendar");
	amt = (amt == 100)?99.999:amt;
	obj.style.filter = "alpha(opacity:"+amt+")";
	obj.style.KHTMLOpacity = amt/100;
	obj.style.MozOpacity = amt/100;
	obj.style.opacity = amt/100;
};

function showJump(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	var jump = document.createElement("div");
	jump.setAttribute("id","jump");
	jump.style.position = "absolute";
	jump.style.top = curtop+15+"px";
	jump.style.left = curleft+"px";
	var output = '<select id="month">\n';
	var months = new Array('Styczeń','Luty','Marzec','Kwiecień','Maj','Czerwiec','Lipiec','Sierpień','Wrzesień','Październik','Listopad','Grudzień');
	var n;
	for(var i=0;i<12;i++) {
		n = ((i+1)<10)? '0'+(i+1):i+1;
		output += '<option value="'+n+'">'+months[i]+'  </option>\n';
	};
	output += '</select> \n<select id="year">\n';
	for(var i=curr_year-1;i<=curr_year+2;i++) {
		
		output += '<option value="'+i+'">'+i+'  </option>\n';
	};
	output += '</select> <a href="javascript:jumpTo()"><img src="/calendar/images/calGo.gif" alt="idź" style="display: inline" /></a> <a href="javascript:hideJump()"><img src="/calendar/images/calStop.gif" alt="zamknij" style="display: inline" /></a>';
	jump.innerHTML = output;
	document.body.appendChild(jump);
};

function hideJump() {
	document.body.removeChild(getObject("jump"));	
};

function jumpTo() {
	var m = getObject("month");
	var y = getObject("year");
	navigate(m.options[m.selectedIndex].value,y.options[y.selectedIndex].value,'');
	hideJump();
};

var req;
var d = new Date();
var curr_year = d.getFullYear();

function navigate(month,year,evt) {
	setFade(0);
	var url = "/calendar/super_calendar.php?month="+month+"&year="+year+"&event="+evt;
	if(window.XMLHttpRequest) {
		req = new XMLHttpRequest();
	} else if(window.ActiveXObject) {
		req = new ActiveXObject("Microsoft.XMLHTTP");
	}
	req.open("GET", url, true);
	req.onreadystatechange = callback;
	req.send(null);
};

function callback() {	
	if(req.readyState == 4) {
		var response = req.responseXML;	
		var resp = response.getElementsByTagName("response");
		getObject("calendar").innerHTML = resp[0].getElementsByTagName("content")[0].childNodes[0].nodeValue;
		fade(70);
	}
};

function getObject(obj) {
	var o;
	if(document.getElementById) o = document.getElementById(obj);
	else if(document.all) o = document.all.obj;	
	return o;	
};

function fade(amt) {
	if(amt <= 100) {
		setFade(amt);
		amt += 10;
		setTimeout("fade("+amt+")", 5);
    }
};

function setFade(amt) {
	var obj = getObject("calendar");
	amt = (amt == 100)?99.999:amt;
	obj.style.filter = "alpha(opacity:"+amt+")";
	obj.style.KHTMLOpacity = amt/100;
	obj.style.MozOpacity = amt/100;
	obj.style.opacity = amt/100;
};

function showJump(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	var jump = document.createElement("div");
	jump.setAttribute("id","jump");
	jump.style.position = "absolute";
	jump.style.top = curtop+15+"px";
	jump.style.left = curleft-70+"px";
	var output = '<select id="month">\n';
	var months = new Array('Styczeń','Luty','Marzec','Kwiecień','Maj','Czerwiec','Lipiec','Sierpień','Wrzesień','Październik','Listopad','Grudzień');
	var n;
	for(var i=0;i<12;i++) {
		n = ((i+1)<10)? '0'+(i+1):i+1;
		output += '<option value="'+n+'">'+months[i]+'  </option>\n';
	}
	output += '</select> \n<select id="year">\n';
	for(var i=curr_year-1;i<=curr_year+2;i++) {
		
		output += '<option value="'+i+'">'+i+'  </option>\n';
	}
	output += '</select> <a href="javascript:jumpTo()"><img src="/calendar/images/calGo.gif" alt="idź" style="display: inline" /></a> <a href="javascript:hideJump()"><img src="/calendar/images/calStop.gif" alt="zamknij" style="display: inline" /></a>';
	jump.innerHTML = output;
	document.body.appendChild(jump);
};

function hideJump() {
	document.body.removeChild(getObject("jump"));	
};

function jumpTo() {
	var m = getObject("month");
	var y = getObject("year");
	navigate(m.options[m.selectedIndex].value,y.options[y.selectedIndex].value,'');
	hideJump();
};
