$(document).ready(function() {

function kontakt() {
	var name = $("#yourname").val();
	var nachricht = $("#nachricht").val();
	var badbehaviour = $("#email").val();
	var mail = $("#mail").val();
	if (badbehaviour !== "" ) {
		$('#kontaktformular .positive').before('<div id="throbber" />').fadeTo(0,0);
		$('#ausgabe').html('Leider bist Du ein Spammer!');
	}
	else if (badbehaviour == "" & name !== "" & mail !== "" & nachricht !== "") {
		$('#kontaktformular .positive').before('<div id="throbber" />').fadeTo(0,0);
		$('#ausgabe').fadeTo(200,0).delay(200).fadeTo(200,1);

		var dataString = 'name=' + name + '&mail=' + mail + '&nachricht=' + nachricht;
		$.ajax({
			type: "POST", 
			url: "http://www.steilstoff.de/wp-content/themes/steilstoff/mail.php",  
			data: dataString,
			success:
			function(data) {
				$('#ausgabe').fadeTo(600,0, function() {
					$('#kontaktformular input').val('');
				if (data == 'Die E-Mail konnte nicht versendet werden.') {
					$('#throbber').remove();
					$('#kontaktformular .positive').fadeTo(200,0, function() {
						$(this).before('<div id="bad" />');
					});
					$('#ausgabe').html(data).fadeTo(1200,1);
				}
				else {
					$('#throbber').remove();
					$('#kontaktformular .positive').fadeTo(200,0, function() {
						$(this).before('<div id="good" />');
					});
					$('#ausgabe').html(data).fadeTo(1200,1);
				}
				});
			}
		});
	}			
	return false;
};
	$("#kontaktformular").validate({
		errorPlacement: function(error, element) {
		error.appendTo('#kontaktformular #ausgabe');
	},	
	rules: {
		yourname: {
			required:	true
		},
		nachricht: {
			required:	true
		},
		mail: {
			required: true,
			email: true
		}			
	},
	messages: {
		yourname: "Bitte gib deinen Namen ein.",
		nachricht: "Bitte gib eine Nachricht ein.",			
		mail: "Bitte gib deine Mailadresse ein."		
	},
	submitHandler: function() {
		kontakt();	
	}	
	});
	$('#s').val('Suche').toggleValue('Suche');
        $("#tweets").tweet({
            username: "steilstoff",
            count: 1
        });
	$('.twitter-followers a').each(function(){
		var ziel = $(this).attr('href').substring(19);
		var target = ziel+': ';
		var title = $(this).attr('title');
		if (title == target) {
			var title = ziel+' ist auf twitter.com'
			$(this).attr('title',title)
		}
	}).easyTooltip({
		tooltipId: "tooltip"
	});
	$('#single-content').children('h2').each(function() {
	$(this).prepend('&#x9b;&#x9b; ');
	}); 
	$('#single-responses a').click( function() {
		var ziel = $(this).attr("href");
			if ($.browser.opera) {
				var target = 'html';
			}else{
				var target = 'html,body';
			}
			$(target).scrollTo($('#comments-wrapper'), 800 ,{axis:'y'});
	return false;		
	});
	$('.alignnone').append('<div class="clearer"></div>');
	$('#single-content .wp-caption img').captify();
	Shadowbox.init();
	$('.wp-caption a').each(function() {
	$(this).attr('rel','shadowbox');	
	var title = $(this).children('div.caption-wrapper').children('img').attr('title');
	$(this).attr('title',title);	
	});
	$(".featured-caption").each(function() {
	var msgArr = new Array();
	msgArr[0] = "fade";
	msgArr[1] = "scrollLeft";
	msgArr[2] = "scrollRight";
	msgArr[3] = "scrollUp";
	msgArr[4] = "scrollDown";
	msgArr[5] = "cover";
	var effekt = msgArr[Math.floor(Math.random()*msgArr.length)];
		var rand_no = Math.floor((7000-2000)*Math.random()) + 2000;
		$(this).children('a').cycle({fx:effekt,timeout:rand_no});
	});
	$('.top-caption a.specialhover').cycle({fx:'scrollRight',containerResize: 0,timeout:6000,speed:800}).css({'overflow':'hidden'});
	$("#logo").hover(function() {
		$(this).next("#tipsy").stop(true, true).animate({opacity:"1"},100).fadeIn();

	}, function() {
		$(this).next("#tipsy").animate({opacity: '0'}, 400).fadeOut();
	});
	$(".specialhover,.moreandmore,.top-header a").hover(function() {
		$('.specialhover,.top-header a').stop(true, true).css({'border-bottom':'1px solid #06f5e1'});
		$(".top-content .moreandmore").css({'background-position':'0 -29px'});

	}, function() {
		$('.specialhover,.top-header a').css({'border-bottom':'1px solid transparent'});
		$(".top-content .moreandmore").css({'background-position':'0 0'});
	});
	$(".featured-caption a,.featured-header a,.featured-content .moreandmore").hover(function() {
		$('.featured-caption a,.featured-header a').stop(true, true).css({'border-bottom':'1px solid #06f5e1'});
		$(".featured-content .moreandmore").css({'background-position':'0 -29px'});

	}, function() {
		$('.featured-caption a,.featured-header a').css({'border-bottom':'1px solid transparent'});
		$(".featured-content .moreandmore").css({'background-position':'0 0'});
	});
	$(".comments-wrapper").hover(function() {
		$(this).children('.comments-author-and-headline').children('.comments-headline').css({'border-bottom':'1px solid #06f5e1'});

	}, function() {
		$(this).children('.comments-author-and-headline').children('.comments-headline').stop(true, true).css({'border-bottom':'1px solid transparent'});
	});
	$(".related_post li a, #search li a").hover(function() {
		$(this).children('span').css({'border-bottom':'1px solid #06f5e1'});

	}, function() {
		$(this).children('span').stop(true, true).css({'border-bottom':'1px solid transparent'});
	});

	$('.reply a').click(function() {
		$('label.error').remove();
		var at = $(this).parent('.reply').prevAll('.comment-meta:first').children('.kommentar-author').text();
		$('#comment,#author,#email,#url').val('');
		$('#comment').val('@ '+at+',\n');
		var ziel = $(this).attr("href");
			if ($.browser.opera) {
				var target = 'html';
			}else{
				var target = 'html,body';
			}
			$(target).scrollTo($('#commentform'), 800 ,{axis:'y'});
		return false;
	});


});

