/*
	AJAX-Navi fuer den Lesezirkel-Coverflow
	
	Ausgalagert wegen dem setInterval in document.ready
*/
oldHash = "";

function activeColumn(id,jahr,detail)
{
	
	if (!id && $('#XYZ_ABC').val())
		id = $('#XYZ_ABC').val();
	hash = id;
	
	//archiv-eingabe auslesen	
	if (jahr)
	{
		hash += ','+jahr;
	}
	else
	{
		jahr = '';
		hash += ',0';
	}
	
	//Detailansicht einer Kolumne
	if (detail && detail != '' && detail != 0)
	{
		eintrag = detail;
		$('#coverflowContainer').css('display','none');
		hash += ','+eintrag;
	}
	else
	{
		if ($('#coverflowContainer').css('display') == 'none')
			$('#coverflowContainer').css('display','block');
		eintrag = '';
		hash += ',0';
	}
		
	window.location.hash = '#'+hash;
	oldHash = window.location.hash;
	//alert(hash+'  '+oldHash);
	$.get('getEintraege.php',{sn : id, a: jahr, e: eintrag}, function(data){
											 $('#my_content').html(data);
											 setID (id);
											 },'html') 
}

function changeArchiv(id)
{
	var archiv = $('#archivSelect option:selected');
		
	if (archiv)
	{
		jahr = archiv.val();
	}
	else
		jahr = '';
		
	activeColumn(id,jahr);
}


function setState(hash)
{
	oldHash = hash;
	if (hash)
	{
		hash = hash.substring(1);
		values = hash.split(',');
		//alert(values[0]+' || '+values[1]);
		if (values[0] || values[1] || values[2])
			activeColumn(values[0],values[1], values[2]);
	}
	else
		$('#my_content').html('');
	
}


function initialiseStateFromURL()
{
	//alert('old_hash = '+oldHash+' || new_hash = '+window.location.hash);
	if (window.location.hash != oldHash)
	{
		setState(window.location.hash);
	}
}

$(document).ready(function(){
	
	oldHash = window.location.hash;
	setState(window.location.hash);
    setInterval(initialiseStateFromURL, 500);

});
