$(document).ready(function(){
    $('#my_story_bottom h2').bind('click.record', function(e){
		//$('.hard_question_video_comment_box object').hide();
		var comment = $('<div id="mystory-comment-dialog"/>');
		comment.append('<form>' +
			'<p><strong>Step #1: </strong>Enter your name & email</p>'+
			'<p>Name: <input type="text" name="name" value="" size="45" class="required" /></p>'+
			'<p>Email: <input type="text" name="email" size="45" class="required email" /></p>'+
			'<div id="messagebox"><ul></ul></div>'+
		'</form>').dialog({
			height: 300
			,width: 550
			,modal: true
			,closeOnEscape: true
			,title: $('#my_story #my_story_top .my_story_top_text').html()
			,zIndex: 3999
			,bgiframe: true
			,open: function(e, ui){
				$('#mystory-comment-dialog form').validate({
					rules: {
						name: {required: true, minlength: 6}
						,email: {required: true, email: true}
					}
					,messages: {
						name: {
							required: "Please specify your name"
							,minlength: jQuery.format("At least {0} characters required!")
						}
						,email: {
							required: "We need your email address to contact you"
							,email: "Your email address must be in the format of name@domain.com"
						}
					}
					,errorClass: "invalid"
					,errorContainer: "#messagebox"
					,errorLabelContainer: "#messagebox ul"
					,wrapper: "li"

				});
			}
			,close: function(e, ui){
				if ($('#comment-record-dialog') && (!$('#comment-record-dialog').dialog('isOpen'))){
					//$('.hard_question_video_comment_box object').show();
				}
			}
			,buttons: {
				"Next": function(){
					if ($('#mystory-comment-dialog form').valid()){
						$("#mystory-comment input[name='name']").val($("#mystory-comment-dialog input[name='name']").val())
						$("#mystory-comment input[name='email']").val($("#mystory-comment-dialog input[name='email']").val())
						//alert('name: '+ $("#mystory-comment input[name='name']").val() + '\nemail: '+ $("#mystory-comment input[name='email']").val());
						var record = $('<div id="comment-record-dialog"/>');
						record.load("/ajax/mystory-record/500/400/").dialog({
							height: 470
							,width: 550
							,modal: true
							,closeOnEscape: true
							,title: $('#my_story #my_story_top .my_story_top_text').html()
							,zIndex: 3999
							,bgiframe: true
							,open: function(e, ui){
								$('#mystory-comment-dialog').dialog('destroy');
							}
							,close: function(e, ui){
								//$('.hard_question_video_comment_box object').show();
							}
						});
					}
				}
			}
		});
		return false;
    }).css('cursor','pointer');
});
function recordDone(username,user_video_number,video_id) {
	$("#mystory-comment input[name='comment']").val(user_video_number+'|'+video_id);
	$('#mystory-comment form').attr('action','/ajax/mystory-comment/').ajaxSubmit({
		success:function(data){
			$('#comment-record-dialog').dialog('close').dialog('destroy');
			$('#my_story_bottom h2').html('Thanks for submitting your video!').unbind('click.record').bind('click.record', function(e){return false;});
		}
	});
}