$(document).ready(function(){ 
	var opera ='<base href="http://www.gurkha-imports.com/gurkha-imports" /> <base href="http://www.gurkha-imports.com/katalog" /> <base href="http://www.gurkha-imports.com/khukuris" /> <base href="http://www.gurkha-imports.com/media" /> <base href="http://www.gurkha-imports.com/geschichte" /> <base href="http://www.gurkha-imports.com/aktuelles" /> <base href="http://www.gurkha-imports.com/interaktiv" /> <base href="http://www.gurkha-imports.com/forum" />'; 
	$('head').append(opera);
	$("a[href^='#print']").click(function(){
		window.print();
		return false; 
	});
	$("a[href^='#top']").click(function(){
		$('html, body').animate({ scrollTop: $("#top").offset().top }, 'slow');
		return false;
	});
	$('#headImg').cycle({
		fx: 'fade',
		timeout: 10000,
		speed: 1000
	});
	$('#fo01').focus( function() {
		if($(this).val() == 'Ihre E-Mail Adresse')
			$(this).attr('value', '');
	}).blur( function() {
		if($(this).val() == '')
			$(this).attr('value', 'Ihre E-Mail Adresse');
	}); 
	$('noscript').css('display','none');
	$("a[rel^='extern']").attr('target', '_blank');
	if($("#slider").length > 0) {
		$("#slider").easySlider({
			auto: true,
			continuous: true,
			numeric: true,
			pause: 10000,
			speed: 500
		});
	}
	Cufon.replace('h2') ('h3') ('h4') ('h6') ('.feedbackUser blockquote p.head');
	$('#nav li ul').each(function() {
		$(this).hide(0);
	});
	navTimer = null;
	$('#nav ul li').hover(function(e) {
		ae = $(this);
		navTimer = window.setTimeout(function() { ae.find('ul').fadeIn('fast') }, 200);
	},function() {
		$(this).find('ul').fadeOut('slow');
	}).mouseleave(function() {
		window.clearTimeout(navTimer);
	}); 
	if($("a[rel='galerie[uds]'], a[rel='galerie[kt]'], a[rel='galerie[review-one]'], a[rel='galerie[review-two]']").length > 0) {
		$("a[rel='galerie[uds]'], a[rel='galerie[kt]'], a[rel='galerie[review-one]'], a[rel='galerie[review-two]']").colorbox({ maxWidth: '80%', maxHeight: '80%' }); 	
	}
	if($('.manufaktur ul').length > 0) {
		$('body').append('<div id="tooltip"></div>');
	}
	$('.manufaktur ul li').hover(function() {
		var actEl = $(this);
		var needEl = $('#tooltip');
		var _l = actEl.position().left + 40;
		var _t = actEl.position().top + 0;
		needEl.css({
			left: _l,
			top: _t,
			opacity: '0.9'
		});
		var text = actEl.find('img').attr('title');
		actEl.data('text', text);
		needEl.html(actEl.find('div').html());
		actEl.find('img').attr('title', '');
		needEl.stop(true, true).fadeIn(400);
	}, function() {
		var actEl = $(this);
		actEl.find('img').attr('title', actEl.data('text'));
		$('#tooltip').stop(true, true).fadeOut(400);
	}).mousemove(function(e) {
		$('#tooltip').css({
			left: e.pageX + 15,
			top: e.pageY + 15
		})
	});
	if($('#anfrageformular, #feedbackformular').length > 0) {
		$('#anfrageformular, #feedbackformular').submit(function() {
			$('.form #error').remove();
			var ae = $(this);
			ae.find('label.error').removeClass('error');
			var i = 0;
				var g = 0;
			ae.find('p.required input, p.required textarea').each(function() {
				if($(this).val() == '') {
					i++;
					$(this).siblings('label').addClass('error');
				}
				if($(this).parent().hasClass('mail')) {
					function validEmail(email) {
						var strReg = "^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})$";
						var regex = new RegExp(strReg);
						return(regex.test(email));
					}
					if(!validEmail($(this).val())) {
						i++;
						$(this).siblings('label').addClass('error');
					}
				}
			});
			if(i > 0) {
				$(this).prepend('<div id="error">Bitte f&uuml;llen Sie alle erforderlichen Felder aus!</div>');
				$('html, body').animate({ scrollTop: $("#error").offset().top }, 'slow');
			} else {
				if($('#wwwebsite').val() == '') {
					return true;
				}
			}
			return false;
		})
	}
	$('#feedbackformular').hide(0);
	$('.feedbackButton').click(function() {
		$('html, body').animate({ scrollTop: $("#colMain").offset().top },400);
		window.setTimeout(function() { 
			if($('#feedbackformular:hidden').length > 0) {
				$('#feedbackformular').fadeIn('slow');
			} else {
				$('#feedbackformular').fadeOut('slow');
			}
		}, 400);
		return false;
	});
	$('#newsletterBar').submit(function() {
		var ae = $(this);
		ae.find('div').remove();
		if(ae.find('input.formShow').val() != 'Ihre E-Mail Adresse') {
			return true;
		} else {
			ae.append('<div class="error">Bitte geben Sie eine richtige E-Mail Adresse an!</div>');
		}
		return false;
	});
	if($('#tabs').length > 0) {
		$("#tabs").tabs();
	}
	if($('.formHide').length > 0) {
		if(!$('input[name^="af13"]').is(':checked')) {
			$('.formHide').hide(0);
		}
		$('.formShow').click(function() {
			var ae = $(this);
			if(ae.is(':checked')) {
				ae.parent().siblings('div.formHide').stop(true, true).slideDown('slow');
			} else {
				ae.parent().siblings('div.formHide').stop(true, true).slideUp('slow');
			}
		});	
	}
	if( $('a[rel^="color[inline]"]').length > 0){
		$('a[rel^="color[inline]"]').colorbox({
			width:"50%", 
			height:"80%",
			inline:true,
			href: $(this).attr('href'),
			opacity:0.8
		});
	}
	$('#af23b').click(function() {
		if($('#af13').is(':checked')) {
			if($('#af22').val() != 1) {
				warnung();
			}
		} else {
			if($('#af12').val() != 1) {
				warnung();
			}
		}
	});
	$('#af12, #af22').change(function() {
		if($('#af13').is(':checked')) {
			if($('#af23b').is(':checked')) {
				warnung();
			}
		} else {
			if($('#af23b').is(':checked')) {
				warnung();
			}
		}
	});
	$('.nachnahme').show(0);
	$('#warnung a').click(function() {
		$.fn.colorbox.close();
	});
	function warnung() {
		$('#af23b').colorbox({
			inline:true,
			href: '#warnung',
			open: true,
			opacity:0.8
		});
		$('#af23a').attr('checked','checked');
		$('#af23b').removeAttribute('checked');
	}
});