$(document).ready(function() {
	$("#commentForm").validate();
        $('#gallery a').lightBox();

        /* obsluga forma dodawania kategorii */
        $('#category').show();
        $('#addkat').submit(function(){
        $('#category').load('index.php/admin/kategorie/addkat/',{kat: $('#ckat').attr('value')});
        $('#category').show();
        return false;
        });

          $('#addkat2').submit(function(){
        $('#category').load('index.php/admin/strony/addkat/',{kat: $('#ckat').attr('value')});
        $('#category').show();
        return false;
        });

$('#editkat').submit(function(){
        $('#category').load('index.php/admin/kategorie/editkat/',{editkat: $('#ceditkat').attr('value'),katid: $('#ckatid').attr('value')});
        $('#category').show();
        return false;
        });

       $('#editkat2').submit(function(){
        $('#category').load('index.php/admin/strony/editkat/',{editkat: $('#ceditkat').attr('value'),katid: $('#ckatid').attr('value')});
        $('#category').show();
        return false;
        });



        //Speed of the slideshow
	var speed = 5000;

	//You have to specify width and height in #slider CSS properties
	//After that, the following script will set the width and height accordingly
	$('#mask-gallery, #gallery li').width($('#slider').width());
	$('#gallery').width($('#slider').width() * $('#gallery li').length);
	$('#mask-gallery, #gallery li').height($('#slider').height());

	//Assign a timer, so it will run periodically
	var run = setInterval('newsscoller(0)', speed);

	$('#gallery li:first').addClass('selected');





	//Mouse over, pause it, on mouse out, resume the slider show
	$('#slider').hover(

		function() {
			clearInterval(run);
		},
		function() {
			run = setInterval('newsscoller(0)', speed);
		}
	);



});

function DelImagePrd(img)
{

$('#prd_image').load('index.php/admin/prd/delfoto/'+img, function()
          {
             $('#prd_image').find('a');
           });

}


function Link(div,div2)
{
$(div2).livequery('click', function(event) {
if($(this).attr('name') != '#'){
		   event.preventDefault();
		    $("#loading").show();
			$(div).load(
				$(this).attr('href'),
				function(){
					$(div).find('a');
					$("#loading").hide();
				}
			);
                    
} else {
  return true;
 }
});

}

function Link2(div,tar)
{
$("#loading").ajaxStart(function(){
$(this).show();
});

    $(div).load(tar, function()
          {
             $(div).find('a');
            
           });
$("#loading").ajaxStop(function() {
$(this).hide();
});


}

function Link3(div,tar)
{
$("#loading").ajaxStart(function(){
$(this).show();
});

$('a').live('click', function(event) {
    $(div).load(tar, function()
          {
             $(div).find('a');

           });
    });
    
$("#loading").ajaxStop(function() {
$(this).hide();
});


}

function Link4(div,tar)
{

if(confirm('Czy usunść wpis?')) {
$("#loading").ajaxStart(function(){
$(this).show();
});

    $(div).load(tar, function()
          {
             $(div).find('a');

           });
$("#loading").ajaxStop(function() {
$(this).hide();
});
}

}


function Show(pole)
{

$(pole).live("click", function(event){
             $($('#actTab').attr('value')).css( "display", "none" );
             $(pole).css( "display", "block" );

             $("#actTab").val('P'+pole);
           
  return false;
});
}


function HideMsgBasket(){
			//$("#PopupItem").slideUp(500);
			$("#Customers").fadeOut(500);

		}
		function LoadMsgBasket(){
		//	$("#PopupItem").slideDown(500);
		$("#Customers").fadeIn(500);
			setTimeout('HideMsgBasket()',3000);
		}

function SetMsgBasket(){
			$(window).scroll(function () {
				var vscroll = (document.all ? document.scrollTop : window.pageYOffset);
				$("#Customers").css("top",vscroll);
		    }

                    );
		}



function Link_pk(div, tar)
{
$("#loader").ajaxStart(function(){
$(this).show();
});
$("#loader").ajaxStop(function() {
$(this).hide();
});
$(div).load(tar, function()
          {
             $(div).find('a');
           });
}


function newsscoller(prev) {

	//Get the current selected item (with selected class), if none was found, get the first item
	var current_image = $('#gallery li.selected').length ? $('#gallery li.selected') : $('#gallery li:first');


	//if prev is set to 1 (previous item)
	if (prev) {

		//Get previous sibling
		var next_image = (current_image.prev().length) ? current_image.prev() : $('#gallery li:last');


	//if prev is set to 0 (next item)
	} else {

		//Get next sibling
		var next_image = (current_image.next().length) ? current_image.next() : $('#gallery li:first');

	}

	//clear the selected class
	$('#gallery li').removeClass('selected');

	//reassign the selected class to current items
	next_image.addClass('selected');
	

	//Scroll the items
	$('#mask-gallery').scrollTo(next_image, 800);


}