$(document).ready(function(){

$("#topslider").slinkySlider({
	numberofpanels		:	4,	// number of panels to load
	smallsize		:	230,	// size in pixels of collapsed panel
	transition		:	500, 	// time in milliseconds for transition
	doauto			:	true,	// automatic timed animation? true/false
	autotimer		:	4000,	// time between automatic animations
	panelspacing		:	8,	// gap between collapsed panels
	panelname		:	"/panel"	// sets the HTML filename (means filename will be "panel[x].html")
});

$('span.email').nospam({
      replaceText: true,    // BOOLEAN, optional default false. If set to true, replaces matched elements' text with the e-mail address
      filterLevel: 'low' // STRING, optional accepts 'low' or 'normal', default 'normal'.
                            // low: email/domain/tld
                            // normal: dlt/niamod/liame (email/domain/tld reversed)
});

$('span.red').nospam({
      replaceText: true,    // BOOLEAN, optional default false. If set to true, replaces matched elements' text with the e-mail address
      filterLevel: 'low' // STRING, optional accepts 'low' or 'normal', default 'normal'.
                            // low: email/domain/tld
                            // normal: dlt/niamod/liame (email/domain/tld reversed)
});

$('.bottom_left span').niceTitles();

$("#tabset").buildMbTabset({
	stop:function(){if ($("#array").is(":checked")) alert($.mbTabset.mbTabsetArray)},
	sortable:false
});

$(".menu").jyaddm();

$('#jobs_scroll').galleryView({
	filmstrip_size: 4,
	frame_width: 175,
	frame_height: 135,
	background_color: 'transparent',
	nav_theme: 'jobs',
	border: 'none',
	show_captions: false,
	caption_text_color: 'black',
	transition_speed: 400,
	transition_interval: 2000
});


$("a.group").fancybox({ 'zoomSpeedIn': 300, 'zoomSpeedOut': 300, 'overlayShow': false }); 

$('dl').fademenu();

$('#date').calendar({dateFormat: '%d.%m.%Y'});
$('#arrival').calendar({dateFormat: '%d.%m.%Y'});
$('#departure').calendar({dateFormat: '%d.%m.%Y'});
$('#when').calendar({dateFormat: '%d.%m.%Y'});

$(".booking").toggle(function(){
						 if(document.getElementById(this.rel).style.display == "block"){
						 	$("#" + this.rel).slideUp(1000); 
						 	this.innerHTML = "hier klicken";
						 	return
						 	};
					 	this.innerHTML = "schlie&szlig;en";
				    $("#" + this.rel).slideDown(1000);
				  },function(){
						if(document.getElementById(this.rel).style.display == "none"){
							$("#" + this.rel).slideDown(1000);
							this.innerHTML = "schlie&szlig;en";
							return
						};
						this.innerHTML = "hier klicken";
				    $("#" + this.rel).slideUp(1000);
  			});
			
$(".link").toggle(function(){
						 if(document.getElementById(this.rel).style.display == "block"){
						 	$("#" + this.rel).slideUp(1000); 
						 	this.innerHTML = "Hier klicken!";
						 	return
						 	};
					 	this.innerHTML = "Schlie&szlig;en!";
						document.getElementById(this.rel+"_title").style.color ="#000000";
						document.getElementById(this.rel+"_text").style.color ="#000000";
				    $("#" + this.rel).slideDown(1000);
				  },function(){
						if(document.getElementById(this.rel).style.display == "none"){
							$("#" + this.rel).slideDown(1000);
							this.innerHTML = "Schlie&szlig;en!";
							return
						};
						this.innerHTML = "Hier klicken!";
						document.getElementById(this.rel+"_title").style.color ="#3F75CD";
						document.getElementById(this.rel+"_text").style.color ="#3F75CD";
				    $("#" + this.rel).slideUp(1000);
  			});			

$(".toggleBtn").toggle(function(){
						 if(document.getElementById(this.rel).style.display == "block"){
						 	$("#" + this.rel).slideUp(500); 
						 	this.innerHTML = "+";
						 	return
						 	};
					 	this.innerHTML = "-";
				    $("#" + this.rel).slideDown(500);
				  },function(){
						if(document.getElementById(this.rel).style.display == "none"){
							$("#" + this.rel).slideDown(500);
							this.innerHTML = "-";
							return
						};
						this.innerHTML = "+";
				    $("#" + this.rel).slideUp(500);
  			});
  
	$(".toggleBtn_red").toggle(function(){
						 if(document.getElementById(this.rel).style.display == "block"){
						 	$("#" + this.rel).slideUp(500); 
						 	this.innerHTML = "+";
						 	return
						 	};
					 	this.innerHTML = "-";
				    $("#" + this.rel).slideDown(500);
				  },function(){
						if(document.getElementById(this.rel).style.display == "none"){
							$("#" + this.rel).slideDown(500);
							this.innerHTML = "-";
							return
						};
						this.innerHTML = "+";
				    $("#" + this.rel).slideUp(500);
  			});
			
	$(".geschmacksrichtungen").toggle(function(){
						 if(document.getElementById(this.rel).style.display == "block"){
						 	$("#" + this.rel).slideUp(500); 
						 	this.innerHTML = "Weitere Geschmacksrichtungen anzeigen...";
						 	return
						 	};
					 	this.innerHTML = "";
				    $("#" + this.rel).slideDown(500);
				  },function(){
						if(document.getElementById(this.rel).style.display == "none"){
							$("#" + this.rel).slideDown(500);
							this.innerHTML = "";
							return
						};
						this.innerHTML = "Weitere Geschmacksrichtungen anzeigen...";
				    $("#" + this.rel).slideUp(500);
  			});			
			
//clickMenu('gallery');			
  
  $('div.faq> div.news_text').hide(); 
  $('div.faq> div.news_header > div.news_header_title').click(function() {
          $(this).parent().next('div.news_text:hidden').slideDown('fast')
          .siblings('div.news_text:visible').slideUp('fast');
        });

                var myClose = function(hash){
                    hash.w.fadeOut('3000', function(){
                        hash.o.remove();
                    });
                };
                var openInIframe = function(hash){
                    var newWidth = 0, newHeight = 0, newLeft = 0, newTop = 0;
                    var $trigger = $(hash.t);
                    var $modal = $(hash.w);
                    var myUrl = $trigger.attr('href');
                    var myTitle = $trigger.attr('title');
                    var $modalContent = $("iframe", $modal);
                    
                    $modalContent.html('').attr('src', myUrl);
                    //let's use the anchor "title" attribute as modal window title
                    $('#jqmTitleText').text(myTitle);
                    
                    myUrl = (myUrl.lastIndexOf("#") > -1) ? myUrl.slice(0, myUrl.lastIndexOf("#")) : myUrl;
                    var queryString = (myUrl.indexOf("?") > -1) ? myUrl.substr(myUrl.indexOf("?") + 1) : null;
                    
                    if (queryString != null && typeof queryString != 'undefined') {
                        var queryVarsArray = queryString.split("&");
                        for (var i = 0; i < queryVarsArray.length; i++) {
                            if (unescape(queryVarsArray[i].split("=")[0]) == 'width') {
                                var newWidth = queryVarsArray[i].split("=")[1];
                            }
                            if (escape(unescape(queryVarsArray[i].split("=")[0])) == 'height') {
                                var newHeight = queryVarsArray[i].split("=")[1];
                            }
                        }
                        // let's run through all possible values: 90%, nothing or a value in pixel
                        if (newHeight != 0) {
                            if (newHeight.indexOf('%') > -1) {
                                newHeight = Math.floor(parseInt($(window).height()) * (parseInt(newHeight) / 100));
                            }
                            var newTop = Math.floor(parseInt($(window).height() - newHeight) / 2);
                        }
                        else {
                            newHeight = $modal.height();
                        }
                        if (newWidth != 0) {
                            if (newWidth.indexOf('%') > -1) {
                                newWidth = Math.floor(parseInt($(window).width() / 100) * parseInt(newWidth));
                            }
                            var newLeft = Math.floor(parseInt($(window).width() / 2) - parseInt(newWidth) / 2);
                            
                        }
                        else {
                            newWidth = $modal.width();
                        }
                        // do the animation so that the windows stays on center of screen despite resizing
                        $modal.jqmShow().animate({
                            width: 730,
							//width: newWidth
							//height: newHeight
                            height: 560,
							top: 5,
                            //top: newTop,
                            left: newLeft,
                            marginLeft: 0
                        }, 2000);
                    }
                    
                    else {
                        // don't do animations
                        $modal.jqmShow();
                    }
                }
	  
	  // Close Button Highlighting. IE doesn't support :hover. Surprise?
	  $('input.jqmdX')
	  .hover(
	    function(){ $(this).addClass('jqmdXFocus'); }, 
	    function(){ $(this).removeClass('jqmdXFocus'); })
	  .focus( 
	    function(){ this.hideFocus=true; $(this).addClass('jqmdXFocus'); })
	  .blur( 
	    function(){ $(this).removeClass('jqmdXFocus'); });

			
    $("a.navilink").click(function () {
		var elementn = $(this).attr("rel") + '_navi';
		var visn = document.getElementById(elementn).style.display;
		$('div.hidden > div:visible').slideUp(500);
		if(visn == '' || visn == 'none') $("#" + elementn).slideToggle("slow");
    });

	$('span.link').click(function() {
				  var element = $(this).attr("rel") + '_content';
				  var vis = document.getElementById(element).style.display;
				  $('div.hidden > div:visible').hide();
				  if(vis == '' || vis == 'none')  $('#' + element).show();
   			});
			
//thickbox replacement
    var closeModal = function(hash)
    {
        var $modalWindow = $(hash.w);

        //$('#jqmContent').attr('src', 'blank.html');
        $modalWindow.fadeOut('2000', function()
        {
            hash.o.remove();
            //refresh parent

            if (hash.refreshAfterClose === 'true')
            {

                window.location.href = document.location.href;
            }
        });
    };
    var openInFrame = function(hash)
    {
        var $trigger = $(hash.t);
        var $modalWindow = $(hash.w);
        var $modalContainer = $('iframe', $modalWindow);
        var myUrl = $trigger.attr('href');
        var myTitle = $trigger.attr('title');
        var newWidth = 0, newHeight = 0, newLeft = 0, newTop = 0;
        $modalContainer.html('').attr('src', myUrl);
        $('#jqmTitleText').text(myTitle);
        myUrl = (myUrl.lastIndexOf("#") > -1) ? myUrl.slice(0, myUrl.lastIndexOf("#")) : myUrl;
        var queryString = (myUrl.indexOf("?") > -1) ? myUrl.substr(myUrl.indexOf("?") + 1) : null;

        if (queryString != null && typeof queryString != 'undefined')
        {
            var queryVarsArray = queryString.split("&");
            for (var i = 0; i < queryVarsArray.length; i++)
            {
                if (unescape(queryVarsArray[i].split("=")[0]) == 'width')
                {
                    var newWidth = queryVarsArray[i].split("=")[1];
                }
                if (escape(unescape(queryVarsArray[i].split("=")[0])) == 'height')
                {
                    var newHeight = queryVarsArray[i].split("=")[1];
                }
                if (escape(unescape(queryVarsArray[i].split("=")[0])) == 'jqmRefresh')
                {
                    // if true, launches a "refresh parent window" order after the modal is closed.

                    hash.refreshAfterClose = queryVarsArray[i].split("=")[1]
                } else
                {

                    hash.refreshAfterClose = false;
                }
            }
            // let's run through all possible values: 90%, nothing or a value in pixel
            if (newHeight != 0)
            {
                if (newHeight.indexOf('%') > -1)
                {

                    newHeight = Math.floor(parseInt($(window).height()) * (parseInt(newHeight) / 100));

                }
                var newTop = Math.floor(parseInt($(window).height() - newHeight) / 2);
            }
            else
            {
                newHeight = $modalWindow.height();
            }
            if (newWidth != 0)
            {
                if (newWidth.indexOf('%') > -1)
                {
                    newWidth = Math.floor(parseInt($(window).width() / 100) * parseInt(newWidth));
                }
                var newLeft = Math.floor(parseInt($(window).width() / 2) - parseInt(newWidth) / 2);

            }
            else
            {
                newWidth = $modalWindow.width();
            }

            // do the animation so that the windows stays on center of screen despite resizing
            $modalWindow.css({
                width: newWidth,
                height: newHeight,
                opacity: 0
            }).jqmShow().animate({
                width: newWidth,
                height: newHeight,
                top: 10,
                left: newLeft,
                marginLeft: 0,
                opacity: 1
            }, 'slow');
        }
        else
        {
            // don't do animations
            $modalWindow.jqmShow();
        }

    }

    $('#modalWindow').jqm({
        overlay: 95,
        modal: true,
        trigger: '',
        target: '#jqmContent',
        onHide: closeModal,
        onShow: openInFrame
    });
			
});

