function setBackground(url) {
	if($('div#fullscreenBackgroundImage img.preloader').attr('src') != url) $('div#fullscreenBackgroundImage img.preloader').attr('src', url);
	}

function setMainNavSelected(id) {
	$('#contentLeft ul li').removeClass('selected');
	$('#mainNavigation_'+id).addClass('selected');
	}

function resizeBackgroundToFullscreen() {
	$('div#fullscreenBackgroundImage img.background').css({
			'width' : 'auto',
			'height': 'auto'
			});
	var targetWidth = $('div#fullscreenBackgroundImage').width();
	var targetHeight = $('div#fullscreenBackgroundImage').height();
	var ratio = targetWidth/$('div#fullscreenBackgroundImage img.background').width();
	if(ratio * $('div#fullscreenBackgroundImage img.background').height() < targetHeight) {
		ratio = targetHeight/$('div#fullscreenBackgroundImage img.background').height();
		}
	
	$('div#fullscreenBackgroundImage img').css({
			'width' : $('div#fullscreenBackgroundImage img.background').width()*ratio,
			'height': $('div#fullscreenBackgroundImage img.background').height()*ratio
			});	
	$('div#fullscreenBackgroundImage img.background').show().gx({'opacity':'1'},800,'Linear');
	}
	
	function setHash(hash) {
		window.location.hash = hash;
		$('body').data('currentHash',window.location.hash);
		}
	
	function ajaxLoadContent(url) {
		var data = { 'requestType': 'ajax' };

		$('#contentFrame').fadeOut(200);
		$.ajax({
			cache: false,
   			type: "POST",
   			url: url,
   			success: function(qdata){
				pageTracker._trackPageview(url); 
   				$('#contentFrame').html(qdata).fadeIn(200); 	  				
   				},
	  		data: data
 			});
		}

	function checkHash() {
		if(window.location.hash != $('body').data('currentHash') && window.location.hash != '') {
			ajaxLoadContent(window.location.hash.substr(1,window.location.hash.length));
			setHash(window.location.hash);
			}
		}
$(document).ready(function() {
	if(window.location.hash == '' || window.location.hash == '#'+currentHash) {
		setHash(currentHash);
		resizeBackgroundToFullscreen();
		}
	else {
		$('#contentFrame').html('');
		}
	window.setInterval("checkHash()", 500);

	$('a.ajaxLink:not(.disabled)').live('click', function() {
		if($(this).attr('href') != 'javascript:;') {
			$(this).data('target', $(this).attr('href'))
					.attr('href', 'javascript:;');
					}
		setHash('#'+$(this).data('target'));
		window.scrollTo(0, 0);
		ajaxLoadContent($(this).data('target'));
		
		return false;
		});
		
	$('div#fullscreenBackgroundImage img.preloader').load(function() {
		$('div#fullscreenBackgroundImage img.preloader').show();
		/*$('div#fullscreenBackgroundImage img.background').fadeOut(800,function() {
			$(this).attr('src', $('div#fullscreenBackgroundImage img.preloader').attr('src'));			
			});*/

			if($('body').hasClass('setdark')) $('body').addClass('dark');
		else if($('body').hasClass('removedark')) $('body').removeClass('dark');
		
		if($('body').hasClass('setbrightLogo')) $('body').addClass('brightLogo');
		else if($('body').hasClass('removebrightLogo')) $('body').removeClass('brightLogo');
		
		$('body').removeClass('setdark').removeClass('setbrightLogo').removeClass('removedark').removeClass('removebrightLogo');

		$('div#fullscreenBackgroundImage img.background').gx({'opacity':'0'},800,'Linear',function(el) {
			el.attr('src', $('div#fullscreenBackgroundImage img.preloader').attr('src'));
			resizeBackgroundToFullscreen();
			});
		});
	$(window).bind("resize", function(){
		resizeBackgroundToFullscreen();
		});
	
	});