jQuery(document).ready(function(){
	jQuery("#header_navi a").hover(
		function(){
			var title = jQuery(this).attr("title");
			jQuery(this).append("<div class='temp_div'>" + title + "</div>");
		},
		function(){
			jQuery(".temp_div").remove();
		}
	);
	
	jQuery("#buttons a").live("mouseover", function(){
		jQuery(this).find("div").show();
	});
	
	jQuery("#buttons a").live("mouseout", function(){
		jQuery(this).find("div").hide();
	});
	
	jQuery("#logos_rechts a").hover(
		function(){
			jQuery(this).append("<div class='temp_div2'>&nbsp;</div>");
		},
		function(){
			jQuery(".temp_div2").remove();
		}
	);
	
	jQuery("#impressum").live("click", function(){
		jQuery('<div id="impressum_div"></div>').insertAfter(jQuery("#impressum")).load("index.php?article_id=14", function(){
			jQuery(this).dialog({
				title: 'Impressum',
				width: 600,
				height: 400,
				close: function(){
					$(this).remove();	
				}
			});
		});
	});
	
	jQuery("#news_arrow").live("click", function(){
		var istop = jQuery("#content_news").scrollTop();
		var istop2 = istop + 249;
		var max1 = jQuery(".content_news").length;
		var max2 = (max1/3) * 249;
		
		jQuery("#news_arrow_f").show();
		if(istop2 < max2) jQuery("#content_news").scrollTop(istop2);
		if((istop2 + (249*2)) > max2){
			jQuery("#news_arrow").hide();
		}
	});
	
	jQuery("#news_arrow_f").live("click", function(){
		var istop = jQuery("#content_news").scrollTop();
		var istop2 = istop - 249;
		if(istop2 == 0){ jQuery("#content_news").scrollTop(0); jQuery("#news_arrow_f").hide(); jQuery("#news_arrow").show(); }
		else if(istop < 0){ jQuery("#content_news").scrollTop(0); jQuery("#news_arrow_f").hide(); jQuery("#news_arrow").show(); }
		else jQuery("#content_news").scrollTop(istop2);
	});
	
	jQuery(".input1").live("focus", function(){
		if(jQuery(this).val() == "Name") jQuery(this).val("");
		jQuery(this).css("background", "url('images/input_name_i.png') #fff").css("background-position", "196px 3px");
	});
	jQuery(".input1").live("blur", function(){
		jQuery(this).css("background", "url('images/input_name.png') #f7f7f7").css("background-position", "196px 3px");
		if(jQuery(this).val() == "") jQuery(this).val("Name");
	});
	jQuery(".input2").live("focus", function(){
		if(jQuery(this).val() == "Email") jQuery(this).val("");
		jQuery(this).css("background", "url('images/input_mail_i.png') #fff").css("background-position", "196px 7px");
	});
	jQuery(".input2").live("blur", function(){
		jQuery(this).css("background", "url('images/input_mail.png') #f7f7f7").css("background-position", "196px 7px");
		if(jQuery(this).val() == "") jQuery(this).val("Email");
	});
	jQuery(".input3").live("focus", function(){
		if(jQuery(this).val() == "Ihre Nachricht") jQuery(this).val("");
		jQuery(this).css("background", "url('images/input_text_i.png') #fff").css("background-position", "196px 6px");
	});
	jQuery(".input3").live("blur", function(){
		jQuery(this).css("background", "url('images/input_text.png') #f7f7f7").css("background-position", "196px 6px");
		if(jQuery(this).val() == "") jQuery(this).val("Ihre Nachricht");
	});
	
	jQuery("#submit").live("click", function(){
		var name = jQuery("input.input1").val();
		var mail = jQuery("input.input2").val();
		var text = jQuery("textarea.input3").val();
		var error = "";
		
		if((name == "") || (name == "Name")){
			error = "Bitte einen Namen angeben!";
		}
		
		if((error == "") && ((mail == "") || (mail == "Email"))){
			error = "Bitte eine Email angeben!";
		}
		
		if((error == "") && ((text == "") || (text == "Ihre Nachricht"))){
			error = "Bitte eine Nachricht angeben!";
		}
		
		if(error == ""){
			jQuery.ajax({
				url: "kontakt.php",
				type: "POST",
				data: {name:name, mail:mail, text:text},
				dataType: "html",
				success: function(html){
					if(html){
						alert(html);
					} else {
						jQuery(".input1").val("Name").css("background", "url('images/input_name.png') #f7f7f7").css("background-position", "196px 3px");
						jQuery(".input2").val("Email").css("background", "url('images/input_mail.png') #f7f7f7").css("background-position", "196px 7px");
						jQuery(".input3").val("Ihre Nachricht").css("background", "url('images/input_text.png') #f7f7f7").css("background-position", "196px 6px");
						
						jQUery('<div id="alert_div">Vielen Dank für Ihr Interesse<br>Ihre Anfrage wurde erfolgreich versendet<br>Ich werde mich schnellstmöglich um Ihr Anliegen kümmern<br><br>Mit freundlichen Grüßen<br>Christoph Nguyen</div>').insertAfter(jQuery("#submit"));
						jQuery("#alert_div").dialog({
							title: 'ERFOLGREICH VERSENDET',
							close: function(){
								jQuery("#alert_div").remove().destroy();
							},
							modal: true,
							resizable: false
						});
					}
				}
			});
		} else {
			alert(error);	
		}
	});
});
