$(document).ready(function() {
   $('a.lightbox').lightBox(); // Select all links with lightbox class

$("#commentForm").validate();
// third example
	$("#red").treeview({
		animated: "fast",
		collapsed: true,
		unique: true,
		persist: "cookie",
		toggle: function() {
			window.console && console.log("%o was toggled", this);
		}
	});
    
        $('#category').show();
        $('#addkat2').submit(function(){
        $('#category').load('index.php/admin/kategorie/addkat/',{kat: $('#caddkat').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 MarketSK(login)
{

$('#POLET').load('index.php/admin/sk/show/'+login, function()
          {
             $('#POLET').find('a');
           });

}

function DelImagePrd(img)
{

$('#prd_image').load('index.php/admin/prd/delfoto/'+img, function()
          {
             $('#prd_image').find('a');
           });

}

   function DeleFromCart(ItemID){
                                    $.get("index.php/cart/delete/"+ItemID,
                                    {},
                                    function(returned_data)
                                    {
                                            $("#PRDR").html(returned_data);
                                    });



		}




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('oder den Eintrag löschen?')) {
$("#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);


}

