/******************************************************************************
 INITIALIZATION
 ******************************************************************************/

$(document).ready(function(){
	Wishpipe.showEmailAddress();
	Wishpipe.showLatestTweet();
	Wishpipe.handleAnchorScroll();
});

/******************************************************************************
 WISHPIPE OBJECT 
 ******************************************************************************/

var Wishpipe = {};
		
// SHOW EMAIL ADDRESS
Wishpipe.showEmailAddress = function(){
	$('span.email').html("<n uers=\"znvygb:zp\100jvfucvcr\056pbz\" gvgyr=\"Rznvy Jvfucvcr\">zp\100jvfucvcr\056pbz<\057n>".replace(/[a-zA-Z]/g, function(c){
		return String.fromCharCode((c<="Z"?90:122)>=(c=c.charCodeAt(0)+13)?c:c-26);
	}));
	$('dd.email').html("<n uers=\"znvygb:zp\100jvfucvcr\056pbz\" gvgyr=\"Rznvy Jvfucvcr\">zp\100jvfucvcr\056pbz<\057n>".replace(/[a-zA-Z]/g, function(c){
		return String.fromCharCode((c<="Z"?90:122)>=(c=c.charCodeAt(0)+13)?c:c-26);
	}));
}

	
// SHOW LATEST TWEET
Wishpipe.showLatestTweet = function(){
	var url = 'http://twitter.com/statuses/user_timeline/wishpipe.json?count=0&callback=?';
	$('#twitter blockquote p').toggleClass('loading');
	$('#twitter blockquote p a').html('Loading latest tweet...');
	$.getJSON(url, function(tweets){
		$('#twitter blockquote p').toggleClass('loading');
		var latestTweet = tweets[0].text;
		$('#twitter blockquote p a').html(latestTweet);
	})
}

// HANDLE ANCHOR SCROLL
Wishpipe.handleAnchorScroll = function(){
	$('.scroll').click(function(event){
		event.preventDefault();
		var fullUrl = this.href;
		var urlParts = fullUrl.split('#');
		var urlTarget = urlParts[1];
		var targetAnchorOffset = $('#'+urlTarget).offset();
		var targetLocation = targetAnchorOffset.top;
		$('html, body').animate({scrollTop:targetLocation}, 500);
		this.blur();
	})
}