var VideoComment = {
			
	init: function(config) {
		VideoComment.path = '/sys6_site/modules/video_youtube/';
		jQuery('#video_submit').bind("click", function() {
				return VideoComment.form_error(config);
		});
	},

	form_error: function(config) {
		na = jQuery('#comment_name');
		co = jQuery('#comment');
			
		if(na.val() == '') {
			alert(config.emptyname);
			na.focus();
			return false;
		}
		if(co.val() == '') {
			alert(config.emptycomment);
			co.focus();
			return false;
		}
		
		if(config.maxcomment != "undefined") {
			if(co.val().length > config.maxcomment) {
				alert(config.toolong);
				co.focus();
				return false;
			}
		}
		VideoComment.hide_submit('true');
		VideoComment.post_comment();
		return false;
	},
	
	hide_submit: function(hide)	{
		if(hide == 'true') {
			jQuery('#form_submit').hide();
			jQuery('#form_submitter').show();
		}
		else {
			jQuery('#form_submit').show();
			jQuery('#form_submitter').hide();
		}
		
	},
		
	post_comment: function() {
		na = jQuery('#comment_name').val();
		co = jQuery('#comment').val();
		
		siteid = jQuery('#post_siteid').val();
		pointid = jQuery('#post_pointid').val();
		vid = jQuery('#videoid').val();
		
		if((siteid != 'undefined' && siteid > 0) && (pointid != 'undefined' && pointid > 0)) {
			jQuery.ajax({
				type: 'POST',
				url: VideoComment.path+'video.comment.php?vid=' + vid + '&pointid='+pointid+'&siteid='+siteid+'&name='+encodeURIComponent(na) + '&comment=' + encodeURIComponent(co),
				success: function(response) { VideoComment.post_done(response); }
			});
		}
	},
	
	post_done: function(response){
		jQuery('#comment').val('');
		jQuery('#thankyou').fadeIn('slow').animate({opacity: 1.0}, 3000).fadeOut('slow');
		jQuery('#video_ajax_comments').html(response);
		var targetOffset = jQuery('#video_player').offset().top;
		jQuery('html,body').animate({scrollTop: targetOffset}, 1000);
		VideoComment.hide_submit('false');
	}
	
};
