$(document).ready( function() {

	$(".pageOff").live({
		mouseover: function() {
			$(this).attr('src', "img/pageOn.gif");
		},
		mouseout: function() {
			$(this).attr('src', "img/pageOff"+$(this).attr("alt")+".gif");
		}
	});

	$(".smoothHover").live({
		mouseover: function() {
			$(this).children().children().last().stop().animate({
				opacity: '1'
			}, 150).animate({
				opacity: '0.9'
			}, 100);
		},
		mouseout: function() {
			$(this).children().children().last().stop().animate({
				opacity: '0'
			}, 200);
		}
	});

	$("#logo").live({
		mouseover: function() {
			$(this).stop().animate({
				opacity: '0.8'
			}, 150).animate({
				opacity: '0.7'
			}, 100);
		},
		mouseout: function() {
			$(this).stop().animate({
				opacity: '0'
			}, 200);
		}
	});

	$(".vignette").live({
		mouseover: function() {
			$(this).stop().animate({
				opacity: '0'
			}, 150).animate({
				opacity: '0.1'
			}, 100);
		},
		mouseout: function() {
			$(this).stop().animate({
				opacity: '1'
			}, 200);
		}
	});

	$(".neuigkeitVignette").live({
		mouseover: function() {
			$(this).stop().animate({
				opacity: '0'
			}, 150).animate({
				opacity: '0.1'
			}, 100);
		},
		mouseout: function() {
			$(this).stop().animate({
				opacity: '1'
			}, 200);
		}
	});

	
	$(".showName").live({
		mouseover: function() {
			var lName = $(this).children().children().attr("alt");
			$('#nameLabel').html( lName );
		},
		mouseout: function() {
			$('#nameLabel').html( "" );
		}
	});

	/* Ajax Links au§erhalb des Menues
	////////////////////  */
	
	$(".browse").live({
		click: function() {
			var link = $(this);
			
			var exp = link.attr("href").split('?');
			exp = exp[1];
			exp = exp.split('&');
			var content = "";
			var sub = "";
			var tag = "";
			var rel = link.attr("rel");
			
			$.each( exp, function(index, item) {
				if( item.match(/c=/) != null )
				{
					content = item.replace('c=','');
				}
				else if( item.match(/d=/) != null )
				{
					sub = item.replace('d=', '');
				}
				else if( item.match(/tag=/) != null )
				{
					tag = item.replace('tag=', '');
				}
			});
			
			if( (
				content != "impressum"
			&&
				content != "sitemap")
			&&
				sub == ""
			&&
				rel != "pages"
			&&
				rel != "back"
			&&
				tag == "")
			{
				$('#'+content).click();
			}
			else
			{	
				if( rel == "subContent" )
				{
					$(this).parent().children().each( function() {
						$(this).removeClass("active");
					});
					$(this).addClass("active");
				}
				
				var toLoad = $(this).attr('href')+' #content > *';
				
				$('#content').fadeOut('slow', function() {
	    			$('#load').css("display", "block");
	
	    			$('#content').load(toLoad, function() {
	        			$('#content').fadeIn('slow');
	    				$('#load').css("display", "none");
						
						$('#menu ul li a').each( function() {
	    					$(this).removeClass('active');
	    	    			$(this).animate({
	    						paddingTop : '16px',
	    						color: '#b6b6b6'
	    	        		}, 100);
	    	        	});
	    	        	
						if( sub != "" || tag != "" || rel == "pages")
						{
							$('#'+content).stop().animate({
								paddingTop: '12px',
								color: '#868686'
							}, 150, function () {
								$(this).addClass('active');
							});
						}
						if(content == "fotos" || content == "aktuelles")
						{
		       				$.getScript("js/getFotos.js");
						}
	    			});
				});				
			}
			
			return false;
		}
	});

	/* Form Validation
	////////////////////  */

	function placeholder(fId, stdValue)
	{
		$("#"+fId).live({
			focus: function () {
			if( $(this).val() == "" || $(this).val() == stdValue )
	
				$(this).val("");
				$(this).animate({backgroundColor: "#232327"}, 100);
	
			},
			blur: function () {
	         if( $(this).val() == "" || $(this).val() == stdValue )

			 	$(this).val( stdValue );
		  		$(this).animate({backgroundColor: "#37373d"}, 100);
		  		
			}
		});
	}
	placeholder("fName", "Name");
	placeholder("fEmail", "E-Mail");
	placeholder("fAlter", "Alter");
	placeholder("fTelefon", "Telefon");
	placeholder("fBetreff", "Betreff");
	placeholder("fText", "Deine Nachricht");
	placeholder("fAbfrage", "Sicherheitsabfrage");
	
	placeholder("nLName", "Name");
	placeholder("nLEmail", "E-Mail");
	placeholder("nLCaptcha", "....");
	
	$("#fText").live({
		focus: function () {
		if( $("#fText").val() == "" || $("#fText").val() == "Deine Nachricht" )
			$("#fText").animate({
				width: "550px"
			}, 300);
		}
	});
	
	$("#fText").live({
		blur: function () {
         if( $("#fText").val() == "" || $("#fText").val() == "Deine Nachricht" )
			$("#fText").animate({
				width: "245px"
			}, 300);
		}
	});
});
