/* ---------------------------------------------------------------------------
** that wonderful of obfuscation techniques, rot13.
** ------------------------------------------------------------------------ */

$(function(){
  // Document is ready

  /* replace my email address with a clickable link */
	var address = str_rot13("yhxr@tvhyvnav.pbz.nh",rot13init());
	var link = $('<a></a>').attr({
			'href': 'mailto:' + address,
	}).html(address);
	
	$('#emailAddress').html(link);

	// smooth scroll
	// jQuery SmoothScroll | Version 10-04-30: adapted from http://blog.medianotions.de/en/articles/2009/smoothscroll-for-jquery
	$('a[href*=#]').click(function(e) {

		e.preventDefault();

		// duration in ms
		var duration=500;

		// easing values: swing | linear
		var easing='swing';

		// get / set parameters
		var newHash=this.hash;
		var target=$(this.hash).offset().top;
		var oldLocation=window.location.href.replace(window.location.hash, '');
		var newLocation=this;

		// make sure it's the same location		
		if(oldLocation+newHash==newLocation)
		{
			// animate to target and set the hash to the window.location after the animation
			$('html:not(:animated),body:not(:animated)').animate({ scrollTop: target }, duration, easing, function() {
				// add new hash to the browser location
				window.location.href=newLocation;
			});
		}
	});

	// video
	// apparently shadowbox requires you to link to moogaloop. oh well.
	$('a.js_robot_vid').attr('href', 'http://vimeo.com/moogaloop.swf');
	Shadowbox.setup($('a.js_robot_vid'), {
			height:			360,
			width:			640,
			flashVars:	{
					clip_id: 	"13871662",
					autoplay:	"1"
			}
	});
	
});

Shadowbox.init({
	// skip the automatic setup again, we do this later manually
	skipSetup: true
});


/* Cheers A List Apart for rot13 */
function rot13init() {
	var map = new Array();
	var s = "abcdefghijklmnopqrstuvwxyz";
	for (var i = 0 ; i < s.length ; i++)
		map[s.charAt(i)] = s.charAt((i+13)%26);
	for (var i = 0 ; i < s.length ; i++)
		map[s.charAt(i).toUpperCase()] = s.charAt((i+13)%26).toUpperCase();
	return map;
}

function str_rot13(a,map) {
	var s = "";
	for (var i = 0 ; i < a.length ; i++) {
		var b = a.charAt(i);
		s += (b>='A' && b<='Z' || b>='a' && b<='z' ? map[b] : b);
	}
	return s;
}


