/*
* Author:      Marco Kuiper (http://www.marcofolio.net/)
*/

// Speed of the automatic slideshow
var slideshowSpeed = 7000;

// Variable to store the images we need to set as background
// which also includes some text and url's.
var photos = [ {
		"title" : "",
		"image" : "front_bg_1.jpg",
		"url" : "http://www.sxc.hu/photo/1271909",
		"firstline" :"<img src='"+template_url+"/images/echo_logo.png' style='float:left'>ECHO Jazz 2011<br>»newcomer des jahres national«",
		"secondline" : ""
	},  
	  	{
		"title" : "jazzecho",
		"image" : "front_bg_1.jpg",
		"url" : "http://www.sxc.hu/photo/1271915",
		"firstline" : "&raquo;......tim allhoff gehört zu den wichtigsten newcomern der deutschen klavierszene.&laquo;",
		"secondline" : ""
	},
		 {
		"title" : "",
		"image" : "front_bg_2.jpg",
		"url" : "http://www.sxc.hu/photo/1221065",
		"firstline" : "Neuer Deutscher Jazzpreis 2010",
		"secondline" : ""
	}, {
		"title" : " jon regen, keyboard magazine",
		"image" : "front_bg_2.jpg",
		"url" : "http://www.sxc.hu/photo/1271915",
		"firstline" : "&raquo;...truly a talent deserving wider recognition, allhoff proves that great music knows no boundaries.&laquo;",
		"secondline" : ""
	}, {
		"title" : "reinhard k&ouml;chl",
		"image" : "front_bg_3.jpg",
		"url" : "http://www.sxc.hu/photo/1271915",
		"firstline" : "&raquo;&#8230;ein hoffnungstr&auml;ger, der zusammen mit seinen begleitern die v&ouml;llig &uuml;berlaufene form des pianotrios zu neuer attraktivit&auml;t f&uuml;hren kann&#8230;&laquo;",
		"secondline" : ""
	}, {
		"title" : "wiesbadener kurier",
		"image" : "front_bg_3.jpg",
		"url" : "http://www.sxc.hu/photo/1271915",
		"firstline" : "&raquo;...das alles wirkt so leicht, locker und verspielt, dass man aus dem staunen kaum herauskommt. dieses trio wird zweifelsfrei f&uuml;r internationales aufsehen sorgen.&laquo;",
		"secondline" : ""
	}, {
		"title" : "audio magazin",
		"image" : "front_bg_4.jpg",
		"url" : "http://www.sxc.hu/photo/1271915",
		"firstline" : "&raquo;die delikatesse debussys und die raffinesse brad mehldaus (&#8230;) wenn das das vorspiel ist, was verspricht dann erst das hauptprogramm?&laquo;",
		"secondline" :""
	}
	, {
		"title" : "donaukurier",
		"image" : "front_bg_4.jpg",
		"url" : "http://www.sxc.hu/photo/1271915",
		"firstline" : "&raquo;wer dem tim allhoff trio zuh&ouml;rt, erf&auml;hrt, was jazz tats&auml;chlich bedeutet.&laquo;",
		"secondline" : ""	}
];



$(document).ready(function() {

	$("#headerimg,#headertxt").hide(0);

	var activeContainer = 1;	
	var currentImg = 0;
	var animating = false;
	var navigate = function(direction) {
		// Check if no animation is running. If it is, prevent the action
		if(animating) {
			return;
		}
		
		// 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 = -1;
	var showImage = function(photoObject, currentContainer, activeContainer) {
		animating = true;
		
		// Make sure the new container is always on the background
		currentZindex--;
		
		// Set the background image of the new active container
		$("#headerimg" + activeContainer).css({
			"background-image" : "url("+template_url+"/images/" + photoObject.image + ")",
			"display" : "block",
			"z-index" : currentZindex
		});
		
		// Hide the header text
		$("#headertxt").fadeOut(2000,function(){ //.css({"display" : "none"});
		
		// Set the new header text
		$("#firstline").html(photoObject.firstline);
		$("#secondline")
			
			.html(photoObject.secondline);
		$("#pictureduri")
			.html(photoObject.title);
			
		});
		
		// Fade out the current container
		// and display the header text when animation is complete
		$("#headerimg" + currentContainer).fadeOut(2000,function() {
			setTimeout(function() {
				$("#headertxt").fadeIn();			//.css({"display" : "block"});
				animating = false;
			}, 500);
		});
	};
	
	var stopAnimation = function() {
		// Change the background image to "play"
	
		
		// Clear the interval
		clearInterval(interval);
	};
	
	// We should statically set the first image
	navigate("next");
	
	// Start playing the animation
	interval = setInterval(function() {
		navigate("next");
	}, slideshowSpeed);
	
});
