var $jnc = jQuery.noConflict();

// 1000 = 1 sec
_animationOnStartUp = 500; // duration of animation image on home page and fading elements
_showElements = 300; // delay before showing elements in header and footer
_dropAnimate = 900; // dropdown showing delay
_contentFadingTime = 2000; // fading from home to inner page
var GlobalCurentPage = false;

$jnc(function(){
	initSlideDrop();
	contentPosition();
	onStartUp();
	ajaxContent();
	searchForm();
	initNav();
	initMap();
	$jnc('input:text, input:password').each(function(){
		$jnc(this).attr('def', $jnc(this).attr('value'));
		$jnc(this).focus(function(){
			if($jnc(this).attr('value')==$jnc(this).attr('def')) $jnc(this).attr('value','');
		}).blur(function(){
			if($jnc(this).attr('value')=='') $jnc(this).attr('value',$jnc(this).attr('def'));
		});
	});
})
function initNav(){
	$jnc('#nav > li:has("ul")').each(function(){
		$jnc(this).click(function(){
			return false;
		});
	});
}
function clickMeNow(link){
	var _navLink = $jnc('#nav a');
	_navLink.filter('[href*='+link+']').eq(0).trigger('click');
};
// imageMap
function initMap() {
	var _map = document.getElementById("map");
	var _map1 = document.getElementById("map1");
	if (_map) createMap(_map);
	if (_map1) createMap1(_map1);
}

function createMap(_map) {
	var state_list = document.getElementById("map-hover").getElementsByTagName("li");
	var _select = $jnc('#map-select');
	var _selopt = _select.find('option');
	var text_list = document.getElementById("map-text") ? document.getElementById("map-text").getElementsByTagName("li") : null;
	if(state_list){
		for(var i=0; i<state_list.length; i++) {
			if(text_list) text_list[i].index = i;
			if(state_list) state_list[i].index = i;
		}

		var _areas = _map.getElementsByTagName("area");
		for (i = 0; i < _areas.length; i ++){
			if (_areas[i].alt){
				var _node = document.getElementById(_areas[i].alt);
				if(text_list) var _text = text_list[_node.index];
				if (_node) {
					_areas[i]._node = _node;
					if(text_list) _areas[i]._text = _text;
					_areas[i].onclick = function(){
						var _val = this.alt;
						if (this._node.className.indexOf("activestate") == -1)
						{
							for(var x=0; x<state_list.length; x++) {
								state_list[x].className = state_list[x].className.replace("activestate", "");
								if(text_list) text_list[x].className = text_list[x].className.replace("activestate", "");
							}
							this._node.className += " activestate";
							if(text_list) this._text.className += " activestate";
							var _optText = _selopt.removeAttr('selected').filter(':[title*='+_val+']:eq(0)').attr('selected','selected').text();
							_select.attr('title', _val).prev().find('span.center').text(_optText);
						}else{
							this._node.className = this._node.className.replace("activestate", "");
							if(text_list) this._text.className = this._text.className.replace("activestate", "");
							var _optText = _selopt.removeAttr('selected').eq(0).attr('selected','selected').text();
							_select.attr('title', '-1').prev().find('span.center').text(_optText);
						}
						VSA_handleResize();
						return false;
					}
				}
			};
		}
		_map.reset = function(){
			var state_list = document.getElementById("map-hover").getElementsByTagName("li");
			var _select = $jnc('#map-select');
			var _selopt = _select.find('option');
			var text_list = document.getElementById("map-text") ? document.getElementById("map-text").getElementsByTagName("li") : null;
			if(state_list){
				for(var i=0; i<state_list.length; i++) {
					if(text_list) text_list[i].index = i;
					if(state_list) state_list[i].index = i;
				}

				var _areas = _map.getElementsByTagName("area");
				for (i = 0; i < _areas.length; i ++){
					if (_areas[i].alt){
						_areas[i]._node.className = _areas[i]._node.className.replace("activestate", "");
						if(text_list) _areas[i]._text.className = _areas[i]._text.className.replace("activestate", "");
						var _optText = _selopt.removeAttr('selected').eq(0).attr('selected','selected').text();
						_select.attr('value', '-1').prev().find('span.center').text(_optText);
					}
				}
			}
		}
	}
}
function createMap1(_map) {
	var state_list1 = document.getElementById("map-hover1").getElementsByTagName("li");
	var text_list1 = document.getElementById("map-text1") ? document.getElementById("map-text1").getElementsByTagName("li") : null;
	if(state_list1){
		for(var i=0; i<state_list1.length; i++) {
			if(text_list1) text_list1[i].index = i;
			if(state_list1) state_list1[i].index = i;
		}

		var _areas1 = _map.getElementsByTagName("area");
		for (i = 0; i < _areas1.length; i ++){
			if (_areas1[i].alt){
				var _node = document.getElementById(_areas1[i].alt);
				if(text_list1) var _text = text_list1[_node.index];
				if (_node) {
					_areas1[i]._node = _node;
					if(text_list1) _areas1[i]._text = _text;
					_areas1[i].onclick = function(){
						var _val = this.alt;
						if (this._node.className.indexOf("activestate") == -1)
						{
							for(var x=0; x<state_list1.length; x++) {
								state_list1[x].className = state_list1[x].className.replace("activestate", "");
								if(text_list1) text_list1[x].className = text_list1[x].className.replace("activestate", "");
							}
							this._node.className += " activestate";
							if(text_list1) this._text.className += " activestate";
						}else{
							this._node.className = this._node.className.replace("activestate", "");
							if(text_list1) this._text.className = this._text.className.replace("activestate", "");
						}
						VSA_handleResize();
						return false;
					}
				}
			};
		}
		_map.reset = function(){
			var state_list1 = document.getElementById("map-hover1").getElementsByTagName("li");
			var text_list1 = document.getElementById("map-text1") ? document.getElementById("map-text1").getElementsByTagName("li") : null;
			if(state_list1){
				for(var i=0; i<state_list1.length; i++) {
					if(text_list1) text_list1[i].index = i;
					if(state_list1) state_list1[i].index = i;
				}

				var _areas1 = _map.getElementsByTagName("area");
				for (i = 0; i < _areas1.length; i ++){
					if (_areas1[i].alt){
						_areas1[i]._node.className = _areas1[i]._node.className.replace("activestate", "");
						if(text_list1) _areas1[i]._text.className = _areas1[i]._text.className.replace("activestate", "");
					}
				}
				VSA_handleResize();
			}
		}
	}
}


/* 
	skip intro animation or animation between chenga pages;
 */
function scipAnimation(_prev, _next){
	$jnc('strong.logo').unbind('click').bind('click',function(){
		if(_prev.find('#sidebar').is(':animated')){
			_prev.find('#sidebar').stop(true, true);
			_next.find('#sidebar').stop(true,true);
			return false;
		};
	});
}

function initShadowbox(){
	if(typeof Shadowbox.init == 'function'){
		var _link = $jnc('a[rel^=shadowbox]');
		_link.unbind('click').bind('click',function(){
			var slink = this.href+'?shadowbox=open';
			var _arg = {};
			if(this.rel && this.rel!=''){
				var _param = this.rel.split(';');
				for(var i=0; i<_param.length; i++) {
					if(_param[i].indexOf('=')!=-1){
						_arg[_param[i].split('=')[0]] = _param[i].split('=')[1];
					}
				};
			};
			Shadowbox.open({
				width: (_arg['width'] || 542),
				height: (_arg['height'] || 600),
				content: slink,
				player: "iframe"
			});
			return false;
		});
	}
};
var prevPage = [];
var nextPage = [];
function ajaxContent(){
	var _backBtn = $jnc('#back-btn');
	var prevPage = [];
	var nextPage = [];

	var _d = _contentFadingTime;
	var _navLink = $jnc('#nav a');
	var _pLink = $jnc('a.content-pointer');
	var _counter = 1;
	var _content = $jnc('#ajax-content');
	var _width=0;
	if (window.innerWidth) _width = window.innerWidth;
	else _width = document.documentElement.clientWidth;

	if('http://www.reisswolf.de/home/' != window.location.href){
		prevPage.push($jnc('#nav .current_page_item:eq(0) > a:eq(0)').addClass('active'));
	};

	_backBtn.unbind('click').bind('click',function(){
		var _thisLink = $jnc(this);
		if(prevPage.length > 1){
			nextPage.push(prevPage.pop());
			var _prevLink = prevPage.pop();
			if(!_prevLink) return false;
			if(_prevLink.hasClass('active')){
				var _pages = _content.children('div');
				var _prev = GlobalCurentPage;
				var _next = _pages.filter('[relto='+_prevLink.attr('relto')+']');
				GlobalCurentPage = _next;
				if(_prev.find('#sidebar').is(':animated')){
					_prev.find('#sidebar').stop(true, true);
					_next.find('#sidebar').stop(true,true);
				};
				_prev.css({zIndex: 5}).find('#sidebar').css({opacity: 1}).animate({opacity: 0},_d, function(){
					_prev.hide();
				});
				_next.css({display:'block', zIndex: 10}).find('#sidebar').css({opacity: 0}).animate({opacity: 1},_d, function(){
					$jnc(this).css({opacity: 'auto'});
					_next.show();
				});
				if($jnc('.scrollable .scroll-content', _next).length) {
					$jnc('.scrollable .scroll-content', _next).scrollTop(0);
					$jnc('.scrollable .vscroll-slider', _next).css({
						top: 0
					});
				}

				scipAnimation(_prev, _next);
				initShadowbox();
				prevPage.push(_prevLink);
				// scroll to
				if($jnc('html').attr('scrollto')) {
					var _targ = $jnc('#'+$jnc('html').attr('scrollto'));
					$jnc('html').removeAttr('scrollto');
					if(_targ){
						var _targOffset = _targ.position().top;
						setTimeout(function(){
							_targ.parents('.scrollable').children().attr('scrollTop',_targOffset);
							setTimeout(VSA_performResizeEvent,100);
						},100);
					}
				}
			}else{
				_prevLink.trigger('click');
			}
		}
		return false;
	})


	if($jnc('#main').length){
		_pLink.live('click',function(){
			var _rel = $jnc(this).attr('rel');
			if(_rel) $jnc('html').attr('scrollto', _rel);
			var _newHref = $jnc(this).attr('href');
			if($jnc("a[href="+_newHref+"]", $jnc('#nav')).length >= 1){
				_navLink.filter("[href="+_newHref+"]").trigger('click');
			}else{
				var _thisLink = $jnc(this);
				if(_thisLink.attr('relTo')!=null){
					var _pages = _content.children('div');
					var _prev = GlobalCurentPage;
					var _next = _pages.filter('[relto='+_thisLink.attr('relto')+']');
					if(_prev.find('#sidebar').is(':animated')){
						_prev.find('#sidebar').stop(true, true);
						_next.find('#sidebar').stop(true,true);
					};
					_prev.css({zIndex: 5}).find('#sidebar').css({opacity: 1}).animate({opacity: 0},_d, function(){
						_prev.hide();
					});
					_next.css({display:'block', zIndex: 10}).find('#sidebar').css({opacity: 0}).animate({opacity: 1},_d, function(){
						$jnc(this).css({opacity: 'auto'});
						_next.show();
					});
					GlobalCurentPage = _next;
					if($jnc('.scrollable .scroll-content', _next).length) {
						$jnc('.scrollable .scroll-content', _next).scrollTop(0);
						$jnc('.scrollable .vscroll-slider', _next).css({
							top: 0
						});
					}

					scipAnimation(_prev, _next);
					initShadowbox();
					prevPage.push(_thisLink);
					nextPage = [];
					// scroll to
					if($jnc('html').attr('scrollto')) {
						var _targ = $jnc('#'+$jnc('html').attr('scrollto'));
						$jnc('html').removeAttr('scrollto');
						if(_targ){
							var _targOffset = _targ.position().top;
							setTimeout(function(){
								_targ.parents('.scrollable').children().attr('scrollTop',_targOffset);
								setTimeout(VSA_performResizeEvent,100);
							},100);
						}
					};
					return false;
				}else{
					_counter = _navLink.length + $jnc('a.content-pointer').length;
					_thisLink.attr('relTo','content'+_counter);
					var _url = $jnc(this).attr('href');
					$jnc.ajax({
						type: 'post',
						data: 'ajax=1',
						url: _url,
						success: function(html){
							var _prev = GlobalCurentPage;
							_content.append('<div>'+html+'</div>');
							var _next = _content.children("div:last");
							_next.attr('relto', 'content'+_counter);
							GlobalCurentPage = _next;

							/*addition function initialize in ajax content*/

							// init custom scroll if needed
							var _scrollables = _next.find('div.scrollable');
							_scrollables.each(function(){
								VSA_scrollAreas.push(new ScrollArea(VSA_scrollAreas.length, this));
							});
							initShadowbox();
							initInAjax(_next);
							/*addition function initialize in ajax content*/
							_next.css({
								position: 'absolute',
								top:0,
								left:0,
								width: '100%',
								height: '337px',
								zIndex:10
							});
							scipAnimation(_prev, _next);
							prevPage.push(_thisLink);
							nextPage = [];
							_prev.css({zIndex: 5}).find('#sidebar').css({opacity: 1}).animate({opacity: 0},_d, function(){
								_prev.hide();
							});
							_next.css({display:'block', zIndex: 10}).find('#sidebar').css({opacity: 0}).animate({opacity: 1},_d, function(){
								$jnc(this).css({opacity: 'auto'});
								_navLink.removeClass('active');
								_next.show();
							});
						},
						error: function(){
							alert('Ajax error1')
						}
					});
				}
			}
			return false;
		})
		_navLink.click(function(){
			 //reset map
				var _map = document.getElementById("map");
				var _map1 = document.getElementById("map1");
				if (_map) _map.reset();
				if (_map1) _map1.reset();
				$jnc('span.hint-holder').each(function(){
					$jnc(this).find('> div').css({height: '0px'});
				});
			//reset map
			if($jnc(this).parents('li:eq(0)').find('ul').length) return false;   
			var _ttlink = $jnc(this);
			if(_content.find('*:animated')) _content.find('*:animated').each(function(){
				$jnc(this).stop(true, true);
			});
			var _thisLink = $jnc(this);
			if(!_thisLink.hasClass('active')){
				_navLink.removeClass('active');
				_thisLink.addClass('active');
				if(_thisLink.parents('.drop:eq(0)').length){
					_thisLink.parents('li:eq(1)').find('a:eq(0)').addClass('active');
				};
			}else return false;
			var _url = $jnc(this).attr('href');
			if(_url != '#'){
				if($jnc(this).attr('relTo')!=null){
					var _pages = _content.children('div');
					var _prev = GlobalCurentPage;
					var _next = _pages.filter('[relto='+_thisLink.attr('relto')+']');
					GlobalCurentPage = _next;
					_prev.css({zIndex: 5}).find('#sidebar').css({opacity: 1}).animate({opacity: 0},_d, function(){
						_prev.hide();
					});
					_next.css({display:'block', zIndex: 10}).find('#sidebar').css({opacity: 0}).animate({opacity: 1},_d, function(){
						$jnc(this).css({opacity: 'auto'});
						_next.show();
					});
					if($jnc('.scrollable .scroll-content', _next).length) {
						$jnc('.scrollable .scroll-content', _next).scrollTop(0);
						$jnc('.scrollable .vscroll-slider', _next).css({
							top: 0
						});
					}

					scipAnimation(_prev, _next);
					prevPage.push(_ttlink);
					nextPage = [];
					// scroll to
					if($jnc('html').attr('scrollto')) {
						var _targ = $jnc('#'+$jnc('html').attr('scrollto'));
						$jnc('html').removeAttr('scrollto');
						if(_targ){
							var _targOffset = _targ.position().top;
							setTimeout(function(){
								_targ.parents('.scrollable').children().attr('scrollTop',_targOffset);
								setTimeout(VSA_performResizeEvent,100);
							},100);
						}
					}

					return false;
				}else{
					$jnc(this).attr('relTo','content'+_navLink.index(_thisLink));
					$jnc.ajax({
						type: 'post',
						data: 'ajax=1',
						url: _url,
						success: function(html){
							if($jnc('.white-block:eq(0)').width() == 0){
								_content.append('<div>'+html+'</div>');
								var _thisContent = _content.children('div:last');
								_thisContent.css({
									width:'100%',
									position: 'relative',
									top:0,
									left: 0,
									height: '337px',
									zIndex: 5
								})
								_thisContent.attr('relto', 'content'+_navLink.index(_thisLink));
								GlobalCurentPage = _thisContent;

								/*addition function initialize in ajax content*/
								VSA_initScrollbars();
								initShadowbox();
								initInAjax(_thisContent);
								/*addition function initialize in ajax content*/
								$jnc('strong.logo').unbind('click').bind('click',function(){
									if($jnc('.white-block:eq(0)').is(':animated')){
										$jnc('.white-block:eq(0)').stop(true, true);
										_thisContent.stop(true, true);
										return false;
									};
								});
								ieHover('span.hint-holder');
								_thisContent.css({opacity:0});
								if (window.innerWidth) _width = window.innerWidth;
								else _width = document.documentElement.clientWidth;
								$jnc('.white-block:eq(0)').animate({width: _width-423},_d,function(){
									_thisContent.animate({opacity: 1},_d,function(){
										_thisContent.css({opacity: ''});
										$jnc('.white-block:eq(0)').css({width: '100%'});
										if(_backBtn.is(':hidden')) _backBtn.fadeIn(200);
										prevPage.push(_ttlink);
										nextPage = [];
									});
									_thisContent.width('100%');
								})
							}else{
								prevPage.push(_ttlink);
								nextPage = [];
								if(_backBtn.is(':hidden')) _backBtn.fadeIn(200);
								var _pages = _content.children('div');
								if(!GlobalCurentPage) GlobalCurentPage = _pages.eq(0);
								var _prev = GlobalCurentPage;
								_content.append('<div>'+html+'</div>');
								var _next = _content.children("div:last");
								_next.attr('relto', 'content'+_navLink.index(_thisLink));
								GlobalCurentPage = _next;

								/*addition function initialize in ajax content*/

								// init custom scroll if needed
								var _scrollables = _next.find('div.scrollable');
								_scrollables.each(function(){
									VSA_scrollAreas.push(new ScrollArea(VSA_scrollAreas.length, this));
								});

								initShadowbox();
								initInAjax(_next);
								/*addition function initialize in ajax content*/

								ieHover('span.hint-holder');
								_next.css({
									position: 'absolute',
									top:0,
									left:0,
									width: '100%',
									height: '337px',
									zIndex:10
								})

								scipAnimation(_prev, _next);

								_prev.css({zIndex: 5}).find('#sidebar').css({opacity: 1}).animate({opacity: 0},_d, function(){
									_prev.hide();
								});
								_next.css({display:'block', zIndex: 10}).find('#sidebar').css({opacity: 0}).animate({opacity: 1},_d, function(){
									$jnc(this).css({opacity: 'auto'});
									_next.show();
								});
							}
						},
						error: function(){
							alert('Ajax error2')
						}
					})
				}
			}
			return false;
		})
	}
}
function Skip(){
	var _main = $jnc('.startUp').css({
			width:'100%', float: 'right'
		});
		$jnc('.not-visible').css({opacity: 0, visibility: 'visible'}).animate({opacity: 1}, 0, function(){
			$jnc('.not-visible').css({opacity: 'auto'});
			setTimeout(function(){
				$jnc('#nav').removeClass('not-visible');
			},_showElements);
		});
		$jnc('.fading-block').css({opacity: 0, visibility: 'visible'}).animate({opacity: 1},0, function(){
			$jnc('.fading-block').css({opacity: 'auto'});
		});
}
function onStartUp(){
	var _d = _animationOnStartUp;
	var step = 10;
	var _width=0;
	if (window.innerWidth) _width = window.innerWidth;
	else _width = document.documentElement.clientWidth;
	$jnc(window).resize(function(){
		if (window.innerWidth) _width = window.innerWidth;
		else _width = document.documentElement.clientWidth;
	});
	var _k = 1 + (_d*_d/5000)/_width;
	var _main = $jnc('.startUp');
	var _t = null; _w = 0;

//skip start animation
	var _skip = false;
	if('http://www.reisswolf.de/home/' != window.location.href){
		$jnc('#main').css('width','auto');
		_skip = true;
	};
	$jnc('strong.logo').click(function(){
		if(_main.width() < _width){
			_skip = true
			return false;
		};
	});

	function autoAnim(){
		_t = setTimeout(function(){
			animW();
		},_k)
	}
	if(_main.length){
		autoAnim();
	}else{
		if(typeof(VSA_initScrollbars)=='function') VSA_initScrollbars();
		initInAjax();
		$jnc('.not-visible').css({visibility: 'visible'});
		$jnc('#nav').removeClass('not-visible');
		$jnc('.fading-block').css({visibility: 'visible'});
	}
	function animW(){
		_skip  ? _w = _width : _w=_w+step;
		_main.css({
			width: _w+'px'
		});
		if(_t){
			clearTimeout(_t);
			autoAnim();
		}
		if(_w >= _width*2/3) _k += 0.7;
		if(_w >= _width){
			if(_t) clearTimeout(_t);
			_main.css({width:'100%', float: 'right'});
			$jnc('.not-visible').css({opacity: 0, visibility: 'visible'}).animate({opacity: 1}, _showElements, function(){
				$jnc('.not-visible').css({opacity: 'auto'});
				setTimeout(function(){
					$jnc('#nav').removeClass('not-visible');
				},_showElements);
			});
			$jnc('.fading-block').css({opacity: 0, visibility: 'visible'}).animate({opacity: 1},_d, function(){
				$jnc('.fading-block').css({opacity: 'auto'});
			});
			if(typeof(VSA_initScrollbars)=='function') VSA_initScrollbars();
			initInAjax();
		}
	}
}

function contentPosition(){
	var _contHeight = parseInt($jnc('#main').height());
	var _fMinHeight = parseInt($jnc('#footer').height());
	var _hMinHeight = parseInt($jnc('#header').height());

	setPad();
	function setPad(){
		if (window.innerHeight) _height = window.innerHeight;
		else _height = document.documentElement.clientHeight;
		if(_height - (_fMinHeight + _hMinHeight + _contHeight) > 0 ){
			var _difHeight = _height - (_fMinHeight + _hMinHeight + _contHeight);
			$jnc('#header').css({
				paddingTop: Math.floor(_difHeight*0.36),
				height: _hMinHeight+'px'
			})
			$jnc('#footer').css({
				paddingTop: Math.floor(_difHeight*0.32),
				paddingBottom: Math.floor(_difHeight*0.32),
				height: _fMinHeight+'px'
			})
		}
	}
	//resize
	$jnc(window).resize(function(){setPad();})
}
function initSlideDrop(){
	var _d  = _dropAnimate;
	var li = $jnc('#nav li');
	li.each(function(){
		var _this = $jnc(this);
		_this.mouseenter(function(){
			_this.addClass('hover');
				_this.drop = _this.find('div.drop');
				if(_this.drop.length){
					_this.find("a:first").addClass("with-drop");
					_this.drop.h = _this.drop.find('> div:eq(0)').outerHeight(true);
					_this.drop.css({overflow: 'hidden', height: 0}).hide();
					_this.drop.animate({height: _this.drop.h},{duration: _d, queue: false, easing: 'easeOutExpo'});
				}
		}).mouseleave(function(){
			if(_this.drop){
				if(_this.drop.length){
					_this.drop.animate({height: 0},{duration: _d, queue: false, complete:function(){
						_this.removeClass('hover');
					}});
				}else{
					_this.removeClass('hover');
				}
			}else{
				_this.removeClass('hover');
			}
		})
	})
}

function ieHover(h_list){
	if ($jnc.browser.msie && $jnc.browser.version < 7){
		$jnc(h_list).live('mouseover', function(){
			$jnc(this).addClass('hover');
		}).live('mouseout', function(){
			$jnc(this).removeClass('hover');
		});
	}
}


//form validation 
function initValidate(_holder){
	var _form = $jnc('.validate',_holder);
	_form.each(function(){
		var _this = this;
		var _submit = $jnc('.submit', $jnc(this));
		var _required = $jnc('select.required, input.required', $jnc(this));
		_required.each(function(){
			$jnc(this).attr('def', $jnc(this).attr('value'));
			$jnc(this).focus(function(){
				if($jnc(this).attr('value')==$jnc(this).attr('def')) $jnc(this).attr('value','');
			}).blur(function(){
				if($jnc(this).attr('value')=='') $jnc(this).attr('value',$jnc(this).attr('def'));
			})
		})
		var _emailReg = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		_submit.click(function(){
			var eror = false;
			_required.each(function(){
				if($jnc(this).hasClass('select') && this.type.indexOf('select')!=-1){
					if($jnc(this).val()=='' ||$jnc(this).val()==-1){
						$jnc(this).parents('div:eq(0)').addClass('alert');
						eror = true;
					}else{
						$jnc(this).parents('div:eq(0)').removeClass('alert');
					}
				}else{
					if ($jnc(this).val()==0 || $jnc(this).val()==$jnc(this).attr('def')) {
						eror = true;
						$jnc(this).parents('div:eq(0)').addClass('alert');
					} else {
					$jnc(this).parents('div:eq(0)').removeClass('alert');
					if ($jnc(this).hasClass('email')){
							if (!_emailReg.test($jnc(this).val())){
								eror = true;
								$jnc(this).parents('div:eq(0)').addClass('alert');
							}
						};
					}
				}
			});
			if (eror) return false;
			else {
				$jnc(_this).submit();
			}
			return false;
		});
	})
}

function searchForm(){
	var _form = $jnc('#search-form');
	var _input = $jnc('input', _form);
	_form.submit(function(){
		var _url = 'http://www.reisswolf.de/';
		var _data = $jnc(this).serialize();
		$jnc.ajax({
			url: _url,
			data: 'searchData=1&'+_data,
			type: 'post',
			success: function(msg){
				$jnc('#search-popup1 .frame').html(msg);
				//init popup
				Shadowbox.open({
					content:    '<div id="search-popup"><div class="frame">'+msg+'</div></div>',
					player:     "html",
					overlayOpacity: 0.78,
					title:      false,
					height:     $jnc('#search-popup1').innerHeight(true),
					width:      $jnc('#search-popup1').innerWidth(true)
				});
			},
			error: function(){
				alert('incorect url or not found page');
			}
		});
		return false;
	});
	_input.keypress(function(e){
		if(e.keyCode == 13) {
			_form.submit();
			return false;
		}
	})
}
function openClose(hold){
	var _cur = null;
	$jnc('span.hint-holder', hold).each(function(){
		var _this = this;
		_this.drop = $jnc(this).find('div:eq(0)');
		_this.drop.css({height: '',display: 'block'});
		_this.drop.h = _this.drop.height();
		_this.drop.css({height: '0px'});
		_this.opener = $jnc(_this).find('a:eq(0)');
		_this.opener.click(function(){
			if(_this.drop.height() > 0){
				_this.drop.animate({height: 0}, 300);
			}else{
				if(_cur) _cur.drop.animate({height: 0}, 300);
				_this.drop.animate({height: _this.drop.h}, 300, function(){
					_cur = _this;
					VSA_handleResize();
				});
			}
			return false;
		})
	});
}
//init function when ajax content loaded
function initInAjax(_holder){
	_holder = _holder || document;
	if(typeof(initCastomForms)=="function") initCastomForms();
	initValidate(_holder);
	initMap();
	openClose(_holder);
	customInitCF7();
	initShadowbox();
	if($jnc('html').attr('scrollto')) {
		var _targ = $jnc('#'+$jnc('html').attr('scrollto'), _holder);
		$jnc('html').removeAttr('scrollto');
		if(_targ){
			var _targOffset = _targ.position().top;
			setTimeout(function(){
				_holder.find('div.scrollable > div').attr('scrollTop',_targOffset);
				setTimeout(VSA_performResizeEvent,100);
			},2000);
		}
	}
}

function customInitCF7() {
	try {
		$jnc('div.wpcf7 > form').ajaxForm({
			beforeSubmit: wpcf7BeforeSubmit,
			dataType: 'json',
			success: wpcf7ProcessJson
		});
	} catch (e) {
	}

	try {
		$jnc('div.wpcf7 > form').each(function(i, n) {
			wpcf7ToggleSubmit($jnc(n));
		});
	} catch (e) {
	}

	try {
		if (_wpcf7.cached) {
			$jnc('div.wpcf7 > form').each(function(i, n) {
				wpcf7OnloadRefill(n);
			});
		}
	} catch (e) {
	}
}
