$(document).ready(function(){
	function replaceSlideTreeGraphics() {
		jQuery('#ttnews-cat-tree img').each(function(){
			if(jQuery(this).attr('src') == 'typo3/gfx/ol/minusonly.gif') {
				jQuery(this).attr('src', 'fileadmin/templates/images/tt_news/minus.gif');
			}

			if(jQuery(this).attr('src') == 'typo3/gfx/ol/minus.gif') {
				jQuery(this).attr('src', 'fileadmin/templates/images/tt_news/minus.gif');
			}

			if(jQuery(this).attr('src') == 'typo3/gfx/ol/minusbottom.gif') {
				jQuery(this).attr('src', 'fileadmin/templates/images/tt_news/minus.gif');
			}

			if(jQuery(this).attr('src') == 'typo3/gfx/ol/plus.gif') {
				jQuery(this).attr('src', 'fileadmin/templates/images/tt_news/plus.gif');
			}

			if(jQuery(this).attr('src') == 'typo3/gfx/ol/joinbottom.gif') {
				jQuery(this).attr('src', 'fileadmin/templates/images/tt_news/plus.gif');
			}

			if(jQuery(this).attr('src') == 'typo3/gfx/ol/join.gif') {
				jQuery(this).attr('src', 'fileadmin/templates/images/tt_news/plus.gif');
			}

			if(jQuery(this).attr('src') == 'typo3/gfx/ol/plusbottom.gif') {
				jQuery(this).attr('src', 'fileadmin/templates/images/tt_news/plus.gif');
			}

			if(jQuery(this).attr('src') == 'typo3/gfx/ol/minusonly-sz.gif') {
				jQuery(this).attr('src', 'fileadmin/templates/images/tt_news/minus-sz.gif');
			}

			if(jQuery(this).attr('src') == 'typo3/gfx/ol/minus-sz.gif') {
				jQuery(this).attr('src', 'fileadmin/templates/images/tt_news/minus-sz.gif');
			}

			if(jQuery(this).attr('src') == 'typo3/gfx/ol/minusbottom-sz.gif') {
				jQuery(this).attr('src', 'fileadmin/templates/images/tt_news/minus-sz.gif');
			}

			if(jQuery(this).attr('src') == 'typo3/gfx/ol/plus-sz.gif') {
				jQuery(this).attr('src', 'fileadmin/templates/images/tt_news/plus-sz.gif');
			}

			if(jQuery(this).attr('src') == 'typo3/gfx/ol/joinbottom-sz.gif') {
				jQuery(this).attr('src', 'fileadmin/templates/images/tt_news/plus-sz.gif');
			}

			if(jQuery(this).attr('src') == 'typo3/gfx/ol/join-sz.gif') {
				jQuery(this).attr('src', 'fileadmin/templates/images/tt_news/plus-sz.gif');
			}

			if(jQuery(this).attr('src') == 'typo3/gfx/ol/plusbottom-sz.gif') {
				jQuery(this).attr('src', 'fileadmin/templates/images/tt_news/plus-sz.gif');
			}
		});
	}
	
	replaceSlideTreeGraphics();
	
	jQuery('#ttnews-cat-tree img').click(function(){
		replaceSlideTreeGraphics();
		
	});

	//VSA_initScrollbars();
	addClass({
		tagName:'a',
		tagClass:'link-opener',
		classAdd:'show-block',
		addToParent:true
	})

	clearFormFields({
		clearInputs: true,
		clearTextareas: true,
		passwordFieldText: true,
		addClassFocus: "focus",
		filterClass: "default"
	});
	hoverForIE6(".entry .icos li", "hover");
	$('.eventagentmarginalselect').customSelectWithLinks();
	$('.kunstler-select').customSelectWithLinks();
	$('.paginatorItmesOnPage').customSelectWithLinks();
	$('.sortbydropdown').customSelectWithLinks();
	$('.facet_queries').customSelectWithLinks();
	$('#kalender-ts').customSelectWithLinks();
	$('#newsCatSelect').customSelectWithLinks();

	$('#kalender-box select').customSelect();
	$('#kalender-ts').customSelectWithLinks();

	$('select').customSelect();
	$('input:radio').customRadio();
	$('input:checkbox').customCheckbox();
//	$('#kalender-box select').customSelect();
	initFacetDateSelector();
	initAdvDateSelector();

	initFormLightbox();

	initAdvancedSearchSelectors();

    var loginWindowTimer = false;

	jQuery(".link2").mouseenter(showloginwindow);
    jQuery(".link-drop").mouseenter(restoreloginwindow);
	jQuery(".link-drop-frame").mouseleave(hideloginwindow);
	
	jQuery('#blogArchiveArea a.selectButton').click(function() {
  	jQuery('.blogArchiveLayer').toggle();
  	
	});

	jQuery('div.inputRow div').click(function() {

		if(jQuery('#commitcheckbox:checked').val() != null) {
			$('div.buttonRow input[type=submit]').removeAttr('disabled');
			//$('div.buttonRow input[type=submit]').attr("value", "OK");
			$('div.buttonRow input[type=submit]').removeClass('gray');
		}else{
			$('div.buttonRow input[type=submit]').attr('disabled', 'disabled');
			//$('div.buttonRow input[type=submit]').attr("value", "Bitte markieren Sie die Checkbox");
			$('div.buttonRow input[type=submit]').addClass('gray');
		}
	});

	jQuery('div.inputRow label').click(function() {   // HACK because #commitcheckbox:checked is triggert after this event.

		if(jQuery('#commitcheckbox:checked').val() == null) {
			$('div.buttonRow input[type=submit]').removeAttr('disabled');
			//$('div.buttonRow input[type=submit]').attr("value", "OK");
			$('div.buttonRow input[type=submit]').removeClass('gray');
		}else{
			$('div.buttonRow input[type=submit]').attr('disabled', 'disabled');
			//$('div.buttonRow input[type=submit]').attr("value", "Bitte markieren Sie die Checkbox");
			$('div.buttonRow input[type=submit]').addClass('gray');
		}
	});

});

function reinitKalender(){
	jQuery('#kalender-ts').customSelectWithLinks();
	jQuery('#kalender-box select').customSelect();
	jQuery('#kalender-ts').customSelectWithLinks();
}

function hideloginwindow(){
    loginWindowTimer = setTimeout(function(){
        jQuery(".link-drop").css("display","none");
    },5000)
}

function restoreloginwindow(){
    clearTimeout(loginWindowTimer);
}

function showloginwindow(){
    jQuery(".link-drop").css("display","block");
    //clearTimeout(loginWindowTimer);
}

function initFormLightbox(){
	var form = $('form.content-form');
	var submit = $('input.with-popup',form);
	var popup = submit.pvlightbox();

	submit.click(function(){
		$.ajax({
			url:form.attr('action'),
			data:form.serialize(),
			error:function(){
				alert('AJAX Error');
			},
			success:function(){
				popup.show();
			}
		});
		return false;
	})
}



$.fn.pvlightbox = function(options){
	return new pvlightbox($(this).eq(0),options)
}
function pvlightbox(link, options) {
	this.init(link,options)
}
pvlightbox.prototype = {
	init:function(link,options){
		var el = this;
		//options
		el.options = $.extend({
			fadeSpeed:400,
			closer:'a.close',
			scroll:false,
			wrapper:'#wrapper',
			IE:false,
			zIndex:1002
		},options);
		//popup & default css styles
		if ($.browser.msie && el.options.IE) el.popup = $(link.attr('href')).css({
			visibility:'hidden'
		})
		else el.popup = $(link.attr('title')).css({
			opacity:0,
			visibility:'hidden'
		});
		if (el.options.zIndex) el.popup.css({
			zIndex : el.options.zIndex
		});
		el.closer = $(el.popup.find(el.options.closer));
		el.popup.visible = false;
		pvlightbox.prototype.activePopup = false;
		if (!pvlightbox.prototype.firstRun) {
			pvlightbox.prototype.firstRun = 'done'
			if ($.browser.msie && $.browser.version < 7) pvlightbox.prototype.selects = $('select',document);
			//create fader
			if (!$('#fader').length) {
				$('body').append('<div id="fader"></div>');
				pvlightbox.prototype.fader = $('#fader');
				pvlightbox.prototype.fader.css({
					position:'absolute',
					top:0,
					left:0,
					background:'#000',
					opacity:0,
					display:'none'
				});
				if (el.options.zIndex) pvlightbox.prototype.fader.css({
					zIndex : el.options.zIndex-1
				});
			}
			//fader click event
			pvlightbox.prototype.fader.click(function(){
				if (pvlightbox.prototype.activePopup == false) el.hideFader()
				else pvlightbox.prototype.activePopup.hidePopup(function(){
					el.hideFader()
				});
				return false;
			});
			//esc event
			$(document).keydown(function (e) {
				if (e.keyCode == 27) {
					if (pvlightbox.prototype.activePopup == false) el.hideFader()
					else pvlightbox.prototype.activePopup.hidePopup(function(){
						el.hideFader()
					});
					return false;
				}
			});
			//minWidth
			pvlightbox.prototype.minWidth = $('body').css('min-width');
			if (pvlightbox.prototype.minWidth == '0px' || typeof(pvlightbox.prototype.minWidth) == 'undefined') {
				if (el.options.wrapper) {
					pvlightbox.prototype.wrapper = $(el.options.wrapper);
					pvlightbox.prototype.minWidth = $(el.options.wrapper).outerWidth();
				}
			}
			pvlightbox.prototype.minWidth = parseInt(pvlightbox.prototype.minWidth);
		}
		if ($.browser.msie && $.browser.version < 7) {
			el.popupSelects = $('select',el.popup);
			pvlightbox.prototype.selects = pvlightbox.prototype.selects.not(el.popupSelects);
		}
		//open event
		link.click(function(){
			if (pvlightbox.prototype.activePopup == el) {
				return false;
			}
			if (pvlightbox.prototype.activePopup) {
				pvlightbox.prototype.activePopup.hidePopup(function(){
					el.showPopup()
					el.positioning(true);
				});
			} else {
				el.showFader(function(){
					el.showPopup()
				});
				el.positioning(true);
			}
			return false;
		});
		//close event
		el.closer.click(function(){
			el.hidePopup(function(){
				el.hideFader()
			});
			return false;
		});
		//resize event
		$(window).resize(function(){
			if (el.popup.visible) el.positioning(false);
		});
		if (el.options.scroll) {
			$(window).scroll(function(){
				el.positioning(true);
			});
		}
	},
	showPopup:function(){
		var el = this;
		el.popup.visible = true;
		pvlightbox.prototype.activePopup = el;
		if ($.browser.msie && el.options.IE) el.popup.css({
			visibility:'visible'
		})
		else el.popup.stop().css({
			'visibility':'visible'
		}).animate({
			opacity:1
		},el.options.fadeSpeed)
	},
	hidePopup:function(callback){
		var el = this;
		if ($.browser.msie && el.options.IE) {
			el.popup.css({
				left:'-9999px',
				top:'-9999px',
				visibility:'hidden'
			});
			el.popup.visible = false;
			pvlightbox.prototype.activePopup = false;
			if ($.isFunction(callback)) callback();
		} else {
			el.popup.stop().animate({
				opacity:0
			},el.options.fadeSpeed,function(){
				el.popup.css({
					left:'-9999px',
					top:'-9999px',
					visibility:'hidden'
				});
				el.popup.visible = false;
				pvlightbox.prototype.activePopup = false;
				if ($.isFunction(callback)) callback();
			});
		}
	},
	showFader:function(callback){
		var el = this;
		el.fader.stop().css({
			display:'block'
		}).animate({
			opacity:0.5
		},el.options.fadeSpeed,function(){
			if ($.isFunction(callback)) callback();
		});
		if ($.browser.msie && $.browser.version < 7) pvlightbox.prototype.selects.css({
			'visibility': 'hidden'
		});
	},
	hideFader:function(){
		var el = this;
		el.fader.stop().animate({
			opacity:0
		},el.options.fadeSpeed,function(){
			el.fader.css({
				display:'none'
			});
			if ($.browser.msie && $.browser.version < 7) pvlightbox.prototype.selects.css({
				'visibility': 'visible'
			});
		});
	},
	positioning:function(openFlag){
		var el = this;
		//x offset
		var windowW = $(window).width();
		var popupW = el.popup.outerWidth();
		if (windowW < pvlightbox.prototype.minWidth) {
			el.popup.css({
				left:pvlightbox.prototype.minWidth/2-popupW/2
			})
			el.fader.css({
				width:pvlightbox.prototype.minWidth
			});
		} else {
			el.popup.css({
				left:windowW/2-popupW/2
			});
			el.fader.css({
				width:windowW
			})
		}
		//y offset
		var docH = $(document).height();
		var popupH = el.popup.outerHeight();
		if (openFlag) {
			var windowH = $(window).height();
			var popupH = el.popup.outerHeight();
			if (popupH < windowH) el.popup.css({
				top:windowH/2-popupH/2+$(window).scrollTop()
			});
			else if ($(window).scrollTop()+popupH > docH){
				el.popup.css({
					top:docH-popupH
				});
			} else {
				el.popup.css({
					top:$(window).scrollTop()
				});
			}
		}
		el.fader.css({
			height:docH
		});
	}
}

//ie6 hover
function hoverForIE6(h_list, h_class){
	if($.browser.msie && $.browser.version < 7){
		if(!h_class) var h_class = 'hover';
		$(h_list).mouseenter(function(){
			$(this).addClass(h_class);
		}).mouseleave(function(){
			$(this).removeClass(h_class);
		});
	}
}

// custom forms plugin
(function(jQuery){
	// custom checkboxes module
	jQuery.fn.customCheckbox = function(_options){
		var _options = jQuery.extend({
			checkboxStructure: '<div></div>',
			checkboxDisabled: 'disabled-checkbox',
			checkboxDefault: 'checkboxArea',
			checkboxChecked: 'checkboxAreaChecked'
		}, _options);
		return this.each(function(){
			var checkbox = jQuery(this);
			if(!checkbox.hasClass('outtaHere') && checkbox.is(':checkbox')){
				var replaced = jQuery(_options.checkboxStructure);
				this._replaced = replaced;
				if(checkbox.is(':disabled')) replaced.addClass(_options.checkboxDisabled);
				else if(checkbox.is(':checked')) replaced.addClass(_options.checkboxChecked);
				//				else if(checkbox.attr('checked', true)) replaced.addClass(_options.checkboxChecked);
				else replaced.addClass(_options.checkboxDefault);

				if (!checkbox.is(':disabled')){
					replaced.click(function(){
						if(checkbox.is(':checked')) checkbox.removeAttr('checked');
						else checkbox.attr('checked', 'checked');
						changeCheckbox(checkbox);
					});
					checkbox.click(function(){
						changeCheckbox(checkbox);
					});
				}

				replaced.insertBefore(checkbox);
				checkbox.addClass('outtaHere');
			}
		});
		function changeCheckbox(_this){
			_this.change();
			if(_this.is(':checked')) _this.get(0)._replaced.removeClass().addClass(_options.checkboxChecked);
			else _this.get(0)._replaced.removeClass().addClass(_options.checkboxDefault);
		}
	}

	// custom radios module
	jQuery.fn.customRadio = function(_options){
		var _options = jQuery.extend({
			radioStructure: '<div></div>',
			radioDisabled: 'disabled',
			radioDefault: 'radioArea',
			radioChecked: 'radioAreaChecked'
		}, _options);
		return this.each(function(){
			var radio = jQuery(this);
			if(!radio.hasClass('outtaHere') && radio.is(':radio')){
				var replaced = jQuery(_options.radioStructure);
				this._replaced = replaced;
				if(radio.is(':disabled')) replaced.addClass(_options.radioDisabled);
				else if(radio.is(':checked')) replaced.addClass(_options.radioChecked);
				else replaced.addClass(_options.radioDefault);
				replaced.click(function(){
					if($(this).hasClass(_options.radioDefault)){
						radio.attr('checked', 'checked');
						changeRadio(radio.get(0));
					}
				});
				radio.click(function(){
					changeRadio(this);
				});
				replaced.insertBefore(radio);
				radio.addClass('outtaHere');
			}
		});
		function changeRadio(_this){
			$(_this).change();
			$('input:radio[name='+$(_this).attr("name")+']').not(_this).each(function(){
				if(this._replaced && !$(this).is(':disabled')) this._replaced.removeClass().addClass(_options.radioDefault);
			});
			_this._replaced.removeClass().addClass(_options.radioChecked);
		}
	}

	// custom selects module
	jQuery.fn.customSelect = function(_options) {

		var _options = jQuery.extend({
			selectStructure: '<div class="selectArea"><span class="left"></span><span class="center"></span><a href="#" class="selectButton"></a><div class="disabled"></div></div>',
			hideOnMouseOut: false,
			copyClass: true,
			selectText: '.center',
			selectBtn: '.selectButton',
			selectDisabled: '.disabled',
			optStructure: '<div class="optionsDivVisible"><div class="select-top"></div><div class="select-center"><ul></ul><div class="select-bottom"></div></div>',
			optList: 'ul'
		}, _options);
		return this.each(function() {
			var select = jQuery(this);
			if(!select.hasClass('outtaHere') && !select.attr('multiple')) {
				if(select.is(':visible')) {
					var hideOnMouseOut = _options.hideOnMouseOut;
					var copyClass = _options.copyClass;
					var replaced = jQuery(_options.selectStructure);
					var selectText = replaced.find(_options.selectText);
					var selectBtn = replaced.find(_options.selectBtn);
					var selectDisabled = replaced.find(_options.selectDisabled).hide();
					var optHolder = jQuery(_options.optStructure);
					var optList = optHolder.find(_options.optList);
					if(copyClass) optHolder.addClass('drop-'+select.attr('class'));

					if(select.attr('disabled')) selectDisabled.show();
					select.find('option').each(function(){
						var selOpt = $(this);
						//						var target = $(this).attr('value');
						//						var _opt = jQuery('<li><a href="'+target+'">' + selOpt.html() + '</a></li>');
						var _opt = jQuery('<li><a href="#">' + selOpt.html() + '</a></li>');
						if(selOpt.attr('selected')) {
							selectText.html(selOpt.html());
							_opt.addClass('selected');
						}
						_opt.children('a').click(function() {
							optList.find('li').removeClass('selected');
							select.find('option').removeAttr('selected');
							$(this).parent().addClass('selected');
							selOpt.attr('selected', 'selected');
							selectText.html(selOpt.html());
							select.change();
							optHolder.hide();
							return false;
						});
						optList.append(_opt);
					});
					replaced.width(select.outerWidth());
					replaced.insertBefore(select);
					optHolder.css({
						width: select.outerWidth(),
						display: 'none',
						position: 'absolute'
					});
					jQuery(document.body).append(optHolder);

					var optTimer;
					replaced.hover(function() {
						if(optTimer) clearTimeout(optTimer);
					}, function() {
						if(hideOnMouseOut) {
							optTimer = setTimeout(function() {
								optHolder.hide();
							}, 200);
						}
					});
					optHolder.hover(function(){
						if(optTimer) clearTimeout(optTimer);
					}, function() {
						if(hideOnMouseOut) {
							optTimer = setTimeout(function() {
								optHolder.hide();
							}, 200);
						}
					});
					selectBtn.click(function() {
						if(optHolder.is(':visible')) {
							optHolder.hide();
						}
						else{
							if(_activeDrop) _activeDrop.hide();
							optHolder.children('ul').css({
								height:'auto',
								overflow:'hidden'
							});
							optHolder.css({
								top: replaced.offset().top + replaced.outerHeight(),
								left: replaced.offset().left,
								display: 'block'
							});
							if(optHolder.children('ul').height() > 200) optHolder.children('ul').css({
								height:200,
								overflow:'auto'
							});
							_activeDrop = optHolder;
						}
						return false;
					});
					select.addClass('outtaHere');
				}
			}
		});
	}

	// custom selects module
	jQuery.fn.customSelectWithLinks = function(_options) {
		var _options = jQuery.extend({
			selectStructure: '<div class="selectArea"><span class="left"></span><span class="center"></span><a href="#" class="selectButton"></a><div class="disabled"></div></div>',
			hideOnMouseOut: false,
			copyClass: true,
			selectText: '.center',
			selectBtn: '.selectButton',
			selectDisabled: '.disabled',
			optStructure: '<div class="optionsDivVisible"><div class="select-top"></div><div class="select-center"><ul></ul><div class="select-bottom"></div></div>',
			optList: 'ul'
		}, _options);
		return this.each(function() {
			var select = jQuery(this);
			if(!select.hasClass('outtaHere')) {
				if(select.is(':visible')) {
					var hideOnMouseOut = _options.hideOnMouseOut;
					var copyClass = _options.copyClass;
					var replaced = jQuery(_options.selectStructure);
					var selectText = replaced.find(_options.selectText);
					var selectBtn = replaced.find(_options.selectBtn);
					var selectDisabled = replaced.find(_options.selectDisabled).hide();
					var optHolder = jQuery(_options.optStructure);
					var optList = optHolder.find(_options.optList);
					if(copyClass) optHolder.addClass('drop-'+select.attr('class'));

					if(select.attr('disabled')) selectDisabled.show();
					select.find('option').each(function(){
						var selOpt = $(this);
						var target = $(this).attr('value');
						var _opt = jQuery('<li><a href="'+target+'">' + selOpt.html() + '</a></li>');
						if(selOpt.attr('selected')) {
							selectText.html(selOpt.html());
							_opt.addClass('selected');
						}
						_opt.children('a').click(function() {
							//							optList.find('li').removeClass('selected');
							//							select.find('option').removeAttr('selected');
							//							$(this).parent().addClass('selected');
							//							selOpt.attr('selected', 'selected');
							//							selectText.html(selOpt.html());
							//							select.change();
							//							optHolder.hide();
							//							return false;
							});
						optList.append(_opt);
					});
					replaced.width(select.outerWidth());
					replaced.insertBefore(select);
					optHolder.css({
						width: select.outerWidth(),
						display: 'none',
						position: 'absolute'
					});
					jQuery(document.body).append(optHolder);

					var optTimer;
					replaced.hover(function() {
						if(optTimer) clearTimeout(optTimer);
					}, function() {
						if(hideOnMouseOut) {
							optTimer = setTimeout(function() {
								optHolder.hide();
							}, 200);
						}
					});
					optHolder.hover(function(){
						if(optTimer) clearTimeout(optTimer);
					}, function() {
						if(hideOnMouseOut) {
							optTimer = setTimeout(function() {
								optHolder.hide();
							}, 200);
						}
					});
					selectBtn.click(function() {
						if(optHolder.is(':visible')) {
							optHolder.hide();
						}
						else{
							if(_activeDrop) _activeDrop.hide();
							optHolder.children('ul').css({
								height:'auto',
								overflow:'hidden'
							});
							optHolder.css({
								top: replaced.offset().top + replaced.outerHeight(),
								left: replaced.offset().left,
								display: 'block'
							});
							if(optHolder.children('ul').height() > 200) optHolder.children('ul').css({
								height:200,
								overflow:'auto'
							});
							_activeDrop = optHolder;
						}
						return false;
					});
					select.addClass('outtaHere');
				}
			}
		});
	}

	// event handler on DOM ready
	var _activeDrop;
	jQuery(function(){
		jQuery('body').click(hideOptionsClick)
		jQuery(window).resize(hideOptions)
	});
	function hideOptions() {
		if(_activeDrop && _activeDrop.length) {
			_activeDrop.hide();
			_activeDrop = null;
		}
	}
	function hideOptionsClick(e) {
		if(_activeDrop && _activeDrop.length) {
			var f = false;
			$(e.target).parents().each(function(){
				if(this == _activeDrop) f=true;
			});
			if(!f) {
				_activeDrop.hide();
				_activeDrop = null;
			}
		}
	}
})(jQuery);

//clear forms
function clearFormFields(o)
{
	if (o.clearInputs == null) o.clearInputs = true;
	if (o.clearTextareas == null) o.clearTextareas = true;
	if (o.passwordFieldText == null) o.passwordFieldText = false;
	if (o.addClassFocus == null) o.addClassFocus = false;
	if (!o.filterClass) o.filterClass = "default";
	if(o.clearInputs) {
		var inputs = document.getElementsByTagName("input");

		for (var i = 0; i < inputs.length; i++ ) {
			if((inputs[i].type == "text" || inputs[i].type == "password") && inputs[i].className.indexOf(o.filterClass)) {

				inputs[i].valueHtml = inputs[i].value;
				inputs[i].onfocus = function ()	{

					if($(this).parent().parent().attr('class') != 'top-part'){   // hack sothat no clearinputfields @ eventagentForm

						if(this.valueHtml == this.value) this.value = "";
						if(this.fake) {
							inputsSwap(this, this.previousSibling);
							this.previousSibling.focus();
						}
						if(o.addClassFocus && !this.fake) {
							this.className += " " + o.addClassFocus;
							this.parentNode.className += " parent-" + o.addClassFocus;
						}
					}
					
				}
				inputs[i].onblur = function () {
					if($(this).parent().parent().attr('class') != 'top-part'){
						if(this.value == "") {
							this.value = this.valueHtml;
							if(o.passwordFieldText && this.type == "password") inputsSwap(this, this.nextSibling);
						}
						if(o.addClassFocus) {
							this.className = this.className.replace(o.addClassFocus, "");
							this.parentNode.className = this.parentNode.className.replace("parent-"+o.addClassFocus, "");
						}
					}
				}
				if(o.passwordFieldText && inputs[i].type == "password") {
					var fakeInput = document.createElement("input");
					fakeInput.type = "text";
					fakeInput.value = inputs[i].value;
					fakeInput.className = inputs[i].className;
					fakeInput.fake = true;
					inputs[i].parentNode.insertBefore(fakeInput, inputs[i].nextSibling);
					inputsSwap(inputs[i], null);
				}
			}
		}
	}
	if(o.clearTextareas) {
		var textareas = document.getElementsByTagName("textarea");
		for(var i=0; i<textareas.length; i++) {
			if(textareas[i].className.indexOf(o.filterClass)) {
				textareas[i].valueHtml = textareas[i].value;
				textareas[i].onfocus = function() {
					if(this.value == this.valueHtml) this.value = "";
					if(o.addClassFocus) {
						this.className += " " + o.addClassFocus;
						this.parentNode.className += " parent-" + o.addClassFocus;
					}
				}
				textareas[i].onblur = function() {
					if(this.value == "") this.value = this.valueHtml;
					if(o.addClassFocus) {
						this.className = this.className.replace(o.addClassFocus, "");
						this.parentNode.className = this.parentNode.className.replace("parent-"+o.addClassFocus, "");
					}
				}
			}
		}
	}
	function inputsSwap(el, el2) {
		if(el) el.style.display = "none";
		if(el2) el2.style.display = "inline";
	}
}

//add class
function addClass (_options) {
	var _tagName = _options.tagName;
	var _tagClass = _options.tagClass;
	var _classAdd = _options.classAdd;
	var _addToParent = false || _options.addToParent;
	var _el = document.getElementsByTagName(_tagName);
	if (_el) {
		for (var i=0; i < _el.length; i++) {
			if (_el[i].className.indexOf(_tagClass) != -1) {
				_el[i].onclick = function() {
					if (_addToParent) {
						if (this.parentNode.className.indexOf(_classAdd) == -1) {
							this.parentNode.className += ' '+_classAdd;
						} else {
							this.parentNode.className = this.parentNode.className.replace(_classAdd,'');
						}
					} else {
						if (this.className.indexOf(_classAdd) == -1) {
							this.className += ' '+_classAdd;
						} else {
							this.className = this.className.replace(_classAdd,'');
						}
					}
					return false;
				}
			}
		}
	}
}

//custom scroll
var VSA_scrollAreas = new Array();

var VSA_default_imagesPath = "images";
var VSA_default_btnUpImage = "button-up.gif";
var VSA_default_btnDownImage = "button-down.gif";
var VSA_default_scrollStep = 5;
var VSA_default_wheelSensitivity = 10;
var VSA_default_scrollbarPosition = 'right';//'left','right','inline';
var VSA_default_scrollButtonHeight = 13;
var VSA_default_scrollbarWidth = 17;

var VSA_resizeTimer = 2000;

function VSA_initScrollbars(){
	var scrollElements = VSA_getElements("scrollable", "DIV", document, "class");
	for (var i=0; i<scrollElements.length; i++)
	{
		VSA_scrollAreas[i] = new ScrollArea(i, scrollElements[i]);
	}
}

function ScrollArea(index, elem) //constructor
{
	this.index = index;
	this.element = elem;

	var attr = this.element.getAttribute("imagesPath");
	this.imagesPath = attr ? attr : VSA_default_imagesPath;

	attr = this.element.getAttribute("btnUpImage");
	this.btnUpImage = attr ? attr : VSA_default_btnUpImage;

	attr = this.element.getAttribute("btnDownImage");
	this.btnDownImage = attr ? attr : VSA_default_btnDownImage;

	attr = Number(this.element.getAttribute("scrollStep"));
	this.scrollStep = attr ? attr : VSA_default_scrollStep;

	attr = Number(this.element.getAttribute("wheelSensitivity"));
	this.wheelSensitivity = attr ? attr : VSA_default_wheelSensitivity;

	attr = this.element.getAttribute("scrollbarPosition");
	this.scrollbarPosition = attr ? attr : VSA_default_scrollbarPosition;

	attr = this.element.getAttribute("scrollButtonHeight");
	this.scrollButtonHeight = attr ? attr : VSA_default_scrollButtonHeight;

	attr = this.element.getAttribute("scrollbarWidth");
	this.scrollbarWidth = attr ? attr : VSA_default_scrollbarWidth;

	this.scrolling = false;

	this.iOffsetY = 0;
	this.scrollHeight = 0;
	this.scrollContent = null;
	this.scrollbar = null;
	this.scrollup = null;
	this.scrolldown = null;
	this.scrollslider = null;
	this.scroll = null;
	this.enableScrollbar = false;
	this.scrollFactor = 1;
	this.scrollingLimit = 0;
	this.topPosition = 0;

	//functions declaration
	this.init = VSA_init;
	this.scrollUp = VSA_scrollUp;
	this.scrollDown = VSA_scrollDown;
	this.createScrollBar = VSA_createScrollBar;
	this.scrollIt = VSA_scrollIt;

	this.init();

}


function VSA_init(){

	this.scrollContent = document.createElement("DIV");
	this.scrollContent.style.position = "absolute";
	this.scrollContent.innerHTML = this.element.innerHTML;
	this.scrollContent.style.overflow = "hidden";

	this.scrollContent.style.width = this.element.offsetWidth + "px";
	this.scrollContent.style.height = this.element.offsetHeight + "px";


	this.element.innerHTML = "";
	this.element.style.overflow = "hidden";
	this.element.style.display = "block";
	this.element.style.visibility = "visible";
	this.element.style.position = "relative";
	this.element.appendChild(this.scrollContent);

	this.scrollContent.className = 'scroll-content';

	this.element.index = this.index;
	this.element.over = false;

	var _this = this;
	this.element.onmouseover = function(){
		_this.element.over = true;
	};
	this.element.onmouseout = function(){
		_this.element.over = false;
	}

	if (document.all)
	{
		this.element.onscroll = VSA_handleOnScroll;
		this.element.onresize = VSA_handleResize;
	}
	else
	{
		window.onresize = VSA_handleResize;
	}

	this.createScrollBar();

	if (window.addEventListener)
		/** DOMMouseScroll is for mozilla. */
		this.element.addEventListener('DOMMouseScroll', VSA_handleMouseWheel, false);
	/** IE/Opera. */
	this.element.onmousewheel = document.onmousewheel = VSA_handleMouseWheel;

}

function VSA_createScrollBar(){

	if (this.scrollbar != null)
	{
		this.element.removeChild(this.scrollbar);
		this.scrollbar = null;
	}

	if (this.scrollContent.scrollHeight <= this.scrollContent.offsetHeight)
		this.enableScrollbar = false;
	else if (this.element.offsetHeight > 2*this.scrollButtonHeight)
		this.enableScrollbar = true;
	else
		this.enableScrollbar = false;

	if (this.scrollContent.scrollHeight - Math.abs(this.scrollContent.scrollTop) < this.element.offsetHeight)
		this.scrollContent.style.top = 0;

	if (this.enableScrollbar){

		this.scrollbar = document.createElement("DIV");
		this.element.appendChild(this.scrollbar);
		this.scrollbar.style.position = "absolute";
		this.scrollbar.style.top = "0px";
		this.scrollbar.style.height = this.element.offsetHeight+"px";
		this.scrollbar.style.width = this.scrollbarWidth + "px";

		this.scrollbar.className = 'vscroll-bar';

		if(this.scrollbarWidth != this.scrollbar.offsetWidth){
			this.scrollbarWidth = this.scrollbar.offsetHeight;
		}

		this.scrollbarWidth = this.scrollbar.offsetWidth;

		if(this.scrollbarPosition == 'left'){
			this.scrollContent.style.left = this.scrollbarWidth + 5 + "px";
			this.scrollContent.style.width = this.element.offsetWidth - this.scrollbarWidth - 5 + "px";
		}else if(this.scrollbarPosition == 'right'){
			this.scrollbar.style.left = this.element.offsetWidth - this.scrollbarWidth  + "px";
			this.scrollContent.style.width = this.element.offsetWidth - this.scrollbarWidth - 5 + "px";
		}

		//create scroll up button
		this.scrollup = document.createElement("DIV");
		this.scrollup.index = this.index;
		this.scrollup.onmousedown = VSA_handleBtnUpMouseDown;
		this.scrollup.onmouseup = VSA_handleBtnUpMouseUp;
		this.scrollup.onmouseout = VSA_handleBtnUpMouseOut;
		this.scrollup.style.position = "absolute";
		this.scrollup.style.top = "0px";
		this.scrollup.style.left = "0px";
		this.scrollup.style.height = this.scrollButtonHeight + "px";
		this.scrollup.style.width = this.scrollbarWidth + "px";

		this.scrollup.innerHTML = '<img src="' + this.imagesPath + '/' + this.btnUpImage + '" border="0"/>';
		this.scrollbar.appendChild(this.scrollup);

		this.scrollup.className = 'vscroll-up';

		if(this.scrollButtonHeight != this.scrollup.offsetHeight){
			this.scrollButtonHeight = this.scrollup.offsetHeight;
		}

		//create scroll down button
		this.scrolldown = document.createElement("DIV");
		this.scrolldown.index = this.index;
		this.scrolldown.onmousedown = VSA_handleBtnDownMouseDown;
		this.scrolldown.onmouseup = VSA_handleBtnDownMouseUp;
		this.scrolldown.onmouseout = VSA_handleBtnDownMouseOut;
		this.scrolldown.style.position = "absolute";
		this.scrolldown.style.left = "0px";
		this.scrolldown.style.top =  this.scrollbar.offsetHeight - this.scrollButtonHeight + "px";
		this.scrolldown.style.width = this.scrollbarWidth + "px";
		this.scrolldown.innerHTML = '<img src="' + this.imagesPath + '/' + this.btnDownImage + '" border="0"/>';
		this.scrollbar.appendChild(this.scrolldown);

		this.scrolldown.className = 'vscroll-down';

		//create scroll
		this.scroll = document.createElement("DIV");
		this.scroll.index = this.index;
		this.scroll.style.position = "absolute";
		this.scroll.style.zIndex = 0;
		this.scroll.style.textAlign = "center";
		this.scroll.style.top = this.scrollButtonHeight + "px";
		this.scroll.style.left = "0px";
		this.scroll.style.width = this.scrollbarWidth + "px";

		var h = this.scrollbar.offsetHeight - 2*this.scrollButtonHeight;
		this.scroll.style.height = ((h > 0) ? h : 0) + "px";

		this.scroll.innerHTML = '';
		this.scroll.onclick = VSA_handleScrollbarClick;
		this.scrollbar.appendChild(this.scroll);
		this.scroll.style.overflow = "hidden";

		this.scroll.className = "vscroll-line";

		//create slider
		this.scrollslider = document.createElement("DIV");
		this.scrollslider.index = this.index;
		this.scrollslider.style.position = "absolute";
		this.scrollslider.style.zIndex = 1;
		this.scrollslider.style.textAlign = "center";
		this.scrollslider.innerHTML = '<div id="scrollslider' + this.index + '" style="padding:0;margin:0;"><div class="scroll-bar-top"></div><div class="scroll-bar-bottom"></div></div>';
		this.scrollbar.appendChild(this.scrollslider);

		this.subscrollslider = document.getElementById("scrollslider"+this.index);
		this.subscrollslider.style.height = Math.round((this.scrollContent.offsetHeight/this.scrollContent.scrollHeight)*(this.scrollbar.offsetHeight - 2*this.scrollButtonHeight)) + "px";

		this.scrollslider.className = "vscroll-slider";

		this.scrollHeight = this.scrollbar.offsetHeight - 2*this.scrollButtonHeight - this.scrollslider.offsetHeight;
		this.scrollFactor = (this.scrollContent.scrollHeight - this.scrollContent.offsetHeight)/this.scrollHeight;
		this.topPosition = getRealTop(this.scrollbar) + this.scrollButtonHeight;
		/* this.scrollbarHeight = this.scrollbar.offsetHeight - 2*this.scrollButtonHeight - this.scrollslider.offsetHeight; */

		this.scrollslider.style.top = 1 / this.scrollFactor * Math.abs(this.scrollContent.scrollTop) + this.scrollButtonHeight + "px";
		this.scrollslider.style.left = "0px";
		this.scrollslider.style.width = "100%";
		this.scrollslider.onmousedown = VSA_handleSliderMouseDown;
		if (document.all)
			this.scrollslider.onmouseup = VSA_handleSliderMouseUp;
	}
	else
		this.scrollContent.style.width = this.element.offsetWidth + "px";
}

function VSA_handleBtnUpMouseDown(){
	var sa = VSA_scrollAreas[this.index];
	sa.scrolling = true;
	sa.scrollUp();
}

function VSA_handleBtnUpMouseUp(){
	VSA_scrollAreas[this.index].scrolling = false;
}

function VSA_handleBtnUpMouseOut(){
	VSA_scrollAreas[this.index].scrolling = false;
}

function VSA_handleBtnDownMouseDown(){
	var sa = VSA_scrollAreas[this.index];
	sa.scrolling = true;
	sa.scrollDown();
}

function VSA_handleBtnDownMouseUp(){
	VSA_scrollAreas[this.index].scrolling = false;
}

function VSA_handleBtnDownMouseOut(){
	VSA_scrollAreas[this.index].scrolling = false;
}

function VSA_scrollIt(){
	this.scrollContent.scrollTop = this.scrollFactor * ((this.scrollslider.offsetTop + this.scrollslider.offsetHeight/2) - this.scrollButtonHeight - this.scrollslider.offsetHeight/2);
}

function VSA_scrollUp(){
	if (this.scrollingLimit > 0)
	{
		this.scrollingLimit--;
		if (this.scrollingLimit == 0) this.scrolling = false;
	}
	if (!this.scrolling) return;
	if ( this.scrollContent.scrollTop - this.scrollStep > 0)
	{
		this.scrollContent.scrollTop -= this.scrollStep;
		this.scrollslider.style.top = 1 / this.scrollFactor * Math.abs(this.scrollContent.scrollTop) + this.scrollButtonHeight + "px";
	}
	else
	{
		this.scrollContent.scrollTop = "0";
		this.scrollslider.style.top = this.scrollButtonHeight + "px";
		return;
	}
	setTimeout("VSA_Ext_scrollUp(" + this.index + ")", 30);
}

function VSA_Ext_scrollUp(index){
	VSA_scrollAreas[index].scrollUp();
}

function VSA_scrollDown(){
	if (this.scrollingLimit > 0)
	{
		this.scrollingLimit--;
		if (this.scrollingLimit == 0) this.scrolling = false;
	}
	if (!this.scrolling) return;


	this.scrollContent.scrollTop += this.scrollStep;
	this.scrollslider.style.top =  1 / this.scrollFactor * Math.abs(this.scrollContent.scrollTop) + this.scrollButtonHeight + "px";

	if (this.scrollContent.scrollTop >= (this.scrollContent.scrollHeight - this.scrollContent.offsetHeight))
	{
		this.scrollContent.scrollTop = (this.scrollContent.scrollHeight - this.scrollContent.offsetHeight);
		this.scrollslider.style.top = this.scrollbar.offsetHeight - this.scrollButtonHeight - this.scrollslider.offsetHeight + "px";
		return;
	}

	setTimeout("VSA_Ext_scrollDown(" + this.index + ")", 30);
}

function VSA_Ext_scrollDown(index){
	VSA_scrollAreas[index].scrollDown();
}

function VSA_handleMouseMove(evt){
	var sa = VSA_scrollAreas[((document.all && !window.opera) ? this.index : document.documentElement.scrollAreaIndex)];
	var posy = 0;
	if (!evt) var evt = window.event;

	if (evt.pageY)
		posy = evt.pageY;
	else if (evt.clientY)
		posy = evt.clientY;

	if (document.all && !window.opera)
	{
		posy += document.documentElement.scrollTop;
	}

	var iNewY = posy - sa.iOffsetY - getRealTop(sa.scrollbar);
	iNewY += sa.scrollButtonHeight;

	if (iNewY < sa.scrollButtonHeight)
		iNewY = sa.scrollButtonHeight;
	if (iNewY > (sa.scrollbar.offsetHeight - sa.scrollButtonHeight) - sa.scrollslider.offsetHeight)
		iNewY = (sa.scrollbar.offsetHeight - sa.scrollButtonHeight) - sa.scrollslider.offsetHeight;

	sa.scrollslider.style.top = iNewY + "px";

	sa.scrollIt();
}

function VSA_handleSliderMouseDown(evt){
	if (!(document.uniqueID && document.compatMode && !window.XMLHttpRequest))
	{
		document.onselectstart = function() {
			return false;
		}
		document.onmousedown = function() {
			return false;
		}
	}

	var sa = VSA_scrollAreas[this.index];
	if (document.all && !window.opera){
		sa.scrollslider.setCapture()
		sa.iOffsetY = event.offsetY;
		sa.scrollslider.onmousemove = VSA_handleMouseMove;
	}else{
		if(window.opera){
			sa.iOffsetY = event.offsetY;
		}else{
			sa.iOffsetY = evt.layerY;
		}
		document.documentElement.scrollAreaIndex = sa.index;
		document.documentElement.addEventListener("mousemove", VSA_handleMouseMove, true);
		document.documentElement.addEventListener("mouseup", VSA_handleSliderMouseUp, true);
	}
	return false;
}

function VSA_handleSliderMouseUp()
{
	if (!(document.uniqueID && document.compatMode && !window.XMLHttpRequest))
	{
		document.onmousedown = null;
		document.onselectstart = null;
	}

	if (document.all && !window.opera)
	{
		var sa = VSA_scrollAreas[this.index];
		sa.scrollslider.onmousemove = null;
		sa.scrollslider.releaseCapture();
		sa.scrollIt();
	}
	else
	{
		var sa = VSA_scrollAreas[document.documentElement.scrollAreaIndex];
		document.documentElement.removeEventListener("mousemove", VSA_handleMouseMove, true);
		document.documentElement.removeEventListener("mouseup", VSA_handleSliderMouseUp, true);
		sa.scrollIt();
	}
	return false;
}

function VSA_handleResize()
{
	if (VSA_resizeTimer)
	{
		clearTimeout(VSA_resizeTimer);
		VSA_resizeTimer = 0;
	}
	VSA_resizeTimer = setTimeout("VSA_performResizeEvent()", 100);
}

function VSA_performResizeEvent()
{
	for (var i=0; i<VSA_scrollAreas.length; i++)
		VSA_scrollAreas[i].createScrollBar();
}
function VSA_handleMouseWheel(event){
	if (this.index != null) {
		var sa = VSA_scrollAreas[this.index];

		if (sa.scrollbar == null) return;
		sa.scrolling = true;
		sa.scrollingLimit = sa.wheelSensitivity;

		var delta = 0;
		if (!event) /* For IE. */
			event = window.event;
		if (event.wheelDelta) { /* IE/Opera. */
			delta = event.wheelDelta/120;

		/*if (window.opera)
                        delta = -delta;*/
		} else if (event.detail) { /** Mozilla case. */
			delta = -event.detail/3;
		}
		if (delta && sa.element.over) {
			if (delta > 0)
				sa.scrollUp();
			else
				sa.scrollDown();

			if (event.preventDefault)
				event.preventDefault();
			event.returnValue = false;
		}
	}
}

function VSA_handleSelectStart()
{
	event.returnValue = false;
}

function VSA_handleScrollbarClick(evt)
{
	var sa = VSA_scrollAreas[this.index];
	var offsetY = (document.all ? event.offsetY : evt.layerY);

	if (offsetY < (sa.scrollButtonHeight + sa.scrollslider.offsetHeight/2))
		sa.scrollslider.style.top = sa.scrollButtonHeight + "px";
	else if (offsetY > (sa.scrollbar.offsetHeight - sa.scrollButtonHeight - sa.scrollslider.offsetHeight))
		sa.scrollslider.style.top = sa.scrollbar.offsetHeight - sa.scrollButtonHeight - sa.scrollslider.offsetHeight + "px";
	else
	{
		sa.scrollslider.style.top = offsetY + sa.scrollButtonHeight - sa.scrollslider.offsetHeight/2 + "px";
	}
	sa.scrollIt();
}

function VSA_handleOnScroll()
{
//event.srcElement.doScroll("pageUp");
}

//--- common functions ----

function VSA_getElements(attrValue, tagName, ownerNode, attrName) //get Elements By Attribute Name
{
	if (!tagName) tagName = "*";
	if (!ownerNode) ownerNode = document;
	if (!attrName) attrName = "name";
	var result = [];
	var nl = ownerNode.getElementsByTagName(tagName);
	for (var i=0; i<nl.length; i++)
	{
		//	if (nl.item(i).getAttribute(attrName) == attrValue)
		//		result.push(nl.item(i));
		if (nl.item(i).className.indexOf(attrValue) != -1)
			result.push(nl.item(i));
	}
	return result;
}

var _ie = false;
if(navigator.userAgent.toLowerCase().indexOf("msie") != -1 && navigator.userAgent.toLowerCase().indexOf("opera") == -1) _ie = true;

function getRealTop(elem)
{
	if(_ie) {
		var nTop = 0;
		if(elem)
		{
			do
			{
				nTop += elem.offsetTop - elem.scrollTop;
				elem = elem.offsetParent;
			}
			while(elem)
		}
		return nTop;
	}
	else {
		var posTop = 0;
		while (elem.offsetParent) {
			posTop += elem.offsetTop;
			elem = elem.offsetParent;
		}
		var _res = new Object();
		return posTop;
	}

}

function getCleanURLarray(){

		sc_array = new Array();
		sc_array["facet"] = new Array();
		
	sc_array = jQuery.deparam.querystring( window.location.href ,1);
	
	if(sc_array["facet"] == undefined){  // if sc_array[Facet] is empty we make an object from it.
		/*
		sc_array = new Array();
		sc_array["facet"] = new Array();
		sc_array["facet"]["facet"] = new Array();
		sc_array["facet"]["facet"]["a"] = "tmp";
		*/
		
		sc_array = { facet: { } };
		
//		sc_array = jQuery.deparam(jQuery.param({ a:[1,2], b:{ c:[3], d:4 } , facet:{ c:[3], d:4 } }));
//		sc_array = jQuery.deparam(jQuery.param({a:{a:1}}));
	}else{
		delete sc_array["facet"]["datepickerOneDay"];
		delete sc_array["facet"]["SpecialDay"];
		delete sc_array["facet"]["SpecialRange"];
		delete sc_array["facet"]["EventWeekEndDay"];
		delete sc_array["facet"]["EventWeekEndDay"];
		delete sc_array["facet"]["SpecialRangeDetail"];
	}
	
	
	
			//sc_array["facet"]["blank"] = 1;
			//sc_array["facet"]['blankDetail'] = Array();
			//sc_array["facet"]['blankDetail'][0] = "nwoe";
	
	
	return sc_array;
}




function initAdvDateSelector(){

	$(function() {
		$( "#datepickerOneDaySelectAdv" ).datepicker({
			showOn: "both",
			buttonImage: "/fileadmin/templates/images/ico-calendar2.gif",
			buttonImageOnly: true,
			numberOfMonths: 2,
			minDate: 0

		});






	});

	var dates = $( "#datefromAdv, #datetoAdv" ).datepicker({

		beforeShow: function() {
			$('.vscroll-slider').css("z-index", 0);
		},

		showOn: "both",
		buttonImage: "/fileadmin/templates/images/ico-calendar2.gif",
		buttonImageOnly: true,
		minDate: 0,
		changeMonth: true,
		numberOfMonths: 2,
		onSelect: function( selectedDate ) {
			var option = this.id == "datefromAdv" ? "minDate" : "maxDate",
			instance = $( this ).data( "datepicker" );
			date = $.datepicker.parseDate(
				instance.settings.dateFormat ||
				$.datepicker._defaults.dateFormat,
				selectedDate, instance.settings );

			dates.not( this ).datepicker( "option", option, date );

		}
	});


	jQuery(function($){
		$.datepicker.regional['de'] = {
			clearText: 'löschen',
			clearStatus: 'aktuelles Datum löschen',
			closeText: 'schließen',
			closeStatus: 'ohne Änderungen schließen',
			prevText: '&#x3c;zurück',
			prevStatus: 'letzten Monat zeigen',
			nextText: 'Vor&#x3e;',
			nextStatus: 'nächsten Monat zeigen',
			currentText: 'heute',
			currentStatus: '',
			monthNames: ['Januar','Februar','März','April','Mai','Juni','Juli','August','September','Oktober','November','Dezember'],
			monthNamesShort: ['Jan','Feb','Mär','Apr','Mai','Jun','Jul','Aug','Sep','Okt','Nov','Dez'],
			monthStatus: 'anderen Monat anzeigen',
			yearStatus: 'anderes Jahr anzeigen',
			weekHeader: 'Wo',
			weekStatus: 'Woche des Monats',
			dayNames: ['Sonntag','Montag','Dienstag','Mittwoch','Donnerstag','Freitag','Samstag'],
			dayNamesShort: ['So','Mo','Di','Mi','Do','Fr','Sa'],
			dayNamesMin: ['So','Mo','Di','Mi','Do','Fr','Sa'],
			dayStatus: 'Setze DD als ersten Wochentag',
			dateStatus: 'Wähle D, M d',
			dateFormat: 'dd.mm.yy',
			firstDay: 1,
			initStatus: 'Wähle ein Datum',
			isRTL: false
		};
		$.datepicker.setDefaults($.datepicker.regional['de']);
	});

	$.datepicker.setDefaults( $.datepicker.regional[ "de" ] );

}

function initFacetDateSelector(){

	if( jQuery("#SpecialDay").attr('checked') != true){
		jQuery("#datepickerOneDay").slideUp();
	}

	if( jQuery("#SpecialRange").attr('checked') != true){
		jQuery("#SpecialRangeDetail").slideUp();
	}

	if( !jQuery("#SpecialRangeDetail option:last").attr('selected')){
		jQuery("#RangepickerOuter").slideUp();
	}


	if( jQuery("#EventWeekEndDay").attr('checked') != true && jQuery("#SpecialDay").attr('checked') != true && jQuery("#SpecialRange").attr('checked') != true && !jQuery("#SpecialRangeDetail option:last").attr('selected')){
		jQuery('#alleAnzeigenTermin').slideUp();
	}


	jQuery("#SpecialDay").click(SpecialDay);
	jQuery("#SpecialDay").parent().find(".checkboxAreaChecked").click(SpecialDay);
	jQuery("#SpecialDay").parent().find(".checkboxArea").click(SpecialDay);

	jQuery("#SpecialRange").click(SpecialRange);
	jQuery("#SpecialRange").parent().find(".checkboxAreaChecked").click(SpecialRange);
	jQuery("#SpecialRange").parent().find(".checkboxArea").click(SpecialRange);

	jQuery("#EventWeekEndDay").click(EventWeekEndDay);
	jQuery("#EventWeekEndDay").parent().find(".checkboxAreaChecked").click(EventWeekEndDay);
	jQuery("#EventWeekEndDay").parent().find(".checkboxArea").click(EventWeekEndDay);

	jQuery(function($){
		$.datepicker.regional['de'] = {
			clearText: 'löschen',
			clearStatus: 'aktuelles Datum löschen',
			closeText: 'schließen',
			closeStatus: 'ohne Änderungen schließen',
			prevText: '&#x3c;zurück',
			prevStatus: 'letzten Monat zeigen',
			nextText: 'Vor&#x3e;',
			nextStatus: 'nächsten Monat zeigen',
			currentText: 'heute',
			currentStatus: '',
			monthNames: ['Januar','Februar','März','April','Mai','Juni','Juli','August','September','Oktober','November','Dezember'],
			monthNamesShort: ['Jan','Feb','Mär','Apr','Mai','Jun','Jul','Aug','Sep','Okt','Nov','Dez'],
			monthStatus: 'anderen Monat anzeigen',
			yearStatus: 'anderes Jahr anzeigen',
			weekHeader: 'Wo',
			weekStatus: 'Woche des Monats',
			dayNames: ['Sonntag','Montag','Dienstag','Mittwoch','Donnerstag','Freitag','Samstag'],
			dayNamesShort: ['So','Mo','Di','Mi','Do','Fr','Sa'],
			dayNamesMin: ['So','Mo','Di','Mi','Do','Fr','Sa'],
			dayStatus: 'Setze DD als ersten Wochentag',
			dateStatus: 'Wähle D, M d',
			dateFormat: 'dd.mm.yy',
			firstDay: 1,
			initStatus: 'Wähle ein Datum',
			isRTL: false
		};
		$.datepicker.setDefaults($.datepicker.regional['de']);
	});

	$.datepicker.setDefaults( $.datepicker.regional[ "de" ] );

	$(function() {
		$( "#datepickerOneDaySelect" ).datepicker({
			showOn: "both",
			buttonImage: "/fileadmin/templates/images/ico-calendar2.gif",
			buttonImageOnly: true,
			numberOfMonths: 2,
			beforeShow: function() {
				$('.vscroll-slider').css("z-index", 0);
			},
			minDate: 0,

			onSelect: function(dateText, inst){
				sc_array = getCleanURLarray();

				if(sc_array["facet"] == undefined){
					sc_array = jQuery.deparam(jQuery.param({"facet":{"SpecialDay":1, "datepickerOneDay":dateText}}));
				}else{
					sc_array["facet"]["SpecialDay"] = "1";
					sc_array["facet"]["datepickerOneDay"] = dateText;
				}

				window.location = jQuery.param.querystring(window.location.href, sc_array, 0);
			}
		});
	});

	var dates = $( "#datefrom, #dateto" ).datepicker({

		beforeShow: function() {
			$('.vscroll-slider').css("z-index", 0);
		},

		showOn: "both",
		buttonImage: "/fileadmin/templates/images/ico-calendar2.gif",
		buttonImageOnly: true,
		minDate: 0,
		changeMonth: true,
		numberOfMonths: 2,
		onSelect: function( selectedDate ) {
			var option = this.id == "datefrom" ? "minDate" : "maxDate",
			instance = $( this ).data( "datepicker" );
			date = $.datepicker.parseDate(
				instance.settings.dateFormat ||
				$.datepicker._defaults.dateFormat,
				selectedDate, instance.settings );

			dates.not( this ).datepicker( "option", option, date );

			if(jQuery('#datefrom').val() != '' && jQuery('#dateto').val() != ''  ){

				sc_array = getCleanURLarray();

				sc_array["facet"]["datefrom"] = jQuery('#datefrom').val();
				sc_array["facet"]["dateto"] = jQuery('#dateto').val();
				sc_array["facet"]["SpecialRange"] = 1;
				sc_array["facet"]['SpecialRangeDetail'] = Array();
				sc_array["facet"]['SpecialRangeDetail'][0] = "ownRange";

				window.location = jQuery.param.querystring(window.location.href, sc_array, 0);
			}
		}
	});

	jQuery("#SpecialRangeDetail").click(function(){

		if(jQuery("#SpecialRangeDetail :selected").val() == 'nwoe'){

			sc_array = getCleanURLarray();
			sc_array["facet"]["SpecialRange"] = 1;
			sc_array["facet"]['SpecialRangeDetail'] = Array();
			sc_array["facet"]['SpecialRangeDetail'][0] = "nwoe";

			window.location = jQuery.param.querystring(window.location.href, sc_array, 0);
		}

		if(jQuery("#SpecialRangeDetail :selected").val() == '8tage'){

			sc_array = getCleanURLarray();
			sc_array["facet"]["SpecialRange"] = 1;
			sc_array["facet"]['SpecialRangeDetail'] = Array();
			sc_array["facet"]['SpecialRangeDetail'][0] = "8tage";

			window.location = jQuery.param.querystring(window.location.href, sc_array, 0);
		}

		if(jQuery("#SpecialRangeDetail :selected").val() == 'month'){

			sc_array = getCleanURLarray();
			sc_array["facet"]["SpecialRange"] = 1;
			sc_array["facet"]['SpecialRangeDetail'] = Array();
			sc_array["facet"]['SpecialRangeDetail'][0] = "month";

			window.location = jQuery.param.querystring(window.location.href, sc_array, 0);
		}

		if( jQuery("#SpecialRangeDetail option:last").attr('selected')){
			jQuery('#RangepickerOuter').slideDown();
		}else{
			jQuery('#datefrom').val('');
			jQuery('#dateto').val('');
			jQuery('#RangepickerOuter').slideUp();
		}

	});

	jQuery("#alleAnzeigenTermin").click(function(){
		sc_array = getCleanURLarray();
		window.location = jQuery.param.querystring(window.location.href, sc_array, 0);
//		jQuery("#EventWeekEndDay").attr('checked', false);
//		jQuery("#SpecialDay").attr('checked', false);
//		jQuery("#SpecialRange").attr('checked', false);
	});

}

function initAdvancedSearchSelectors() {
	if( jQuery("#AdvStatus3").attr('checked') != true){
		jQuery("#AdvSelectedStatiDetail").slideUp();
		jQuery("#AdvSpecialTimeDetail").slideUp();
		jQuery("#AdvSpecialDateDetail").slideUp();
	}
	jQuery("#AdvStatus3").change(function(){
		if ( jQuery(this).attr('checked') == true ) {
			jQuery("#AdvSelectedStatiDetail").slideDown();
		}
	});
	jQuery("#AdvStatus2, #AdvStatus2").change(function(){
		if ( jQuery(this).attr('checked') == true ) {
			jQuery("#AdvSelectedStatiDetail").slideUp();
		}
	});

	if( jQuery("#AdvEvent-status3").attr('checked') != true){
		jQuery("#AdvSpecialTimeDetail").slideUp();
	}
	jQuery("#AdvEvent-status3").change(function(){
		if ( jQuery(this).attr('checked') == true ) {
			jQuery("#AdvSpecialTimeDetail").slideDown();
		}
	});
	jQuery("#AdvEvent-status1, #AdvEvent-status2").change(function(){
		if ( jQuery(this).attr('checked') == true ) {
			jQuery("#AdvSpecialTimeDetail").slideUp();
		}
	});

	if( jQuery("#AdvEvent-status2").attr('checked') != true){
		jQuery("#AdvSpecialDateDetail").slideUp();
	}
	jQuery("#AdvEvent-status2").change(function(){
		if ( jQuery(this).attr('checked') == true ) {
			jQuery("#AdvSpecialDateDetail").slideDown();
		}
	});
	jQuery("#AdvEvent-status1, #AdvEvent-status3").change(function(){
		if ( jQuery(this).attr('checked') == true ) {
			jQuery("#AdvSpecialDateDetail").slideUp();
		}
	});

}


function resetfields(){

	jQuery('#SpecialRangeDetail').val('');
	jQuery('#datefrom').val('');
	jQuery('#dateto').val('');
	jQuery('#datepickerOneDay').val('');
	jQuery('#datepickerOneDay').slideUp();
	jQuery('#SpecialRangeDetail').slideUp();
	jQuery('#RangepickerOuter').slideUp();

}

function SpecialDay(){
	resetfields();
	if( jQuery("#SpecialDay").attr('checked') == true){
		jQuery('#datepickerOneDay').slideDown(500,function(){
			});
//		jQuery('#alleAnzeigenTermin').slideDown(500,function(){
//			$("#RangepickerOuter").css("height", "25px");
//		});

		jQuery("#SpecialRange").attr('checked', false);
		jQuery("#EventWeekEndDay").attr('checked', false);

		jQuery("#SpecialRange").parent().find(".checkboxAreaChecked").removeClass('checkboxAreaChecked').addClass('checkboxArea');
		jQuery("#EventWeekEndDay").parent().find(".checkboxAreaChecked").removeClass('checkboxAreaChecked').addClass('checkboxArea');

	}else{
		sc_array = getCleanURLarray();
		window.location = jQuery.param.querystring(window.location.href, sc_array, 0);
	}
}



function var_dump(obj) {
	if(typeof obj == "object") {
		return "Type: "+typeof(obj)+((obj.constructor) ? "\nConstructor: "+obj.constructor : "")+"\nValue: " + obj;
	} else {
		return "Type: "+typeof(obj)+"\nValue: "+obj;
	}
}//end function var_dump

function SpecialRange(){
	resetfields();
	if( jQuery("#SpecialRange").attr('checked') == true){
		jQuery('#SpecialRangeDetail').slideDown();
//		jQuery('#alleAnzeigenTermin').slideDown();
		jQuery("#SpecialDay").attr('checked', false);
		jQuery("#EventWeekEndDay").attr('checked', false);
		jQuery("#SpecialDay").parent().find(".checkboxAreaChecked").removeClass('checkboxAreaChecked').addClass('checkboxArea');
		jQuery("#EventWeekEndDay").parent().find(".checkboxAreaChecked").removeClass('checkboxAreaChecked').addClass('checkboxArea');

	}else{
		sc_array = getCleanURLarray();
		window.location = jQuery.param.querystring(window.location.href, sc_array, 0);
	}
}

function EventWeekEndDay(){

	resetfields();
	if( jQuery("#EventWeekEndDay").attr('checked') == true){

//		jQuery('#alleAnzeigenTermin').slideDown();
		jQuery("#SpecialRange").attr('checked', false);
		jQuery("#SpecialDay").attr('checked', false);
		jQuery("#SpecialRange").parent().find(".checkboxAreaChecked").removeClass('checkboxAreaChecked').addClass('checkboxArea');
		jQuery("#SpecialDay").parent().find(".checkboxAreaChecked").removeClass('checkboxAreaChecked').addClass('checkboxArea');

		sc_array = getCleanURLarray();

		if(sc_array["facet"] == undefined){
			sc_array = jQuery.deparam(jQuery.param({facet:{EventWeekEndDay:1}}));
		}else{
			sc_array["facet"]["EventWeekEndDay"] = "1";
		}

		window.location = jQuery.param.querystring(window.location.href, sc_array, 0);

	}else{
		sc_array = getCleanURLarray();
		window.location = jQuery.param.querystring(window.location.href, sc_array, 0);
	}
}


function params_unserialize(p){
	var ret = {},
	seg = p.replace(/^\?/,'').split('&'),
	len = seg.length, i = 0, s;
	for (;i<len;i++) {
		if (!seg[i]) {
			continue;
		}
		s = seg[i].split('=');
		ret[s[0]] = s[1];
	}
	return ret;
}
/*
 * jQuery BBQ: Back Button & Query Library - v1.2.1 - 2/17/2010
 * http://benalman.com/projects/jquery-bbq-plugin/
 *
 * Copyright (c) 2010 "Cowboy" Ben Alman
 * Dual licensed under the MIT and GPL licenses.
 * http://benalman.com/about/license/
 */
(function($,p){var i,m=Array.prototype.slice,r=decodeURIComponent,a=$.param,c,l,v,b=$.bbq=$.bbq||{},q,u,j,e=$.event.special,d="hashchange",A="querystring",D="fragment",y="elemUrlAttr",g="location",k="href",t="src",x=/^.*\?|#.*$/g,w=/^.*\#/,h,C={};function E(F){return typeof F==="string"}function B(G){var F=m.call(arguments,1);return function(){return G.apply(this,F.concat(m.call(arguments)))}}function n(F){return F.replace(/^[^#]*#?(.*)$/,"$1")}function o(F){return F.replace(/(?:^[^?#]*\?([^#]*).*$)?.*/,"$1")}function f(H,M,F,I,G){var O,L,K,N,J;if(I!==i){K=F.match(H?/^([^#]*)\#?(.*)$/:/^([^#?]*)\??([^#]*)(#?.*)/);J=K[3]||"";if(G===2&&E(I)){L=I.replace(H?w:x,"")}else{N=l(K[2]);I=E(I)?l[H?D:A](I):I;L=G===2?I:G===1?$.extend({},I,N):$.extend({},N,I);L=a(L);if(H){L=L.replace(h,r)}}O=K[1]+(H?"#":L||!K[1]?"?":"")+L+J}else{O=M(F!==i?F:p[g][k])}return O}a[A]=B(f,0,o);a[D]=c=B(f,1,n);c.noEscape=function(G){G=G||"";var F=$.map(G.split(""),encodeURIComponent);h=new RegExp(F.join("|"),"g")};c.noEscape(",/");$.deparam=l=function(I,F){var H={},G={"true":!0,"false":!1,"null":null};$.each(I.replace(/\+/g," ").split("&"),function(L,Q){var K=Q.split("="),P=r(K[0]),J,O=H,M=0,R=P.split("]["),N=R.length-1;if(/\[/.test(R[0])&&/\]$/.test(R[N])){R[N]=R[N].replace(/\]$/,"");R=R.shift().split("[").concat(R);N=R.length-1}else{N=0}if(K.length===2){J=r(K[1]);if(F){J=J&&!isNaN(J)?+J:J==="undefined"?i:G[J]!==i?G[J]:J}if(N){for(;M<=N;M++){P=R[M]===""?O.length:R[M];O=O[P]=M<N?O[P]||(R[M+1]&&isNaN(R[M+1])?{}:[]):J}}else{if($.isArray(H[P])){H[P].push(J)}else{if(H[P]!==i){H[P]=[H[P],J]}else{H[P]=J}}}}else{if(P){H[P]=F?i:""}}});return H};function z(H,F,G){if(F===i||typeof F==="boolean"){G=F;F=a[H?D:A]()}else{F=E(F)?F.replace(H?w:x,""):F}return l(F,G)}l[A]=B(z,0);l[D]=v=B(z,1);$[y]||($[y]=function(F){return $.extend(C,F)})({a:k,base:k,iframe:t,img:t,input:t,form:"action",link:k,script:t});j=$[y];function s(I,G,H,F){if(!E(H)&&typeof H!=="object"){F=H;H=G;G=i}return this.each(function(){var L=$(this),J=G||j()[(this.nodeName||"").toLowerCase()]||"",K=J&&L.attr(J)||"";L.attr(J,a[I](K,H,F))})}$.fn[A]=B(s,A);$.fn[D]=B(s,D);b.pushState=q=function(I,F){if(E(I)&&/^#/.test(I)&&F===i){F=2}var H=I!==i,G=c(p[g][k],H?I:{},H?F:2);p[g][k]=G+(/#/.test(G)?"":"#")};b.getState=u=function(F,G){return F===i||typeof F==="boolean"?v(F):v(G)[F]};b.removeState=function(F){var G={};if(F!==i){G=u();$.each($.isArray(F)?F:arguments,function(I,H){delete G[H]})}q(G,2)};e[d]=$.extend(e[d],{add:function(F){var H;function G(J){var I=J[D]=c();J.getState=function(K,L){return K===i||typeof K==="boolean"?l(I,K):l(I,L)[K]};H.apply(this,arguments)}if($.isFunction(F)){H=F;return G}else{H=F.handler;F.handler=G}}})})(jQuery,this);
/*
 * jQuery hashchange event - v1.2 - 2/11/2010
 * http://benalman.com/projects/jquery-hashchange-plugin/
 *
 * Copyright (c) 2010 "Cowboy" Ben Alman
 * Dual licensed under the MIT and GPL licenses.
 * http://benalman.com/about/license/
 */
(function($,i,b){var j,k=$.event.special,c="location",d="hashchange",l="href",f=$.browser,g=document.documentMode,h=f.msie&&(g===b||g<8),e="on"+d in i&&!h;function a(m){m=m||i[c][l];return m.replace(/^[^#]*#?(.*)$/,"$1")}$[d+"Delay"]=100;k[d]=$.extend(k[d],{setup:function(){if(e){return false}$(j.start)},teardown:function(){if(e){return false}$(j.stop)}});j=(function(){var m={},r,n,o,q;function p(){o=q=function(s){return s};if(h){n=$('<iframe src="javascript:0"/>').hide().insertAfter("body")[0].contentWindow;q=function(){return a(n.document[c][l])};o=function(u,s){if(u!==s){var t=n.document;t.open().close();t[c].hash="#"+u}};o(a())}}m.start=function(){if(r){return}var t=a();o||p();(function s(){var v=a(),u=q(t);if(v!==t){o(t=v,u);$(i).trigger(d)}else{if(u!==t){i[c][l]=i[c][l].replace(/#.*/,"")+"#"+u}}r=setTimeout(s,$[d+"Delay"])})()};m.stop=function(){if(!n){r&&clearTimeout(r);r=0}};return m})()})(jQuery,this);
