// JavaScript Document

function Main () {
	
	var logoHalfHeight = 65;
	var backgroundPictureHeight = 2048;	
	
	this.init = function ($) {
		
		$("div.flintGallery li a").prettyPhoto({theme: 'facebook'});
		$("div.flintGallery li a, div.flintGallery li a img").attr( "title", "" ).attr( "alt", "" );
		$( "#gallery" ).flintGallery();
		

		onWindowResize();
		
		// bind resize event 
		$(window).bind( "resize.verticalCenter", onWindowResize );
		
		
		function reverseString ( string ) {
			return string.split("").reverse().join("");
		}
		
		$(".email").each(
			function () {
				var mail = $(this).text();
				$(this).attr( "href", "mailto:" + reverseString( mail ) );
				$(this).text( reverseString( mail ) );
				
			}
		)		
		
	}
	
	/**
	 *	Center content in window
	 */
	function onWindowResize ( event ) {
		
		var container = $( "#container" );
		var marginTop = Math.round( Math.max( 0, ( $(window).height() - container.height() ) / 2 - logoHalfHeight ) );
		container.css( "margin-top", marginTop + "px" );
		
		if ( marginTop > 0 ) {
			$( "html" ).css( "background-position", "left " + Math.round( ( $(window).height() - backgroundPictureHeight ) / 2 ) + "px" );
		}
		
	}
	
}

var main = new Main();

jQuery(document).ready( function ($) { main.init($) });
