$(document).ready(function() {
    $('a[rel=tipsy]').tipsy({gravity: 's'});
    $(document).pngFix();
    layout.placeElements();
});

$(window).resize(function() {
	layout.placeElements();
});

var layout = {
	
	lampanMaxHeight: 500, lampmanMarginTop: 121,
	iconMaxSize: 90, iconMarginBottom: 20,
	
	placeElements: function() {
		this.calculateIconSize();
		this.calculateLampmanHeight();
		this.setCSS();
	},
	
	setCSS: function() {
		$('h1').css({position: 'relative', zIndex: 2});
		$('#lampman').css({position: 'absolute', width: '100%', top: this.lampmanMarginTop})
		$('#lampman img').css({height: this.lampmanHeight});
		$('#buttons').css({position: 'absolute', width: '100%', bottom: this.iconMarginBottom});
		$('#buttons img').css({height: this.iconSize, width: this.iconSize});
	}, 
	
	calculateIconSize: function() {
		this.iconSize = Math.round($(window).height() * 0.125);
		if (this.iconSize > this.iconMaxSize) this.iconSize = this.iconMaxSize;
	},
	
	calculateLampmanHeight: function() {
		this.lampmanHeight = $(window).height() - this.lampmanMarginTop - this.iconSize - this.iconMarginBottom;
		if (this.lampmanHeight > this.lampmanMaxHeight) this.lampmanHeight = this.lampmanMaxHeight;
	}
}


/* Google analytics */

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-64047-2']);
_gaq.push(['_trackPageview']);

(function() {
	var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
	ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
	var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
