jQuery.fn.defuscate = function(){
   return this.each(function(){
	 var email = String($(this).html()).replace(/\s*\(.+\)\s*/, "@");
	 $(this).before().html('<a href="mailto:'+email+'">'+email+'</a>');
   });
};

$(function(){

	$('#revilio, #current_item').click(function(){
		$('#addemail, #text.panel').fadeOut(100, function(){
			$('#begin, #footer, #nvtd').fadeOut(1000);
		});
		return false;
	});
	$('#homelink').click(function(){
		$('#begin, #footer, #nvtd').fadeIn(1000, function(){
			$('#addemail, #text.panel').fadeIn(100);
		});
	});

// about nula

	$("#about").columnize({	columns:2, balance:true, height:300 });

// menus and slide ups

	$(".revilient").hide();
	var visible = false;

	function hideInfotext(){
		if (!$.browser.mozilla) {
			$("#text.panel").fadeOut("slow", function(){ $(this).removeClass("positioner"); });
		} else {
			$("#text.panel").animate({top:"100%"});
		}
		visible = false;
	};

	$(".revilator").click(function(){
		$(this).next().slideToggle();
		$(this).parents().siblings().children('.revilient').slideUp();
		if (visible) { hideInfotext(); }
	});

	$(".showhideinfo").click(function(){
		$(".revilient").slideUp();
		if (!visible) {
			if (!$.browser.mozilla) {
				$("#text.panel").hide().addClass("positioner").fadeIn("slow");
			} else {
				slide_upto = ($(window).height() - $("#text.panel").height()) - 72;
				$("#text.panel").animate({top: slide_upto});
			}
			visible = true;
		} else {
			hideInfotext();
		}
		return false;
	});

// synch function menu with footer icon highlights

	$("a#mailinglist").hover(
		function () { $("a#email").addClass("hoverer"); },
		function () { $("a#email").removeClass("hoverer"); }
    );
	$("a#blog").hover(
		function () { $("a#weblog").addClass("hoverer"); },
		function () { $("a#weblog").removeClass("hoverer"); }
    );
	$("a#rssfeed").hover(
		function () { $("a#rss").addClass("hoverer"); },
		function () { $("a#rss").removeClass("hoverer"); }
    );
	$("a#tweetfeed").hover(
		function () { $("a#twitter").addClass("hoverer"); },
		function () { $("a#twitter").removeClass("hoverer"); }
    );
	$("a#cafepress").hover(
		function () { $("a#mdse").addClass("hoverer"); },
		function () { $("a#mdse").removeClass("hoverer"); }
    );
	$("#apropos a").hover(
		function () { $("a#info").addClass("hoverer"); },
		function () { $("a#info").removeClass("hoverer"); }
    );
	$("a#itmsfeed").hover(
		function () { $("a#itms").addClass("hoverer"); },
		function () { $("a#itms").removeClass("hoverer"); }
    );

// mailing list

	var open = false;
	$('#nav a#email,a#mailinglist').click(function(){
		$('#addemail').load('./lib/email/form.php').show();
		$("#footer").slideToggle();
		open = true;
		return false;
	});

	$('#addemail a#cancel').live("click", function(){
		$("#footer").slideToggle(333,function(){
			$('#addemail').load('./lib/email/form.php').hide();
		});
		return false;
	});

	$('a#loadform').live("click", function(){
		$('#addemail p').fadeTo(500,0,function(){
			$('#addemail p').load('./lib/email/form.php');
		}).fadeTo(500,1);
		return false;
	});

	$('#addemail a#submit').live("click", function() {
		$.post(
			"./lib/email/list.php",
			{ email: $("#emailaddress").val()},
			function(html){
				$("#addemail p").fadeTo(500,0,function(){
					$("#addemail p").html(html);
				}).fadeTo(500,1);
			}
		);
		return false;
	});

// email defuscator

	$(".email").defuscate();

});
