$(document).ready(function() {
	
	// image for #bg loading function; different versions because implementation is diff. in browsers (fullscreen)
	if (!window.ie) {
		loadBackpic = function(newSrc) {
			$('body').css('background-image','url('+newSrc+')');
		}
	} else {
		var bg=$('#bg');
		bg.show();
		loadBackpic = function(newSrc) {
			
			var newImage = $('<img src="'+newSrc+'" />');
			newImage.addClass('bg');
			newImage.load(function() {
				$('#bg img').remove();
				$('#bg').append(newImage);
				var scale=Math.max(bg.width()/newImage.width(),bg.height()/newImage.height());
				newImage.css('width',parseInt(newImage.width()*scale)+"px");
				
			});
		}
	};
	
	clearBackpic = function() {
		loadBackpic('image/fond.png');
	};
	
	loadBackpic($('#bg img').attr('src'));
	
	jQuery("div.tabs").each(function(){

		var tabbox = jQuery(this);
		//Spätere Divs erstellen

		var buttons = jQuery("<div class='button'></div>");
		var contents = jQuery("<div class='tab-content'></div>");
		// Diese Divs ineinander verschachteln
		tabbox.append(buttons);
		tabbox.append(contents);
		//Check Variable erstellen              

		var first = true;
		//var maxheight = 0;
		var showContent = false;
		jQuery(".tab",tabbox).each(function(){
			//Button & Content finden
			var button = jQuery("h4",this)[0];
			var content = jQuery(".tabcontent",this)[0];

			//Alle Contents Ausblenden
			if(!first) {
				jQuery(button).addClass('inactive');
			} else {
				showContent=$(content);
				jQuery(button).addClass('active');
			};

			//Inhalte in neu erstellte Divs packen
			buttons.append(button);
			contents.append(content);
			//maxheight = Math.max(maxheight,contents.height());
			jQuery(content).hide();

			//Buttons
			jQuery(button).click(function(){

				// Alle Buttons ausnblenden
				jQuery("div.tab-content div.tabcontent", tabbox).hide();

				// Bilder Tauschen
				jQuery("h4", buttons).each(function(){
					jQuery(this).addClass("inactive");
				});

				// Click den richtigen Content einblenden
				jQuery(content).show();
				jQuery(this).removeClass('inactive');
			});

			// Hover für Inaktiven Link einstellen
			jQuery("a",button).hover(
				function(){
					var source = jQuery(this).css("background-image");
					jQuery(this).css("background-image",source.replace(/sidenav_i/,"sidenav_s"));                   
				}, 
				function(){
					var source = jQuery(this).css("background-image");
					jQuery(this).css("background-image",source.replace(/sidenav_s/,"sidenav_i"));   
				}
			);

			// Alle Nicht JS Ansicht Div Reste löschen
			jQuery(this).remove();

			// Ändern der Check Variable
			first = false;

		});
			
		showContent.show();
		//tabbox.css('height',maxheight+50);
	
	});
	
	
	jQuery('div.tx-sfarrangement-pi1 div.map').each(function() {
		
			if (window.pois) {
				
				var hotel=pois.shift();
				hotel.poi=new google.maps.LatLng(hotel.tx_sfgeoaddress_lat,hotel.tx_sfgeoaddress_lon);
				
				var map = new google.maps.Map(this,{
					center: hotel.poi,
					zoom: 12,
					mapTypeId: google.maps.MapTypeId.ROADMAP
				});

				marker = new google.maps.Marker({
					position: hotel.poi,
					map: map
				});
				
				var markers=[],m;
				for (var i=0;i<pois.length;i++) {
					poi = pois[i];
					
					m=new google.maps.Marker({
						position: new google.maps.LatLng(poi.tx_sfgeoaddress_lat,poi.tx_sfgeoaddress_lon),
						map: map
					});
					
					markers.push(m);
					
				};
				
			}


		
	});
	
	var galleryClasses={};
	var galleryClassesArray=[];
	jQuery("a.tx_sfgallery_pi1").each(function() {
		var myClass=jQuery(this).attr('rel');
		if (!galleryClasses[myClass]) {
			galleryClasses[myClass]=true;
			galleryClassesArray.push(myClass);
		};
	});

	for (var i=0;i<galleryClassesArray.length;i++) {
		jQuery("a[rel='"+galleryClassesArray[i]+"']").colorbox();
	};
	
	jQuery('ul.innerfade').innerfade();
	
	jQuery('#socialbuttons img').click(function() {
		$('#dialog').fadeIn();
	});
	
	jQuery('#dialog-closer img').click(function() {
		$('#dialog').fadeOut();
	});
	
	var tagCloudEnabler = function() {
		
		jQuery('div.tx-vgetagcloud-pi1').each(function() {
			
			var $=jQuery
			var cloud=$(this);
			var items=[];
			$('li',cloud).each(function() {
				var that=$(this);
				var href=$('a',that).attr('href');
				items.push(	new Tag(that.text(), parseInt(that[0].style.fontSize), href));
			});
			cloud.html("");
			if (items.length) new TagCloud(this,items, 300, 200, {radius: 70 }).Animate();
		})
	};
	
	tagCloudEnabler();
	
	$('#suche').each(function() {
		var s=$(this);
		s.data('init',s.val());
		s.focus(function() {
			if (s.val() == s.data('init')) s.val('');
		})
		
		s.blur(function() {
			if (s.val() == '') s.val=s.data('init');
		})
	})

});


