
function slideShow() {

	//Set the opacity of all images to 0
	//$('#slideshow div.item').css({opacity: 0.0});

	//Get the first image and display it (set it to full opacity)
	//$('#slideshow div.item:first').css({opacity: 1.0});

	//Set the caption background to semi-transparent
	//$('#slideshow .caption').css({opacity: 0.8});

	//Resize the width of the caption according to the image width
	//$('#slideshow .caption').css({width: $('#slideshow div.item').find('img').css('width')});

	//Get the caption of the first image from REL attribute and display it
	$('#slideshow .content')
		.html( $('#slideshow div.item:first')
		.find('div.body').html() )
		.animate({opacity: 1}, 400);

	
	var nav = slideNavigation({"iNumPage" : 1, "iAllPages" : iSlideshowCount});
	nav.makeHTML();

			
	//Call the gallery function to run the slideshow, 6000 = change to next image after 6 seconds
	oTimerSlider = setInterval('gallery()',8000);
	

}

function slideNavigation(args){

	var nav = new Object();

	nav.sHtml = '';
	nav.oParameters = new Object();

	nav.iAllPages = 0; //liczba wszystkich stron
	nav.iNumPage = 0; //numer biezcej strony
	nav.sLeft  = '<a href="javascript:;" onclick="setPrevSlide()" class="slideprev"><span></span>poprzednie</a>'; //strzalki w lewo
	nav.sRight = '<a href="javascript:;" onclick="setNextSlide()" class="slidenext">następne<span></span></a>'; //strzalki w prawo
	
	for (var i in args){
		if (typeof(nav[i]) == "undefined"){
			nav.oParameters[i] = args[i];
		}
		else {
			nav[i] = args[i];
		}
	}

	nav.makeHTML = function(){

		var htmlSlideLeft = this.sLeft;
		var htmlSlideRight = this.sRight;
		var htmlSlideCenter = '';

		if( this.iAllPages > 0){

			for(var i=1; i<=this.iAllPages; i++){

				if(i == this.iNumPage)
					htmlSlideCenter += '<a href="javascript:;" class="selected">' + i + '</a>';
				else
					htmlSlideCenter += '<a href="javascript:;" onclick="setSlide('+i+')">' + i + '</a>';

			}

			if(this.iNumPage > 1){
				$('#slideFieldLeft').html(htmlSlideLeft);
			}else{
				$('#slideFieldLeft').html('');
			}

			if(this.iNumPage < this.iAllPages){
				$('#slideFieldRight').html(htmlSlideRight);
			}else{
				$('#slideFieldRight').html('');
			}
			
			$('#slideFieldCenter').html(htmlSlideCenter);

		}

		
		
	}

	return nav;
   
}

function setPrevSlide(){
	gallery(iNumPageSlider-1);
	clearTimeout(oTimerSlider);
}

function setNextSlide(){
	gallery();
	clearTimeout(oTimerSlider);
}

function setSlide(index){
	gallery(index);
	clearTimeout(oTimerSlider);
}


function gallery(index) {

	iNumPageSlider = (index) ? index : 0;

	var next;

	//if no IMGs have the show class, grab the first image
	var current = ( $('#slideshow div.item.show') ?  $('#slideshow div.item.show') : $('#slideshow div.item:first') );
	
	//Get next image, if it reached the end of the slideshow, rotate it back to the first image
	if(iNumPageSlider)
		next = $('#slideshow div.item:eq('+(iNumPageSlider-1)+')');
	else
		next = ( (current.next().length) ? ( (current.next().hasClass('caption') ) ? $('#slideshow div.item:first') : current.next() ) : $('#slideshow div.item:first') );

	iNumPageSlider = $("#slideshow div.item").index(next) + 1;

	var nav = slideNavigation({"iNumPage" : iNumPageSlider, "iAllPages" : iSlideshowCount});
	nav.makeHTML();
	
	var caption = next.find('div.body').html();
	next.css({'opacity': 0.0}).addClass('show').animate({opacity: 1.0}, 1000);

	//Hide the current image
	current.animate({opacity : 0.0}, 1000).removeClass('show');

	//$('#slideshow .caption').animate({opacity: 0.0}, {queue:false, duration:50}).animate({height: '1px'}, {queue:true, duration:300});
	//$('#slideshow .caption').animate({opacity: 1.0},100 ).animate({height:'80px'},500 );

	$('#slideshow .content').html(caption);

}