/**
 * Executed when document is finished loading elements into DOM
 */
$(document).ready(function()
{			
	$(".read_more").click(function(){
		var textblock_id = $(this).attr("id");
		var id = textblock_id.substring(6);			
		$("#content_"+id).slideToggle("fast");	
		if($(this).html() == translation_open)
		{
			$(this).html(translation_close)
		}
		else
		{
			$(this).html(translation_open)
		}
	});			
			
	ajax_loadYears(article_year);
	
	$.ajax({
	  url: webroot + language + "/sections/getMonths/" + section_id + "/" + article_year + "/" + article_month,
	  cache: false,
	  success: function(html){
		$("div#submenu div#months").html(html);
		ajax_loadMonths();		
		ajax_loadArticles();	
	  }
	});	

	$.ajax({
		  url: webroot + language + "/sections/getArticles/" + section_id + "/" + article_id,
		  cache: false,
		  success: function(html){
			$("div#submenu div#items").html(html);
			ajax_loadMonths();
			ajax_loadArticles();			
		  }
	});		
});

/**
 * Print email link (protection from spambots)
 * If javascript is disabled, nothing is visible
 *
 * @param string p1 Part 1 - this is username
 * @param string p2 Part 2 - this is domain and TLD
 */
function writemail(p1, p2)
{
	document.write("<a href='mailto:"+p1+"@"+p2+"'>"+p1+"@"+p2+"</a>");
}

// Load years for article filter
function ajax_loadYears(article_year)
{				
	$.ajax({
	  url: webroot + language + "/sections/getYears/" + section_id + "/" + article_year,
	  cache: false,
	  success: function(html){
		$("div#submenu div#years").html(html);
		ajax_loadMonths();						
	  }
	});	
}

function ajax_loadMonths()
{
	// Get months for specified year
	$(".article_year").click(function(){
		var year_id = $(this).attr("id");
		var id = year_id.substring(5);		
		
		//alert("years");
		
		ajax_loadYears(id);
				
		$.ajax({
		  url: webroot + language + "/sections/getMonths/" + section_id + "/" + id,
		  cache: false,
		  success: function(html){
			$("div#submenu div#months").html(html);
			//ajax_loadMonths();		
			ajax_loadArticles();	
		  }
		});	
		
		$.ajax({
		  url: webroot + language + "/sections/getArticles/" + section_id + "/" + article_id,
		  cache: false,
		  success: function(html){
			$("div#submenu div#items").html(html);
			//ajax_loadMonths();
			ajax_loadArticles();			
		  }
		});	
			
	});
}

function ajax_loadArticles()
{		
	// Get articles for specified year
	$(".article_month").click(function(){ 
		
		var month_id = $(this).attr("id");
		var id = month_id.substring(6);				
				
		//alert("months");		
				
		$.ajax({
		  url: webroot + language + "/sections/getMonths/" + section_id + "/" + article_year + "/" + id,
		  cache: false,
		  success: function(html){
			$("div#submenu div#months").html(html);
			//ajax_loadMonths();
			ajax_loadArticles();			
		  }
		});	
		
		$.ajax({
		  url: webroot + language + "/sections/getArticles/" + section_id + "/" + article_id,
		  cache: false,
		  success: function(html){
			$("div#submenu div#items").html(html);
			//ajax_loadMonths();
			ajax_loadArticles();			
		  }
		});	
			
	});
}

isset = function(e) {
	try 
	{
		if (eval(e)) {}
	}
	catch(err) 
	{
		return false;
	}
	return true;
}
