/*
* Author:      Marco Kuiper (http://www.marcofolio.net/)
*/

// Speed of the automatic slideshow
var clubowe_slideshowSpeed =15000;
var clubowe_rand_slideshow =1;

// Variable to store the images we need to set as background
// which also includes some text and url's.
var club_photos = [ /*{
		"title" : "",
		"image" : p+"sys/img/imprezy_clubowe/klub-mirage-warszawa-imprezy-0.jpg",
		"url" : "",
		"firstline" : "",
		"secondline" : ""
	}
    
    , */
    {
		"title" : "",
		"image" : p+"sys/img/imprezy_clubowe/klub-mirage-warszawa-imprezy-1.jpg",
		"url" : "",
		"firstline" : "",
		"secondline" : ""
	}/*,
	{
		"title" : "",
		"image" : p+"sys/img/imprezy_clubowe/klub-mirage-warszawa-imprezy-2.jpg",
		"url" : "",
		"firstline" : "",
		"secondline" : ""
	}*/
];


var club_navigate;
var  club_interval;
$(document).ready(function() {
		
	
	 
	
//	
//	// Backwards navigation
//	$("#back").click(function() {
//		stopAnimation();
//		club_navigate("back");
//	});
//	
//	// Forward navigation
//	$("#next").click(function() {
//		stopAnimation();
//		club_navigate("next");
//	});
//	
//	var  club_interval;
//	$("#control").toggle(function(){
//		stopAnimation();
//	}, function() {
//		// Change the background image to "pause"
//		$(this).css({ "background-image" : "url(images/btn_pause.png)" });
//		
//		// Show the next image
//		club_navigate("next");
//		
//		// Start playing the animation
//		 club_interval = set club_interval(function() {
//			club_navigate("next");
//		}, clubowe_slideshowSpeed);
//	});
	
	
	var activeContainer = 1;	
	var currentImg = 0;
	var animating = false;
	 club_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 == club_photos.length + 1) {
				currentImg = 1;
			}
		} else {
			currentImg--;
			if(currentImg == 0) {
				currentImg = club_photos.length;
			}
		}
		
		// Check which container we need to use
		var currentContainer = activeContainer;
		if(activeContainer == 1) {
			activeContainer = 2;
		} else {
			activeContainer = 1;
		}
		
		
		if(rand_slideshow)currentImg=rand(1,club_photos.length);
		
		showImage(club_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
        //alert("#club_headerimg" + activeContainer);
		$("#club_headerimg" + activeContainer).css({
			"background-image" : "url(" + photoObject.image + ")",
			"display" : "block",
			"z-index" : currentZindex,
            "position": "fixex",
            "left" : "0px",
            "top" : "0px"
		});
		
		// Hide the header text
		$("#headertxt").css({"display" : "none"});
		
		// Set the new header text
		$("#club_firstline").html(photoObject.firstline);
		$("#club_secondline")
			.attr("href", photoObject.url)
			.html(photoObject.secondline);
		$("#club_pictureduri")
			.attr("href", photoObject.url)
			.html(photoObject.title);
		
		
		// Fade out the current container
		// and display the header text when animation is complete
		$("#club_headerimg" + currentContainer).fadeOut(function() {
			setTimeout(function() {
				$("club_#headertxt").css({"display" : "block"});
				animating = false;
			}, 500);
		});
	};
	
	var stopAnimation = function() {
		// Change the background image to "play"
		$("#club_control").css({ "background-image" : "url(images/btn_play.png)" });
		
		// Clear the  club_interval
		clearInterval( club_interval);
	};
	
	// We should statically set the first image
	club_navigate("next");
	
	// Start playing the animation
	// club_interval = set club_interval(function() {		club_navigate("next");	}, clubowe_slideshowSpeed);
	
	
	


	
});


function clubowe_back_run(){ 

    club_interval = setInterval(function() {club_navigate("next");	}, clubowe_slideshowSpeed);
}
function clubowe_back_stop(){
    clearInterval( club_interval);
}






