//REPLACING FONT
Cufon.replace("h3");

//STYLESWITCHER WITH COOKIE
if($.cookie("css")) {
    $("link").attr("href",$.cookie("css"));
}
$(document).ready(function() {
    $("#label a").live('click', function(){
        $("link").attr("href",$(this).attr('rel'));
        $.cookie("css",$(this).attr('rel'), {expires: 365, path: '/'});
		Cufon.replace("h3");
        return false;
		
    });
});

//REWRITES EMAIL FOR SPAM REDUCTION
$(function() {
	var at = / at /;
	var dot = / dot /g;
	$("span.mailme").each(function () {
		var addr = $(this).text().replace(at,"@").replace(dot,".");
		$(this).after('<a href="mailto:'+ addr +'" title="Send an email">'+ addr +'</a>');
		$(this).remove();
	});
});

//OPENS LINKS IN NEW WINDOW/TAB
$(function() {
	$(".external").attr("target","_blank");
});


//SLIDE ANIMATION LABEL
$(function() {
	$('#label').hover(function(){
		$(this).animate({top:'-4px'},{queue:false,duration:700});
		}, function(){
			$(this).animate({top:'-68px'},{queue:false,duration:500});
	});
});

//MAKING TEXTAREA SCALE IN HEIGT
$(function() {
	$('#input_bericht').elastic();
});

//CREATING FOCUS ON THE FORM FIELD (THIS IS DONE IN THE JS FILE SO IE6 WILL ALSO WORK)
$(document).ready(function() {  
     $('input[type="text"],textarea').addClass("idleField");  
     $('input[type="text"],textarea').focus(function() {  
         $(this).removeClass("idleField").addClass("focusField");
     });  
     $('input[type="text"],textarea').blur(function() {  
         $(this).removeClass("focusField").addClass("idleField");  
     });  
 }); 


//VALIDATE FORMS
$(document).ready(function(){
    $("#contactform").validate();
	$("#comment").validate();
});

//SLIDER FOR THE LATEST PROJECT
$(document).ready(function(){
	$('#slider').karmicFlow({ auto: true, timer: 4500, duration: 800 });
});

//EXTERNAL LINKS
$(document).ready(function(){
	$("a[href^='http:']:not([href*='" + window.location.host + "'][target='_blank'])").live('click', function(){
        $(this).attr('target','_blank');
    });

});

//GETTING THE LAST TWEET TO SHOW
$(document).ready(function () {
	$("#footer").append('<div id="twitter"></div>'); //creating div where the tweets will be shown in.
	$("#twitter").append('<h3>Twittert</h3>'); //creating div where the tweets will be shown in.
	$("#twitter").tweet({
		username:"visualsuspect", //setting username
		count:1,	// setting amount of tweets
		loading_text: "loading tweets..." //settging loading text, this will be shown in the div while getting tweets from twitter
	});
	Cufon.replace("h3");
});

//CREATES A NICE LOOKING BLOCK FOR CODE EXAMPLES IN BLOG
$(document).ready(function () {
	$.beautyOfCode.init({
		brushes: ['Xml', 'JScript', 'CSharp', 'Plain', 'Php', 'Css'],
		ready: function() {
			$.beautyOfCode.beautifyAll();
			}
		});
});

//AJAX CONTACTFORM
$(document).ready(function() {	
	$("#send_form").live('click', function(){
		var formdata = $("#contactform").serialize();
		$.ajax({
			type: "POST",
			url: "../sendmail.php",
			data: formdata,
			timeout: 2000,
			error: function (XMLHttpRequest, textStatus, errorThrown) {
				submitError(XMLHttpRequest, textStatus, errorThrown, fin_error_saving);
			},
			success: function (data) {
				$("#form_holder").html(data);
			}
		});
		return false;
	});
});