/** jQuery JS
  *
  * @author Wido Widlewski 
  *
  */

jQuery.noConflict();

jQuery(document).ready(function(){
	
	
	// interval for slideshow
	var interval;
	// time in ms to fade the next image
	var slideshow_timeout = 250;

	
	/*
	soundManager.url = 'js/soundmanager2.swf';	
	soundManager.debugMode = false;
	*/
	
	var inhalt_images = jQuery('#content').find('div.item');
	

	// START

	jQuery('#logo').hide();
	
	jQuery('#content').hide();
	jQuery('#content').find('div.item').hide();
	
	jQuery('#content').css('height', '570px');
	jQuery('#content').find('div.item').css('position', 'absolute');
	
	jQuery('#content').find('div.item').find('div.caption').hide();
	
	jQuery('#slogan').hide();
	jQuery('#address').hide();


	/*
	soundManager.onload = function() {

		soundManager.createSound({
			id: 'ping',
			url: 'bell.mp3'
		});
	
	
		soundManager.setVolume('ping', 100);
		soundManager.play('ping');
		
		*/
		
		
		jQuery('#logo').fadeIn(500, function(){
			
			
			jQuery('#slogan').fadeIn(1000, function(){
				
				jQuery('#content').show();
				
				jQuery('#address').fadeIn(500, function(){
					
					jQuery('#content').find('div.item:first').fadeIn();	
						
					// set interval		
					interval = window.setInterval(function(){
						
						cycle_images(0);
						
					}, slideshow_timeout);
						
					
					
				});
				
			});
			
		});

		/*

	} // soundmanager

	*/


	// SLIDESHOW
	
	// cycle images, show next image from current image, or first, when the current image is the last
	
	function cycle_images(act_image) {

		var next_image = parseInt(act_image + 1);

		if (next_image == inhalt_images.length)
		{
			next_image = 0;	
		}
	
	
		inhalt_images.each(function(index){
			
			
			if (next_image == index)
			{
				//jQuery('#header_images').find('div.csc-textpic-imagewrap').find('div.csc-textpic-imagerow').hide();
				
				jQuery('#content').find('div.item').each(function(){
					if (jQuery(this).css('display') == 'block')
					{
						//jQuery(this).fadeOut();	
						jQuery(this).hide();
					}
				});
				
				
				//jQuery(this).fadeIn(500);
				jQuery(this).show();
				
				
			}
			
		});
		
			
		window.clearInterval(interval);
		interval = window.setInterval(function(){
			
			cycle_images(next_image);
			
		}, slideshow_timeout);
		
		
	} // cycle_images


	
	// mosueover
	
	jQuery('#content').find('div.item').mouseover(function(){
		
		window.clearInterval(interval);
		
		//jQuery(this).find('div.caption').fadeIn();	
		jQuery(this).find('div.caption').show();	
		
		//jQuery(this).css('cursor', '');
		
	});
	
	
	
	// mosueout
	
	jQuery('#content').find('div.item').mouseout(function(){
		
		//jQuery('#content').find('div.item').find('div.caption').fadeOut();
		jQuery('#content').find('div.item').find('div.caption').hide();
		
		//jQuery(this).css('cursor', '');
		
		var act_image = 0;
			
		jQuery('#content').find('div.item').each(function(index){
			if (jQuery(this).css('display') == 'block')
			{
				act_image = index;
			}
		});
			
		interval = window.setInterval(function(){
			
			cycle_images(act_image);
			
		}, slideshow_timeout);
					
			
			
			
	});
	


});
