var units = 0;
var currentUnit = 0;
var curdate = new Date()
var month = curdate.getMonth()+1;
var selectedMonth = month;
var inGalleryMode = 0; 
var gallerySlideshow;
var galleryIndexEast = 0;
var galleryIndexWest = 0;
var galleryIndexSouth = 0;
var galleryIndexEvents = 0;
var galleryIndexIsland = 0;
var galleryIndexMonkeys = 0;
var url = "";
var monthArray = new Array("Januar","Februar","M&auml;rz","April","Mai","Juni","Juli","August","September","Oktober","November","Dezember");
var prefix;
var quality;
var suffix;
var leftArrow = 0;
var rightArrow = 0;
var urlchangeinterval;
var flash = false;

function iHaveFlash()
{
	flash = true;
	$("#background_noflash").remove();
	$("#units_slider").hide();
	$("#logo_noflash").stop().hide();
	$("#logo").show();
	$("#background").show();
	//$("#intro_cont").hide();
	$("#intro_noflash").hide();

	var logoflash = getFlashMovieObject("logo");
	if(flash != false)
		logoflash.SetVariable("unit", currentUnit);

	
	url = window.location.href;
	var path = url.split("#");
	if (path[1]) {
		path = path[1];
		path = path.split("/");
		var alias = path[path.length - 1];
		if (path.length == 2) {
			if (alias != "west" && alias != "east" && alias != "south" && alias != "monkeys" && alias != "events" && alias != "island") {
			}
			else 
				if (currentUnit != alias) {

					loadUnit(alias);
				}
		}
		else 
			if (path.length > 2) {
			if(currentUnit != path[path.length - 2])
				{
					currentUnit = path[path.length - 2];
					if (currentUnit != alias) {
						loadUnit(currentUnit);
					}
				}
			loadContent(alias);
			}
	}
				
}

$(document).ready(function(){
	
	$.geekGaTrackPage('UA-8309769-3');
	$("#logo_noflash").fadeIn('slow');
	
	$('#dock').css({"top": $(window).height()-180+"px"});

	if(iphone == true){
		$("html").css({"overflow": "visible", "height": "auto"});
		$("body").css({"overflow": "visible", "height": "auto"});
		$("#root").css({"overflow": "visible", "height": "auto"});
		
		$('#dock').css({"top": $("#content").height()+"px"});
		$('intro_iphone').hide();
	}
	
	$('#units_slider .cont, #units_slider img').css({"top": -$("#units_slider").height()+11+ "px"});
	
	if(iphone == false)
		$("#content").css({left: $(window).width() - $("#content").width() - 40 + "px"});
	else
		$("#content").css({left: 600+"px"});
	
	$("#logo").css({left: $(window).width()/2 - 290 +"px"});
	
	if(iphone == true)
		urlchangeinterval = setInterval("urlChangeEvent()", "1000");
	else
		urlchangeinterval = setInterval("urlChangeEvent()", "100");
	
	if(1 == 2)
		clearInterval(urlchangeinterval);
	
	var domain = document.URL.split("?")[0];
	
	if(domain == "http://monkeysplaza.com" || domain == "http://monkeysplaza.com/" || domain == "http://monkeysplaza.com/index.php" ||
	   domain == "http://www.monkeysplaza.com/" || domain == "http://www.monkeysplaza.com/" || domain == "http://www.monkeysplaza.com/index.php")
	{
			$("#root").hide();
	}
	else
	{
		$("#intro").parent().hide();
	}	

	$("#arrow_left").click(function(){
		prevGalleryImage();
	});

	$("#arrow_right").click(function(){
		nextGalleryImage();
	});
	
	$(document).mousemove(function(e){
		if(units == 0)
		{
			if(e.pageX < $(window).width()/2 + 90 && e.pageX > $(window).width()/2 - 90 && e.pageY > 150 && e.pageY < 163)
			{
				units = 1;
				$("#units_slider .cont, #units_slider img").animate({"top": 0+"px"}, 400);
			}
		}
		
		if(units == 1)
		{
			if((e.pageX > $(window).width()/2 + 90 || e.pageX < $(window).width()/2 - 90) || (e.pageY < 150 || e.pageY > 150 + $("#units_slider").height()))
			{
				units = 0;
				$("#units_slider .cont, #units_slider img").stop().animate({"top": -$("#units_slider").height()+11+ "px"}, 400);
			}
		}
		
		if(inGalleryMode != 0)
		{
			if(e.pageX < $(window).width()/3 && leftArrow == 0)
			{
				if(rightArrow == 1)
					$("#arrow_right").fadeTo('normal', 0.5);
				$("#arrow_left").fadeTo('normal', 1);
				leftArrow = 1;
				rightArrow = 0;
			}
			if(e.pageX > $(window).width()/3*2 && rightArrow == 0)
			{
				$("#arrow_right").fadeTo('normal', 1);
				if(leftArrow == 1)
					$("#arrow_left").fadeTo('normal', 0.5);
				rightArrow = 1;
				leftArrow = 0;
			}
			if(e.pageX < $(window).width()/3*2 && e.pageX > $(window).width()/3)
			{
				if(rightArrow == 1)
					$("#arrow_right").fadeTo('normal', 0.5);
				if(leftArrow == 1)
					$("#arrow_left").fadeTo('normal', 0.5);
				leftArrow = 0;
				rightArrow = 0;
			}
		}
	});

});

$(window).resize(function(){
	if (iphone == false) {
		$("#content").css({
			left: $(window).width() - $("#content").width() - 40 + "px"
		});
		$("#logo").css({
			left: $(window).width() / 2 - 290 + "px"
		});
		$('#dock').css({
			"top": $(window).height() - 180 + "px"
		});
		
		$("#content").html("<div id='container' style=\"padding-bottom: 30px\">" + $("#content #container").html() + "</div>");
		
		var maxHeight = $(window).height() - 190 - ($(window).height() - ($('#dock').position()).top);
		var newHeight = $('#content #container').height() + 50;
		if (newHeight > maxHeight) 
			newHeight = maxHeight;
		$('#content').css({
			height: newHeight + "px"
		});
		
		$('#content #container').css({
			height: $('#content').height() - 40 + "px"
		});
		$('#content #container').jScrollPane({
			scrollbarWidth: 6,
			wheelSpeed: 35
		});
		if (flash == false) 
			$("#background_noflash").fsback();
			
		$("#island_newsletterform").css({top: ($("#content").position()).top-150+"px", 
 										 left: ($("#content").position()).left-150+"px"});	}

});

function getFlashMovieObject(movieName)
{
  if (window.document[movieName]) 
  {
      return window.document[movieName];
  }
  if (navigator.appName.indexOf("Microsoft Internet")==-1)
  {
    if (document.embeds && document.embeds[movieName])
      return document.embeds[movieName]; 
  }
  else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
  {
  	if(window[movieName])
	{
		 return window[movieName];
	}
    return document.getElementById(movieName);
  }
}	

function loadBackground(alias)
{
	
	if(alias == "monkeys")
		alias = "monkeys_spirit"
	if(alias == "west")
		alias = "west_ambiente"
	if(alias == "east")
		alias = "east_ambiente"
	if(alias == "south")
		alias = "south_ambiente"
	if(alias == "island")
		alias = "island_start"
	if(alias == "events")
		alias = "events_inszenierung"
	if(alias == "newsletter_archiv" || alias == "newsletter_delete")
		alias = "monkeys_spirit"
		
	data = "tl_files/monkeys/images/bgs/"+alias+".jpg";
	
	if (flash != false && iphone == false) {
		if (alias != "presse") 
		if (alias != "reservierung") 
		if (alias != "partner") 
		if (alias != "newsletter")
		if (alias != "newsletter_bestaetigung") 
		if (alias != "specials") 
		if (alias != "karriere") {
			var mov = getFlashMovieObject("background");
			mov.setBrowser(navigator.appName.indexOf("Microsoft Internet")!=-1);
			mov.sendToActionScript(data);
		}
	}
	else {
		if (iphone == true) {
			//data = "tl_files/monkeys/images/bgs/" + alias+"_iphone.jpg";
			$("body").css({"background-image": "url("+data+")", "background-repeat": "no-repeat", "background-position": "center", "background-attachment":"fixed"});
		}
		else {
			$("#background_noflash").attr("src", data);
			$("#background_noflash").fsback();
		}
	}
	
}

function loadGalleryImage(img)
{
	var mov = getFlashMovieObject("background");
	if (img && flash != false) {
		mov.setBrowser(navigator.appName.indexOf("Microsoft Internet")!=-1);
		mov.sendToActionScript(img);
	}
}

function loadLogo(unit)
{
/*	
		var mov = getFlashMovieObject("logo");
		if(unit && mov)
			mov.sendToActionScript(unit);
*/			
}

function loadUnit(id)
{
$("#intro_iphone").hide();
//	window.clearInterval(gallerySlideshow);
	if ((id == "west" || id == "monkeys" || id == "east" || id == "south" || id == "island" || id == "events")) {
		
		if(id == "monkeys"){
			$.geekGaTrackPage('UA-8309769-11');
			loadContent("monkeys_spirit");
		}
		if(id == "west"){
			$.geekGaTrackPage('UA-8309769-7');
			loadContent("west_ambiente");
		}
		if(id == "east"){
			$.geekGaTrackPage('UA-8309769-8');
			loadContent("east_ambiente");
		}
		if(id == "south"){
			$.geekGaTrackPage('UA-8309769-6');
			loadContent("south_ambiente");
		}
		if(id == "island"){
			$.geekGaTrackPage('UA-8309769-10');
			loadContent("island_news");
		}
		if(id == "events"){
			$.geekGaTrackPage('UA-8309769-9');
			loadContent("events_inszenierung");
		}
		
//		loadLogo(id);
//		alert(id);

		var logoflash = getFlashMovieObject("logo");
		if(flash != false)
			logoflash.SetVariable("unit", id);
		
		currentUnit = id;
		
		$('.dock-container').fadeOut(300, function(){
			$.get("tl_files/monkeys/ajax/loadSubmenu.ajax.php?id=" + id, function(data){
			
				$('.dock-container').html(data);
				
				if (iphone == false) {
					$('#dock').Fisheye({
						maxWidth: 25,
						items: 'a',
						itemsText: 'span',
						container: '.dock-container',
						itemWidth: 60,
						proximity: 55,
						alignment: 'center',
						valign: 'bottom',
						halign: 'center'
					});
					
					$('.dock-item').mouseover(function(){
						$(this).children("img").attr("src", "tl_files/monkeys/images/menu/hover/"+$(this).attr("id")+".png");
					});					
					$('.dock-item').mouseout(function(){
						$(this).children("img").attr("src", "tl_files/monkeys/images/menu/"+$(this).attr("id")+".png");
					});					
					
				}
				else
				{
					$(".dock-item").css({"position": "static", "float": "left"});
					$(".dock-container").css({display: "inline-block"});
					$(".dock").css({"text-align": "center"});
				}
				
				$('.dock-container').fadeIn(600);
			});
			
		});
	}
	else
	{
		$.geekGaTrackPage('UA-8309769-11');
		if (currentUnit == 0) {
			currentUnit = "monkeys";
			if (currentUnit != alias)
				loadUnit(currentUnit);
		}
	}
}

function loadContent(id)
{
	var logoflash = getFlashMovieObject("logo");
	if(flash != false)
		logoflash.SetVariable("unit", currentUnit);
	
	
$("#intro_iphone").hide();
	if(id == "island_link"){
		window.open("http://www.monkeysisland.com/");
		setURL("island_start");
		}
			
	if(id == "monkeys_gallery" || id == "west_gallery" || id == "south_gallery" || id == "east_gallery" || id == "island_gallery" || id == "events_gallery")
		startSlideshow();
	else
	$('#content #container').fadeOut(300, function(){
		if(inGalleryMode == 1)
			stopSlideshow();
	
		if (id != "specials" && id != "presse" && id != "newsletter" && id!= "newsletter_archiv" && id!= "newsletter_delete" && id != "island_news" && id != "island_reservierung") 
			var url = "tl_files/monkeys/ajax/loadContents.ajax.php?id=" + id
		else {
			if (id == "specials") {
				var url = "tl_files/monkeys/ajax/loadEventcalendar.ajax.php?month=" + selectedMonth;
			}
			if(id == "island_news"){
				var url = "tl_files/monkeys/ajax/loadEventcalendar.ajax.php?unit=island&month=" + selectedMonth;
			}
			if (id == "presse") {
				var url = "tl_files/monkeys/ajax/loadPress.ajax.php?key="+$("#key").attr("value");
			}
			if (id == "newsletter") {
				var url = "tl_files/monkeys/ajax/loadNewsletter.ajax.php";
			}
			if (id == "newsletter_archiv") {
				var url = "tl_files/monkeys/ajax/loadNewsletterArchiv.ajax.php";
			}
			if (id == "newsletter_delete") {
				var url = "tl_files/monkeys/ajax/loadNewsletterDelete.ajax.php";
			}
			if (id == "island_reservierung") {
				var url = "tl_files/monkeys/ajax/loadReservation_island.ajax.php";
			}
		}
		
		$.get(url, function(data){
			if (iphone == false) {
				$("#content").html("<div id='container'>" + $("#content #container").html() + "</div>");
				$('#content #container').html(data);
				$('#content #container').show();
				
				if ($("#calendar").html() == "") 
					$("#calendar").html("Keine Veranstaltungen in diesem Monat")
				
				if (currentUnit == "east") {
					sIFR.replace(absarah_bold, {
						selector: 'h1',
						css: '.sIFR-root { background-color: none; color: #FFFFFF; font-size: 30;}',
						wmode: 'transparent',
						transparent: true
					});
					sIFR.replace(absarah_bold, {
						selector: 'h2',
						css: '.sIFR-root { background-color: none; color: #FFFFFF; font-weight: bold;}',
						wmode: 'transparent',
						transparent: true
					});
					sIFR.replace(absarah_bold, {
						selector: 'h3',
						css: '.sIFR-root { background-color: none; color: #FFFFFF; font-weight: bold; font-size: 25;}',
						wmode: 'transparent',
						transparent: true
					});
					sIFR.replace(absarah_bold, {
						selector: '.events_day',
						css: '.sIFR-root { background-color: none; color: #FFFFFF; font-size: 30; text-align: center;}',
						wmode: 'transparent',
						transparent: true
					});
				}
				
				if (currentUnit == "west") {
					sIFR.replace(absarah_light, {
						selector: 'h1',
						css: '.sIFR-root { background-color: none; color: #FFFFFF; font-size: 30;}',
						wmode: 'transparent',
						transparent: true
					});
					sIFR.replace(absarah_light, {
						selector: 'h2',
						css: '.sIFR-root { background-color: none; color: #FFFFFF; font-weight: bold;}',
						wmode: 'transparent',
						transparent: true
					});
					sIFR.replace(absarah_light, {
						selector: 'h3',
						css: '.sIFR-root { background-color: none; color: #FFFFFF; font-weight: bold; font-size: 25;}',
						wmode: 'transparent',
						transparent: true
					});
					sIFR.replace(absarah_light, {
						selector: '.events_day',
						css: '.sIFR-root { background-color: none; color: #FFFFFF; font-size: 30; text-align: center;}',
						wmode: 'transparent',
						transparent: true
					});
				}
				if (currentUnit == "island") {
					sIFR.replace(absarah_thin, {
						selector: 'h1',
						css: '.sIFR-root { background-color: none; color: #FFFFFF; font-size: 30;}',
						wmode: 'transparent',
						transparent: true
					});
					sIFR.replace(absarah_thin, {
						selector: 'h2',
						css: '.sIFR-root { background-color: none; color: #FFFFFF; font-weight: bold;}',
						wmode: 'transparent',
						transparent: true
					});
					sIFR.replace(absarah_thin, {
						selector: 'h3',
						css: '.sIFR-root { background-color: none; color: #FFFFFF; font-weight: bold; font-size: 25;}',
						wmode: 'transparent',
						transparent: true
					});
					sIFR.replace(absarah_thin, {
						selector: '.events_day',
						css: '.sIFR-root { background-color: none; color: #FFFFFF; font-size: 30; text-align: center;}',
						wmode: 'transparent',
						transparent: true
					});
				}
				if (currentUnit == "events") {
					sIFR.replace(absarah_sans_light, {
						selector: 'h1',
						css: '.sIFR-root { background-color: none; color: #FFFFFF; font-size: 30;}',
						wmode: 'transparent',
						transparent: true
					});
					sIFR.replace(absarah_sans_light, {
						selector: 'h2',
						css: '.sIFR-root { background-color: none; color: #FFFFFF; font-weight: bold;}',
						wmode: 'transparent',
						transparent: true
					});
					sIFR.replace(absarah_sans_light, {
						selector: 'h3',
						css: '.sIFR-root { background-color: none; color: #FFFFFF; font-weight: bold; font-size: 25;}',
						wmode: 'transparent',
						transparent: true
					});
					sIFR.replace(absarah_sans_light, {
						selector: '.events_day',
						css: '.sIFR-root { background-color: none; color: #FFFFFF; font-size: 30; text-align: center;}',
						wmode: 'transparent',
						transparent: true
					});
				}
				if (currentUnit == "monkeys") {
					sIFR.replace(absarah_sans_headline, {
						selector: 'h1',
						css: '.sIFR-root { background-color: none; color: #FFFFFF; font-size: 30;}',
						wmode: 'transparent',
						transparent: true
					});
					sIFR.replace(absarah_sans_headline, {
						selector: 'h2',
						css: '.sIFR-root { background-color: none; color: #FFFFFF; font-weight: bold;}',
						wmode: 'transparent',
						transparent: true
					});
					sIFR.replace(absarah_sans_headline, {
						selector: 'h3',
						css: '.sIFR-root { background-color: none; color: #FFFFFF; font-weight: bold; font-size: 25;}',
						wmode: 'transparent',
						transparent: true
					});
					sIFR.replace(absarah_sans_headline, {
						selector: '.events_day',
						css: '.sIFR-root { background-color: none; color: #FFFFFF; font-size: 30; text-align: center;}',
						wmode: 'transparent',
						transparent: true
					});
				}
				if (currentUnit == "south") {
					sIFR.replace(absarah_sans_bold, {
						selector: 'h1',
						css: '.sIFR-root { background-color: none; color: #FFFFFF; font-size: 30;}',
						wmode: 'transparent',
						transparent: true
					});
					sIFR.replace(absarah_sans_bold, {
						selector: 'h2',
						css: '.sIFR-root { background-color: none; color: #FFFFFF; font-weight: bold;}',
						wmode: 'transparent',
						transparent: true
					});
					sIFR.replace(absarah_sans_bold, {
						selector: 'h3',
						css: '.sIFR-root { background-color: none; color: #FFFFFF; font-weight: bold; font-size: 25;}',
						wmode: 'transparent',
						transparent: true
					});
					sIFR.replace(absarah_sans_bold, {
						selector: '.events_day',
						css: '.sIFR-root { background-color: none; color: #FFFFFF; font-size: 30; text-align: center;}',
						wmode: 'transparent',
						transparent: true
					});
				}
								
				sIFR.replace(absarah_sans_headline, {
					selector: '.posttitle',
					css: '.sIFR-root { background-color: none; color: #FFFFFF; font-size: 25;}',
					wmode: 'transparent',
					transparent: true
				});
				sIFR.replace(absarah_sans_headline, {
					selector: '.category_selector .link',
					css: '.sIFR-root { background-color: none; color: #FFFFFF; font-size: 15; cursor: pointer;}',
					wmode: 'transparent',
					transparent: true
				});
				
				if(id == "island_news"){
					$.get("tl_files/monkeys/ajax/island_newsletterform.php", function(data){
						$("#root").append(data);
						$("#island_newsletterform").css({top: ($("#content").position()).top-150+"px", 
														 left: ($("#content").position()).left-150+"px"});
					});
				}
				else {
					$("#island_newsletterform").remove();
				}
				
				if(id == "island_news" || id == "island_ambiente" || id == "island_events" || id == "island_anfahrt" || id == "island_kontakt"){
					showWiFi();
				}
				else
				{
					$("#wifi").remove();
				}
				
				$("#content .event_month").hide();
				$("#content .month_" + month).show();
				
				var maxHeight = $(window).height() - 190 - ($(window).height() - ($('#dock').position()).top);
				var newHeight = $('#content #container').height() + 50;
			
				if (newHeight > maxHeight) 
					newHeight = maxHeight;

				if (!data) 
					newHeight = 0;
				
				//			$('#content #container').hide();
				$('#content').css({"height": newHeight + "px"});
				{
					
					setTimeout("resizeImages()", 500);
					
					if(id != "impressum")
						loadBackground(id);
					else
						loadBackground("monkeys");
					
					//$("#content").css({"background-image": "url(images/logo_background.png)"});
					if (id == "specials") {
						//					$("#content").css({"padding-bottom": "70px"});
						$('#content #container').css({
							"height": newHeight - 145 + "px"
						});
					}
					else 
						if (id == "presse") {
							$('#content #container').css({
								"height": newHeight - 55 + "px"
							});
						}
						else 
							$('#content #container').css({
								"height": newHeight - 15 + "px"
							});
					
					//				$('#content #container').show();
					
					
					$(".currentmonth").html(monthArray[selectedMonth - 1]);
					
					if ($("#container .month_selector").html()) {
						
						$("#container").css({"height": $("#container").height()-100+"px"});
						
						
						$("#content").prepend("<div class=\"month_selector\">" + $("#container .month_selector").html() + "</div>");
						$("#container .month_selector").hide();
						
						sIFR.replace(absarah_sans_headline, {
							selector: '.currentmonth',
							css: '.sIFR-root { background-color: none; color: #FFFFFF; font-size: 17;}',
							wmode: 'transparent',
							transparent: true
						});
						sIFR.replace(absarah_sans_headline, {
							selector: '.date_day',
							css: '.sIFR-root { background-color: none; color: #FFFFFF; font-size: 60;}',
							wmode: 'transparent',
							transparent: true
						});
						sIFR.replace(absarah_sans_headline, {
							selector: '.date_month',
							css: '.sIFR-root { background-color: none; color: #FFFFFF; font-size: 16;}',
							wmode: 'transparent',
							transparent: true
						});
						sIFR.replace(absarah_sans_headline, {
							selector: '.date_unit',
							css: '.sIFR-root { background-color: none; color: #FFFFFF; font-size: 15;}',
							wmode: 'transparent',
							transparent: true
						});
						sIFR.replace(absarah_sans_headline, {
							selector: '#month_prev, #month_next',
							css: '.sIFR-root { background-color: none; color: #FFFFFF; font-size: 17; cursor: pointer; text-align: center;}',
							wmode: 'transparent',
							transparent: true
						});
						
						if (id == "island_news") {
							sIFR.replace(absarah_thin, {
								selector: '.specials_headline',
								css: '.sIFR-root { background-color: none; color: #FFFFFF; font-size: 25;}',
								wmode: 'transparent',
								transparent: true,
								tuneHeight: -8
							});
							sIFR.replace(absarah_thin, {
								selector: '.specials_unit',
								css: '.sIFR-root { background-color: none; color: #FFFFFF; font-size: 16;}',
								wmode: 'transparent',
								transparent: true
							});
							sIFR.replace(absarah_thin, {
								selector: '.specials_head',
								css: '.sIFR-root { background-color: none; color: #FFFFFF; font-size: 35;}',
								wmode: 'transparent',
								transparent: true
							});
						}
						else
						{
							sIFR.replace(absarah_sans_headline, {
								selector: '.specials_headline',
								css: '.sIFR-root { background-color: none; color: #FFFFFF; font-size: 25;}',
								wmode: 'transparent',
								transparent: true,
								tuneHeight: -8
							});
							sIFR.replace(absarah_sans_headline, {
								selector: '.specials_unit',
								css: '.sIFR-root { background-color: none; color: #FFFFFF; font-size: 16;}',
								wmode: 'transparent',
								transparent: true
							});
							sIFR.replace(absarah_sans_headline, {
								selector: '.specials_head',
								css: '.sIFR-root { background-color: none; color: #FFFFFF; font-size: 35;}',
								wmode: 'transparent',
								transparent: true
							});						
						}
						
					}
					
					if ($("#container .category_selector").html()) {
						$("#content").prepend("<div class=\"category_selector\">" + $("#container .category_selector").html() + "</div>");
						$("#container .category_selector").hide();
					}
										
					if (iphone == false) 
						setTimeout("scrollBar()", 1000);
				}
			}
			else
			{
				$("#content").html("<div id='container'>" + $("#content #container").html() + "</div>");
				$('#content #container').html(data);
				$('#content #container').show();
				$('#dock').css({"top": $("#content").height()+260+"px"});
				$('#global_menu').css({"top": $("#content").height()+320+"px"});
				loadBackground(id);
			}
		});

	});
}

function prevMonth()
{
	selectedMonth -= 1;
	
	if(currentUnit == 'island')
		loadContent("island_news");
	else
		loadContent("specials");
}

function nextMonth()
{
	selectedMonth += 1;
	
	if(currentUnit == 'island')
		loadContent("island_news");
	else
		loadContent("specials");
}

function urlChangeEvent()
{
	if(flash == true)
	$("#logo_noflash").hide();
	
	if(window.location.href != url)
	{	
		if(flash == false)
		{
			$("#background").hide();
			$("#logo").hide();
			$("background_noflash").show();
		}
		else
		{
			$("background_noflash").hide();
			$("#background").show();
			$("#units_slider").hide();
			$("#logo").show();
			$("#logo_noflash").stop().hide();
		}
		url = window.location.href;
		var path = url.split("#");
		if (path[1]) {
			path = path[1];
			path = path.split("/");
			var alias = path[path.length - 1];
			
			if (path.length == 2) {
				if (alias != "west" && alias != "east" && alias != "south" && alias != "monkeys" && alias != "events" && alias != "island") {
					loadContent(alias);
				}
				else {
// !"! Hier wird ausgeführt		
					if (currentUnit != alias) {
						loadUnit(alias);
					}
				}
			}
			else 
				if (path.length > 2) {
				if(currentUnit != path[path.length - 2])
					{
						currentUnit = path[path.length - 2];
						if (currentUnit != alias)
							loadUnit(currentUnit);
					}
				loadContent(alias);
				}
		}		
	}
}

function setURL(id)
{
	$("#intro_iphone").hide();
	$("#intro_noflash").hide();
	$("#intro").parent().hide();
	$("#root").show();
	$("#intro_iphone").hide();
	$("#intro_cont").hide();

	$.get("tl_files/monkeys/ajax/getURL.ajax.php?id="+id, function(data){
		window.location.href = data;
	});
}

function loadUnitsContent(id)
{
		window.clearInterval(gallerySlideshow);
		$('#content').fadeOut(300, function(){
		
			$.get("tl_files/monkeys/ajax/loadContents.ajax.php?pid=" + id, function(data){
				$('#content').html(data);
				$('#content').fadeIn(600);
			});
		});
}

function nextGalleryImage(){
	if (currentUnit == "east") {
		if (galleryIndexEast + 1 != galleryItemsEast.length) {
			galleryIndexEast += 1;
		}
		else {
			galleryIndexEast = 0;
		}
		loadGalleryImage("tl_files/monkeys/images/gallery_east/" + galleryItemsEast[galleryIndexEast]);
	}
	if (currentUnit == "west") {
		if (galleryIndexWest + 1 != galleryItemsWest.length) {
			galleryIndexWest += 1;
		}
		else {
			galleryIndexWest = 0;
		}
		loadGalleryImage("tl_files/monkeys/images/gallery_west/" + galleryItemsWest[galleryIndexWest]);
	}
	if (currentUnit == "island") {
		if (galleryIndexIsland + 1 != galleryItemsIsland.length) {
			galleryIndexIsland += 1;
		}
		else {
			galleryIndexIsland = 0;
		}
		loadGalleryImage("tl_files/monkeys/images/gallery_island/" + galleryItemsIsland[galleryIndexIsland]);
	}
	if (currentUnit == "events") {
		if (galleryIndexEvents + 1 != galleryItemsEvents.length) {
			galleryIndexEvents += 1;
		}
		else {
			galleryIndexEvents = 0;
		}
		loadGalleryImage("tl_files/monkeys/images/gallery_events/" + galleryItemsEvents[galleryIndexEvents]);
	}
	if (currentUnit == "monkeys") {
		if (galleryIndexMonkeys + 1 != galleryItemsMonkeys.length) {
			galleryIndexMonkeys += 1;
		}
		else {
			galleryIndexMonkeys = 0;
		}
		loadGalleryImage("tl_files/monkeys/images/gallery_monkeys/" + galleryItemsMonkeys[galleryIndexMonkeys]);
	}
	if (currentUnit == "south") {
		if (galleryIndexSouth + 1 != galleryItemsSouth.length) {
			galleryIndexSouth += 1;
		}
		else {
			galleryIndexSouth = 0;
		}
		loadGalleryImage("tl_files/monkeys/images/gallery_south/" + galleryItemsSouth[galleryIndexSouth]);
	}							
}

function prevGalleryImage(){
	if (currentUnit == "east") {
		if (galleryIndexEast - 1 != -1) {
			galleryIndexEast -= 1;
		}
		else {
			galleryIndexEast = galleryItemsEast.length-1;
		}
		loadGalleryImage("tl_files/monkeys/images/gallery_east/" + galleryItemsEast[galleryIndexEast]);
	}
	if (currentUnit == "west") {
		if (galleryIndexWest - 1 != -1) {
			galleryIndexWest -= 1;
		}
		else {
			galleryIndexWest = galleryItemsWest.length-1;
		}
		loadGalleryImage("tl_files/monkeys/images/gallery_west/" + galleryItemsWest[galleryIndexWest]);
	}
	if (currentUnit == "island") {
		if (galleryIndexIsland - 1 != -1) {
			galleryIndexIsland -= 1;
		}
		else {
			galleryIndexIsland = galleryItemsIsland.length-1;
		}
		loadGalleryImage("tl_files/monkeys/images/gallery_island/" + galleryItemsIsland[galleryIndexIsland]);
	}
	if (currentUnit == "events") {
		if (galleryIndexEvents - 1 != -1) {
			galleryIndexEvents -= 1;
		}
		else {
			galleryIndexEvents = galleryItemsEvents.length-1;
		}
		loadGalleryImage("tl_files/monkeys/images/gallery_events/" + galleryItemsEvents[galleryIndexEvents]);
	}
	if (currentUnit == "monkeys") {
		if (galleryIndexMonkeys - 1 != -1) {
			galleryIndexMonkeys -= 1;
		}
		else {
			galleryIndexMonkeys = galleryItemsMonkeys.length-1;
		}
		loadGalleryImage("tl_files/monkeys/images/gallery_monkeys/" + galleryItemsMonkeys[galleryIndexMonkeys]);
	}
	if (currentUnit == "south") {
		if (galleryIndexSouth - 1 != -1) {
			galleryIndexSouth -= 1;
		}
		else {
			galleryIndexSouth = galleryItemsSouth.length-1;
		}
		loadGalleryImage("tl_files/monkeys/images/gallery_south/" + galleryItemsSouth[galleryIndexSouth]);
	}							
}

function startSlideshow()
{
	$("#arrow_right").fadeTo('normal', 0.5);
	$("#arrow_left").fadeTo('normal', 0.5);
	nextGalleryImage();
	$("#content").fadeOut(700);
	inGalleryMode = 1;
	$("#dock").fadeTo("normal",0.50);
}

function stopSlideshow()
{
	$("#content").fadeIn(700);
	inGalleryMode = 0;
	
	$("#arrow_right").hide();
	$("#arrow_left").hide();
	leftArrow = 0;
	rightArrow = 0;
	$("#dock").fadeTo("normal",1);
}

function filterPress(unit)
{
	$(".post").hide();
	$("."+unit).show();
	$(".popup a").css({"font-weight": "normal", color: "#FFFFFF"});
	$(".pl_"+unit).css({"font-weight": "bold", color: "#AAAAAA"});
	
	if(iphone == false)	
		$('#content #container').jScrollPane({scrollbarWidth: 6, wheelSpeed: 35});
}

function showPopup()
{
	$(".category_selector .popup").show();
	$(".category_selector .popup").css({"top": ($(".category_selector").position()).top + $(".category_selector").height() +"px", 
										"left": ($(".category_selector").position()).left +"px"});
}

function hidePopup()
{
	$(".category_selector .popup").hide();
}

function newsletterabo()
{
	$.ajax({type: "POST",
				url: "tl_files/monkeys/ajax/insertNewsletter.ajax.php",
				data: ({
					email: $("#email").attr("value")
				}),
				success: function(data){
					loadContent('newsletter_bestaetigung');
					},
				 contentType: "application/x-www-form-urlencoded;"
				});
}

function newsletterabodelete()
{
	$.ajax({type: "POST",
				url: "tl_files/monkeys/ajax/deleteNewsletter.ajax.php",
				data: ({
					email: $("#email").attr("value")
				}),
				success: function(data){
					loadContent('newsletterdelete_bestaetigung');
					},
				 contentType: "application/x-www-form-urlencoded;"
				});
}

function newsletterabo_island()
{
	$.ajax({type: "POST",
				url: "tl_files/monkeys/ajax/insertNewsletter_island.ajax.php",
				data: ({
					email: $("#inf_email").attr("value"),
					unit: 'island'
				}),
				success: function(data){
					loadContent('newsletter_bestaetigung');
					},
				 contentType: "application/x-www-form-urlencoded;"
				});
}

function reservation()
{
	$.ajax({type: "POST",
				url: "tl_files/monkeys/ajax/insertReservation.ajax.php",
				data: ({
					name: $("#name").attr("value"),
					email: $("#email").attr("value"),
					tel: $("#tel").attr("value"),
					date: $("#date").attr("value"),
					time: $("#time").attr("value"),
					anzahl: $("#anzahl").attr("value")
				}),
				success: function(data){
					loadContent('reservierung_bestaetigung');
					},
				 contentType: "application/x-www-form-urlencoded;"
				});
}

function scrollBar()
{
	$('#content #container').jScrollPane({
								scrollbarWidth: 6,
								wheelSpeed: 35
	});
}

function resizeImages()
{
$("#container img").each(function(){
						var h = $(this).height();
						var w = $(this).width();
						
						if(w > 285)
						{
							$(this).css({"width": 285+"px"});
							$(this).css({"height": h*285/w+"px"});
						}
					});}

function showWiFi()
{
	$("#root").append("<img id=\"wifi\" src=\"tl_files/monkeys/images/wifi.png\" style=\"position: absolute; left: 10px; top: 10px;\" />");
}
