function boxRotator(id, active) {

	var id=id+'DD';

	var lastActive = active;

	var repeatTime = 0;

	var DDCount = 0;

	var DDaCount = 0;

	var ts = -1;



	//szukanie zakladek DD

	var tag = document.getElementsByTagName('div');

	for (i=0;i<tag.length;i++) {

		if (tag[i].id.indexOf(id)==0) {

			DDCount++;

		}

	}

	//szukanie zakladek DDa

	tag = document.getElementsByTagName('a');

	for (i=0;i<tag.length;i++) {

		if (tag[i].id.indexOf(id+'a')==0) {

			DDaCount++;

		}

	}

	if (DDCount!=DDaCount) alert("Bląd ilości div'ów i zakladek: "+DDCount+":"+DDaCount);



	this.click = function (n) {

		try {

			document.getElementById(id+lastActive).style.display='none';

			document.getElementById(id+n).style.display='';

			document.getElementById(id+'a'+lastActive).className='';

			document.getElementById(id+'a'+n).className='on';

			lastActive=n;

		} catch (err) {}

	

	}

	this.next = function () {

		if (lastActive==DDCount) this.click(1); else this.click(lastActive+1);

	}

	

	this.previous = function () {

		if (lastActive>1) this.click(lastActive-1); else this.click(DDCount);	

	}

	this.click(active);

}





/* KALENDARZ */

var toS;

var toH;

var nrPrev=1;

function show(nr) {

	clearTimeout(toS);

	toS = setTimeout("showD("+nr+");", 150);

}

function hide(nr) {

	clearTimeout(toH);

	toH = setTimeout("hideD("+nr+");", 150);

}

function showD(nr) {

	document.getElementById("l" + nrPrev).style.display = "none";

	document.getElementById("i" + nrPrev).style.zIndex = 5;

	document.getElementById("i" + nr).style.zIndex = 7;

	document.getElementById("l" + nr).style.zIndex = 6;

	document.getElementById("l" + nr).style.display = "";

	nrPrev = nr;

}

function hideD(nr) {

	document.getElementById("i" + nr).style.zIndex = 5;

	document.getElementById("l" + nr).style.display = "none";

}



var nr=0;

var oc2=0;



//Podmenu

function setSubMenu(_nr) {

	if (nr == _nr) {

		if (oc2==0) {

			setTimeout('document.getElementById("sub"+nr).style.display = "none"; nr = 0;', 100);

			document.getElementById("z"+nr).className='';

		}

		oc2 = 1;

	} else {

		if (nr>0) {

			document.getElementById("sub"+nr).style.display = "none";

			document.getElementById("z"+nr).className='';

		}

		oc2 = 0;

		document.getElementById("sub"+_nr).style.display = "block";

		document.getElementById("z"+_nr).className='on';

		nr = _nr;

	}

}



function popup(sciezka,szerokosc,wysokosc,x,y) {

	window.open(sciezka, "gliok", "toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=1, resizable=0, copyhistory=0, width="+szerokosc+", height="+wysokosc+", left="+x+", top="+y+"");

}


var eventScroll = {

container: {},
	   arrows: {},
	   maxwidth: 0,
	   cwidth: 0,
	   step: 148,		

	   init: function(obj) {

		   if (obj) {

			   if (typeof(obj) !== 'object') var obj = document.getElementById(obj)

				   this.arrows = obj.getElementsByTagName('a')				
					   this.container = obj.getElementsByTagName('ul')[0]
					   this.cwidth = this.container.getElementsByTagName('li').length * this.step
					   this.maxwidth = this.container.parentNode.offsetWidth

					   if ((this.arrows.length > 0) && (typeof(this.container) === 'object')) {

						   var	arrowLeft = this.arrows[0],
						   arrowRight = this.arrows[this.arrows.length-1]

							   if (window.addEventListener) {
								   arrowLeft.addEventListener('click', function() { eventScroll.scrollLeft() }, false)
								   arrowRight.addEventListener('click', function() { eventScroll.scrollRight()}, false)
							   }
							   else {									
								   arrowLeft.onclick = function(event) { eventScroll.scrollLeft()}
								   arrowRight.onclick = function(event) { eventScroll.scrollRight()}
							   }

						   if (this.cwidth < this.maxwidth) this.arrows[this.arrows.length-1].className = 'arrow-right arrow-right-off' 

					   }

					   else return false					

		   }

		   else return false			

	   },


scrollRight: function() {
		     var offsetL = this.container.offsetLeft

			     if ( this.cwidth > this.maxwidth - offsetL) {
				     this.container.style.left = this.container.offsetLeft - this.step + 'px'
					     this.arrows[0].className = 'arrow-left'
					     if ( this.cwidth == (this.maxwidth - this.container.offsetLeft)) this.arrows[this.arrows.length-1].className = 'arrow-right arrow-right-off' 
			     }
			     return false
	     },

scrollLeft: function() {
		    var offsetL = this.container.offsetLeft			

			    if (offsetL < 0) {
				    this.container.style.left = offsetL + this.step + 'px'
					    this.arrows[this.arrows.length-1].className = 'arrow-right'
					    if (this.container.offsetLeft >= 0 ) this.arrows[0].className = 'arrow-left arrow-left-off' 
			    }
			    return false
	    }



}



function getElementPosition(elemID){

	var offsetTrail = elemID,
	    offsetLeft = 0,
	    offsetTop = 0;

	while (offsetTrail) {
		offsetLeft += offsetTrail.offsetLeft;
		offsetTop += offsetTrail.offsetTop;
		offsetTrail = offsetTrail.offsetParent;
	}

	if (navigator.userAgent.indexOf('Mac') != -1 && typeof document.body.leftMargin != 'undefined') {
		offsetLeft += document.body.leftMargin;
		offsetTop += document.body.topMargin;
	}

	return {left:offsetLeft, top:offsetTop};

}

function showPopup(obj, id, classname) {
	if ((typeof(obj) === 'undefined') || (typeof(id) === 'undefined')) {
		return false
	} else {

		var popup = document.getElementById(id);
		var popups = document.getElementsByClassName(classname);

		for (var i = popups.length; i--; ) {
			popups[i].style.display = 'none';
		}

		if (popup != null) {
			popup.style.display = 'block';
			popup.style.left = getElementPosition(obj).left + obj.offsetWidth + 10 + 'px'
				popup.style.top = getElementPosition(obj).top + 'px'
				popup.getElementsByTagName('div')[0].style.height = popup.offsetHeight + 'px'
		}
		else { return false }
	}
}	

