var boxProdukt = {
_POS : null,
_widthTD : null,
_boxCenterProd : null,
_countProd : null,

init : function(){
boxProdukt._POS = reklamaStart;
var tableProdukt = document.getElementById('tableProdukt');
var tdProd = tableProdukt.getElementsByTagName('td')[0];
boxProdukt._widthTD = tdProd.offsetWidth;
boxProdukt._boxCenterProd = document.getElementById('boxCenterProd');
boxProdukt._boxCenterProd.scrollLeft = boxProdukt._POS * boxProdukt._widthTD;
//boxProdukt._countProd = tabImageSend.length;
boxProdukt._countProd = tableProdukt.rows[0].cells.length;


var boxLeftProd = document.getElementById('boxLeftProd');
var boxRightProd = document.getElementById('boxRightProd');

boxProdukt.addEvent(boxLeftProd,'click',boxProdukt.scrollLeftBox);
boxProdukt.addEvent(boxRightProd,'click',boxProdukt.scrollRightBox);

boxProdukt.checkButton();
},
addEvent : function(elem,eventS,funkcja){
if(window.addEventListener) elem.addEventListener(eventS,funkcja,false);
else elem.attachEvent('on'+eventS,funkcja,false);  
},
scrollLeftBox : function(){
if(boxProdukt._POS>0) boxProdukt._POS = boxProdukt._POS - 1;

setTimeout(boxProdukt.przesunLeft,1);
boxProdukt.checkButton();

var indexWstawImg = boxProdukt._POS;
boxProdukt.wstawImg(indexWstawImg);

},
scrollRightBox : function(){

 var boxRightProd = document.getElementById('boxRightProd');
 var aBoxRight = boxRightProd.getElementsByTagName('a')[0];
    
 if (aBoxRight.className == 'aBoxRightNone')  return false;
 
if(boxProdukt._POS<(boxProdukt._countProd-ileImg)) boxProdukt._POS = boxProdukt._POS + 1;
setTimeout(boxProdukt.przesunRight,1);
boxProdukt.checkButton();

var indexWstawImg = boxProdukt._POS+(ileImg-1);
boxProdukt.wstawImg(indexWstawImg);
},
wstawImg : function(indexImg){
if(!tabUsedImg[indexImg]){

     var tdIndex = document.getElementById('b'+indexImg);
     var divIndex = tdIndex.getElementsByTagName('div')[0];
     divIndex.innerHTML = tabImageSend[indexImg];
	tabUsedImg[indexImg] = 1;
}

},
przesunLeft : function(){
var offsetDiv = parseInt(boxProdukt._boxCenterProd.scrollLeft);
var endPos = parseInt(boxProdukt._POS * boxProdukt._widthTD);

if(offsetDiv > endPos){
var diff = 5;

if(offsetDiv-boxProdukt._POS * boxProdukt._widthTD<30) diff = 3; 
if(offsetDiv-boxProdukt._POS * boxProdukt._widthTD<10) diff = 1; 

boxProdukt._boxCenterProd.scrollLeft = parseInt(offsetDiv-diff);
setTimeout(boxProdukt.przesunLeft,10);
}
},
przesunRight : function(){
  
  
var offsetDiv = parseInt(boxProdukt._boxCenterProd.scrollLeft);
var endPos = parseInt(boxProdukt._POS * boxProdukt._widthTD);

if(offsetDiv < endPos){

diff = 5;

if(boxProdukt._POS * boxProdukt._widthTD-offsetDiv<30) diff = 3; 
if(boxProdukt._POS * boxProdukt._widthTD-offsetDiv<10) diff = 1; 


boxProdukt._boxCenterProd.scrollLeft = parseInt(offsetDiv+diff);
setTimeout(boxProdukt.przesunRight,10);
}

},
checkButton : function(){
var boxLeftProd = document.getElementById('boxLeftProd');
var boxRightProd = document.getElementById('boxRightProd');

var aBoxLeft = boxLeftProd.getElementsByTagName('a')[0];
var aBoxRight = boxRightProd.getElementsByTagName('a')[0];


//document.getElementsByTagName('a')


if(boxProdukt._POS == 0) {
	//aBoxLeft.style.visibility = 'hidden';
	//aBoxRight.style.visibility = 'visible';
	
	aBoxLeft.className = 'aBoxLeftNone';
	aBoxRight.className = 'aBoxRight';
	
}	
else if(boxProdukt._POS == boxProdukt._countProd-ileImg){
	//aBoxRight.style.visibility = 'hidden';
	//aBoxLeft.style.visibility = 'visible';
	
	aBoxRight.className = 'aBoxRightNone';
	aBoxLeft.className = 'aBoxLeft';
}
else{
	aBoxRight.className = 'aBoxRight';
    aBoxLeft.className = 'aBoxLeft';
	//aBoxRight.style.visibility = 'visible';
	//aBoxLeft.style.visibility = 'visible';
}

//alert(boxProdukt._POS == boxProdukt._countProd-ileImg);
}

};
