$(document).ready(function() {
	$('#content-container').hide();
	$('#header').hide();
	$('#content-container').fadeIn(1200);
	$('#header').fadeIn(1200);
	
});

//JQUERY
function showRecentArticles(moduleId, timespan){
	
	jQuery.ajax({
		type: 'POST',
		url: '/adminajax/get_recent_categorized_articles_homepage',
		data: { 
			timespan: timespan , 
			moduleId: moduleId
		},
		beforeSend:function(){
			jQuery('#loadingArticles').show();
			jQuery('#articleList').empty();			
		},
		success:function(resp){
      		var articles = resp;
      		if (articles == '') {
      			articles = "<p style='margin-left:12px;'>No articles categorized in the selected timespan</p>";
      		}
      		
      		
      		jQuery('#articleList').hide();
      		jQuery('#articleList').html(articles);
      		jQuery('#articleList').fadeIn('slow');
      		jQuery('#loadingArticles').hide(); 	      		
      		jQuery('#lastFunction').html("recent");
      		
		},
		error:function(){
			jQuery('#articleList').html("<p>Could not retrieve articles</p>");
		}
	});
}

function toggleLogin(){
	$('#login-container').slideToggle();
}

function toggleModuleUl(){
	$('#moduleList').slideToggle('fast');
}
function upModuleUl(){
	$('#moduleList').slideUp('fast');
}

function getCrumbsById(articleID){
	
	if (articleID && !jQuery('crumbs').data('loading'+articleID)) {
		
		if ( jQuery('#crumbs_'+articleID).is(':visible') || jQuery('#crumbs_'+articleID).html() != ''){
			
			jQuery('#crumbs_'+articleID).slideToggle('slow');
			
		} else {
			
			//Set running flag
			jQuery('crumbs').data('loading'+articleID, true);
			
			// AJAX request
			jQuery.ajax({
				type: 'POST',
				url: '/adminajax/get_crumbs_by_id',
				data: { 
					articleID: articleID
				},
				beforeSend:function(){
					jQuery('#crumbs_'+articleID).fadeIn('slow');
					jQuery('#crumbs_'+articleID).html('<p><img src="/public_images/spinner_moz.gif" /> Loading topics...</p>');
				},
				success:function(resp){
					jQuery('#crumbs_'+articleID).hide();
					jQuery('#crumbs_'+articleID).html(resp);
					jQuery('#crumbs_'+articleID).slideDown('slow');					
				},
				error:function(){
					//jQuery('#articleList').html("<p>Could not retrieve articles</p>");
				}
			});
			
		}
		
	} 

}


function getCitation(articleID){
	
	if (articleID && !jQuery('citation').data('loading'+articleID)) {
		
		if ( $('#citation_'+articleID).is(':visible') || $('#citation_'+articleID).html() != ''){
			
			$('#citation_'+articleID).slideToggle('slow');
			
		} else {
			
			//Set running flag
			jQuery('citation').data('loading'+articleID, true);
			
			// AJAX request
			jQuery.ajax({
				type: 'POST',
				url: '/adminajax/get_citation',
				data: { 
					articleID: articleID
				},
				beforeSend:function(){
					$('#citation_'+articleID).fadeIn('slow');
					$('#citation_'+articleID).html('<p><img src="/public_images/spinner_moz.gif" /> Loading citation...</p>');
				},
				success:function(resp){
					$('#citation_'+articleID).hide();
					$('#citation_'+articleID).html(resp);
					$('#citation_'+articleID).slideDown('slow');				
				},
				error:function(){
					//jQuery('#articleList').html("<p>Could not retrieve articles</p>");
				}
			});
			
		}
		
	} 

}

function selectFeature(id){
	$('div.section:visible').hide();
	$('#'+id).fadeIn('slow');
	 //$('div.section:visible').toggle('slide');   
	 //$('#'+id).toggle('slide'); 
}
