$(document).ready(function() {

	if(($("#teaser-gallery > img").length) > 1) initializeGallery();


	$("#brochure-opener").click(function(){
    $('html,body').animate({scrollTop: '0px'}, 500, function() {
  	  
  		$('div#brochure-section > div.wrap').css('backgroundImage', 'url(/fileadmin/img/ajax-loader.gif)');
  		$("div#brochure-section").animate({
  			marginTop: "470px"
  		}, 500, 'linear', function(){ $("div#brochure-section > div.wrap").html('<iframe style="display:none;" onLoad="this.style.display = \'block\'; $(\'div#brochure-section > div.wrap\').css(\'backgroundImage\', \'none\');" src="/index.php?id=168" width="100%"  height="460" allowtransparency="true" frameborder="0" scrolling="auto" name="kontakt"><p>Ihr Browser kann leider keine eingebetteten Frames anzeigen</p></iframe>');} );
    });	
	});
		
	$("#contact-opener").click(function(){
    $('html,body').animate({scrollTop: '0px'}, 500, function() {
  		$('div#contact-section > div.wrap').css('backgroundImage', 'url(/fileadmin/img/ajax-loader.gif)');
  		$("div#contact-section").animate({
  			marginTop: "470px"
  		}, 500, 'linear', function(){ $("div#contact-section > div.wrap").html('<iframe style="display:none;" onLoad="this.style.display = \'block\'; $(\'div#contact-section > div.wrap\').css(\'backgroundImage\', \'none\');" src="/index.php?id=129" width="100%"  height="460" allowtransparency="true" frameborder="0" scrolling="auto" name="kontakt"><p>Ihr Browser kann leider keine eingebetteten Frames anzeigen</p></iframe>');} );
    });	
	});

	$("#booking-opener").click(function(){
    $('html,body').animate({scrollTop: '0px'}, 500, function() {
  		$('div#booking-section > div.wrap').css('backgroundImage', 'url(/fileadmin/img/ajax-loader.gif)');
  		$("div#booking-section").animate({
  			marginTop: "470px"
  		}, 500, 'linear', function(){$("div#booking-section > div.wrap").html('<iframe style="display:none; background-color:transparent;" onLoad="this.style.display = \'block\'; $(\'div#booking-section > div.wrap\').css(\'backgroundImage\', \'none\');" src="/index.php?id=152" width="100%"  height="460" allowtransparency="true" frameborder="0" scrolling="auto" name="booking"><p>Ihr Browser kann leider keine eingebetteten Frames anzeigen</p></iframe>');});
    });  		
	});
	
	$(".gift-opener").click(function(){
    $('html,body').animate({scrollTop: '0px'}, 500, function() {
      $('div#gift-section > div.wrap').css('backgroundImage', 'url(/fileadmin/img/ajax-loader.gif)');
      $("div#gift-section").animate({
        marginTop: "500px"
      }, 500, 'linear', function(){$("div#gift-section > div.wrap").html('<iframe style="display:none; background-color:transparent;" onLoad="this.style.display = \'block\'; $(\'div#gift-section > div.wrap\').css(\'backgroundImage\', \'none\');" src="/index.php?id=155" width="100%"  height="490" allowtransparency="true" frameborder="0" scrolling="auto" name="gift"><p>Ihr Browser kann leider keine eingebetteten Frames anzeigen</p></iframe>');} );
    });
	});	
	
	$("#brochure-closer").click(function(){
		$("div#brochure-section").animate({
			marginTop: "0px"
		}, 500);					
	});	
	
	$("#contact-closer").click(function(){
		$("div#contact-section").animate({
			marginTop: "0px"
		}, 500);					
	});
	
	$("#gift-closer").click(function(){
		$("div#gift-section").animate({
			marginTop: "0px"
		}, 500);					
	});
	
	$("#booking-closer").click(function(){
		$("div#booking-section").animate({
			marginTop: "0px"
		}, 500);					
	});
	
	
	
	
	$("#content-section .article .image-col a img").after("<span class='zoom-icon'></span>"); 
	
	
	 /*
    $("ul.partner-logos a[title]").tooltip({
    	tip: '#tooltip',
    	position: "top right",
    	offset: [10, -25]
    });
    
   $("area[title]").tooltip({
    	 tip: '#tooltip'
    });*/
	

	/* quickfix, handling flyout for brochure download, when getting a get-param */
	var params = window.location.search;
	if(params == '' ) return;
	params = params.substr(1, params.length);
	if(params == 'flyout=brochure') {
		$("#brochure-opener").click();
	}	
	
	
});



function hideTeaserBody() {
	$('#teaser-body').animate({ right: '-246px'}, 1000, function() {showTeaserGallery();});
}

function showTeaserBody() {
	$('#teaser-body').animate({ right: '0px'}, 1000, function() {showButtons();});
}

function hideTeaserGallery(){
	$('#teaser-gallery').css('visibility','hidden');
	// replace bg-image with active image from slideshow
	var activeIndex = $('#teaser-gallery').data('galleria').getData();
 	var activeImage = $('#teaser-gallery').data('galleria').getData(activeIndex );
	$('#teaser').css('background-image','url(' + activeImage.image + ')');
	if ($('#teaser-body').length) $('#teaser').animate({height: '300px'},1000, function() { showTeaserBody(); });
	else $('#teaser').animate({height: '300px'},1000, function() { showButtons(); });
}

function showTeaserGallery() {
	$('#teaser').animate({height: '500px'}, 1000, function() {
		$('#teaser-gallery').css('visibility','visible');
	});
}

function showButtons() {
	$('#teaser').append('<a id="video-play-icon" style=""></a>');
	$('#video-play-icon').click(function() {
		$("#video-play-icon").remove();
		//$('body').append('<div id="overlay"></div>');
		$('#teaser-gallery').append('<a id="close-video"></a>');
		$('#close-video').click(function() { closeGallery(); });
		
		// Start hiding sequence	
		if($('#teaser-body').length) hideTeaserBody();
		else showTeaserGallery();
	});	
}

function initializeGallery() {
	$('#teaser-gallery').galleria({
		width:980,
		height:500,
		transition: 'fade'
	});
	
	showButtons();
}


function closeGallery() {
	$('#close-video').remove();
	hideTeaserGallery();
}






function initializeVideo() {
	$('#teaser').addClass('video');
	$('#teaser').append('<a id="video-play-icon" ></a>');

	$('#teaser').click(function() {
		$('#teaser').unbind('click');
		$("#video-play-icon").hide();
		var position = $('#teaser').position();
		$('#teaser').append('<a id="close-video"></a>');
		$('#close-video').click(function() {closeVideo();});		

		$('#teaser').append('<div id="teaser-video" style="opacity:0; background-image: url(/fileadmin/videos/video_preview.jpg); position: absolute; left:0px; top:0px; z-index: 1000;"></div>');
		$('#teaser-body').animate({ right: '-246px'}, 1000, function() { showVideo(); });
	});
}

function showVideo(){
	$('#teaser-video').animate({
		opacity: '1'
	}, 1000, function(){
		$('#teaser-video,#teaser').animate({
			height: '552px'
		}, 1000, function(){
			var so = new SWFObject("/fileadmin/mediaplayer/mediaplayer.swf", "video_mediaplayer", "980", "552", "8");
			so.addParam("allowscriptaccess", "always");
			so.addParam("allowfullscreen", "true");
			so.addParam("wmode", "transparent");
			so.addVariable("skin", "/fileadmin/mediaplayer/skin.swf");
			so.addVariable("controlbar", "over");
			so.addVariable("file", "/fileadmin/videos/imagevideo_980_552.flv");
			so.addVariable('width', '980');
			so.addVariable('height', '552');
			so.addVariable('image', '/fileadmin/videos/video_preview.jpg');
			so.addVariable('showstop', 'true');
			so.addVariable('autostart', '1');
			so.addVariable('streching', 'none');
			
			so.write("teaser-video");
		});
	});
}

function closeVideo() {
	$('#teaser-video,#close-video').remove();
	$('#teaser').animate({height: '300px'},1000, function() {
		$('#teaser-body').animate({ right: '0px'}, 1000);
		initializeVideo();
	});
}
