//http://www.zachstronaut.com/posts/2009/02/02/analytics-browser-window-size.html
if (typeof pageTracker !== 'undefined') {
	pageTracker._trackEvent(
		'Browser Dimensions',
		'load',
		$(window).width() + 'x' + $(window).height(),
		$(window).width()
	);
	$(window).resize(function () {
		if ($(this).data('gatimer')) {
			clearTimeout($(this).data('gatimer'));
			$(this).data('gatimer', null);
		}
		$(this).data(
			'gatimer',
			setTimeout(function () {
				pageTracker._trackEvent(
					'Browser Dimensions',
					'resize',
					$(window).width() + 'x' + $(window).height(),
					$(window).width()
				);
			},500)
		);
	});
}

var social = {
	addPlusOne : function(){
		var po = document.createElement('SCRIPT'), s = document.getElementsByTagName('script')[0];
		po.type = 'text/javascript'; 
		po.async = true; 
		po.src = 'https://apis.google.com/js/plusone.js';
		s.parentNode.insertBefore(po, s);	
	},
	
	footer : function() {
		if ( $(window).height() < $('#navigation').height() + 40 ) {
			this.vars.$footer.removeClass('fixed').addClass('static');
		} else {
			this.vars.$footer.addClass('fixed').removeClass('static');
		}
	},
			
	init : function() {
		var $fb = $('<iframe src="http://www.facebook.com/plugins/like.php?app_id=191407030923773&amp;href='+this.vars.url+'&amp;send=false&amp;layout=button_count&amp;width=400&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:400px; height:21px;" allowTransparency="true" class="social"></iframe>'),
			$plusone = $('<div class="social social-gpo"><div class="g-plusone" data-size="medium" data-count="true" data-href="'+this.vars.url+'"></div></div?'),
			$tweetbutton = $('<iframe allowtransparency="true" frameborder="0" scrolling="no" src="http://platform.twitter.com/widgets/tweet_button.html?count=horizontal&amp;text='+this.vars.title+'&amp;via=evilnickname" style="width:130px; height:21px;" class="social"></iframe>');

		this.addPlusOne();
		this.footer();
		
		this.vars.$social
			.append($plusone, $tweetbutton, $fb, this.vars.$toplink)
			.appendTo(this.vars.$footer);
		$('#container').after(this.vars.$footer);	
				
		$(window).resize( function() { 
			social.footer() 
		});
	},

	vars : {
		$footer 	: $('<div id="sitefooter" class="fixed" />'),
		$social 	: $('<div id="socialstuff" />'),
		$toplink : $('<a href="#content" id="gototop"><span>go to top</span></a>'),
		title 	: $('#content h1:first').text(),
		url 		: location.href
	}
	
}
social.init();
