// Ajax functions
function showBusy(divBlock){
	$(divBlock).css('display','block');
	$(divBlock).block({
		overlayCSS: {backgroundColor: '#fff'},
		message:'<img src="'+base_url+'img/ajax_loader.gif" />',
		css:{border:'0', background:'none'}
	})
}

function updatePage(html,divBlock,div){
	setTimeout(function(){
		$(div).html(html);
		_typeface_js.renderDocument(); //Font rendering
		shadowboxImg(); //Class->rel
		Shadowbox.setup();
	}, 400);
	setTimeout(function(){
		$(divBlock).unblock();
	}, 900); 
	setTimeout(function(){	
		$(divBlock).css('display','none');
	}, 1300); 
}


// Slide function
function slide(navigation_id, pad_out, pad_in, time, multiplier){
	// creates the target paths
	var list_elements = navigation_id + " li.sliding-element";
	var link_elements = list_elements + " a";

	// creates the hover-slide effect for all link elements
	$(link_elements).each(function(i)
	{
		$(this).hover(
		function()
		{
			$(this).animate({ paddingRight: pad_out }, 150);
		},
		function()
		{
			$(this).animate({ paddingRight: pad_in }, 150);
		});
	});
}

function shadowboxImg() {
	
	$("img.shadowbox").attr('title',function(index,attr){
			$(this).parent().attr('rel','shadowbox['+attr+']');
	});
	
	$("img.shadowbox").attr('alt',function(index,attr){
			$(this).parent().attr('title',attr);
	});
}

$(document).ready(function(){ 
	
	// Shadowbox initialization
	Shadowbox.init({
	    // skip the automatic setup again, we do this later manually
	    skipSetup: false,
		overlayOpacity:0.8
	});
	shadowboxImg();


	//Nav slide
	slide("#sliding-navigation", 25, 15, 150, 0.8);

	//Ajax Navigation
	$('.ajax_link').live('click',function(eve){
		eve.preventDefault();
		var link = $(this).attr('href');	
		
		//Find "active"
		$('#sliding-navigation .active').removeClass('active');
		
		$(this).parent().addClass('active');
		
		$.ajax({
			url: link,
			type: "GET",
			dataType: "html",
			beforeSend: function(){
				showBusy('#mainloading');
			},
			success: function(html){
				updatePage(html,'#mainloading','#maincontent');
			}
		})
	});



}); /*End of $(document).ready(function())*/
