$(document).ready(function(){

    var cities = new Array();
	var themes = new Array();
	
	function updateArrays()
	{
		cities.length = 0;
		themes.length = 0;
		$("li.button_red a").each( function () {
			if($(this).hasClass("selectcity")) cities.push($(this).attr("name"));
			if($(this).hasClass("selecttheme")) themes.push($(this).attr("name"));
		});
		
	}
	
	$("a.selectcity").click ( function () {
		if($(this).parent().hasClass("button_grey"))
		{
			$("a.selectcity").parent().removeClass("button_red").addClass("button_grey");
			$(this).parent().removeClass("button_grey").addClass("button_red");
		}
		else if($(this).parent().hasClass("button_red"))
		{
			$(this).parent().removeClass("button_red");
			$(this).parent().addClass("button_grey	");
		}
		updateArrays();
	});
    
	$("a.selecttheme").click ( function () {
		if($(this).parent().hasClass("button_grey"))
		{
			$(this).parent().removeClass("button_grey");
			$(this).parent().addClass("button_red");
		}
		else if($(this).parent().hasClass("button_red"))
		{
			$(this).parent().removeClass("button_red");
			$(this).parent().addClass("button_grey	");
		}
		updateArrays();
	});
    
	$("#start").click( function (){
	
		if(cities.length == 0) cities.push(0);
		window.location = "/mmconcierge/" + cities.join(',') + "/"+themes.join(",");
		
	});
	
	function init(){
			$("#move_next").unbind();
			$("#move_prev").unbind();
			
			var curr = "";
			
			$("#move_next").nextAll("img").each(function(){
			
			
				if (!($(this).hasClass("hide"))) 
					curr = $(this);
			});
			
			var changeToPrev = curr.prev("img");
			if (changeToPrev.length > 0) {
				
				$("#move_prev").show();
				
				$("#move_prev").click(function(){
					curr.addClass("hide");
					changeToPrev.removeClass("hide");
					
					init();
					
					//SPECYFICZNE DLA CONCIERGE
					$("a[title="+curr.attr("id") + "]").removeClass("active");
					$("a[title="+changeToPrev.attr("id") + "]").addClass("active");
				
				});
			}
			else {
				$("#move_prev").hide();
				
			}
			
			var changeTo = curr.next("img");
			
			if (changeTo.length > 0) {
				$("#move_next").show();
				
				$("#move_next").click(function(){
					curr.addClass("hide");
					changeTo.removeClass("hide");
					
					init();
					
					//SPECYFICZNE DLA CONCIERGE
					$("a[title="+curr.attr("id") + "]").removeClass("active");
					$("a[title="+changeTo.attr("id") + "]").addClass("active");
				
				});
			}
			else {
				$("#move_next").hide();
				
			}
	}
	
		$("a.toggler").click( function () {
		
		init();
	});
	
	init();
	
});

