var album = {
	
	init: function() {
		//dojo.require("dojox.image.Lightbox");
  		dojo.require("dojo.parser");
	},
	
	addComment: function(idphoto) {
		console.log('add photo comment where id: '+idphoto);
		
		var div = dojo.byId('postComment');
		div.style.display = 'block';
	},
	
	submitComment: function(idphoto) {
		console.log(idphoto);
		
		var title = dojo.byId('title').value;
		var comment = dojo.byId('comment').value;
		
		if(title=='' || comment=='') {
			alert('Error: Must set a title and the comment!');
			return;
		}
		
		var div = dojo.byId('postComment');
		var msg = dojo.byId('msgComment');
		
		dojo.xhrPost({
			url: '/album/postComment',
			load: function(data) {
				if(data==1) {
					div.style.display = 'none';
					msg.innerHTML = 'Comment Submitted successfully!';
					msg.style.color = '#499500';
					msg.style.backgroundColor = '#AEF26D';
					msg.style.borderColor = '#499500';
					msg.style.display = 'block';
				} else {
					div.style.display = 'none';
					msg.innerHTML = 'Error submitting the comment!';
					msg.style.color = '#A62000';
					msg.style.backgroundColor = '#FF8E73';
					msg.style.borderColor = '#A62000';
					msg.style.display = 'block';
				}
				// clear the form
				album.clearForm();
				// hide the message after 2 seconds
				var t=setTimeout("album.hideMessage()",2000);
			},
			error: function(e){console.log('error in submitComment(): '+e.errorMsg());},
			content: {idphoto : idphoto, title : title, comment : comment},
			sync: true
		});
		
		
		
	},
	
	cancelPostComment: function() {
		var div = dojo.byId('postComment');
		div.style.display = 'none';
	},
	
	clearForm: function() {
		dojo.byId('title').value = '';
		dojo.byId('comment').value = '';
	},
	
	hideMessage: function() {
		var msg = dojo.byId('msgComment');
		dojo.fadeOut({
			node : msg,
			onEnd : function() {
				msg.style.display = 'none';
			},
			duration : 2000
		}).play();
	}
}

dojo.addOnLoad(function(){
	album.init();
});