var topYloc = null;

$(window).scroll(function () { 
	var scrollTop = $(document).scrollTop();
	scrollTop = parseInt(scrollTop);
	
	var offset = topYloc+scrollTop+"px";  
	$("#toplink").animate({top:offset},{duration:500,queue:false});
});

$(document).ready(function(){
						   
	$('#contact-form').submit(function(){

			var action = $(this).attr('action');
	 
			$('#submit')
				.before('<img src="images/ajax-loader.gif" width="16" height="16" class="loader" />')
				.attr('disabled','disabled');
	 
			$.post(action, { 
				name: $('#name').val(),
				email: $('#email').val(),
				text: $('#text').val(),
				domain: $('#domain').val(),
				gebot: $('#gebot').val(),
				firma: $('#firma').val(),
				bot: $('#bot').val(),
				form: $('#form').val()
			},
				function(data){
					$('#contact-form #submit').attr('disabled','');
					$('#contact-form img.loader').fadeOut(500,function(){$(this).remove()});
					$('.response').remove();
					$('.responseSent').remove();
					
					if(data=='E-Mail gesendet, wir melden uns in Kürze.') { 
						$('#name').attr("value","");
						$('#email').attr("value","");
						$('#text').attr("value","");
						$('#gebot').attr("value","");
						$('#firma').attr("value","");
						$('#bot').attr("value","");
						$('#submit').after('<div class="responseSent">'+data+'</div>');
					}
					else {						
						$('#submit').after('<div class="response">'+data+'</div>');
					}
					
					
				}
			);
	 
		return false;
	});
						   
	//back to top scroll function. Any link with a hash (#) will scroll to that id on the page
	$('a[href*=#]').click(function() {
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
			var $target = $(this.hash);
			$target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
			if ($target.length) {
				var targetOffset = $target.offset().top;
				targetOffset = targetOffset - 35;
				$('html,body').animate({scrollTop: targetOffset}, 500);
				return false;
			}
		}
	});
	
	topYloc = parseInt($("#toplink").css("top").substring(0,$("#toplink").css("top").indexOf("px")));

});
