var liczbaN = 0;
var doc=document;
var boxLock = -1;
var liczbaN1 = 1; 
var czas = 10000;
var iloscElementow = 10;

function getId(div){
	if (div != ''){
		return document.getElementById(div);
	}
} 

function testId(id){
	if(!id){ 
		id=document;
	}
	else{
		if(typeof(id)!='object'){
			if(getId(id)){
				id=getId(id);
			}
		}
	}
	return id;
}

function ustawKlase(id , zm){
	var id = testId(id);
	if(zm != ''){
		id.className=zm;
	}
}

function dodajKlase(id , zm){
	var id = testId(id);
	if(zm != ''){
		if(!wezKlase(id , zm)){
			id.className+=' '+zm;
		}
	}
}

function wezKlase(id , zm){
	var id = testId(id);
	if(zm != ''){
		var wezel = new RegExp("(^"+zm+"$|\\s"+zm+"\\s|^"+zm+"\\s|\\s"+zm+"$)");
		return wezel.test(id.className);
	}
}

function pokaz(id){
	var id = testId(id);
	id.style.display='block';
}

function ukryj(id){
	var id = testId(id);
	id.style.display='none';
}

function wezWezel(typ){
	var zm;
	if(typeof(typ)=='undefined'){
		typ = window.event; 
	}else{
		typ = typ;
	}
	if(typ.target){
		zm=typ.target;
	}
	else if(typ.srcElement){
		zm=typ.srcElement;
	}
	if(zm.nodeType==3){
		zm=targ.parentNode;
	}
	return zm;
}

function boxChangeOut(){
	var czas = 10000;
	if(boxLock==-1){ 
		boxLock = setTimeout('boxChangeOver(); boxChangeOut(); boxShow('+iloscElementow+');', czas);
	}
 } 

 function boxChangeOver(){
	if(boxLock!=-1){
		clearTimeout(boxLock);
		boxLock=-1;
	}
 }

 function boxArt(){
	pokaz('box');
	pokaz('boxBar');
	getId('box').onmouseover = function() { boxChangeOver() }
	getId('box').onmouseout = function() { boxChangeOut() } 
	pokaz('boxArt'+liczbaN1);
 }
		 
 function boxShow(wezel){
	var podstawienie = 1;
	if (wezel == 10){ 
		if (liczbaN1 < liczbaN) {
			liczbaN1++; 
		}
		else {
			liczbaN1 = podstawienie 
		}
	} 
	else if ((wezel <= liczbaN) && (wezel > 0)){ 
		liczbaN1 = wezel; 
	}
	else{
		liczbaN1 = podstawienie;
	}

	var licz = 1;
	for (; licz <= liczbaN ; licz++){
		if (licz==liczbaN1) {
			ustawKlase('boxNav'+licz , 'aBox active');
			pokaz('boxArt'+licz);
		} else {
			ustawKlase('boxNav'+licz , 'aBox');
			ukryj('boxArt'+licz);
		}
	}
	return false;
 }

 function startBox(){
	var subStart = 6;
	var subEnd = 1;
	var tagName = 'div';
	var BOX = getId('box');
	var BOX_TAB = BOX.getElementsByTagName(tagName);
	var i=0;
	var nazwaKlasy = 'subBox'; 
	var err;
	while (i<BOX_TAB.length) { 
		if (BOX_TAB[i].className != nazwaKlasy) {
			err = 0;
		}else{
			liczbaN++;
			var link = doc.createElement('a');
			link.appendChild(doc.createTextNode(liczbaN)); // to co między linkiem
			link.id='boxNav'+liczbaN;
			if(liczbaN == 1){
				link.className='aBox active';
			}else{
				link.className='aBox';
			}
			link.href = '';
			link.onclick=function(arg){
				boxShow(wezWezel(arg).id.substr(subStart,subEnd)); 
				return false; 
				arg.preventDefault(); 
			}
			getId('boxLista').appendChild(link); //wpisanie linku w diva 
		}
		i++;
	}

	boxChangeOut();
			
	boxArt();
}

