window.addEvent('domready', function() {

	var pageURI = new URI(window.location);

	var slider = new Fx.Slide('contentHolder', {
    duration: 600,
    transition: Fx.Transitions.Sine.easeInOut
});
	$('container').set('load', {
			onComplete: function() {
				slider.slideIn();
				$('container').fade(1);
				milkbox = new Milkbox();
			},
			onFailure: function() {
				$('container').set('Sorry, something went wrong. Please try again.');
				slider.slideIn();
				$('container').fade(1);
			},
			evalScripts: true
		});
		
	if (pageURI.get('fragment')) {
		doRequest(pageURI.get('fragment'));
	} else {
		doRequest('home');
	}
	
	
    $('logo').addEvent('click', function(e) {
		doRequest('home');
	});
	$('tab_1').addEvent('click', function(e) {
		doRequest('home');
	});
	$('tab_2').addEvent('click', function(e) {
		doRequest('theweather');
	});
	$('tab_3').addEvent('click', function(e) {
		doRequest('clinktasks');
	});
	$('tab_4').addEvent('click', function(e) {
		doRequest('contact');
	});

	function doRequest(page) {		
		if (!((page == 'home') && (pageURI.get('fragment') == null))) {
			window.location = "http://" + pageURI.get('host') + pageURI.get('directory') + "#" + page;
		}
		
		$('container').fade(0);
		slider.slideOut();
		setTimeout("$('container').load('_" + page + ".html');", 600);
 	}
});
