function identityLine() { // Draw 45 degr line
	for (var ypos=0; ypos<949; ypos++) {
		xpos = 949-ypos;
		var dot = document.createElement('div');
		jQuery(dot).addClass("dot");
		jQuery(dot).css("left",xpos+"px");
		jQuery(dot).css("top",ypos+"px");
		jQuery("#id-feature").append(jQuery(dot));
	}
}
function externalLinks() { // Open links in new window
	jQuery("a[rel*='external']").each(function(){
		jQuery(this).attr("target", "_blank");
	});
}
function visitedLinks() { // Make visited cases and posts fade out
	jQuery("h3 a").each(function(){
		if (jQuery(this).css("text-decoration") === "line-through") {
			jQuery(this).css("text-decoration", "none").parent().parent().css("opacity", "0.1").hover(
				function(){
					jQuery(this).fadeTo(100, "1");
				},
				function(){
					jQuery(this).fadeTo(100, "0.1");
				}
			);
		}
	});
}
function populateFields() { // Populate fields with label text and hide all labels
	jQuery('.populate').each(function(){
		if ((jQuery(this).val() === "") || (jQuery(this).val() === jQuery(this).attr('title'))) {
			jQuery(this).val(jQuery(this).attr('title')).addClass("unfilled");
			if (jQuery.cookie('MRTNRSL_'+jQuery(this).attr('title'))) jQuery(this).val(jQuery.cookie('MRTNRSL_'+jQuery(this).attr('title'))).removeClass("unfilled"); // Set remembered personal details
		}
		jQuery(this).focus(function(){
			if (jQuery(this).val() === jQuery(this).attr('title')) jQuery(this).val('').removeClass("unfilled");
		});
		jQuery(this).blur(function(){
			if ((jQuery(this).val() === "") || (jQuery(this).val() === jQuery(this).attr('title'))) {
				jQuery(this).val(jQuery(this).attr('title')).addClass("unfilled");
			}
		});
		jQuery('label[for='+jQuery(this).attr('id')+']').addClass('structural');
	});	
}
function onFormSubmit() { 
	jQuery(':submit').click(function(){
		jQuery('.populate').each(function(){
			if (jQuery(this).val() === jQuery(this).attr('title')) jQuery(this).val(''); // Empty field forms if containing default text
			if ((jQuery(this).val() !== "") && ((jQuery(this).attr('title') === "Name") || (jQuery(this).attr('title') === "E-mail") || (jQuery(this).attr('title') === "URL"))) 
				jQuery.cookie('MRTNRSL_'+jQuery(this).attr('title'), jQuery(this).val(), { expires: 200, path: '/' }); // Remember personal details
		});
	});
}
function getTweet() { // Get latest tweet
	if (jQuery('body').attr('id') === "home") {
		jQuery.ajax({
			url: "/assets/snippets/tweet.inc.php",
			cache: false,
			success: function(html){
				jQuery("#tweet").append(html);
			}
		});
	}
}

jQuery(document).ready(function(){
	jQuery.noConflict(); // co-exist with other librarys
	identityLine();
	externalLinks();
	visitedLinks();
	populateFields();
	onFormSubmit();
	getTweet();
	jQuery('body').highlight('–');
});

