function ShowPages(perPage, AllItems, modulo) {

	// show first page
	for(var i=0; i<AllItems; i++) {
		if( i>=0 && i<perPage )
			document.getElementById('s' + (i+1)).style.display = '';
		else
			document.getElementById('s' + (i+1)).style.display = 'none';
	}

	var AllPages = Math.ceil(AllItems/perPage);
	
  	var pages = '<input id="current-page" type="hidden" value="0" />';
  	pages += '<input id="all-pages" type="hidden" value="' + AllPages + '" />';
  	pages += '<input id="per-page" type="hidden" value="' + perPage + '" />';
  	pages += '<input id="modulo" type="hidden" value="' + modulo + '" />';
  	pages += '<input id="all-items" type="hidden" value="' + AllItems + '" />';

	pages += '<a id="prev" style="cursor: pointer;">' + prev + '</a>';
	pages += '&nbsp;&nbsp;';
	pages += '<a id="next" style="cursor: pointer;">' + next + '</a>';

	document.write(pages);
}

function GoToPage(CurrentPage, perPage, AllItems) {
	for(var i=0; i<AllItems; i++) {
	  if( i>=CurrentPage*perPage && i<(CurrentPage+1)*perPage )
		  document.getElementById('s' + (i+1)).style.display = '';
	  else
		  document.getElementById('s' + (i+1)).style.display = 'none';
	}
}

function updateLines(currentPage)
{	
	$('div.line').hide();

	var modulo = parseInt($('input#modulo').val());
	var perPage  = parseInt($('input#per-page').val());

	var firstLine = (perPage * parseInt(currentPage)) / modulo;
	var lastLine = ((perPage * parseInt(currentPage)) + perPage) / modulo;

	//console.log('currentPage: ' + currentPage);
	//console.log('lastLine: ' + lastLine);
	
	for(var i=firstLine; i<=lastLine ; i++)
	{
		$('div.group' + i).show();  // modulo
	}
}


$(document).ready(function()
{	
	$('div.cycle').cycle({
		fx: 'fade'	// choose your transition type, ex: fade, scrollUp, shuffle, etc...
	});

	var perPage  = $('input#per-page').val();  // 4
	var AllItems = $('input#all-items').val(); // 19
	var AllPages = $('input#all-pages').val(); // 5
	var currentPage;
	
	if( parseInt(AllItems) < parseInt(perPage) )
		$('div.pages').css('display', 'none');
	
	$('a#prev').click(function()
	{
		currentPage = $('input#current-page').val();
		
		if( currentPage >= 1 )
		{
			currentPage--;
			GoToPage(currentPage, perPage, AllItems);
			$('#current-page').val( currentPage );
		}
		
		updateLines(currentPage);
	});

	$('a#next').click(function()
	{
		currentPage = $('input#current-page').val();
		
		if( currentPage < AllPages - 1 )
		{
			currentPage++;
			GoToPage( currentPage, perPage, AllItems);
			$('#current-page').val( currentPage );
		}
		
		updateLines(currentPage);
	});
	
	updateLines(0);
	
	
	var errorColor   = '#F3D2D3';
	var correctColor = '#ffffff';
	var errorMarks   = 'background-color';

/*
	$('img#add-newsletter').click(function() {

		$('input#newsletter-email').css(errorMarks, correctColor);

		var hasError = false;
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;

		var emailVal   = $('input#newsletter-email').val(); //required

		if(emailVal == '') {
			$('input#newsletter-email').css(errorMarks, errorColor);
			hasError = true;
		} else if(!emailReg.test( emailVal )) {	
			$('input#newsletter-email').css(errorMarks, errorColor);
			hasError = true;
		}

		if(hasError == false) {

		$.ajax({
			//async:	false,
			type: 	"POST",
		    url:  	"plugins/db-connector.php",
		    data: {
				request: 'add',
				email:	 emailVal
			},
		    success: function(msg) {
				//alert(msg);
				//$('input#newsletter-email').val('added');
        		$('input#newsletter-email').val(msg);
		    },
		    error: function (XMLHttpRequest, textStatus, errorThrown) {
		    	$('input#newsletter-email').val('Wystąpił błąd');
		    	//$('input#newsletter-email').val(errorThrown);
		    }
		});
		
		} else
			return false;
	});
*/

//	var height = 0;
//	
//	$('#footer .inner').each(function()
//	{	
//		if (height < $(this).height())
//		{
//			height = $(this).height();
//		}
//	});
	
	//console.log($('#left-contener').height());
	
	//console.log($('#wrapp-center-right-inner').height());
	
	if ($('#wrapp-center-right-inner').height() < $('#left-contener').height() + 52)
	{
		$('#wrapp-center-right-inner').height($('#left-contener').height() + 50 + 52);
	}
	
	$(function()
	{
		$('a[rel=lightbox-page]').lightBox();
	});

});

