jQuery.noConflict();
// html5shiv MIT @rem remysharp.com/html5-enabling-script
// iepp v1.6.2 MIT @jon_neal iecss.com/print-protector
/*@cc_on(function(m,c){var z="abbr|article|aside|audio|canvas|details|figcaption|figure|footer|header|hgroup|mark|meter|nav|output|progress|section|summary|time|video";function n(d){for(var a=-1;++a<o;)d.createElement(i[a])}function p(d,a){for(var e=-1,b=d.length,j,q=[];++e<b;){j=d[e];if((a=j.media||a)!="screen")q.push(p(j.imports,a),j.cssText)}return q.join("")}var g=c.createElement("div");g.innerHTML="<z>i</z>";if(g.childNodes.length!==1){var i=z.split("|"),o=i.length,s=RegExp("(^|\\s)("+z+")",
"gi"),t=RegExp("<(/*)("+z+")","gi"),u=RegExp("(^|[^\\n]*?\\s)("+z+")([^\\n]*)({[\\n\\w\\W]*?})","gi"),r=c.createDocumentFragment(),k=c.documentElement;g=k.firstChild;var h=c.createElement("body"),l=c.createElement("style"),f;n(c);n(r);g.insertBefore(l,
g.firstChild);l.media="print";m.attachEvent("onbeforeprint",function(){var d=-1,a=p(c.styleSheets,"all"),e=[],b;for(f=f||c.body;(b=u.exec(a))!=null;)e.push((b[1]+b[2]+b[3]).replace(s,"$1.iepp_$2")+b[4]);for(l.styleSheet.cssText=e.join("\n");++d<o;){a=c.getElementsByTagName(i[d]);e=a.length;for(b=-1;++b<e;)if(a[b].className.indexOf("iepp_")<0)a[b].className+=" iepp_"+i[d]}r.appendChild(f);k.appendChild(h);h.className=f.className;h.innerHTML=f.innerHTML.replace(t,"<$1font")});m.attachEvent("onafterprint",
function(){h.innerHTML="";k.removeChild(h);k.appendChild(f);l.styleSheet.cssText=""})}})(this,document);@*/
jQuery(function(){
	addRequired();
	initRememberLink();
	jQuery('html').addClass('js-load');
	
	jQuery('#user-login #edit-name-1').val('ihrname@ihredomain.de');
	
	jQuery('#simplenews-block-form-1 input:submit').val('Abschicken');
	
	jQuery('#simplenews-block-form-1 #edit-mail').val('ihrname@ihredomain.de');
	
	jQuery('#webform-client-form-23 #edit-submit').val('ABSCHICKEN');
	
	jQuery('#edit-mail-wrapper label').text('Newsletter abonnieren');
	
	jQuery('#edit-search-theme-form-1').val('Suchen...');
	
	jQuery('#edit-submit-1').val('Suchen');

	jQuery('.frontlogin #edit-name').val('ihrname@ihredomain.de');

	jQuery('#user-login input:submit').val('LOG IN');
	
	jQuery('#edit-search-block-form-1').val('Bitte geben Sie hier Ihr Thema ein.');
	
	clearInputs();	
	SlideBlock();
	loginBox();
	jQuery('.webform-client-form select').customSelect();
	priceTable();
	ieHover('.contact-form .submit,.faq-search .submit','hover');
	jQuery('.entry').fadeGallery({
		slideElements:'ul.slideset > li',
		IE:true,
		autoHeight:true,
		switchTime:7000,
		autoRotation:7000
	});
	//initSelectTabs();
	initSelTab();
});
//add required span
function addRequired(){
	var holder = jQuery('#content');
	if(holder.length){
		var form = holder.find('.webform-client-form');
		var span = holder.find('span.required');
		if(form.length && span.length){
			var cloneSpan = span.clone().show();
			var row = form.find('#edit-actions');
			cloneSpan.appendTo(row);
		}
	}
}
//init remember link
function initRememberLink(){
	var holders = jQuery('.drop');
	holders.each(function(){
		var holder = jQuery(this);
		if(holder.parent().hasClass('login')){
			var activeClass = 'search-active';
			var search = jQuery('.search');
			holder.click(function(){
				if(search.length){
					if(!search.hasClass(activeClass)){
						search.addClass(activeClass);
					}
				}
			});
			jQuery('body').click(function(e){
				if (!jQuery(e.target).parents('.drop').length || !jQuery(e.target).parents('#search').length) {
					search.removeClass(activeClass);
				}
			});
		}
		var form = holder.find('#user-login');
		var link = holder.find('.remember-link');
		if(form.length && link.length){
			 var cloneLink = link.show().clone();
			 link.hide();
			 cloneLink.appendTo(form);
		}
	});	
}
// tabs function
/*
function initSelectTabs(){
	var sets = document.getElementsByTagName("select");
	for (var i = 0; i < sets.length; i++){
		if (sets[i].className.indexOf("tabswitcher") != -1){
			// hide inactive tabs
			var links = sets[i].getElementsByTagName("option");
			for (var j = 0; j < links.length; j++){
				if(links[j].value.length>0) {
					curtab = document.getElementById(links[j].value);
					if(curtab) {
						if(links[j].selected)
							curtab.style.display = "block";
						else
							curtab.style.display = "none";
					}
				}
			}
			// tabs switch function
			sets[i].onchange = function () {
				var _links = this.parentNode.getElementsByTagName("option");
				for (var k = 0; k < _links.length; k++){
					if(_links[k].value.length>0) {
						_curtab = document.getElementById(_links[k].value);
						if(_curtab) {
							if(_links[k].selected)
								_curtab.style.display = "block";
							else
								_curtab.style.display = "none";
						}
					}
				}
			}

		}
	}
}
*/
function initSelTab(){
	var wrapps = jQuery('.webform-client-form');
	wrapps.each(function(){
		var wrapp = jQuery(this);
		var selTabs = wrapp.find('#edit-submitted-anfragetyp.form-select');
		selTabs.each(function(){
			var selTab = jQuery(this);
			var options = selTab.find('option');
			options.each(function(ind){
				var option = jQuery(this);
				var id = jQuery(option.val()).attr('href');
				jQuery(id).hide();
			});

			function selectChange() {
				options.each(function(){
					var option = jQuery(this);
					var id = jQuery(option.val()).attr('href');
					jQuery(id).hide();
				})
				jQuery(jQuery(selTab.val()).attr('href')).show();
			}

			selTab.change(selectChange);
			selectChange();
		})
	})
}
/*--- IE6 hover ---*/
function ieHover(h_list, h_class){
	if(jQuery.browser.msie && jQuery.browser.version < 7){
		if(!h_class) var h_class = 'hover';
		jQuery(h_list).mouseenter(function(){
			jQuery(this).addClass(h_class);
		}).mouseleave(function(){
			jQuery(this).removeClass(h_class);
		});
	}
}
/*---- clear inputs ---*/
function clearInputs(){
	jQuery('input:text, input:password, textarea').each(function(){
		var _el = jQuery(this);
		var _val = _el.val();
		_el.bind('focus', function(){
			if(jQuery(_el).hasClass('form-text')) jQuery(_el).parents('.search').addClass('search-active-state');
			if(this.value == _val) this.value = '';
		}).bind('blur', function(){
			if(jQuery(_el).hasClass('form-text')) jQuery(_el).parents('.search').removeClass('search-active-state');
			if(this.value == '') this.value = _val;
		});
	});
}
function priceTable(){
	jQuery('.price-section tbody tr:odd').addClass('alt-row');
	jQuery('.price-section th:odd').addClass('alt-cell');
	jQuery('.price-section tbody tr:first-child').addClass('first-row');
	jQuery('.price-section tbody tr:last-child').addClass('last-row');
	jQuery('.price-section tbody td:first-child').addClass('first-cell');
	jQuery('.price-section tbody td:last-child').addClass('last-cell');
}
function loginBox(){
	var _box = jQuery('.login');
	var _drop = jQuery('.login .drop');
	_drop.hide();
	_box.hover(
		function(){_drop.stop(true,true).slideDown(400)},
		function(){_drop.stop(true,true).slideUp(400)}
	);
}
function SlideBlock(){
	var _parentSlide = '.faq-list li';
	var _linkSlide = '.opener';
	var _slideBlock = '.slide';
	var _openClassS = 'active';
	var _durationSlide = 500;
	jQuery('.faq-list li:odd').addClass('alt');
	jQuery(_parentSlide).each(function(){
		var _hold = jQuery(this);
		var _btn = _hold.find(_linkSlide).eq(0);
		var _box = _hold.find(_slideBlock).eq(0);
		if(_box.length && _btn.length){
			var _h = _box.outerHeight();
			if(_hold.hasClass(_openClassS)){
				_box.show();
			}
			else{
				_box.hide();
			}
			_btn.click(function(){
				if(_hold.hasClass(_openClassS)){
					_hold.removeClass(_openClassS);
					_box.stop().animate({height:0}, _durationSlide, function(){ jQuery(this).css({display:'none', height:'auto'});});
				}
				else{
					_hold.addClass(_openClassS);
					if(_box.is(':hidden')){
						_box.show();
						_h = _box.outerHeight();
						_box.height(0);
					}
					_box.stop().animate({height:_h}, _durationSlide, function(){ jQuery(this).height('auto')});
				}
				return false;
			});
		}
	});
}
/*--- custom select's ---*/
jQuery.fn.customSelect = function(_options){
var _options = jQuery.extend({
	selectStructure: '<div class="selectArea"><div class="left"></div><div class="center"></div><a href="#" class="selectButton">&nbsp;</a><div class="disabled"></div></div>',
	selectText: '.center',
	selectBtn: '.selectButton',
	selectDisabled: '.disabled',
	optStructure: '<div class="selectOptions"><div class="select-top"></div><div class="select-list"><ul></ul></div><div class="select-bottom"></div></div>',
	optList: 'ul',
	maxHeight: 99999
}, _options);
return this.each(function(){
	var select = jQuery(this);
	if(!select.hasClass('outtaHere')){
		if(select.is(':visible')){
			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);
			var maxH = _options.maxHeight;
			if(select.attr('disabled')) selectDisabled.show();
			select.find('option').each(function(){
				var selOpt = jQuery(this);
				var _opt = jQuery('<li><a href="#"><span>' + selOpt.html() + '</span></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');
					jQuery(this).parent().addClass('selected');
					selOpt.attr('selected', 'selected');
					selectText.html(selOpt.html());
					select.change();
					optHolder.hide();
					replaced.removeClass('selectAreaActive');
					if(typeof(select.change) == 'function') select.change();
					if(typeof(select.get(0).onchange) == 'function') select.get(0).onchange();
					return false;
				});
				optList.append(_opt);
			});
			replaced.width(select.outerWidth());
			replaced.insertBefore(select);
			optHolder.css({
				width: select.outerWidth(),
				display: 'none',
				position: 'absolute'
			});
			 if(select.attr('class') && select.attr('class') != '')
			optHolder.addClass('drop-'+select.attr('class').split(' ')[0]);
			jQuery(document.body).append(optHolder);
			
			var optTimer;
			replaced.hover(function(){
				if(optTimer) clearTimeout(optTimer);
			}, function(){
				optTimer = setTimeout(function() {
					optHolder.hide();
					replaced.removeClass('selectAreaActive');
				}, 200);
			});
			optHolder.hover(function(){
				if(optTimer) clearTimeout(optTimer);
			}, function() {
				optTimer = setTimeout(function() {
					optHolder.hide();
					replaced.removeClass('selectAreaActive');
				}, 200);
			});
			selectBtn.click(function(){
				if(optHolder.is(':visible')){
					optHolder.hide();
					replaced.removeClass('selectAreaActive');
				}
				else{
					replaced.addClass('selectAreaActive');
					optHolder.css({
						top: replaced.offset().top + replaced.outerHeight(),
						left: replaced.offset().left,
						display: 'block'
					});
					if(optHolder.children('div.select-list').height() > maxH) optHolder.children('div.select-list').css({height:maxH, overflow:'auto'}).customScrollV();
				}
				return false;
			});
			select.addClass('outtaHere');
		}
	}
});
}
// slideshow plugin
jQuery.fn.fadeGallery = function(_options){
	var _options = jQuery.extend({
		slideElements:'div.slideset > div',
		pagerLinks:'div.pager a',
		btnNext:'a.btn-next',
		btnPrev:'a.btn-prev',
		btnPlayPause:'a.play-pause',
		btnPlay:'a.play',
		btnPause:'a.pause',
		pausedClass:'paused',
		disabledClass: 'disabled',
		playClass:'playing',
		activeClass:'active',
		currentNum:false,
		allNum:false,
		startSlide:null,
		noCircle:false,
		pauseOnHover:true,
		autoRotation:false,
		autoHeight:false,
		onChange:false,
		switchTime:3000,
		duration:650,
		event:'click',
		IE:false
	},_options);

	return this.each(function(){
		// gallery options
		var _this = jQuery(this);
		var _slides = jQuery(_options.slideElements, _this);
		var _pagerLinks = jQuery(_options.pagerLinks, _this);
		var _btnPrev = jQuery(_options.btnPrev, _this);
		var _btnNext = jQuery(_options.btnNext, _this);
		var _btnPlayPause = jQuery(_options.btnPlayPause, _this);
		var _btnPause = jQuery(_options.btnPause, _this);
		var _btnPlay = jQuery(_options.btnPlay, _this);
		var _pauseOnHover = _options.pauseOnHover;
		var _autoRotation = _options.autoRotation;
		var _activeClass = _options.activeClass;
		var _disabledClass = _options.disabledClass;
		var _pausedClass = _options.pausedClass;
		var _playClass = _options.playClass;
		var _autoHeight = _options.autoHeight;
		var _duration = _options.duration;
		if (_options.IE && jQuery.browser.msie) {
			if (jQuery.browser.version < 9) _duration = 0;
		}
		var _switchTime = _options.switchTime;
		var _controlEvent = _options.event;
		var _currentNum = (_options.currentNum ? jQuery(_options.currentNum, _this) : false);
		var _allNum = (_options.allNum ? jQuery(_options.allNum, _this) : false);
		var _startSlide = _options.startSlide;
		var _noCycle = _options.noCircle;
		var _onChange = _options.onChange;

		// gallery init
		var _hover = false;
		var _prevIndex = 0;
		var _currentIndex = 0;
		var _slideCount = _slides.length;
		var _timer;
		if(_slideCount < 2) return;

		_prevIndex = _slides.index(_slides.filter('.'+_activeClass));
		if(_prevIndex < 0) _prevIndex = _currentIndex = 0;
		else _currentIndex = _prevIndex;
		if(_startSlide != null) {
			if(_startSlide == 'random') _prevIndex = _currentIndex = Math.floor(Math.random()*_slideCount);
			else _prevIndex = _currentIndex = parseInt(_startSlide);
		}
		_slides.hide().eq(_currentIndex).show();
		if(_autoRotation) _this.removeClass(_pausedClass).addClass(_playClass);
		else _this.removeClass(_playClass).addClass(_pausedClass);

		// gallery control
		if(_btnPrev.length) {
			_btnPrev.bind(_controlEvent,function(){
				prevSlide();
				return false;
			});
		}
		if(_btnNext.length) {
			_btnNext.bind(_controlEvent,function(){
				nextSlide();
				return false;
			});
		}
		if(_pagerLinks.length) {
			_pagerLinks.each(function(_ind){
				jQuery(this).bind(_controlEvent,function(){
					if(_currentIndex != _ind) {
						_prevIndex = _currentIndex;
						_currentIndex = _ind;
						switchSlide();
					}
					return false;
				});
			});
		}

		// play pause section
		if(_btnPlayPause.length) {
			_btnPlayPause.bind(_controlEvent,function(){
				if(_this.hasClass(_pausedClass)) {
					_this.removeClass(_pausedClass).addClass(_playClass);
					_autoRotation = true;
					autoSlide();
				} else {
					_autoRotation = false;
					if(_timer) clearTimeout(_timer);
					_this.removeClass(_playClass).addClass(_pausedClass);
				}
				return false;
			});
		}
		if(_btnPlay.length) {
			_btnPlay.bind(_controlEvent,function(){
				_this.removeClass(_pausedClass).addClass(_playClass);
				_autoRotation = true;
				autoSlide();
				return false;
			});
		}
		if(_btnPause.length) {
			_btnPause.bind(_controlEvent,function(){
				_autoRotation = false;
				if(_timer) clearTimeout(_timer);
				_this.removeClass(_playClass).addClass(_pausedClass);
				return false;
			});
		}

		// gallery animation
		function prevSlide() {
			_prevIndex = _currentIndex;
			if(_currentIndex > 0) _currentIndex--;
			else {
				if(_noCycle) return;
				else _currentIndex = _slideCount-1;
			}
			switchSlide();
		}
		function nextSlide() {
			_prevIndex = _currentIndex;
			if(_currentIndex < _slideCount-1) _currentIndex++;
			else {
				if(_noCycle) return;
				else _currentIndex = 0;
			}
			switchSlide();
		}
		function refreshStatus() {
			if(_pagerLinks.length) _pagerLinks.removeClass(_activeClass).eq(_currentIndex).addClass(_activeClass);
			if(_currentNum) _currentNum.text(_currentIndex+1);
			if(_allNum) _allNum.text(_slideCount);
			_slides.eq(_prevIndex).removeClass(_activeClass);
			_slides.eq(_currentIndex).addClass(_activeClass);
			if(_noCycle) {
				if(_btnPrev.length) {
					if(_currentIndex == 0) _btnPrev.addClass(_disabledClass);
					else _btnPrev.removeClass(_disabledClass);
				}
				if(_btnNext.length) {
					if(_currentIndex == _slideCount-1) _btnNext.addClass(_disabledClass);
					else _btnNext.removeClass(_disabledClass);
				}
			}
			if(typeof _onChange === 'function') {
				_onChange(_this, _currentIndex);
			}
		}
		function switchSlide() {
			_slides.eq(_prevIndex).fadeOut(_duration);
			_slides.eq(_currentIndex).fadeIn(_duration);
			if(_autoHeight) _slides.eq(_currentIndex).parent().animate({height:_slides.eq(_currentIndex).outerHeight(true)},{duration:_duration,queue:false});
			refreshStatus();
			autoSlide();
		}

		// autoslide function
		function autoSlide() {
			if(!_autoRotation || _hover) return;
			if(_timer) clearTimeout(_timer);
			_timer = setTimeout(nextSlide,_switchTime+_duration);
		}
		if(_pauseOnHover) {
			_this.hover(function(){
				_hover = true;
				if(_timer) clearTimeout(_timer);
			},function(){
				_hover = false;
				autoSlide();
			});
		}
		refreshStatus();
		autoSlide();
	});
}
