var animation = null;

function chartAnimation(el){
	if(animation) {
		animation.cancel();
	}
	var num_listElements = this.length;
	var listEntry = null;
	for(var i=0;i<num_listElements;i++){
		listEntry = this[i];
		anchor = listEntry.getChildren('a')[0];
		anchor.className = '';
	}
	el.className = 'aktiv';
	animation = new Fx.Tween('photoArea',
		{
			duration: 500,
			onComplete: function(){
				animation = new Request.HTML(
					{
						method: 'get',
						update: $('photoArea'),
						evalScripts: true,
						url: '/getChartHTML.php?filename='+el.href,
						onSuccess: function(responseTree, responseElements, responseHTML, responseJavascript){
							animation = new Fx.Tween('photoArea',
								{
									onComplete: function(){
										animation = null;
									}
								}
							).start('opacity', '0', '1');
						}
					}
				).send();
			}
		}
	).start('opacity', '1', '0');
	return false;
}

function openNewWindow(){
	window.open(this.href);
	return false;
}

Cufon.replace('#mainNavigation a',{ hover: true, hoverables: { a: true } });
Cufon.replace('h1');

window.addEvent('domready',
	function(){
		if($('chartNavi')){
			var listElements = $('chartNavi').getChildren('li');
			var num_listElements = listElements.length;
			var listEntry = null;
			for(var i=0;i<num_listElements;i++){
				listEntry = listElements[i];
				anchor = listEntry.getChildren('a')[0];
				anchor.addEvent('click', chartAnimation.bind(listElements, anchor));
				if(i == 4){
					anchor.className = 'aktiv';
				}
			}
		}
		var externalLinks = $$('.external');
		var link;
		var numExternalLinks = externalLinks.length;
		for(var i=0;i<numExternalLinks;i++){
			link = externalLinks[i];
			link.addEvent('click', openNewWindow.bind(link));
		}
	}
);
