$('.open-reg').addEvent('click', function(){
	
	Pklib.Glass.showtime = 300;
	Pklib.Glass.show();
	Pklib.Message.text = $('.layer').html();
	Pklib.Message.showtime = 300;
	Pklib.Message.closetime = 200;
	Pklib.Message.show();
	
	$('.' + Pklib.Message.objClass ).css({
	    width: $('.layer').width(),
	    height: $('.layer').height(),
	    top: ( $(window).height() - $('.layer').height() )/2, 
	    left: ( $(window).width() - $('.layer').width() )/2
	});

	$('a.close').addEvent('click', function(){
		Pklib.Glass.close();
		Pklib.Message.close();
		return false;		
	});
	
	$('.' + Pklib.Message.objClass  + ' .section').jScrollPane({
	    showArrows: true, 
	    scrollbarWidth: 25, 
	    scrollbarHeight: 10, 
	    scrollbarMargin: 0, 
	    animateTo: true
	});
	
	$('.' + Pklib.Message.objClass).css({
		backgroundColor: '#920000',
		border: '2px solid #920000'
	});

	return false;
});


//paginacja certyfikatów.
$('document').ready(function(){
    var count_elem = $('div.winners ul').length;
    var elem_per_page = 10;
    var pages_links = Math.ceil(count_elem/elem_per_page);

    generetePagesLinks(pages_links);
    showFirstPage(elem_per_page);
    $('.pagination a').click(function(){
        var page_number = parseInt($(this).index()+1);
        showPage(page_number, elem_per_page);
        return false;
    })

    function generetePagesLinks(elem_count){
       // $('.pagination').append('<a href="#" class="rangeFirst">Pierwsza</a>')
        for (var i = 1; elem_count >= i; i++){
            $('.pagination').append('<a href="#" class="range'+i+'">'+i+'</a>');
        }
      //  $('.pagination').append('<a href="#" class="rangeLast">Ostatnia</a>')
    }
    function showFirstPage(elem_per_page){
        //ustawienie pierwszemu linkowi aktywnej klasy
        $('.pagination a').eq(0).addClass('active');
       
        //wyswietlenie odpowiednich stron
        $('div.winners ul').each(function(){
            var current_index = parseInt($(this).index()+1);
            if(current_index > elem_per_page){
                $(this).css({
                    display: 'none'
                })
            }
        })
    }
    function showPage(page_number, elem_per_page){

        var how_max = parseInt(elem_per_page * page_number);
        var how_min = parseInt((how_max - elem_per_page)+1)

        $('div.winners ul').each(function(){
            var current_index = parseInt($(this).index()+1);
            $(this).css({display: 'none'})
            if(current_index >= how_min && current_index <= how_max){
                $(this).fadeIn();
            }else{
                $(this).fadeOut();
            }
            $('.pagination a').removeClass('active');
        })
        $('.pagination a').eq(parseInt(page_number-1)).addClass('active');
    }
})


