/*** 
    Simple jQuery Slideshow Script
    Released by Jon Raasch (jonraasch.com) under FreeBSD license: free to use or modify, not responsible for anything, etc.  Please link out to me if you like it :)
***/

function slideSwitch() {	
    var $active = $('#headerimages IMG.active');

    if ( $active.length == 0 ) $active = $('#headerimages IMG:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#headerimages IMG:first');

    // uncomment the 3 lines below to pull the images in random order
    
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
						$('.bullet img').attr("src", 'fileadmin/templates/img/bullet-inaktiv.png');
						ind = $('#headerimages IMG.active').index()+1;
						bullet = "#bullet" + ind + " img";
						$(bullet).attr("src", 'fileadmin/templates/img/bullet-aktiv.png');
        });
}

/* ############################ */
/* ### jQuery-Magic - start ### */
/* ############################ */

$(document).ready(function() {

/* ############################## */
/* ### document ready - start ### */
/* ############################## */

/* ---------------------------------- */
/* --- Slideshow - Fotos (by Bua) --- */
/* ---------------------------------- */

// keine slideshow am iPhone
var u = navigator.userAgent.toLowerCase();
var iphone = ((u.indexOf('iphone'))!=-1);
if (!iphone) {
	
	img_src = img_src.split(',');
	img_src.shift();
	
	var img_length = img_src.length - 1; // weil der string mit einem , aufhört
	for (var i = 0; i < img_length; ++i) {
		$('#headerimages').append('<img src="'+ img_src[i] +'" alt="" />');
	}
	
	if($('#headerimages').children().length > 1) {
		$(function() {
				slideInterval = setInterval( "slideSwitch()", 5000 );
		});
		$("#headerimages").after('<div id="slidshowControls"><span id="slidshowPrev"><a href="javascript:void(0);"><img alt="" src="fileadmin/templates/img/pfeil-links.png" /></a></span><span id="slidshowNext"><a href="javascript:void(0);"><img alt="" src="fileadmin/templates/img/pfeil-rechts.png" /></a></span></div>');
	} else {
		$('#slidshowControls').css({'visibility':'hidden'});
	}
	
	var i=0;
	var bullets="";
	for (i=0;i<$('#headerimages IMG').length;i++)
	{
		if(i==0) {
			bullets += '<span id="bullet' + (i+1) + '" class="bullet"><img src="fileadmin/templates/img/bullet-aktiv.png" alt="" /></span>';
		} else {
			bullets += '<span id="bullet' + (i+1) + '" class="bullet"><img src="fileadmin/templates/img/bullet-inaktiv.png" alt="" /></span>';
		}
	}
	$('#slidshowPrev').after(bullets);
	
	$('#slidshowNext').click(function(){
		var ind = $('#headerimages IMG.active').index() + 2;
		if(ind > $('#headerimages IMG').length) {
			ind = 1;
		}
		clearInterval(slideInterval);
		var $active = $('#headerimages IMG.active');
		$active.addClass('last-active');
		var $next = $('#headerimages IMG:nth-child(' + ind + ')');
		$next.css({opacity: 0.0})
			.addClass('active')
			.animate({opacity: 1.0}, 1000, function() {
					$active.removeClass('active last-active');
			});
		$('.bullet img').attr("src", 'fileadmin/templates/img/bullet-inaktiv.png');
		bullet = "#bullet" + ind + " img";
		$(bullet).attr("src", 'fileadmin/templates/img/bullet-aktiv.png');
		 
	});
	
	$('#slidshowPrev').click(function(){
		var ind = $('#headerimages IMG.active').index();
		if(ind < 1) {
			ind = $('#headerimages IMG').length
		}
		clearInterval(slideInterval);
		var $active = $('#headerimages IMG.active');
		$active.addClass('last-active');
		var $next = $('#headerimages IMG:nth-child(' + ind + ')');
		$next.css({opacity: 0.0})
			.addClass('active')

			.animate({opacity: 1.0}, 1000, function() {
					$active.removeClass('active last-active');
			});
		$('.bullet img').attr("src", 'fileadmin/templates/img/bullet-inaktiv.png');
		bullet = "#bullet" + ind + " img";
		$(bullet).attr("src", 'fileadmin/templates/img/bullet-aktiv.png');
		 
	});

}

if (iphone) {
	$('#slidshowControls').css({'visibility':'hidden'});
	$('#col3 #pauschalen dl').css('background','#A01D2F');
	$('body.home #footer').css('display','none');
}

$mainHeight = $('#main').css("height");
$('#hg-w').css("height", $mainHeight);

/* ----------------------- */
/* --- anfrageformular --- */
/* ----------------------- */

$("#zimmerinfo_1").children().hide();
$("#platzhalter_1").show();
$("#zimmerinfo_2").children().hide();
$("#platzhalter_2").show();
$("#zimmerinfo_3").children().hide();
$("#platzhalter_3").show();
$("#zimmerinfo_4").children().hide();
$("#platzhalter_4").show();
$("#zimmertyp_1").change(function(){
					$("#zimmerinfo_1").children().hide();
					$("#" + this.value + "_1").show();
					if(this.value == "") {
						$("#platzhalter_1").show();
					}
			});
$("#zimmertyp_2").change(function(){
					$("#zimmerinfo_2").children().hide();
					$("#" + this.value + "_2").show();
					if(this.value == "") {
						$("#platzhalter_2").show();
					}
			});
$("#zimmertyp_3").change(function(){
					$("#zimmerinfo_3").children().hide();
					$("#" + this.value + "_3").show();
					if(this.value == "") {
						$("#platzhalter_3").show();
					}
			});
$("#zimmertyp_4").change(function(){
					$("#zimmerinfo_4").children().hide();
					$("#" + this.value + "_4").show();
					if(this.value == "") {
						$("#platzhalter_4").show();
					}
});

var zimmertyp = $("h1").text();

zimmertyp = zimmertyp.split(" ").join("-");
zimmertyp = zimmertyp.split('"').join("");
zimmertyp = zimmertyp.split('ü').join("ue");
zimmertyp = zimmertyp.split('ä').join("ae");
zimmertyp = zimmertyp.split('ö').join("oe");

var pauschale = $("h1").text();

pauschale = pauschale.split(" ").join("-");


$("#quickanfrage #zimmertyp_1").val(zimmertyp);

var newsuid = $("#newsuid").text();
if(newsuid) {
	$("#quickanfrage #book").val(newsuid);
}

/* ############################# */
/* ### document ready - ende ### */
/* ############################# */

})

/* ########################## */
/* ### jQuery-Magic - end ### */
/* ########################## */

