$(document).ready(function() {

	// set up share handlers
	
	$("#sharing li a").click(function() {

		// var u = encodeURIComponent(window.location.href);
		// var t = encodeURIComponent(document.title);

		var svc = $(this).attr("rel");
		var href = $(this).attr("href");
		
		// if (svc == "delicious") { href += "?v=5&noui&jump=close&url="+u+"&title="+t; }
		// if (svc == "twitter") { href += "?status="+t+" - "+u; }
		// if (svc == "facebook") { href += "?u="+u+"&t="+t; }
		if (svc == "comment") { return true; }
		if (svc == "permalink") { return false; }
		
		window.open(href, "sharing", "width=650, height=500, menubar=0, toolbar=0");
		return false;
	})


	// var e = $("#commentform label").next();
	// for (var i = 0; i < e.length; i++) {
	// 	if (e[i].value != "") {
	// 		// hide the label... the field already has a value
	// 		$(e[i]).prev().hide();
	// 	} else {
	// 		// show the label... the field is empty
	// 		$(e[i]).prev().show();
	// 	}
	// }
	// 
	// $("#commentform label").next().focus(function() {
	// 	var theField = $(this);
	// 	var theLabel = $(this).prev();
	// 	hideLabel(theLabel, theField);
	// });
	// 
	// $("#commentform label").click(function() {
	// 	var theField = $(this).attr("for");
	// 	var theLabel = $(this);
	// 	hideLabel(theLabel, theField);
	// 	$("#"+theField).focus();
	// });

	$("#home_image").hover(function() {
		$("#flickr_link").css("display", "block");
		$("#flickr_link").hover(function() {
			$(this).css("display", "block");
		}, function() {
			$(this).css("display", "none");
		} );
	}, function() {
		$("#flickr_link").css("display", "none");
	});
	
	$("#archives_link").click(function() {
		$("#archives").slideToggle();
		$(this).toggleClass("open");
	});
	
	
	// $("#twitter li:contains('@')").addClass("reply");
	$("#twitter li").each(function(i) {
		var tweet = $(this).children("span").html();
		if (tweet.indexOf("@") == 0) {
			$(this).addClass("reply");
		}
	});

});

function getHomepage() {
	$.ajax({
		url: "http://api.flickr.com/services/rest/?method=flickr.photos.search&amp;api_key=209a88ceb2d555823f4b7e7be2301dfb&amp;user_id=16808126%40N00&amp;tags=homepage&amp;per_page=1&amp;page=1",
		cache: false,
		dataType: "xml",
		success: function(xml){
			alert(xml);
			// parse XML here
		}
	});
}


function hideLabel(l, e) {
	$(l).hide();
	$(e).blur(function() {
		if (this.value == "") {
			showLabel(l);
		}
	});
}

function showLabel(l) {
	$(l).show();
}

function contact(user, domain, subject) {
	var email = window.location = "mailto:"+user+"@"+domain+"?Subject="+subject;
	return false;
}