var slideshowSpeed = 6000;
var photos = [
	{"image" : "headerbar_1.png"},
	{"image" : "headerbar_2.png"},
	{"image" : "headerbar_3.png"},
	{"image" : "headerbar_4.png"}
]; 

(function($)
{
  // Here is the entry point for your front javascript


/* Header image changer */
	var activeContainer = 1;	
	var currentImg = 0;
	var navigate = function(direction) 
	{
		// Check which current image we need to show
		if (direction == "next")
		{
			currentImg++;
			if (currentImg == photos.length + 1) 
			{
				currentImg = 1;
			}
		}
		else
		{
			currentImg--;
			if (currentImg == 0)
			{
				currentImg = photos.length;
			}
		}
	
		// Check which container we need to use
		var currentContainer = activeContainer;
		if (activeContainer == 1) 
		{
			activeContainer = 2;
		}
		else
		{
			activeContainer = 1;
		}
		
		showImage(photos[currentImg - 1], currentContainer, activeContainer);
		
	};
	
	//var currentZindex = 2;

	var showImage = function(photoObject, currentContainer, activeContainer)
	{
		// Make sure the new container is always on the background
		//currentZindex--;
//alert('currentZindex: '+currentZindex+' / activeContainer: headerimg'+activeContainer);
		// Set the background image of the new active container
		$("#headerimg" + currentContainer).css({"z-index" : 2});
		
		$("#headerimg" + activeContainer).css({
			"background-image" : "url(/theme/images/" + photoObject.image + ")",
			"display" : "block",
			"z-index" : 1
		});
		
		// Fade out the current container
		// and display the header text when animation is complete
		$("#headerimg" + currentContainer).fadeOut(1500);
	}; 

	navigate("next");
	
	// Start playing the animation
	interval = setInterval(function() {
		//currentZindex++;
		navigate("next");
	}, slideshowSpeed);



/* Menu handling */
	//$('ul.sf-menu').superfish().find('ul').bgIframe({opacity:false});
	$('ul.sf-menu').superfish();

})(jQuery);

