// Effects Controllers

var effectList = new Array();

function cancelEffect(effectName){
	var effect = effectList[effectName];
	if(effect!=null){
		effect.cancel();
	}
}
function nameEffect(effectName, effect){
	effectList[effectName] = effect;	
}

function replaceEffect(owner, effect){
	cancelEffect(owner.id);
	nameEffect(owner.id, effect);
}

//Left info pane

function movePane(){
	mainDiv = document.getElementById("comment_pane");
	if(mainDiv!=null){
		animate({element: mainDiv, fps:30, duration: 0.7, opacity: 100});
	}
}

function hidePane()
{
	mainDiv = document.getElementById("comment_pane");
	if(mainDiv!=null){
		animate({element: mainDiv, fps:30, duration: 0.7, opacity: 0});
	}
}
function showImageComments(event, title, comment){
	titleDiv = document.getElementById("image_title");
	if(titleDiv!=null){
		titleDiv.innerHTML = title;
	}
	commentDiv = document.getElementById("image_comment");
	if(commentDiv!=null){
		commentDiv.innerHTML = comment;
	}
}

function movePane2(){
	mainDiv = document.getElementById("comment_pane");
	if(mainDiv!=null){
		replaceEffect($("comment_pane"), new Effect.Opacity($("comment_pane"), { to: 1.0, duration: 0.3}));
		//fade(mainDiv, 5, 5, 0, 100, true);
	//	mainDiv.style.visibility = "visible";
	//	mainDiv.style.left = (window.event.clientX +100)+"px";
	//	mainDiv.style.top = (window.event.clientY - 50)+"px";
	}
}

function hidePane2()
{
	mainDiv = document.getElementById("comment_pane");
	if(mainDiv!=null){
		replaceEffect($("comment_pane"), new Effect.Opacity($("comment_pane"), { to: 0.0, duration: 0.3}));
		//fade(mainDiv, 5, 5, 0, 100, false);
		//mainDiv.style.visibility = "hidden";
	}
}

function loadImageWindow(image){
	var close_window = document.getElementById('close_window');
	clearAnimation(close_window);
	setOpacity(close_window, 0);

	document.getElementById('loading_icon').style.display='none';
	var marginLeft = new Animation({element: 'animation_div', marginLeft: -(image.width/2)-2, top:10, fps: 30, duration: 0.5});
	var size = new Animation({element: 'inner_panel', width: image.width+4, height:image.height+4, fps: 30, duration: 0.5});
	var text = new Animation({element: 'text_panel', width:image.width+4, fps: 30, duration: 0.5});
	var textHeight = new Animation({element: 'text_panel', height:40, opacity: 100, fps: 30, duration: 0.5});
	var closeWindow = new Animation({element: 'close_window', opacity: 50, fps: 30, duration: 0.5});
	
	var imageFade = new Animation({element: image, fps: 30, duration: 0.2, opacity: 100});
	size.nextAnimation = imageFade;
	text.nextAnimation = textHeight;
	textHeight.nextAnimation = closeWindow;
	play(marginLeft);
	play(size);
	play(text);
}

function loadImageErrorWindow(image){
	var div = document.getElementById('inner_panel');
	var errorText = document.createElement('div');
	errorText.style.margin='10px';
	errorText.style.marginTop='65px';
	errorText.id = 'error_text';
	errorText.innerHTML = "Error - the image could not be loaded";
	div.appendChild(errorText);

	var close_window = document.getElementById('close_window');
	clearAnimation(close_window);
	setOpacity(close_window, 0);

	document.getElementById('loading_icon').style.display='none';
	var textHeight = new Animation({element: 'text_panel', height:40, opacity: 100, fps: 30, duration: 0.5});
	var closeWindow = new Animation({element: 'close_window', opacity: 50, fps: 30, duration: 0.5});
	
	textHeight.nextAnimation = closeWindow;
	play(textHeight);
}

function displayImage(source){
	document.getElementById('black_screen').style.display='block';
	document.getElementById('animation_div').style.display='block';
	var image = document.getElementById('preload_image');
	var div = document.getElementById('inner_panel');
	
	if(!image && div){
		
	
		image = new Image();
		image.id = "preload_image";
		image.className = "preloadImage";
        image.onload = (function(){
            loadImageWindow(image);
        });
        image.onerror = (function(){
            loadImageErrorWindow(image);
        });
		div.appendChild(image);
		image.style.display='none';
		image.src = source;
	}
}

function closeImageWindow(){
	document.getElementById('loading_icon').style.display='block';
	document.getElementById('black_screen').style.display='none';
	
	var animation_div = document.getElementById('animation_div');
	clearAnimation(animation_div);
	animation_div.style.marginLeft = '-80px';
	animation_div.style.top = '200px';
	animation_div.style.display='none';
	
	
	var inner_panel = document.getElementById('inner_panel');
	clearAnimation(inner_panel);
	inner_panel.style.width = '160px'; 
	inner_panel.style.height = '160px';
	
	
	var text_panel = document.getElementById('text_panel');
	clearAnimation(text_panel);
	text_panel.style.width = '160px';
	text_panel.style.height = '0px';
	setOpacity(text_panel, 0);
	
	var div = document.getElementById('inner_panel');
	var image = document.getElementById('preload_image');
	var errorText = document.getElementById('error_text');
	if(div && image){
		div.removeChild(image);
	}
	if(div && errorText){
		div.removeChild(errorText);
	}	

}
