function showTopMenu(menu, link){
	$('div.topMenu > div').each(function(){
		if ($(this).is(':visible')){
			$(this).slideUp();
			$('#siteTopMenu').css('position', 'fixed');
			$('#siteTopMenu').css('top', 0);
		}
	});
	if ($(link).parents('li').attr('class') == 'active'){
		$(link).parents('li').removeClass('active');
		$("#dimPage").hide();
		$('.topMenu').children('#' + menu).slideUp();
		$('#siteTopMenu').css('position', 'fixed');
		$('#siteTopMenu').css('top', 0);
	} else {
		$(link).parents('ul').children().each(function(){
			$(this).removeClass('active');
		});
		$("#dimPage").show();
		$('.topMenu').children('#' + menu).slideDown();
		$(link).parents('li').addClass('active');
		$('#siteTopMenu').css('position', 'absolute');
		$('#siteTopMenu').css('top', $(window).scrollTop());

	}
	$(link).blur();
}

function showTopMenu1(menu, link){
	if ($(link).parents('li').attr('class') == 'active'){
		return false;
	} else {
		$('div.topMenu1 > div').each(function(){
			if ($(this).is(':visible')){
				$(this).slideUp();
			}
		});
		$(link).parents('ul').children().each(function(){
			$(this).removeClass('active');
		});
		$('.topMenu1').children('#' + menu).slideDown();
		$(link).parents('li').addClass('active');
	}
	$(link).blur();

}

function resetMenu(){
	$('div.topMenu > div').each(function(){
		if ($(this).is(':visible')){
			$(this).slideUp();
			$('#siteTopMenu').css('position', 'fixed');
		}
	});
	$('ul.topMenus').children().each(function(){
		$(this).removeClass('active');
	});

	//$("#dimPage").hide();
}

function loadWaitArticle(){
	resetMenu();
	$("#dimPage").css('z-index', '100');
	$("#dimPage").css('opacity', '0.95');
	$("#dimPage").html('<div style="text-align: center; padding-top:50px"><h1 style="color: #cb1210;font-family: \'Georgia, times new roman\';font-weight: normal;">Henter...</h1><br /><img src="/gfx/ajaxLoader.gif"><br />Et ųjeblik...</div>');
}

function showArticlesForSubject(subject){
	subjectsHTML = $("#articleSubjects").html();
	$("#articleSubjects").slideUp(function(){
		$("#articleSubjects").html('<div style="text-align:center"><img src="/gfx/ajaxLoader.gif" style="padding:20px;"></div>');
		$("#articleSubjects").slideDown(function(){
			$.ajax({  url:'/ajax/ajax.topMenuArticles.php'
					, type:'post'
					, datatype:'html'
					, data:'action=getArticles&subject=' + subject
					, success: function(data){
						$("#articleSubjects").html(data);
					}
			});
		});
	});
}

function topMenu1BackTo(what, content){

	$("#" + what).slideUp(function(){
		$("#" + what).html(content);
		$("#"+ what).slideDown();
		//showTopMenu1(what, $('.topMenu1 ul.topMenus li:nth-child(2) > a'));
	});
	/*
	$.ajax({  url:'/ajax/ajax.topMenuArticles.php'
			, type:'post'
			, datatype:'html'
			, data:'action=getCategories'
			, success: function(data){
				$("#articleSubjects").html(data);
				$("#articleSubjects").toggle( 'slide', {}, 500 );

				}
		});
	*/

	//$("#articleSubjects").toggle( 'slide', {}, 500 );
}

function showArticleSubjectsForAuthor(author){
	subjectsHTML = $("#articleAuthors").html();
	$("#articleAuthors").slideUp(function(){
		$("#articleAuthors").html('<div style="text-align:center"><img src="/gfx/ajaxLoader.gif" style="padding:20px;"></div>');
		$("#articleAuthors").slideDown(function(){
			$.ajax({  url:'/ajax/ajax.topMenuArticles.php'
				, type:'post'
				, datatype:'html'
				, data:'action=getArticleSubjectsForAuthor&author=' + author
				, success: function(data){
					$("#articleAuthors").html(data);
				}
			});
		});
	});
}

/**
 * Hent atikler til emne - ud fra forfatter -> emne
 * @param author
 * @param subject
 */
function showSubjectArticlesForAuthor(author, subject){
	subjectsArticlesHTML = $("#articleAuthors").html();
	$("#articleAuthors").slideUp(function(){
		$("#articleAuthors").html('<div style="text-align:center"><img src="/gfx/ajaxLoader.gif" style="padding:20px;"></div>');
		$("#articleAuthors").slideDown(function(){
			$.ajax({  url:'/ajax/ajax.topMenuArticles.php'
				, type:'post'
				, datatype:'html'
				, data:'action=getSubjectArticlesForAuthor&author=' + author + "&subject=" + subject
				, success: function(data){
					$("#articleAuthors").html(data);
				}
			});
		});
	});
}

function showArticle(id){
	resetMenu();
	$("#content").html('<div style="text-align: center; margin-top:0px"><h1 class="articleHeader">Henter artiklen.</h1><br /><img src="/gfx/ajaxLoader.gif"><br />Et ųjeblik...</div>');
	$("#content").html('<div style="text-align: center; margin-top:0px; color:#ffffff"><h1 style="color: #ffffff">Henter artiklen.</h1><br /><img src="/gfx/ajaxLoader.gif"><br />Et ųjeblik...</div>');
	$.ajax({  url:'/ajax/ajax.articles.php'
				, type:'post'
				, datatype:'html'
				, contentType: 'application/x-www-form-urlencoded; charset=ISO-8859-1'
				, data:'action=getArticle&id=' + id
				, success: function(data){
					$("#content").html(data);
				}
		});

}

function showNewsBlogsForSubjectID(ID){
	newsBlogSubjectsHTML = $("#newsBlogSubjects").html();
	$("#newsBlogSubjects").slideUp(function(){
		$("#newsBlogSubjects").html('<div style="text-align:center"><img src="/gfx/ajaxLoader.gif" style="padding:20px;"></div>');
		$("#newsBlogSubjects").slideDown(function(){
			$.ajax({  url:'/ajax/ajax.topMenuNewsBlogs.php'
				, type:'post'
				, datatype:'html'
				, data:'action=getNewsBlogsForSubject&subject=' + ID
				, success: function(data){
					$("#newsBlogSubjects").html(data);
				}
			});
		});
	});
}

function showNewsBlogsByYear(year){
	newsBlogsYears = $("#newsBlogsByDate").html();
	$("#newsBlogsByDate").slideUp(function(){
		$("#newsBlogsByDate").html('<div style="text-align:center"><img src="/gfx/ajaxLoader.gif" style="padding:20px;"></div>');
		$("#newsBlogsByDate").slideDown(function(){
			$.ajax({  url:'/ajax/ajax.topMenuNewsBlogs.php'
				, type:'post'
				, datatype:'html'
				, data:'action=getNewsBlogsByYear&year=' + year
				, success: function(data){
					$("#newsBlogsByDate").html(data);
				}
			});
		});
	});
}

function showBooksForBible(bibleID){
	biblesHTML = $("#bibles").html();
	$("#bibles").slideUp(function(){
		$("#bibles").html('<div style="text-align:center"><img src="/gfx/ajaxLoader.gif" style="padding:20px;"></div>');
		$("#bibles").slideDown(function(){
			$.ajax({  url:'/ajax/ajax.bible.php'
					, type:'post'
					, dataType:'json'
					, data:'action=getBooks&bibleID=' + bibleID
					, success: function(data){
						$("#bibles").html(data.books);
						$("#bibleBookTitle").html(data.bibleBookData.title);
					}
			});
		});
	});
}
