$(window).load(function() {
	var aspectRatio = $(".source-image").width() / $(".source-image").height();
	
	function resizeBg() {
		if ( $(window).width()/$(window).height() > aspectRatio ) {
			$(".source-image").width($(window).width());
			$(".source-image").height($(".source-image").width()/aspectRatio);
		} else {
			$(".source-image").height($(window).height());
			$(".source-image").width($(".source-image").height()*aspectRatio);
		}
	}
	
	$(window).resize(function() {
		resizeBg();
	}).trigger("resize");
	
	$('a.cbox').colorbox({
		transition:'fade', speed:500,
		href:$(this).attr('href'),
		initialWidth:"20%", initialHeight:"40%",
		maxWidth:"60%", maxHeight:"60%",
		height: 300,
		onComplete:function(){_gaq.push(['_trackPageview', $(this).attr('href')])}
	});
	
	$(document).bind('cbox_open', function(){
	    $('html').css({overflow:'hidden'});
	}).bind('cbox_closed', function(){
	    $('html').css({overflow:'auto'});
	});
	
	var pos = -592;

	function scrollLogo() {
		$("#logo div").delay(3000).animate({backgroundPosition: pos}, 200, 'swing', function () {
			pos += 148;
			if (pos == 148) pos = -740;
			scrollLogo();
		});
	}
	
	scrollLogo();
});

jQuery.fn.defuscate = function(settings) {
   settings = jQuery.extend({link: true}, settings);
   regex = /\b([A-Z0-9._%-]+)\([^)]+\)((?:[A-Z0-9-]+\.)+[A-Z]{2,6})\b/gi;
   mailto = '<a href="mailto:$1@$2">$1@$2</a>';
   plain = "$1@$2";
   return this.each(function() {
     defuscated = $(this).html().replace(regex, settings.link ? mailto : plain)
     $(this).html(defuscated);
   });
} 
