
	/**

		Image slider in jQuery

	*/

	Slider =
	{
		config		: null,

		config : function()
		{
			if(typeof SliderConfig != "object")

				alert('No slider config');

			else

				Slider.config = SliderConfig;
		},

		prepare : function()
		{
			// randomize photos
			if(Slider.config.randomize)
				Slider.config.names.sort(function(){return 0.5 - Math.random()});

			// fill html with imgs
			for(i=1; i<Slider.config.names.length; i++)
				$('#slider').prepend('<img src="' + Slider.config.path + '/' + Slider.config.names[i] + '.jpg" alt="Widokówka" />');

			$('#slider img:first').addClass('show')
		},

		run : function()
		{
            // take 1st image
            var current = ( $('#slider img.show') ? $('#slider img.show') : $('#slider img:first') );

            // get next image
            var next = current.next('img').length ? current.next('img') : $('#slider img:first');

            current.stop();
			current.css({opacity: '1'});

            next.stop();
			next.css({opacity: '0'});

            current.fadeTo(Slider.config.animation,0, function() { current.removeClass('show'); });
			next.fadeTo(Slider.config.animation,1, function() { next.addClass('show'); });
		}
	};

	$(document).ready(

		function()
		{
			Slider.config();
			Slider.prepare();

			// run the slideshow
			setInterval(Slider.run, Slider.config.interval);
		}

	);

	/* eof */

