﻿$(document).ready(function() {
	ArticleListInit();
});

function ArticleListInit() {
	var HtmlOpen = '<a class="open" href="#">Open</a>';
	var HtmlClose = '<a class="close" href="#">Close</a>';
	
	if ($(".article-list").length > 0 && !($.browser.msie && $.browser.version == 6.0)){
		
		$(".article-list-expand .article-content").each(function() {

			// Hide all content except the first element under .content
			$(this).children(".content").children().hide();
			$(this).children(".content").children(":first").show();

			if ($(this).height() < 80)
				$(this).height(80);
			
			// Add Open button
			$(this).prepend(HtmlOpen);
		});

		$(".article-list-expand .article-content a.open").click(function() {
			ArticleOpen(this);
			return false;
		});
	}
}

function ArticleOpen(placement) {
	var HtmlClose = '<a class="close" href="#">Close</a>';

	$(placement).siblings(".content").children().show();

	$(placement).parent().removeAttr("style")	
	
	$(placement).before(HtmlClose);
	$(placement).remove();
	
	$(".article-list-expand .article-content a.close").click(function() {
		ArticleClose(this);
		return false;
	});
}

function ArticleClose(placement) {
	var HtmlOpen = '<a class="open" href="#">Open</a>';

	$(placement).siblings(".content").children().hide();
	$(placement).siblings(".content").children(":first").show();

	if ($(placement).parent().height() < 80)
		$(placement).parent().height(80);
	
	$(placement).before(HtmlOpen);
	$(placement).remove()

	$(".article-list-expand .article-content a.open").click(function() {
		ArticleOpen(this);
		return false;
	});
}