$(document).ready(function(){ 
	getHash();
	
	$('.skorinc').blend();

	$('.nav-top a, .nav-bottom a').live('click', function(){ 
		
		ajaxCall( $(this).attr('rel') );
	
	})


})


function ajaxCall( page ){
	
	var _ajaxUrl = 'app/page.php';
	var _animSpeed = 500;
	var _source = $('#wrap .inside').html();
		
	$('#wrap .inside').animate({opacity:'hide'}, _animSpeed, function(){
	
		$.ajax({
			type: 'POST',
			url: _ajaxUrl,
			data: {page: page},
			beforeSend: function(){
			
			},
			
			success: function( data ){
				data = $.parseJSON(data);
				
				$('#wrap').append('<div id="page"><a class="nav-button">'+data.title+' <div class="close_page alignright" title="Close">x</div> </a><div class="page_text">'+data.text+'</div></div>');
				
				$('#page').animate({ opacity:'show'}, _animSpeed);
				
				setHash( page );
				
				$('.close_page').live('click', function(){ 
				
					$('#page').animate({opacity:'hide'}, _animSpeed, function(){
						$('#wrap').html('<div class="inside clearfix">'+_source+'</div>');
						$('#wrap .inside').fadeIn();
					});
				})
			}
		
		})
	
	})


}

function setHash( hash ){
	window.location.hash = '!'+hash;
}

function getHash(){
	var _hash = window.location.hash;
	_hash = _hash.replace('#!', '');
	
	if(_hash != ''){	
		ajaxCall(_hash);		
	}
}
