$(document).ready(function(){

    // Aktualna strona komentarzy do profilu
    var interestingsPage = 1;

    if(interestingsPage <= 1) {
        $('#interestingPrev').hide();
    }

    // Poprzednia strona komentarzy do profilu
    $('#interestingPrev').click(function(){
        if(interestingsPage > 1){
        	interestingsPage = interestingsPage - 1;
        	$('#interestingsList').load('/page/page/interestingsajax?interestingsPage='+interestingsPage);
            $('#interestingNext').show();
        }
        if(interestingsPage <= 1) {
            $('#interestingPrev').hide();
        }
        return false;
    });

    // Nastepna strona komentarzy do profilu
    $('#interestingNext').click(function(){
        if(interestingsPage < INTERESTINGS_COUNT / 1){
        	interestingsPage = interestingsPage + 1;
            $('#interestingsList').load('/page/page/interestingsajax?interestingsPage='+interestingsPage);
            $('#interestingPrev').show();
            
            if(interestingsPage == (INTERESTINGS_COUNT / 1)) {
                $('#interestingNext').hide();
            }
        }
        return false;
    });
    
    $('.registerBtn').click(function(){
    	$('.dataForm').submit();
    	return false;
    });
    
    $('a.submitBtn').click(function () {
        $(this).closest('form').submit();
        return false;
    });
    
    $('#loginBtn a').click(function () {
        
    	$(this).closest('form').submit();
        return false;
    });
    
    $('.loginBox').keydown(function(event){
    	if(event.keyCode == 13) 
		{
    		$(this).closest('form').submit();
		}
    	
    });
    
    $('#searchSubmit').live('click', function() {

    	if($('#keyword').val() != '')
    	{
		    var keyword = $('#keyword').val();
		    location.href = '/wyniki-wyszukiwania/'+keyword;
    	}
    	else
    	{
    		$('#keyword').val('Wpisz słowo kluczowe!');
    		$('#keyword').css('border-color', '#ff0000');
    	}

        return false;
   });
   
   $('#keyword').keydown(function(event){

		if(event.keyCode == 13) 
		{
	    	if($('#keyword').val() != '')
	    	{
			    var keyword = $('#keyword').val();
			    location.href = "/wyniki-wyszukiwania/"+keyword;
				return false;
	    	}
			else
			{
				return false;
			}
		}
		false;
   });
    
   $('#keyword').live('click', function() {

    	if($('#keyword').val() == 'Wpisz słowo kluczowe!')
    	{
    		$('#keyword').val('');
    	}

        return false;
   });
   
   // Aktualna strona video thumbs
   var videoPage = 1;

   // Poprzednia strona video thumbs
   $('#videoPrev').click(function(){
       if(videoPage > 1){
    	   videoPage = videoPage - 1;
       	$('#videoThumbsContainer').load('/page/page/videoajax?section='+SECTION+'&structure_ID='+STRUCTURE_ID+'&videoPage='+videoPage);
           $('#videoNext').show();
       }
       //if(videoPage <= 1) {
       //    $('#videoPrev').hide();
       //}
       return false;
   });

   // Nastepna strona video thumbs
   $('#videoNext').click(function(){
       if(videoPage < VIDEO_COUNT / 3){
    	   videoPage = videoPage + 1;
           $('#videoThumbsContainer').load('/page/page/videoajax?section='+SECTION+'&structure_ID='+STRUCTURE_ID+'&videoPage='+videoPage);
           $('#videoPrev').show();
           //if(videoPage == (VIDEO_COUNT / 3)) {
               //$('#videoNext').hide();
           //}
       }
       return false;
   });

   // Aktualna strona zdjec sidebara
   var sidebarPhotosPage = 1;

   if(sidebarPhotosPage <= 1) {
       $('.prevGal').hide();
   }

   // Poprzednia strona zdjec sidebara
   $('.prevGal').click(function(){
       if(sidebarPhotosPage > 1){
    	   sidebarPhotosPage = sidebarPhotosPage - 1;
       	$('#allPhotos').load('/page/page/allphotosajax?photoPage='+sidebarPhotosPage);
           $('.nextGal').show();
       }
       if(sidebarPhotosPage <= 1) {
           $('.prevGal').hide();
       }
       return false;
   });

   // Nastepna strona zdjec sidebara
   $('.nextGal').click(function(){
       if(sidebarPhotosPage < PHOTOS_COUNT / 1){
    	   sidebarPhotosPage = sidebarPhotosPage + 1;
           $('#allPhotos').load('/page/page/allphotosajax?photoPage='+sidebarPhotosPage);
           $('.prevGal').show();
           
           if(sidebarPhotosPage == (PHOTOS_COUNT / 1)) {
               $('.nextGal').hide();
           }
       }
       return false;
   });
});
