$(document).ready(function(){
	slideLogin();
	initGall();
	initTabs('.tabset');
	if(typeof initSIFR == "function")
		initSIFR();
	initSlideGall();
	slideBlock();
	completeInputs();
	clearInputs();
	initMenu();
	initPopup();
	initIEpng();
	openMore();
});
/*--- function open more ---*/
function openMore(){
	$('a.more-btn').click(function(){
		var _box = $(this).parent().nextAll('.more-text:eq(0)');
		if(_box.length){
			_box.show();
			var _h = _box.height();
			_box.height(0);
			$(this).fadeOut(300);
			_box.animate({height:_h}, 300, function(){ $(this).height('auto');});
			return false;
		}
	});
}
function initH(){
	var _h = $('#content').outerHeight(true) + $('#header').outerHeight(true) + $('#footer').outerHeight(true);
	if(_h < $('body').height()) _h = $('body').height();
	if(_h < $(window).height()) _h = $(window).height();
	return _h;
}
/*--- IE6 image align ---*/
function initImageAlign(){
	var holder = document.getElementById("project-image");
	if(holder)
	{
		var image = holder.getElementsByTagName("img").item(0);
		if(image.offsetHeight > 570)
		{
			holder.style.height = image.offsetHeight + "px";
		}
	}
}
if (document.all && !window.opera)
	attachEvent("onload", initImageAlign);
/*--- function init popup ---*/
function initPopup(){
	var stay_time = 4000; // in ms
	/*--- btn to display popup ---*/
	$('a.image-popup-btn').click(function(){
		if(_popup.length){
			var p_btn = this;
			popup_fader.css({opacity: 0, display:'block', height: initH()}).fadeTo(400, 0.8, function(){
				if ($.browser.msie && $.browser.version < 7) _popup.show();
				else _popup.fadeIn(200);
				_init(p_btn);
				_popup.css('top', $(window).scrollTop() + ($(window).height()-_popup.height())/2);
			});
			return false;
		}
	});
	function changeImg(_ind){
		if(_ind != _a){
			if(_ind == 0){
				btn_prev1.addClass('disable');
				btn_prev2.addClass('disable');
				temp_f1 = true;
				btn_prev1.css('margin-right', -btn_prev1.width());
			}
			else{
				btn_prev1.removeClass('disable');
				btn_prev2.removeClass('disable');
			}
			if(_ind == _btn.length -1){
				btn_next1.addClass('disable');
				btn_next2.addClass('disable');
				temp_f2 = true;
				btn_next1.css('margin-left', -btn_next1.width());
			}
			else{
				btn_next1.removeClass('disable');
				btn_next2.removeClass('disable');
			}
			if(!_btn.get(_ind)._img){
				_btn.get(_ind)._img = $(_btn.get(_ind).t_img).css('opacity', 0);
				img_hold.append(_btn.get(_ind)._img);
			}
			_info.html('Bild '+(_ind+1)+' von '+_btn.length);
			_btn.get(_ind)._img.addClass('active').animate({opacity: 1}, {queue:false, duration:500});
			_btn.get(_a)._img.removeClass('active').animate({opacity: 0}, {queue:false, duration:500});
			_btn.eq(_a).removeClass('active');
			_btn.eq(_ind).addClass('active');
			_a = _ind;
		}
		if(_anim){
			clearTimeout(_t);
			_t = setTimeout(function(){
				if(_a == _btn.length - 1) changeImg(0);
				else changeImg(_a + 1);
			}, stay_time);
		}
	}
	function popupPos(){
		var _t100;
		$(window).scroll(function(){
			clearTimeout(_t100);
			if(_popup.is(':visible')){
				_t100 = setTimeout(function(){
					if(_popup.is(':visible')){
						_popup.animate({'top': $(window).scrollTop() + ($(window).height()-_popup.height())/2}, {queue:false, duration:200});
					}
				}, 200);
			}
		}).resize(function(){
			clearTimeout(_t100);
			if(_popup.is(':visible')){
				_t100 = setTimeout(function(){
					if(_popup.is(':visible')){
						_popup.animate({'top': $(window).scrollTop() + ($(window).height()-_popup.height())/2}, {queue:false, duration:200});
					}
				}, 500);
			}
		});
	}
	function _init(_el){
		var t_list = $(_el).parent().children('.popup-images-list').children();
			btn_h = $('<ul></ul>');
		t_list.each(function(){
			var _this = $(this);
			btn_h.append('<li><a href="'+_this.find('.big').text()+'" rel="'+_this.find('.title').text()+'"><img src="'+_this.find('.small').text()+'" width="67" height="67" alt="" /></a></li>');
		});
		btn_h_p.append(btn_h);
		_btn = btn_h.find('a');
		_a = 0;
		_btn.removeClass('active').eq(_a).addClass('active');
		_btn.each(function(_i){
			this._img = false;
			this.t_img = '<img src="'+$(this).attr('href')+'" alt="'+$(this).attr('rel')+'" />';
			if(_i == _a){
				this._img = $(this.t_img);
				img_hold.append(this._img);
				this._img.addClass('active');
			}
		});
		if(_a == 0){
			btn_prev1.addClass('disable');
			btn_prev2.addClass('disable');
		}
		else{
			btn_prev1.removeClass('disable');
			btn_prev2.removeClass('disable');
		}
		
		if(_a == _btn.length -1){
			btn_next1.addClass('disable');
			btn_next2.addClass('disable');
		}
		else{
			btn_next1.removeClass('disable');
			btn_next2.removeClass('disable');
		}
		if(_btn.length == 1){
			btn_prev2.hide();
			btn_next2.hide();
			btn_play.hide();
			btn_stop.hide();
			_info.hide();
			btn_h.parent().hide();
		}
		else{
			btn_prev2.show();
			btn_next2.show();
			if(_anim){
				btn_play.hide();
				btn_stop.show();
			}
			else{
				btn_play.show();
				btn_stop.hide();
			}
			_info.show();
			btn_h.parent().show();
			_info.html('Bild '+(_a+1)+' von '+_btn.length);
		}
		_btn.click(function(){
			if(_anim){
				clearTimeout(_t);
				_anim = false;
				btn_play.show();
				btn_stop.hide();
			}
			changeImg(_btn.index(this));
			return false;
		});
		btn_h_width = btn_h.children().outerWidth()*btn_h.children().length;
		btn_prev1.css('margin-right', -btn_prev1.width());
		btn_next1.css('margin-left', -btn_next1.width());
	}
	
	/*--- popup ---*/
	var _popup = $('#popup-image');
	if($('#popup-fader').length == 0) $('body').append('<div id="popup-fader"></div>');
	var popup_fader = $('#popup-fader').css({
		height:0,
		display: 'none',
		opacity: 0.8
	});
	/*--- popup elements ---*/
	var img_hold = _popup.find('.main-image');
	var btn_h_p = _popup.find('.popup-gallery');
	var btn_h;
	var _btn;
	var _info = _popup.find('.quantity');
	var btn_prev1 = _popup.find('.wrap-main-image .btn-prev a');
	var btn_next1 = _popup.find('.wrap-main-image .btn-next a');
	var btn_prev2 = _popup.find('.popup-buttons .btn-prev');
	var btn_next2 = _popup.find('.popup-buttons .btn-next');
	var btn_play = _popup.find('.popup-buttons .btn-play');
	var btn_stop = _popup.find('.popup-buttons .btn-stop');
	var btn_close = _popup.find('.popup-buttons .btn-close');
	var _a = 0;
	var _t;
	var _d;
	
	btn_play.show();
	btn_stop.hide();
	var _anim = false;

	var temp_f1 = true;
	var temp_f2 = true;
	var temp_f3 = true;
	img_hold.mousemove(function(e){
		if(temp_f1 && (e.pageX - img_hold.offset().left < img_hold.width()/2)){
			temp_f1 = false;
			temp_f2 = true;
			if(!btn_prev1.hasClass('disable')) btn_prev1.animate({marginRight: 0}, {queue:false, duration:200});
			btn_next1.animate({marginLeft: -btn_next1.width()}, {queue:false, duration:200});
		}
		else if(temp_f2 && (e.pageX - img_hold.offset().left > img_hold.width()/2)){
			temp_f2 = false;
			temp_f1 = true;
			if(!btn_next1.hasClass('disable')) btn_next1.animate({marginLeft: 0}, {queue:false, duration:200});
			btn_prev1.animate({marginRight: -btn_prev1.width()}, {queue:false, duration:200});
		}
	}).mouseleave(function(){
		setTimeout(function(){
			if(temp_f3){
				temp_f1 = true;
				temp_f2 = true;
				btn_prev1.animate({marginRight: -btn_prev1.width()}, {queue:false, duration:200});
				btn_next1.animate({marginLeft: -btn_next1.width()}, {queue:false, duration:200});
			}
		}, 200);
	}).click(function(){
		if(_anim){
			clearTimeout(_t);
			_anim = false;
			btn_play.show();
			btn_stop.hide();
		}
		if(!temp_f2 && !btn_next1.hasClass('disable')) changeImg(_a + 1);
		else if(!temp_f1 && !btn_prev1.hasClass('disable')) changeImg(_a - 1); 
		return false;
	});
	btn_next1.mouseenter(function(){
		if(temp_f3){
			temp_f3 = false;
			temp_f1 = true;
			btn_prev1.animate({marginRight: -btn_prev1.width()}, {queue:false, duration:200});
		}
		btn_next1.animate({marginLeft: 0}, {queue:false, duration:200});
	}).mouseleave(function(){
		btn_next1.animate({marginLeft: -btn_next1.width()}, {queue:false, duration:200});
		temp_f3 = true;
	});
	btn_prev1.mouseenter(function(){
		if(temp_f3){
			temp_f3 = false;
			temp_f2 = true;
			btn_next1.animate({marginLeft: -btn_next1.width()}, {queue:false, duration:200});
		}
		btn_prev1.animate({marginRight: 0}, {queue:false, duration:200});
	}).mouseleave(function(){
		btn_prev1.animate({marginRight: -btn_prev1.width()}, {queue:false, duration:200});
		temp_f3 = true;
	});
	
	var temp_f10 = true;
	var temp_f11 = true;
	var temp_f12 = true;
	var btn_h_left = 0;
	var btn_h_width = 0;
	
	btn_h_p.mousemove(function(e){
		if(e.pageX - btn_h_p.offset().left < 100){
			if(temp_f10){
				temp_f10 = false;
				temp_f12 = true;
				if(btn_h_left > 0){
					_d = btn_h_left*3;
					btn_h.stop().animate({marginLeft: 0}, _d, 'linear');
				}
			}
		}
		else if(e.pageX - btn_h_p.offset().left > btn_h_p.width() - 100){
			if(temp_f11){
				temp_f11 = false;
				temp_f12 = true;
				if(btn_h_width - btn_h_left > btn_h_p.width()){
					_d = (btn_h_width - btn_h_p.width() - btn_h_left)*3;
					btn_h.stop().animate({marginLeft: btn_h_p.width() - btn_h_width}, _d, 'linear');
				}
			}
		}
		else{
			if(temp_f12){
				temp_f12 = false;
				temp_f10 = true;
				temp_f11 = true;
				btn_h.stop();
				btn_h_left = -parseInt(btn_h.css('margin-left'));
			}
		}
	}).mouseleave(function(){
		temp_f10 = true;
		temp_f11 = true;
		temp_f12 = true;
		btn_h.stop();
		btn_h_left = -parseInt(btn_h.css('margin-left'));
	});
	/*--- gallery navigation ---*/
	btn_prev1.click(function(){
		if(_anim){
			clearTimeout(_t);
			_anim = false;
			btn_play.show();
			btn_stop.hide();
		}
		temp_f1 = true;
		if(_a - 1 == 0) $(this).css('margin-right', - $(this).width());
		if(this.className.indexOf('disable') == -1) changeImg(_a - 1);
		return false;
	});
	btn_next1.click(function(){
		if(_anim){
			clearTimeout(_t);
			_anim = false;
			btn_play.show();
			btn_stop.hide();
		}
		temp_f2 = true;
		if(_a + 1 == _btn.length - 1) $(this).css('margin-left', - $(this).width());
		if(this.className.indexOf('disable') == -1) changeImg(_a + 1);
		return false;
	});
	btn_prev2.click(function(){
		if(_anim){
			clearTimeout(_t);
			_anim = false;
			btn_play.show();
			btn_stop.hide();
		}
		if(this.className.indexOf('disable') == -1) changeImg(_a - 1);
		return false;
	});
	btn_next2.click(function(){
		if(_anim){
			clearTimeout(_t);
			_anim = false;
			btn_play.show();
			btn_stop.hide();
		}
		if(this.className.indexOf('disable') == -1) changeImg(_a + 1);
		return false;
	});
	
	btn_play.click(function(){
		_anim = true;
		btn_play.hide();
		btn_stop.show();
		_t = setTimeout(function(){
			if(_a == _btn.length - 1) changeImg(0);
			else changeImg(_a + 1);
		}, stay_time);
		return false;
	});
	btn_stop.click(function(){
		_anim = false;
		clearTimeout(_t);
		btn_play.show();
		btn_stop.hide();
		return false;
	});
	btn_close.click(function(){
		_anim = false;
		clearTimeout(_t);
		if ($.browser.msie && $.browser.version < 7){
			_popup.hide();
			popup_fader.hide();
			btn_h_p.empty();
			img_hold.empty();
		}
		else{
			_popup.fadeOut(400, function(){
				popup_fader.fadeOut(200);
				btn_h_p.empty();
				img_hold.empty();
			});
		}
		return false;
	});
	popup_fader.click(function(){
		_anim = false;
		clearTimeout(_t);
		if ($.browser.msie && $.browser.version < 7){
			_popup.hide();
			popup_fader.hide();
			btn_h_p.empty();
			img_hold.empty();
		}
		else{
			_popup.fadeOut(400, function(){
				popup_fader.fadeOut(200);
				btn_h_p.empty();
				img_hold.empty();
			});
		}
		return false;
	});
	popupPos();
}
/*--- IE6 png ---*/
function initIEpng(){
	if ($.browser.msie && $.browser.version < 7) {
		var transparentImage = "images/transparent.html";
		$('img[src$=".png"]').each(function(){
			var src = this.src;
			this.src = transparentImage;
			this.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='scale')";
		});
	}
}
/*--- init Slide Gallery function ---*/
function initSlideGall(){
	var _hold = $('#gallery');
	if(_hold.length > 0){
		var _a = -1;
		var _c = -1;
		var _f = false;
		var _t;
		var t_p;
		var s_posX;

		var list_h = _hold.find('.present > ul');
		var _list = list_h.children();
		var _btn = $('#gallery .slider-list li');
		_btn.children().each(function(){
			$(this).css({'-khtml-user-select': 'none', 'user-select': 'none', '-moz-user-select': 'none'});
			this.onselectstart="return false";
			$(this).hover(function(){
				$(this).addClass('hover');
			}, function(){
				$(this).removeClass('hover');
			});
		});
		var _slider = $('<div class="glass"><div class="glass-l"></div><div class="glass-r"></div></div>').hide();
		$('.#gallery .slider').append(_slider);
		_btn.each(function(_i){
			if($(this).hasClass('active')) _a = _i;
			$(this).children().click(function(){
				_c = -1;
				changeEl(_i);
				_c = 1;
				return false;
			}).mouseenter(function(){
				if(!_f){
					if(_btn.eq(_i).outerWidth() < 120){
						_w = 120;
						_l = _btn.eq(_i).position().left - (_w - _btn.eq(_i).outerWidth())/2;
					}
					else{
						_w = _btn.eq(_i).outerWidth();
						_l = _btn.eq(_i).position().left;
					}
					_slider.animate({width: _w - 103, left: _l}, {queue:false, duration: 500,  easing: 'easeOutBounce'});
				}
			});
		});
		if(_a == -1) _a = 0;
		$('.intro li').hide();
		$('.intro li').eq(_a).show();
		if(_btn.eq(_a).outerWidth() < 120){
			_w = 120;
			_l = _btn.eq(_a).position().left - (_w - _btn.eq(_a).outerWidth())/2;
		}
		else{
			_w = _btn.eq(_a).outerWidth();
			_l = _btn.eq(_a).position().left;
		}
		_slider.css({
			left: _l,
			width: _w - 103
		}).show();
		_list.eq(_a).show();
		/*--- events ---*/
		_hold.hover(function(){
			if(_t) clearTimeout(_t);
		}, function(){
			if(_t) clearTimeout(_t);
			_t = setTimeout(function(){
				if(_a < _list.length - 1) changeEl(_a + 1);
				else changeEl(0);
			}, 8000);
		});
		_hold.find('.slider .btn-prev').click(function(){
			_c = -1;
			if(_a == 0) changeEl(_btn.length - 1);
			else changeEl(_a - 1);
			_c = 1;
			return false;
		});
		_hold.find('.slider .btn-next').click(function(){
			_c = -1;
			if(_a == _btn.length - 1) changeEl(0);
			else changeEl(_a + 1);
			_c = 1;
			return false;
		});
		_hold.find('.slider').mousedown(function(e){
			if((e.pageX > _slider.offset().left) && (e.pageX < _slider.offset().left + _slider.outerWidth())){
				t_p = e.pageX - _slider.offset().left;
				_f = true;
			}
		}).mouseup(function(){
			if(_f){
				var _k = 1000;
				var t_i = 0;
				_btn.each(function(_i){
					var _w1 = Math.abs(($(this).position().left + $(this).outerWidth()/2) - (_slider.position().left + _slider.outerWidth()/2));
					if(_w1 < _k){
						t_i = _i;
						_k = _w1;
					}
				});
				if(t_i == _a){
					if(_btn.eq(_a).outerWidth() < 120){
						_w = 120;
						_l = _btn.eq(_a).position().left - (_w - _btn.eq(_a).outerWidth())/2;
					}
					else{
						_w = _btn.eq(_a).outerWidth();
						_l = _btn.eq(_a).position().left;
					}
					_slider.animate({width: _w - 103, left: _l}, {queue:false, duration: 300, easing: 'easeOutBounce'});
				}
				else{
					_c = -1;
					changeEl(t_i);
					_c = 1;
				}
			}
			_f = false;
		}).mousemove(function(e){
			var t_x = e.pageX - $(this).offset().left - t_p;
			if(_f){
				if((e.pageX - t_p >= $(this).offset().left) && (t_x <= $(this).width() - _slider.outerWidth())){
					s_posX = t_x;
					_slider.css('left', t_x);
				}
			}
		})
		_hold.find('.slider-list').mouseleave(function(){
			if(_btn.eq(_a).outerWidth() < 120){
				_w = 120;
				_l = _btn.eq(_a).position().left - (_w - _btn.eq(_a).outerWidth())/2;
			}
			else{
				_w = _btn.eq(_a).outerWidth();
				_l = _btn.eq(_a).position().left;
			}
			_slider.animate({width: _w - 103, left: _l}, {queue:false, duration: 500, easing: 'easeOutBounce'});
		});
		_t = setTimeout(function(){
			if(_a < _list.length - 1) changeEl(_a + 1);
			else changeEl(0);
		}, 8000);

		/*--- control function ---*/
		function changeEl(_ind){
			if(_c > 0) return false;
			if(_t) clearTimeout(_t);
			
			if(_a != _ind){
				if($('.intro-m').hasClass('opened')) {
					$('.button-up-down a').eq(0).click();
					setTimeout(function(){$('.intro li').hide();$('.intro li').eq(_ind).show();}, 300);
				} else {
					$('.intro li').hide();
					$('.intro li').eq(_ind).show();
				}
				$('.intro .intro-m').css({marginTop: -$('.intro .intro-m').outerHeight()});
				_list.width(_list.parent().width());
				_list.eq(_ind).stop().css({left: list_h.width(), display: 'block'}).animate({left: 0}, 1000);
				_list.eq(_a).stop().animate({left: - list_h.width()}, 1000, function(){
					$(this).css({
						display: 'none',
						left: 0
					});
					_list.width('100%');
				});
				if(_btn.eq(_ind).outerWidth() < 120){
					_w = 120;
					_l = _btn.eq(_ind).position().left - (_w - _btn.eq(_ind).outerWidth())/2;
				}
				else{
					_w = _btn.eq(_ind).outerWidth();
					_l = _btn.eq(_ind).position().left;
				}
				_slider.animate({width: _w - 103, left: _l}, {queue:false, duration: 1000, easing: 'easeOutBounce'});
				_btn.eq(_ind).addClass('active');
				_btn.eq(_a).removeClass('active');
				_a = _ind;

			}
			_t = setTimeout(function(){
				if(_a < _list.length - 1) changeEl(_a + 1);
				else changeEl(0);
			}, 8000);
		}

	}
}
/*--- init menu function ---*/
function initMenu(){
	$('.wrap-nav').each(function(){
		var _hold = $(this);
		var _a = -1;
		var _f1 = false;
		var _w, _l;
		var _slider = $('<div class="active"><div class="nav-l"></div><div class="nav-r"></div></div>').hide();
		_hold.append(_slider);
		var el_list = _hold.find('.main-nav a');
		var _offsetL = _hold.find('.main-nav').position().left;
		el_list.each(function(_i){
			var _el = $(this);
			if(_el.parent().hasClass('active')) _a = _i;
			_el.mouseenter(function(){
				if(_f1){
					_w = $(this).parent().outerWidth() - 14;
					_l = $(this).parent().position().left + _offsetL;
					_slider.animate({ width: _w, left: _l}, {queue:false, duration: 600});
				}
				else{
					_slider.css({
						width: _el.parent().outerWidth() - 14,
						left: _el.parent().position().left + _offsetL,
						opacity: 0,
						display: 'block'
					}).animate({opacity: 1}, {duration:400, queue:false});
				}
			});
		});
		_hold.find('.main-nav').mouseleave(function(){
			if(_f1){
				_w = el_list.eq(_a).parent().outerWidth() - 14;
				_l = el_list.eq(_a).parent().position().left + _offsetL;
				_slider.animate({ width: _w, left: _l}, {queue:false, duration: 600});
			}
			else{
				_slider.animate({opacity: 0}, {duration:400, queue:false});
			}
		});
		if(_a != -1){
			_slider.css({
				width: el_list.eq(_a).parent().outerWidth() - 14,
				left: el_list.eq(_a).parent().position().left + _offsetL
			}).show();
			_f1 = true;
		}
	});
}
/*--- tabs function ---*/
function initTabs(h_list) {
	$(h_list).each(function(_ind, _el) {
		var btn_h = $(_el);
		var _btn = $(_el).find('a.tab');
		var _a = 0;
		_btn.each(function(_ind, _el) {
			this._box = $('#'+_el.href.substr(_el.href.indexOf("#") + 1));
			if($(_el).hasClass('active')) {
				this._box.show();
				_a = _ind;
			}
			else {
				this._box.hide();
			}
			_el.onclick = function() {
				if(!$(this).hasClass('active')){
					_btn.get(_a)._box.slideUp(300);
					_btn.eq(_a).removeClass('active');
					this._box.slideDown(300);
					$(this).addClass('active');
					_a = _ind;
				}
				return false;
			}
		});
	});
}
/*--- slide block function ---*/
function slideBlock(){
	var _hold = $('#content .intro');
	if(_hold.length > 0){
		var _box = _hold.find('.intro-m');
		var _btn = _hold.find('.button-up-down a');
		if(_box.hasClass('opened')){
			_btn.removeClass('btn-3').addClass('btn-2').children('span').eq(0).text('Schließen');
			_box.show();
		}
		else{
			_btn.removeClass('btn-2').addClass('btn-3').children('span').eq(0).text('Mehr Infos');
			_box.css({marginTop: -_box.outerHeight(), visibility: 'hidden'});
		}
		_btn.click(function(){
			if(!_box.is(':animated')){
				_box.css({visibility: 'visible'});
				if(_box.hasClass('opened')){
					$(this).removeClass('btn-2').addClass('btn-3').children('span').eq(0).text('Mehr Infos');
					_box.removeClass('opened');
					_box.animate({marginTop: -_box.outerHeight()}, 300, function(){
						$(this).hide();
					});
				}
				else{
					_box.addClass('opened');
					$(this).removeClass('btn-3').addClass('btn-2').children('span').eq(0).text('Schließen');
					_box.css({marginTop: -_box.outerHeight(), display: 'block'}).animate({marginTop: 0}, 300);
				}
			}
			return false;
		});
	}
}
/*--- clear inputs function ---*/
function clearInputs(){
	$('input:text').each(function(){
		this._val = this.value;
		this.onfocus = function(){
			if(this.value == this._val) this.value = '';
		}
		this.onblur = function(){
			if(this.value == '') this.value = this._val;
		}
	});
	$('.kostenkalk input:text').each(function(){
		this.onfocus = null;
		this.onblur = null;
	});
	$('input:password').each(function(){
		this._val = this.value;
		this.onfocus = function(){
			if(this.value == this._val) this.value = '';
		}
		this.onblur = function(){
			if(this.value == '') this.value = this._val;
		}
	});
	$('textarea').each(function(){
		this._val = this.value;
		this.onfocus = function(){
			if(this.value == this._val) this.value = '';
		}
		this.onblur = function(){
			if(this.value == '') this.value = this._val;
		}
	});
	$('.kostenkalk textarea').each(function(){
		this.onfocus = null;
		this.onblur = null;
	});
}
/*--- gallery function ---*/
function initGall(){	
	$('.category-projects').each(function(){
		var _duration = 10000;
		var _hold = $(this).children('div');
		var _list = _hold.children();
		var hold_w = _hold.width();
		var list_w = 0;
		var _d = 0;
		var _flag = true;
		var _el = _list.children().each(function(){
			list_w += $(this).outerWidth();
		});
		_step = hold_w;
		var _m = list_w;
		
		if(list_w > hold_w){
			
			var t_a = _list.find('a').index(_list.find('a.active:eq(0)'));
			if(t_a != -1){
				t_a = _list.find('a').eq(t_a).position().left;
				_flag = false;
			}
			_list.append(_el.clone(true)).append(_el.clone(true)).css('left', -list_w);
			if(t_a != -1){
				_list.css('left', -(list_w+t_a));
			}
			$(this).children('.btn-prev').click(function(){
				_flag = false;
				_duration = 1000;
				_list.stop();
				listMove(-1.11);
				return false;
			});
			$(this).children('.btn-next').click(function(){
				_flag = false;
				_duration = 1000;
				_list.stop();
				listMove(1.11);
				return false;
			});
			if(_flag) listMove(1.11);
		}
		else{
			$(this).children('.btn-prev').click(function(){
				return false;
			});
			$(this).children('.btn-next').click(function(){
				return false;
			});
		}
		function listMove(_f){
			_m = -parseInt(_list.css('left'));
			if(_f == 1.11){
				if(_m + _step >= 3*list_w - hold_w){
					_m -= list_w;
					_list.css('left', -_m);
				}
				_m += _step;
			}
			else if(_f == -1.11){
				if(_m < _step){
					_m += list_w;
					_list.css('left', -_m);
				}
				_m -= _step;
			}
			else{
				if(_m + _step >= 3*list_w - hold_w){
					_m -= list_w;
					_f -= list_w;
					_list.css('left', -_m);
				}
				_m = _f;
			}
			_m = Math.round(_m/170)*170;
			_list.animate({left: -_m}, _duration, 'linear', function(){
				if(_flag) listMove(1.11);
			});
		}
	});
}

/*--- login inputs values ---*/
function completeInputs(){
	var inputs = $('#form-login :input');
	if(inputs.length > 0) {
		inputs[0].value = 'eMail';
		inputs[1].value = 'Password';
	}
}

/*--- linkable selectbox ---*/
function openUrl(index) {
	location.href = urls[index];
}
function modify_select() {
	alert($('.choose-and-rss li a').length);
	$('.choose-and-rss li a').href += ' openUrl(0);';
}

/*--- sliding login box ---*/
function slideLogin() {
	var classN = ($('#form-login').length > 0) ? '#form-login' : '.form-logout';
	$(classN).animate({top: 4}, 750);
	if($('#userarea .error').length > 0) {
		setTimeout(function(){$('#userarea .error').show().animate({top: '27px'}, 600, 'linear');}, 1150);
		setTimeout(function(){$('#userarea .error').animate({top: '4px'}, 600, 'linear', function(){$('#userarea .error').hide()})}, 11150);
	}
		
}

/*--- horizontal accordion menu ---*/
if(typeof $('.hslide').hSlides == "function") {

	$(function(){

		$('.hslide').hSlides({
			totalWidth: 950, 
			totalHeight: 180, 
			minPanelWidth: 31, 
			maxPanelWidth: 698,
			midPanelWidth: 101,
			activeClass: 'active',
			interval: 50,
			eventHandler: 'hover'
		});
	
	});
}

/*--- Datenschutz Checkboxen prüfen ---*/
$(function(){
	if($("form").length > 0) {
		var doc_forms = $("form");
		for(n = 0; n < doc_forms.length; n++) {
			doc_forms.eq(n).submit(function() {
				if($(this).find(".policy").is(":checked") || $(this).find(".policy").length == 0)
					return true;
				else {
					alert("Bitte akzeptieren Sie die Datenschutzerklärung!");
					return false;
				}
			});
		}
	}
});

/*--- Zeigt lightbox beim ersten Aufruf einer Referenzseite ---*/
/*if(typeof $(window).openDOMWindow == "function") {
	$(function(){
		if($.cookie('lightbox_shown') == 'second')
			return false;
		if(!$.cookie('lightbox_shown')) {
			$.cookie('lightbox_shown', 'first', {path: '/'});
			return false;
		}

		$(window).openDOMWindow({
			windowSourceID: "#unfinished_lightbox",
			eventType: "load",
			height: 350
		});

		$.cookie('lightbox_shown', 'second', {path: '/'});
	});
}*/

/*--- Funktion fuer Kostenkalkulator ---*/
function kickout(divs) {
	if(typeof(divs) == "object")
		for(var n = 0; n < divs.length; n++) {
			$("#q"+divs[n]).hide();
		}
}

function bringin(divs) {
	if(typeof(divs) == "object")
		for(var n = 0; n < divs.length; n++) {
			$("#q"+divs[n]).show();
		}
}

function checksubpages(input, kickout) {
	var subpages = input.value;
	if(subpages > 8) {
		$("#"+kickout).hide();
	} else {
		$("#"+kickout).show();
	}
}

/*--- Contenthöhe an rechte Spalte anpassen ---*/
$(function(){
	if($('#sameheight-left').outerHeight() < $('#sameheight-right').outerHeight() - 50) {
		$('#sameheight-left').css({paddingBottom: $('#sameheight-right').height() - 101 - $('#sameheight-left').height()});
		$('.wrap-content-3').css({paddingBottom: 12});
	}
});