jQuery.noConflict();

/*jquery*/
(function($) { 
  		$(function() {

	var show = $('#flashContent');
	var photos = new Array();
	var interval = null;
	

		photos=['http://template.listoprdak.cz/listoprdak09/images/listoprdak_layout-web_2011_B_01.jpg',
				'http://template.listoprdak.cz/listoprdak09/images/listoprdak_layout-web_2011_B_02.jpg',
				'http://template.listoprdak.cz/listoprdak09/images/listoprdak_layout-web_2011_B_03.jpg',
				'http://template.listoprdak.cz/listoprdak09/images/listoprdak_layout-web_2011_B_04.jpg',
				'http://template.listoprdak.cz/listoprdak09/images/listoprdak_layout-web_2011_B_05.jpg',];
			
	function image_preload(image){
		imageObj = new Image();
		imageObj.src=image;
	}

	function image_preloader(images){
		for(var i=0;i<=images.lenght-1;i++){
			preload(image[i]);
		}
	}

	function slideshow_load_images(images){
		var image = new Array();
		image[0] = $('<img />').attr('src', images[0]).css("opacity", 0).bind('load', function() {
			$(this).appendTo(show).addClass('show').animate({opacity: 1}, 200, 'linear', function(){
				$('#images-loading').remove();
			});
  			
		});			
		
		//create elements
		for(var i=1;i<=images.length-1;i++){
			image[i] = $('<img />').attr('src', images[i]).css("opacity", 0).bind('load', function() {
			    $(this).appendTo(show);
			    
			});			
		}
		
	}


	function slideshow(){
		
		//if no IMGs have the show class, grab the first image
		var current = ($('#flashContent img.show')?  $('#flashContent img.show') : $('#flashContent img:first'));
		
		//Get next image, if it reached the end of the slideshow, rotate it back to the first image
		var next = ((current.next().length) ? ((current.next().hasClass('show'))? $('#flashContent img:first') :current.next()) : $('#flashContent img:first'));	
		
		if ($('#flashContent img').length > 1){
		
			//Set the fade in effect for the next image, show class has higher z-index
			next.css({opacity: 0.0})
			.addClass('show')
			.animate({opacity: 1.0}, 1500);
		
			//Hide the current image
			current.animate({opacity: 0.0}, 1500)
			.removeClass('show').has('.remove').detach();
		}
		
	};
	


	function slideshow_start(){
		
		
		slideshow();
		// 3 seconds
		interval = window.setInterval(function () { slideshow(); }, 4000);
		
		return true;

	}


	$(document).ready(function() {
		//write loading
		show.html('<img src="http://template.listoprdak.cz/listoprdak09/images/loading.gif" id="images-loading" />');
	
		/*start-handler*/
		slideshow_load_images(photos);
			
		//start-slideshow
		slideshow_start();
				
	 });

			
                        
  	});
})(jQuery);




