function initSmallComments(message) {
	var url = '/comments/view/display/update:1/limit:3/article-id:' + $('article-content-container').readAttribute('rel');
	if(message != null) {
		url = '/comments/view/display/message:' + message + '/update:1/limit:3/article-id:' + $('article-content-container').readAttribute('rel');
	}
	new Ajax.Updater('comments-box1', url, {
		'evalScripts': true,
		onLoading: function() {
			showSmallLoading();
		},
		onComplete: function() {
			hideSmallLoading();
			hideLoading();
		}
	});	
}

function initLargeComments(message) {
	var url = '/comments/view/display/update:2/limit:25/article-id:' + $('article-content-container').readAttribute('rel');
	if(message != null) {
		url = '/comments/view/display/message:' + message + '/update:2/limit:25/article-id:' + $('article-content-container').readAttribute('rel');
	}
	new Ajax.Updater('comments-box2', url, {
		'evalScripts': true,
		onLoading: function() {
			showSmallLoading();
		},
		onComplete: function() {
			hideSmallLoading();
			hideLoading();
		}
	});
}

var articleTabVisible = true;
var commentTabVisible = false;

function articleTabClick() {
	if(!articleTabVisible) {
		articleTabVisible = true;
		commentTabVisible = false;
		$('comment-container').hide();
		initSmallComments();
		$('article-container').show();
		$('article-tab-button').removeClassName('tab');
		$('comment-tab-button').removeClassName('tab_selected');
		$('comment-tab-button').addClassName('tab');
		$('article-tab-button').addClassName('tab_selected');
	}
}

function commentTabClick() {
	if(!commentTabVisible) {
		commentTabVisible = true;
		articleTabVisible = false;
		$('article-container').hide();
		initLargeComments();
		$('comment-container').show();
		$('comment-tab-button').removeClassName('tab');
		$('article-tab-button').removeClassName('tab_selected');
		$('article-tab-button').addClassName('tab');
		$('comment-tab-button').addClassName('tab_selected');
	}
}

function addComment(type) {
	if(type == "small") {
		if($('PhotoCommentContent1').value == '')
			initSmallComments('Please enter a comment.');
		else {
			$('PhotoCommentCreateForm1').request({
				onLoading: function() {
					showSmallLoading();
				},
				onComplete: function(transport) {
					initSmallComments(transport.responseText);
				}
			});
		}
	} else {
		if($('PhotoCommentContent2').value == '')
			initLargeComments('Please enter a comment.');
		else {
			$('PhotoCommentCreateForm2').request({
				onLoading: function() {
					showSmallLoading();
				},
				onComplete: function(transport) {
					initLargeComments(transport.responseText);
				}
			});
		}
	}
}

windowLoad = function() {
	init();
	
	if(window.location.hash == '#comments')
		commentTabClick();
	
	//	articleTabClick();
}

Event.observe(window, 'load', windowLoad);

