var menuTapety = {
_idLiMenu : null,
_ulParent : null,
_liChild : null,
_strona : null,
_ktoreMenu : null,
_widthParentUl : null,
_tabLI : new Array,
_ileStron : null,
_arrowLeft : null,
_arrowRight : null,
init : function(idLiMenu,ktoreMenu){
menuTapety._idLiMenu = idLiMenu;
menuTapety._strona = 0;
menuTapety._ktoreMenu = parseInt(ktoreMenu);
var idLi = document.getElementById(idLiMenu);
var ul;
if(ul = idLi.getElementsByTagName('ul')[0]) menuTapety._ulParent = ul;
else menuTapety._ulParent = idLi.parentNode;

menuTapety._widthParentUl = menuTapety._ulParent.offsetWidth-40;

menuTapety._liChild = menuTapety._ulParent.getElementsByTagName('li');
menuTapety.getLI();
menuTapety.przypiszZdarzenia();
menuTapety.getStrona();
menuTapety.ustawStrzalki();
menuTapety.ustawMenu();
},
getLI : function(li){
var objLi = new Object;
var y = 0;
for(var i=0;i<menuTapety._liChild.length;i++){
if(menuTapety._liChild[i].className == 'arrowLeft'){menuTapety._arrowLeft = menuTapety._liChild[i]; continue;}
if(menuTapety._liChild[i].className == 'arrowRight'){menuTapety._arrowRight = menuTapety._liChild[i]; continue;}

//if(menuTapety._liChild[i].className == 'arrowLeft' || menuTapety._liChild[i].className == 'arrowRight') continue;
var liA = menuTapety._liChild[i].getElementsByTagName('a')[0];
var liWidth = liA.offsetWidth;
menuTapety._liChild[i].setAttribute('widthLi',liWidth);
menuTapety._tabLI[y] = menuTapety._liChild[i];
y++;
}
},
przypiszZdarzenia : function(){
menuTapety.addEvent(menuTapety._arrowLeft,'click',menuTapety.moveLeft);
menuTapety.addEvent(menuTapety._arrowRight,'click',menuTapety.moveRight);
},
getStrona : function(){
var widthParentUl = menuTapety._widthParentUl;
var sumaWidth = 0;
var sumaWidthMenu = 0;
for(var i=0;i<menuTapety._tabLI.length;i++){
//if(menuTapety._liChild[i].className == 'arrowLeft' || menuTapety._liChild[i].className == 'arrowRight') continue;
var widthLi = parseInt(menuTapety._tabLI[i].getAttribute('widthLi'));
sumaWidth +=widthLi;
if(i == menuTapety._ktoreMenu) sumaWidthMenu = sumaWidth;
}
menuTapety._ileStron = Math.ceil(sumaWidth/widthParentUl);
menuTapety._strona = Math.floor(sumaWidthMenu/widthParentUl);
},
ustawMenu : function(){
var widthParentUl = menuTapety._widthParentUl;
var widthStart = widthParentUl*menuTapety._strona;
var widthEnd = widthStart+widthParentUl;
var sumaWidth = 0;

for(var i=0;i<menuTapety._tabLI.length;i++){
//if(menuTapety._liChild[i].className == 'arrowLeft' || menuTapety._liChild[i].className == 'arrowRight') continue;
var widthLi = parseInt(menuTapety._tabLI[i].getAttribute('widthLi'));
sumaWidth +=widthLi;

    if(sumaWidth>(widthStart) && sumaWidth<(widthEnd)) menuTapety._tabLI[i].style.display = "inline";
	else  menuTapety._tabLI[i].style.display = "none";
}
},
ustawStrzalki : function(){
var strona = menuTapety._strona + 1;
/*
if(strona == 1) menuTapety._arrowLeft.style.visibility = 'hidden';
else menuTapety._arrowLeft.style.visibility = 'visible';

if(strona == menuTapety._ileStron) menuTapety._arrowRight.style.visibility = 'hidden';
else menuTapety._arrowRight.style.visibility = 'visible';
*/
if(strona == 1) menuTapety._arrowLeft.style.display = 'none';
else menuTapety._arrowLeft.style.display = 'block';

if(strona == menuTapety._ileStron) menuTapety._arrowRight.style.display = 'none';
else menuTapety._arrowRight.style.display = 'block';


//alert(strona);
//alert(menuTapety._ileStron);
},
addEvent : function(elem,eventS,funkcja){
if(window.addEventListener) elem.addEventListener(eventS,funkcja,false);
else elem.attachEvent('on'+eventS,funkcja,false);  
},
moveLeft : function(){
menuTapety._strona = menuTapety._strona - 1;
menuTapety.ustawStrzalki();
menuTapety.ustawMenu();
},
moveRight : function(){
menuTapety._strona = menuTapety._strona + 1;
menuTapety.ustawStrzalki();
menuTapety.ustawMenu();
}
}
