jQuery.noConflict();

jQuery(document).ready(function($){
	
	closer = 0;
	
	if($("body").attr("id")!="sub") {
		$("#navi a").click(function(e) {
			link = $(this).attr("href");
			if($(this).parents("li:first").find("ul").length) return;
			e.preventDefault();
			$("#content").css("visibility","visible").animate({
				"width" : "+=650px"
			},function() {
				self.location.href=link;
			});
		});
	}
	else {
		$("#header a:first").click(function(e) {
			link = "/";
			e.preventDefault();
			$("#content").empty().animate({
				"width" : "-=650px"
			},function() {
				self.location.href=link;
			});
		});
	}
	
	$("#navi a").click(function(e) {
		window.clearInterval(closer);
		closer=0;
		if($(this).parents("li:first").find("ul:visible").length) {
			$("#navi a.active").removeClass("active");
			$("#navi a.act").addClass("active");
			$("#navi ul:visible").animate({
				"width":"0px"
			},function(){
				$(this).hide();
			});
			e.preventDefault();
			return;
		}
	
		$("#navi a.active").removeClass("active");
		$(this).addClass("active");
		click = this;
		if($(this).parents("li:first").find("ul").length==0) {
			$("#navi ul:visible").animate({
				"width":"0px"
			},function(){
				$(this).hide();
			});
		}
		else {
			e.preventDefault();
			if($("#navi ul:visible").length==0) {
				$(this).parents("li").find("ul").stop().animate({
					"width":"200px"
				});
			}
			else {
				$("#navi ul:visible").animate({
					"width":"0px"
				},function() {
					$(this).hide();
					$(click).parents("li:first").find("ul").animate({
						"width":"200px"
					});
				});
			}
		}
	});
	
	$("#navi ul").mouseover(function() {
		window.clearInterval(closer);
		closer=0;
	});
	
	$("#content").click(function(){
		
		window.clearInterval(closer);
		closer=0;
		
		$("#navi a.active").removeClass("active");
		$("#navi a.act").addClass("active");
		$("#navi ul:visible").stop().animate({
			"width":"0px"
		},function(){
			$(this).hide();
		});
	});
	
	$("#content").mouseover(function() {
		if(closer==0) closer = window.setTimeout('jQuery("#content").click()',500);
	});
	
	$(".gallery-small").each(function(){
		var gallery = this;
		$(this).find(".thumbs a").mouseover(function() {
			$(gallery).find(".first").css("visibility","hidden");
			$(gallery).find(".pic").append('<img src="'+$(this).attr("rel")+'" class="preview" />');
			$(gallery).find(".preview").css({
				"position":"absolute",
				"top":"0px",
				"left":"0px",
				"border":"4px solid #000",
				"zIndex":"100"
			});
		});
		$(this).find(".thumbs a").mouseout(function() {
			$(gallery).find(".first").css("visibility","visible");
			$(gallery).find(".preview").remove();
		});
	});
	
	$("#contact").submit(function(e) {
		if(checkFormular(this)) return;
		else e.preventDefault();
	});
});

/*
 * -- Labels in Inputs anzeigen
 */
function labelit() {
	$ = jQuery;
	
	$("input.labelit, textarea.labelit").each(function(){
		
		/*
		 * --	Label Inhalt in Inputs schreiben
		 */
		$(this).parents("form").find("label[for="+$(this).attr("id")+"]").hide();
		if( $(this).val()=="" ) $(this).val($(this).parents("form").find("label[for="+$(this).attr("id")+"]").text());
		
		/*
		 * --	Focus Event
		 */
		$(this).focus(function(e){
			$(this).css("color","");
			if( $(this).parents("form").find("label[for="+$(this).attr("id")+"]").text() == $(this).val() ) {
				$(this).val("");
			}
		});
		$(this).blur(function(e) {
			if( $(this).val()=="" ) {
				$(this).val($(this).parents("form").find("label[for="+$(this).attr("id")+"]").text());
			}
		});
	});
}

/*
 * -- Check Formular
 */
function checkFormular(form) {
	var $ = jQuery;
	var error = false;
	$(form).find(".error").removeClass("error");
	$(form).find(".check-filled").each(function() {
		if($(this).val()=="") {
			error = true;
			$(this).addClass("error");
		}
		if($(this).hasClass("labelit")) {
			if($(this).val() == $(this).parents("form").find("label[for="+$(this).attr("id")+"]").text()) {
				error = true;
				$(this).addClass("error");
			}
		}
	});
	$(form).find(".check-email").each(function() {
		if($(this).val().indexOf("@")==-1) {
			error = true;
			$(this).addClass("error");
		}
		if($(this).hasClass("labelit")) {
			if($(this).val() == $(this).parents("form").find("label[for="+$(this).attr("id")+"]").text()) {
				error = true;
				$(this).addClass("error");
			}
		}
	});
	if(error) return false;
	else return true;
}
