
var baseUrl = ''; //'http://dev/inhouse/veerder/websites/inndeknip/lite';
var itemID;

var page = 2; //init

$(document).ready(function() 
{
	var bg = 'images/bg.png';
	
	_addBackground(bg);

	$('.item p a, .item h3 a').live('click',function()
	{
		itemID = $(this).parents('.item').attr('id');
		_toAction();
		
		return false;
	});
	
	$('#more a').live('click',function()
	{
		$.getJSON(baseUrl+'/nieuws/async_overview/page/'+page, function(json)
		{
			$('#more').before(json.articles);
			_showPagination(json.pagination);
		});

		return false;		
	});	
	
});

function _showPagination(p)
{
	if(p.pages == p.current)
		$('#more').hide();
	else
		page = parseFloat(p.current) + 1;
}

function _addBackground(bg)
{
	if($.backstretch)
		$.backstretch(bg, { speed: 150 });
}

function _toAction()
{
	ref = $('#'+itemID);
			
	if(ref.find('.item-full').is(':visible')) //cur active
	{
		_reset();
	
	} else {
	
		_reset();
		if(ref.find('.item-full').html() == 'loading') //load
		{
			$.getJSON(baseUrl+'/nieuws/async_artikel/id/'+itemID, function(json)
			{
				$('#'+itemID+' .item-full').html(json.article);
				
				$('#'+itemID+' .item-desc').hide();
				$('#'+itemID+' .item-full').slideDown();				
			});	
			
		} else {
			
			$('#'+itemID+' .item-desc').hide();
			$('#'+itemID+' .item-full').slideDown();
		}
	}
}

function _reset()
{
	$('.item-full').hide();
	$('.item-desc').show();
}
