var allowedimagesPlakatCountPlakat = 10;
var firstImagePlakat = 0;
var lastImagePlakat = allowedimagesPlakatCountPlakat - 1;
var imagesPlakatCountPlakat = 0;
var imagesPlakat;
var itemsPlakat;

//--------------------------------------------------------
var topPlakat = '<a href="javascript:cellOperationPlakat(+1);" onMouseOut="swapImgRestore()" onMouseOver=' + "'" + 'swapImage("top","","pic/top_highlight.png",1)' + "'" + '><img src="pic/top.png" name="top" width="17" height="12" border="0"></a>';
var bottomPlakat = '<a href="javascript:cellOperationPlakat(-1);" onMouseOut="swapImgRestore()" onMouseOver=' + "'" + 'swapImage("bottom","","pic/bottom_highlight.png",1)' + "'" + '><img src="pic/bottom.png" name="bottom" width="17" height="12" border="0"></a>';
var topInactivePlakat = '<img src="pic/top_grey.png" name="top" width="17" height="12" border="0">';
var bottomInactivePlakat = '<img src="pic/bottom_grey.png" name="bottom" width="17" height="12" border="0">';
//--------------------------------------------------------
function cellOperationPlakat(direction)
{
	if(imagesPlakatCountPlakat <= allowedimagesPlakatCountPlakat)
	{
		return;
	}
	
	if(direction == -1)
	{	
		if(lastImagePlakat == (imagesPlakatCountPlakat-1))
		{
			return;
		}	
		for(counter = 0; counter < allowedimagesPlakatCountPlakat-1; counter++)
		{
			current = document.getElementById('PTD' + counter);
			next = document.getElementById('PTD' + (counter + 1));
			
			current.innerHTML = next.innerHTML;
			
		}
		
		lastImagePlakat++;
		firstImagePlakat++;
		current = document.getElementById('PTD' + (allowedimagesPlakatCountPlakat-1));
		picTitle = imagesPlakat[lastImagePlakat].Title;
		picPath = imagesPlakat[lastImagePlakat].PicturePath ;
		gallPath = imagesPlakat[lastImagePlakat].GalleryPath;
		
		current.innerHTML = CurrentInnerHtmlPlakat(picTitle, picPath, gallPath);	
	}
	else if(direction == +1)
	{
	 
		if(firstImagePlakat== 0)
		{
			return;
		}	
		
		for(counter = allowedimagesPlakatCountPlakat-1; counter > 0; counter--)
		{
			current = document.getElementById('PTD' + counter);
			prev = document.getElementById('PTD' + (counter - 1));
			
			current.innerHTML = prev.innerHTML;
			
		}
		
		lastImagePlakat--;
		firstImagePlakat--;
		current = document.getElementById('PTD0');
		picTitle = imagesPlakat[firstImagePlakat].Title;
		picPath = imagesPlakat[firstImagePlakat].PicturePath ;
		gallPath = imagesPlakat[firstImagePlakat].GalleryPath;

		current.innerHTML = CurrentInnerHtmlPlakat(picTitle, picPath, gallPath);		
	}
	
	CheckPlakatButtons();
}

function CurrentInnerHtmlPlakat(picTitle, picPath, gallPath)
{
      return '<div align="center"><a href="' + gallPath + '" target="_blank" alt="' + picTitle + '"title="' + picTitle + '"><img src="' + picPath + '"  border="0" ></a></div>';
}

function CheckPlakatButtons()
{
	var tdTop = document.getElementById('plakatTop');
	var tdBottom = document.getElementById('plakatBottom');
	
	
	if(firstImagePlakat == 0 || imagesPlakatCountPlakat <= allowedimagesPlakatCountPlakat )
	{
		tdTop.innerHTML = topInactivePlakat;
	}
	else
	{
		tdTop.innerHTML = topPlakat;
	}

	if(lastImagePlakat == imagesPlakatCountPlakat -1 || imagesPlakatCountPlakat <= allowedimagesPlakatCountPlakat)
	{
		tdBottom.innerHTML = bottomInactivePlakat;
	}
	else
	{
		tdBottom.innerHTML = bottomPlakat;
	}
}

function ProcessResponcePlakat()
{

eval("imagesPlakat =" + itemsPlakat );
imagesPlakatCountPlakat = imagesPlakat.length;
CreateTablePlakat();

}

function CreateTablePlakat()
{
	var table = document.getElementById('plakat');
	var newTBODY = document.createElement('TBODY');
	var limit = imagesPlakatCountPlakat <= allowedimagesPlakatCountPlakat ? imagesPlakatCountPlakat : allowedimagesPlakatCountPlakat;
	for(counter = 0; counter  < limit; counter++)
	{
			
		
		var newTR = document.createElement("TR");
		newTR.id = "PTR" + counter;
		var newTD = document.createElement("TD");
		newTD.id = "PTD" + counter;
		//			
		newTD.className = "pborder" ;
		picTitle = imagesPlakat[counter].Title;
		picPath = imagesPlakat[counter].PicturePath ;
		gallPath = imagesPlakat[counter].GalleryPath;
		newTD.innerHTML =CurrentInnerHtmlPlakat(picTitle, picPath, gallPath);
		newTR.appendChild(newTD);
		newTBODY.appendChild(newTR);
		
	}
	table.appendChild(newTBODY);
	
	CheckPlakatButtons();
}
