var bg_anz = 0;
var bg_pos = 0;
redirect();
load_functions();

function load_functions() {
	var submenu_size = new Array();
	var box_size = new Array();
	$(document).ready(function(){
		ajaxloader();
		$(".img").lightbox();
	
		$(function() {
			var dates = $( "#zeitvon1, #zeitbis1" ).datepicker({
				dateFormat: 'dd.mm.yy',
				defaultDate: "+1w",
				changeMonth: true,
				numberOfMonths: 1,
				showOn: "both",
				buttonImage: rel_pfad+"images/calendar-blue.gif",
				buttonImageOnly: true,
				onSelect: function( selectedDate ) {
					var option = this.id == "zeitvon1" ? "minDate" : "maxDate",
						instance = $( this ).data( "datepicker" );
						date = $.datepicker.parseDate(
							instance.settings.dateFormat ||
							$.datepicker._defaults.dateFormat,
							selectedDate, instance.settings );
					dates.not( this ).datepicker( "option", option, date );
				}
			});
		});
		$(function() {
			var dates = $( "#zeitvon2, #zeitbis2" ).datepicker({
				dateFormat: 'dd.mm.yy',
				defaultDate: "+1w",
				changeMonth: true,
				numberOfMonths: 1,
				showOn: "both",
				buttonImage: rel_pfad+"images/calendar-blue.gif",
				buttonImageOnly: true,
				onSelect: function( selectedDate ) {
					var option = this.id == "zeitvon2" ? "minDate" : "maxDate",
						instance = $( this ).data( "datepicker" );
						date = $.datepicker.parseDate(
							instance.settings.dateFormat ||
							$.datepicker._defaults.dateFormat,
							selectedDate, instance.settings );
					dates.not( this ).datepicker( "option", option, date );
				}
			});
		});
		$(function() {
			var dates = $( "#geburtsdatum" ).datepicker({
				dateFormat: 'dd.mm.yy',
				changeMonth: true,
				changeYear: true,
				yearRange:'-80:+0',
				showOn: "both",
				buttonImage: rel_pfad+"images/calendar-blue.gif",
				buttonImageOnly: true
			});
		});
	
		$("#main_menu li .submenu div").each(
			function(i) {
				submenu_size[i] = $(this).height();
			}
		);
		
		$("#main_menu li:has(.submenu div)").hover(
			function() {
				var i = $("#main_menu li:has(.submenu div)").index(this);
				$(this).find(".submenu div").css({overflow:'hidden', height:'0px', display:'block', 'z-index': '3'}).stop().animate({height:submenu_size[i]+'px'},'fast');
			},
			function() {
				var i = $("#main_menu li:has(.submenu div)").index(this);
				$(this).find(".submenu div").stop().animate({height:'0px'},'fast');
			}
		);
		
		$("#info_box_wrapper .box").each(
			function(i) {
				box_size[i] = $(this).height();
				$(this).css({height:33+'px'});
			}
		);
		
		$("#info_box_wrapper .box").hover(
			function() {
				var i = $("#info_box_wrapper .box").index(this);
				$(this).stop().animate({top:'-150px',height:box_size[i]+'px'},'fast');		
			},
			function() {
				var i = $("#info_box_wrapper .box").index(this);
				$(this).stop().animate({height:33+'px', top:'0'},'fast');
			}
		);
		
		var x = 660;
		var y = 515;	
		var box = $(".karte .map_box").map(function () {
		
			var position_left = $(this).position().left;
			var position_top = $(this).position().top;
			var box_width = $(this).find(".inhalt").outerWidth();
			var box_height = $(this).find(".inhalt").outerHeight();
			var box_2 = $(this).find(".inhalt");
			var postion_x;
			var postion_y;
						
			if(box_width + position_left >= x && box_height + position_top >= y) {
				postion_x = 15 - box_width;
				postion_y = 15 - box_height;
				
				$(this).find(".inhalt_head").clone().appendTo(box_2);
				$(this).find(".inhalt_head:first").remove();
				
				var ecke = '<div style="position:absolute; left:18px; bottom:0px; width:18px; height:18px;"><img src="/images/karte-box-ecke-r-u.gif" style="width:18px; height:18px;" alt="" /></div>';
				$(ecke).appendTo(box_2);
			} else if(box_width + position_left >= x && box_height + position_top < y) {
				postion_y = 15;
				postion_x = 0 - box_width;
				var ecke = '<div style="position:absolute; left:300px; top:-1px; width:18px; height:18px;"><img src="/images/karte-box-ecke-r-o.gif" style="width:18px; height:18px;" alt="" /></div>';
				$(ecke).appendTo(box_2);
			} else if(box_width + position_left < x && box_height + position_top >= y) {
				postion_x = 30;
				postion_y = 15 - box_height;	
				var ecke = '<div style="position:absolute; left:-18px; bottom:0px; width:18px; height:18px;"><img src="/images/karte-box-ecke-l-u.gif" style="width:18px; height:18px;" alt="" /></div>';
				$(ecke).appendTo(box_2);
			} else {
				postion_x = 30;
				postion_y = 15;	
				var ecke = '<div style="position:absolute; left:-18px; top:-1px; width:18px; height:18px;"><img src="/images/karte-box-ecke-l-o.gif" style="width:18px; height:18px;" alt="" /></div>';
				$(ecke).appendTo(box_2);
			}
			
			$(this).find(".inhalt").css({'left':postion_x + 'px','top':postion_y + 'px'});
		});
		
		$(".karte .map_box").hover(
			function () {
				$(this).find(".inhalt").fadeIn(1000);
			},
			function () {
				$(this).find(".inhalt").fadeOut(1000);
			}
		);
		$('#ikarte').flash({swf:rel_pfad+'start.swf',height:430,width:609});
		
		/*Hintergrundbilder*/
	});	
}

$(document).ready(function(){
	$("body .bg_bild").each( function() {
		bg_anz += 1;
	});
	if (bg_anz>1) t=setTimeout("bg_rotate()",30000);
});


function bg_rotate() {
	next = (bg_pos<(bg_anz-1))? bg_pos+1 : 0;
	$(".bg_bild").eq(bg_pos).fadeOut(2000);
	$(".bg_bild").eq(next).fadeIn(2000);
	bg_pos = next;
	t=setTimeout("bg_rotate()",30000);
}

function getArgs(query) {
	var args = new Object();
	var pairs = query.split("&");
	for(var i = 0; i < pairs.length; i++) {
		var pos = pairs[i].indexOf('=');
		if (pos == -1) continue;
		var argname = pairs[i].substring(0,pos);
		var value = pairs[i].substring(pos+1);
		args[argname] = unescape(value);
	}
	return args;
} 


function ajaxloader() {
	$('a').click(function() {
		var l = $(this).attr("href");
		l = l.replace(/http:\/\/www.camping-am-schwielochsee.de/,"");
		var end_lang = l.match(/\/[a-z]{2}\/$/);
		var target = l.match(/^\/zaue\//);
		if (end_lang==null && target && $(this).attr("target")!='_blank') {
			$.ajax({
				type: 'GET',
				url: 'http://www.camping-am-schwielochsee.de'+l,
				dataType: 'html',
				success: function(data) {
					var tag_open = data.indexOf('<div id="wrapper_bg">')+22;
					var tag_close = data.lastIndexOf('</div>');
					var new_data = data.substring(tag_open, tag_close);
					window.location.hash = l;
					$('#wrapper_bg').html(new_data);
					
					load_functions();
				}
			});
			return false;
		}
	});
}

function redirect() {
	var h=window.location.hash;
	h = h.replace(/^#/,"");
	var target = h.match(/^\/zaue\//);
	
	if (target) {
		window.location.href='http://www.camping-am-schwielochsee.de'+h;
	}
}

AudioPlayer.setup("http://www.camping-am-schwielochsee.de/audio-player/player.swf", {
	width: 290,
	autostart: 'yes',
	loop: 'yes',
	initialvolume: 80,
	transparentpagebg: 'yes',
	bg: '1874a2',
	leftbg: '1874a2',
	lefticon: 'ffffff',
	rightbg: '05699b',
	rightbghover: '05699b',
	righticon: 'ffffff',
	righticonhover: 'bcd7e4',
	border: '05699b',
	skip: 'bcd7e4',
	voltrack: 'bcd7e4',
	volslider: 'ffffff',
	loader: 'bcd7e4',
	text: '05699b',
	track: 'ffffff',
	tracker: 'bcd7e4'
});
