
		
jQuery.noConflict();
jQuery(document).ready(function($)
{	
	/* globals */
	var msie = $.browser.msie;
	
	/* page preload */
	$(window).load(function() {
		$("body").css("overflow","auto");
		if( ($.browser.mozilla == true && $.browser.version.slice(0,1) > 1) || $.browser.webkit == true ) $("body").css("overflow-y","scroll");
		$("#wrapper").css("visibility","visible");
		$("body").css("background-image","none");
	});
	
	
	/* fancybox: settings >> */
	
	/* in progress-popup >> */
	if( $("a#hb-start").length > 0 )
	{
		$("a#hb-start").fancybox({
			'hideOnContentClick': true,
			'autoDimensions': false,
			'width': 500,
			'height': 390
		});
		if( hasVisited == false ) $("a#hb-start").trigger('click');
	}
	/* << in progress-popup ende */
	
	if( $("a#hb-login").length > 0 ) $("a#hb-login").fancybox({});
	
	if( $("a[rel=media_group]").length > 0 ) 
	{
		$("a[rel=media_group]").fancybox({
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'titlePosition' 	: 'over',
			'centerOnScroll'	: true,
			'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
				return '<span id="fancybox-title-over">' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
			}
		});
	}
	
	if( $("a[rel=presse_group]").length > 0 ) 
	{		
		$("a[rel=presse_group]").fancybox({
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'titlePosition' 	: 'over',
			'centerOnScroll'	: true,
			'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
				return '<span id="fancybox-title-over">' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
			}
		});
	}
	
	if( $("a[rel=text_bild]").length > 0 ) 
	{		
		$("a[rel=text_bild]").fancybox({
			'titlePosition' 	: 'over',
			'centerOnScroll'	: true,
			'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
				return '<span id="fancybox-title-over">' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
			}
		});
	}
	
	if( $("a.video-ajax-call").length > 0 ) 
	{		
		$("a.video-ajax-call").fancybox({
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'centerOnScroll'	: true
		});
	}
	
	if( $(".container-central-section-media-bilder-item").length > 0 )
	{
		var media = 0;
		
		$(".container-central-section-media-bilder-item").each(function(){
			
			$(this).find("a").attr("rel", "media_" +  media );
			
			if( $("a[media_" +  media + "]").length > 0 ) 
			{
				$("a[media_" +  media + "]").fancybox({
					'titlePosition' 	: 'over',
					'centerOnScroll'	: true,
					'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
						return '<span id="fancybox-title-over">' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
					}
				});
			}
			
			media++;
		});
	}
	
	
	
	
	/* << fancybox: settings ende */
	
	/* media settings start */
	if( $('a.person-media').length > 0 ) $('a.person-media').media( {
		width:		300,
		height:		24,
		mp3Player:	HB_BASE+'/'+HB_TEMP+'/js/media/mediaplayer.swf'
	});
	/* media settings ende */
	
	if( $(".container-central-spielplan-events").length > 0 ) 
	{		
		$( ".container-central-spielplan-events" ).hoverIntent(function(){
			$(this).addClass("container-central-spielplan-events-hover");
		}, function(){
			$(this).removeClass("container-central-spielplan-events-hover");
		});
		
		$( ".container-central-spielplan-events" ).click(function(){
			if($(this).find(".container-central-spielplan-events-weiter").length > 0){
				var url = $(this).find(".container-central-spielplan-events-weiter").attr("href");
				window.location.href = url;
			}
		});
	}
	
	if( $(".container-central-section-besetzung-link").length > 0 ) 
	{
		$( ".container-central-section-besetzung-link" ).click(function(){
			if( $(this).next().is(":hidden") ) { $(this).html("Weitere&nbsp;Besetzungen&nbsp;verbergen"); $(this).next().slideDown(900); }
			else { $(this).next().slideUp(); $(this).html("Weitere&nbsp;Besetzungen&nbsp;zeigen"); }
			return false;
		});
	}
	
	if( $(".container-central-section-termine-link").length > 0 ) 
	{
		$( ".container-central-section-termine-link" ).click(function(){
			if( $(this).next().is(":hidden") ) { $(this).html("Termine&nbsp;verbergen"); $(this).next().slideDown(900); }
			else { $(this).next().slideUp(); $(this).html("Termine&nbsp;anzeigen"); }
			return false;
		});
	}	
	
	if( $(".container-central-tree h5").length > 0 ) 
	{
		$(".container-central-tree h5").append('&nbsp;<img src="'+HB_BASE+'/'+HB_TEMP+'/images/hb-arrow-next-icon.gif" alt="" title="" />');
		
		$( ".container-central-tree h5" ).click(function(){
			if( $(this).next().is(":hidden") ) {
				$(this).next().slideDown();
				$(this).find("img").attr("src",HB_BASE+'/'+HB_TEMP+'/images/hb-arrow-current-icon.gif');
				$(this).addClass("container-central-tree-selected");  }
			else {
				$(this).next().slideUp();
				$(this).removeClass("container-central-tree-selected");	
				$(this).find("img").attr("src",HB_BASE+'/'+HB_TEMP+'/images/hb-arrow-next-icon.gif');
			}
			return false;
		});
	}
		
	if( $("h5").length > 0 ) 
	{
		$(".orchester-tree").next(".container-central-tree-categories").slideDown();
		$(".orchester-tree").find("img").attr("src",HB_BASE+'/'+HB_TEMP+'/images/hb-arrow-current-icon.gif');
		$(".orchester-tree").addClass("container-central-tree-selected");
	}
	
	if( $(".container-central-tree-list > strong").length > 0 ) 
	{
		$(".container-central-tree-list > strong").append('&nbsp;<img src="'+HB_BASE+'/'+HB_TEMP+'/images/hb-arrow-next-icon-small.gif" alt="" title="" />');
		
		$( ".container-central-tree-list > strong" ).click(function(){
			if( $(this).next().is(":hidden") ) {
				$(this).next().slideDown();
				$(this).find("img").attr("src",HB_BASE+'/'+HB_TEMP+'/images/hb-arrow-current-icon-small.gif');
				$(this).addClass("container-central-tree-selected");
			}
			else {
				$(this).next().slideUp();
				$(this).find("img").attr("src",HB_BASE+'/'+HB_TEMP+'/images/hb-arrow-next-icon-small.gif');
				$(this).removeClass("container-central-tree-selected");
			}
			return false;
		});
	}	
	
	if( $(".container-central-tree-items").length > 0 ) 
	{
		if(!msie){
			$(".container-central-tree-items").removeClass("clearfix");
			$(".container-central-tree-items").append("<div class='clear'></div>");
		}
	}
	
	if( $(".container-central-tree-categories").length > 0 ) 
	{
		var ankor = document.URL.split("#")[1];
		if( ankor ) {
			$(".container-central-tree-categories").each(function(){
				var treeSelected = $(this).find("#tree"+ankor);
				if( treeSelected.length > 0 )
				{
					$(this).show();
					$(this).prev().addClass("container-central-tree-selected");
					if( $(this).prev().is("h5") ) $(this).prev().find("img").attr("src",HB_BASE+'/'+HB_TEMP+'/images/hb-arrow-current-icon.gif');
					else if( $(this).prev().is("strong") ) $(this).prev().find("img").attr("src",HB_BASE+'/'+HB_TEMP+'/images/hb-arrow-current-icon-small.gif');
				}
			});
		}
	}
	
	
	$('#Form_filter_sparte').change(function() { $('#Form_filter_sparte').submit(); });
	$('#Form_filter_spielstaette').change(function() { $('#Form_filter_spielstaette').submit(); });
	$('#Form_filter_produktion').change(function() { $('#Form_filter_produktion').submit(); });
	$('#Form_filter_festival').change(function() { $('#Form_filter_festival').submit(); });
	$('#Form_filter_alter').change(function() { $('#Form_filter_alter').submit(); });
	
	$("#searchbox a").click(function(){
		
		if( !$.browser.safari )
		{
			$("#searchfield").css("width","60px");
			$("#searchfield").animate({ width: "+=50" });
			$("#header-navigation-footer a").animate({ paddingLeft: "-=5", paddingRight: "-=5" });
		}
		
		$(this).css("display","none");
		$("#searchform").css("display","inline");
		$("#searchfield").focus();
		return false;
	});

	$("#searchfield").blur(function(){
		setTimeout(function(){
			if( !$.browser.safari )
			{
				$("#searchfield").animate({ width: "-=50" });
				$("#header-navigation-footer a").animate({ paddingLeft: "+=5", paddingRight: "+=5" });
			} 
			$("#searchform").css("display","none");
			$("#searchbox a").css("display","block");
			return false;
		}, 200);
	});
	
	if( $("#searchres").length > 0 )
	{
		var filters = new Array();
		var filter = "";
		var other = "Andere";
		
		$(".container-central-search").each(function(){
			
			if( $(this).find("h6").length > 0 )
				var idString = $(this).find("h6").html();
			else
				var idString = other;
				
			$(this).addClass( idString.toLowerCase().replace(" ","") );
			filters.push(idString)
		});
		
		function sort_unique(arr) {
			arr = arr.sort();
			var ret = [arr[0]];
			for (var i = 1; i < arr.length; i++) {
				// start loop at 1 as element 0 can never be a duplicate
				if (arr[i-1] !== arr[i]) {
					ret.push(arr[i]);
				}
			}
			return ret;
		}
		
		filters = sort_unique(filters);
		
		var isOther = $.inArray(other, filters);
		if( isOther != -1) 
		{
			filters.splice(isOther,1);
			filters.push(other);
		}
		
		
		if(filters.length > 0)
		{
			filter += '<img width="9" height="8" title="" alt="" src="'+HB_BASE+'/'+HB_TEMP+'/images/hb-submenue-arrow.gif" />&nbsp;<a id="show-search-filters" href="#">Suche eingrenzen</a>';
			filter += '<div id="search-filter-items" >';
			for(var i=0;i<filters.length;i++)
			{
				filter += '<input type="checkbox" value="'+filters[i].toLowerCase()+'" checked="checked" /> ' + filters[i] + '<br />';
			}
			filter += '</div>';
			$(".container-central-search-filter-cases").append(filter);
			$("#search-filter-items").hide();
			$("#show-search-filters").click(function(){
				if($("#search-filter-items").is(":visible")) $("#search-filter-items").slideUp();
				else $("#search-filter-items").slideDown();
				return false;
			});
			$("#search-filter-items :checkbox").click(function(){
				
				var className = "." + $.trim($(this).val());
				if( $(this).is(":checked") )
				{
					$( className ).animate({ opacity: 1 },"fast");
					$( className ).slideDown("slow");
				}
				else
				{
					$( className ).animate({ opacity: 0 },"fast");
					$( className ).slideUp("slow");
				}
			});
		}
		
		
		//alert(filter);
	}
	
	/* sparten scripte */
	
	if( $("#header-navigation-sparten").length > 0 )
	{
		if( msie && (navigator.userAgent.indexOf("Trident/5") == -1) && ($.browser.version < 8) ) {
		/* lt ie8 detection */
   					
   					
			var spartenHover = false;
			$( "#header-navigation-sparten span ul li" ).each(function(){
				var li_w = $( this).width();
				var li_h = $( this ).height() + 5;
				$( this ).find("a").after('<p style="position:absolute; z-index:11; margin:0 0 0 -'+li_w+'px; width:'+li_w+'px; height:'+li_h+'px; background:#fff;"></p>');
			});
			$( "#header-navigation-sparten-btn" ).hoverIntent(function() {
				spartenHover = true;
			}, function(){
				spartenHover = false;
			});
			$( "#header-navigation-sparten span" ).hoverIntent(function() {
				if(spartenHover == true) {
					$( "#header-navigation-sparten span ul li p" ).each(function(){
						$( this ).fadeOut(400);
					});
				}
			},
			function(){
				$( "#header-navigation-sparten span ul li p" ).each(function(){ $( this ).fadeIn(500); });
				spartenHover = false;
			});
		} else {
			$( "#header-navigation-sparten ul" ).hide();
			$( "#header-navigation-sparten span" ).hoverIntent(function() {
				$( "#header-navigation-sparten ul" ).fadeIn(400);
			},
			function(){
				$( "#header-navigation-sparten ul" ).fadeOut(500);
			});
		}
		$("#header-navigation-sparten-btn").click(function(){ return false; });
	}
	
		 
	/* sparten scripte ende */
	/* menue pulldown scripte */
	
	if( $( "#header-navigation-menue-list").length > 0 )
	{
		$( "#header-navigation-menue-list ul" ).hover(function(){
			$(this).prev("a.firstrow").addClass("firstrow-active");
		}, function(){
			$(this).prev("a.firstrow").removeClass("firstrow-active");
		});
		
		$( "#header-navigation-menue-list > li" ).hover(function(){
			if( $(this).children().length == 1 ) $(this).addClass("without-dropdown");
		},function(){
			if( $(this).children().length == 1 ) $(this).removeClass("without-dropdown");
		});
	}
		
	/* menue pulldown scripte ende */
	/* form scripte  */
	
	if( $("form").length > 0 )
	{
	
		var inputVal = "";
		$("form ul input, form ul textarea").focus(function(){
			inputVal = $(this).attr("value");
			$(this).attr("value","");
		});
		
		$("form ul input, form ul textarea").blur(function(){
			if($(this).attr("value") == "") $(this).attr("value",inputVal);
			inputVal = "";
		});
		
		
		var inputVals = [];
		var textareaVals = [];
		var isError = false;
		$(function(){ $("form ul input").each(function(){ inputVals.push( $(this).attr("value") ); }) });
		$(function(){ $("form ul textarea").each(function(){ textareaVals.push( $(this).val() ); }) });
		
		$("#Form_ContactForm_action_SendContactForm, #Form_PresseloginForm_action_SendPresseloginForm, #Form_DownloadloginForm_action_SendDownloadloginForm").click(function(){
			
			var formID = $(this).parent().attr("id");
			isError = false;
			
			$("form#" + formID + " ul input").each(function(index){ 
				if( $(this).hasClass("form-error") ) $(this).removeClass("form-error");
				var value = $(this).attr("value");
				if( value == "" || value == inputVals[index] ){ $(this).addClass("form-error"); isError = true; }
			});
			
			if(formID == 'Form_ContactForm_action_SendContactForm') {
				$("form#" + formID + " ul textarea").each(function(index){ 
					if( $(this).hasClass("form-error") ) $(this).removeClass("form-error"); 
					var value = $(this).val();
					if( value == "" || value == textareaVals[index] ){ $(this).addClass("form-error"); isError = true; }
				});
			}
			
			if( $("#" + formID + "_Email").length > 0 && $("#" + formID + "_Email2").length > 0 ) { 
				compareMails ( $("#" + formID + "_Email"), $("#" + formID + "_Email2") );
			}
			else if( $("#" + formID + "_Email").length > 0 ) {
				detectMail ( $("#" + formID + "_Email") );
			}
			
			if(isError == true){ return false; } 
		});
		
	}
	
	function compareMails (e1,e2)
	{
		if( e1.attr("value").search('@') == -1){ e1.addClass("form-error"); isError = true; }
		if( e1.attr("value").search('.') == -1){ e1.addClass("form-error"); isError = true; }
		if( e2.attr("value").search('@') == -1){ e2.addClass("form-error"); isError = true; }
		if( e2.attr("value").search('.') == -1){ e2.addClass("form-error"); isError = true; }
		if( e1.attr("value") != e2.attr("value") ){ e2.addClass("form-error"); isError = true; }
	}
	
	function detectMail (e1)
	{
		if( e1.attr("value").search('.') == -1){ e1.addClass("form-error"); isError = true; }
		if( e1.attr("value").search('@') == -1){ e1.addClass("form-error"); isError = true; }
	}
		
	/* form scripte ende */

	/* start carousel */
	$('.rummel-carousel').jcarousel({
		start:  $( ".rummel-carousel li" ).length,
    	wrap: 'circular',
    	auto: 3,
    	scroll: 1,
    	animation: 1800,
    	itemLoadCallback: itemLoadCallbackCarousel,
    	initCallback: initCallbackCarousel
    });
    
    function itemLoadCallbackCarousel(carousel)
	{		
	    $( "#rummel" ).css("overflow","visible");
	    $( ".rummel-carousel li:empty" ).remove();
	    
		$( ".jcarousel-prev-horizontal,.jcarousel-next-horizontal" ).appendTo('#rummel');
		
		if(msie){
			$('.jcarousel-prev,.jcarousel-next').hover(function(){
				$(this).css('background-position','-53px 0');
			},function(){
				$(this).css('background-position','0 0');
			});
		}
	};
	
	function initCallbackCarousel(carousel)
	{
		// Disable autoscrolling if the user clicks the prev or next button.
		carousel.buttonNext.bind('click', function() {
			carousel.startAuto(0);
		});
		carousel.buttonPrev.bind('click', function() {
			carousel.startAuto(0);
		});
		// Pause autoscrolling if the user moves with the cursor over the clip.
		carousel.clip.hover(function() {
			carousel.stopAuto();
		}, function() {
			carousel.startAuto();
		});
		
		$( ".rummel-carousel li" ).each(function(){
			
			if( $(this).find("a").length > 0 )
			{
				var url = $(this).find("a").attr("href");
				$(this).click(function(){
					window.location.href = url;
				});
				
				$(this).hover(function(){
					$(this).css({
							"cursor" 		: "pointer"
					});
				}, function(){
					$(this).css({
							"cursor" 		: "default"
					});
				});
			}
		});
	};
	
	
	/* carousel ende */
	/* startseite drop down start */
	
	if( $(".container-central-news-feed-item").length > 0 )
	{
		var txtObj = ".container-central-news-feed-item-text";
		var plusObj = ".container-central-news-feed-item-textplus";
		
		$(txtObj).each(function(){
			
			var item = $(this);
			var startH = item.height();
			var openH = Math.round( item.css("line-height").replace("px","") );
			
			
			if( item.css("height").replace("px","") > openH )
			{
				item.css("height", openH+"px" );
				item.next(plusObj).append('<a href="#" class="nohover"><img src="'+HB_BASE+'/'+HB_TEMP+'/images/hb-arrow-next-icon-small.gif" alt="" title="" /></a>');
				
				item.parent().hover(function(){
					$(this).css({
							"cursor" 		: "pointer"
					});
				}, function(){
					$(this).css({
							"cursor" 		: "default"
					});
				});
				
				item.parent().click(function(){
					if( item.height() == openH ) {
						item.animate({ height: startH+"px" },'slow', function(){ 
							item.next(plusObj).find("img").attr("src", HB_BASE+'/'+HB_TEMP+'/images/hb-arrow-min-icon-small.gif');
						});
					} else {
						item.animate({ height: openH+"px" },'slow', function(){ 
							item.next(plusObj).find("img").attr("src", HB_BASE+'/'+HB_TEMP+'/images/hb-arrow-next-icon-small.gif');
						});
					}
				});
			}	
		});
	}
	
	/* startseite drop down ende */
	/* sparten drop down start */
	
	if( $(".container-central-sparte").length > 0 )
	{
		var item = $(".container-central-sparte-teaser-text");
		var startH = item.height();
		var openH = 6 * Math.round( item.css("line-height").replace("px","") );
		var scrollTime = 500;
		
		if( item.css("height").replace("px","") > openH )
		{
			item.css("height", openH+"px" );
			$(".container-central-sparte-teaser-textplus").append('<a href="">mehr lesen</a>&nbsp; <img src="'+HB_BASE+'/'+HB_TEMP+'/images/hb-arrow-next-icon-small.gif" alt="" title="" />');
			
			$(".container-central-sparte-teaser-textplus > a").click(function(){
				if( item.height() == openH )
				{
					item.animate({ height: startH+"px" },'slow', function(){ 
						$(".container-central-sparte-teaser-textplus > img").attr("src", HB_BASE+'/'+HB_TEMP+'/images/hb-arrow-min-icon-small.gif');
						$(".container-central-sparte-teaser-textplus > a").html("weniger lesen");
					});
				} else {
					$(window).scrollTo( "0", scrollTime, {axis:'y'} );
					item.animate({ height: openH+"px" },scrollTime, function(){ 
						$(".container-central-sparte-teaser-textplus > img").attr("src", HB_BASE+'/'+HB_TEMP+'/images/hb-arrow-next-icon-small.gif');
						$(".container-central-sparte-teaser-textplus > a").html("mehr lesen");
					});
				}
				return false;
			});
		}		
	}
	
	/* sparten drop down ende */
	/* submenue drop down start */
	
	if( $(".submenue-list").length > 0 )
	{
		$(".submenue-list li strong").click(function(){
			if( $(this).next("ul").is(":visible") )
			{
				$(this).next("ul").slideUp();
				$(this).removeClass("submenue-items");
			} 
			else 
			{
				$(this).next("ul").slideDown();
				$(this).addClass("submenue-items");
			}
		});
		
		$(".submenue-list li ul").each(function(){
			if( $(this).find(".current").length > 0 ) 
			{
				$(this).show();
				$(this).prev("strong").addClass("submenue-items");
			}
		});
	}
	
	
	/* submenue drop down ende */
});
