var loading = $('<img>').attr('src', '/img/ajax-loader.gif');

function showArticle(id) {

        // load article content
        $.ajax({
                type: "GET",
                url: "/press.php",
                data: "mode=ajax&id=" + id,
                success: function(newsHtml) {
                        $("#article" + id).html(newsHtml).slideDown();
			$("#articleBlock" + id).scrollTo(1000);
                },
                beforeSend: function() { // add loading indicator
                        $("#headline" + id + " img").show();
                },
                complete: function() { // remove loading indicator
                        $("#headline" + id + " img").hide();
			$("#headline" + id + " a").html('[&nbsp;collapse&nbsp;]').attr('href','javascript:hideArticle(' + id + ')');
                }
        });

}

function hideArticle(id) {
	$("#article" + id).slideUp();
	$("#headline" + id + " a").html('[&nbsp;expand&nbsp;]').attr('href','javascript:showArticle(' + id + ')');
}

function showNewsList(year) {
        $.ajax({
                type: "GET",
                url: "/press.php",
                data: "mode=ajax&year=" + year + "&type=" + newsType,
                success: function(newsHtml) {
                        $("#newsList" + year).html(newsHtml).slideDown();
			$("#archive" + year).scrollTo(1000);
                },
                beforeSend: function() { // add loading indicator
                        $("#archive" + year + " img").show();
                },
                complete: function() { // remove loading indicator
                        $("#archive" + year + " img").hide();
			$("#archive" + year + " a").html('[&nbsp;collapse&nbsp;]').attr('href','javascript:hideNewsList(' + year + ')');
                }
        });
}

function hideNewsList(year) {
	$("#newsList" + year).slideUp();
	$("#archive" + year + " a").html('[&nbsp;expand&nbsp;]').attr('href','javascript:showNewsList(' + year + ')');
}

$(document).ready(function() {
	if (typeof(startId) != 'undefined') {
		showArticle(startId);
	}
});

jQuery.fn.extend({
  scrollTo : function(speed, easing) {
    return this.each(function() {
      var targetOffset = $(this).offset().top;
      $('html,body').animate({scrollTop: targetOffset}, speed, easing);
    });
  }
});
