
function updateSceneTitle() {
    if ($('#title').val() !== '') {
    	$('#scene_title').html($('#title').val() + ' ');
    	$('#hidden_scene_name').val($('#title').val());
    	$('#change_title_popup').jqmHide();
    }
    else {
        alert("Enter a name for the scene.");
    }
}

function showTitleChange(evt) {
    $('#updated_title').val($('#scene_title').html());
    $('#title_change_input').show();
}

function showDescriptionEditor() {
	$("#desc_ctl_txt").html("hide text editor");
    $("#desc_help_txt").html("enter any information about the scene or some background for it. the description will be saved when you save the scene");
    $("#scene_description_control").unbind();
    $("#scene_description_control").bind('click', function() { hideDescriptionEditor(); });
    $('#scene_description').show('slow');
    $("#desc_ctl_img").attr("src", "/images/shrink.gif");
    $("#desc_ctl_img").attr("alt", "Image button to click to hide text editor.");
    $("#scene_description_control").attr("title", "click to hide text editor");
    $("#scene_description_control").tooltip({ showURL: false, delay: 0 });
}

function hideDescriptionEditor() {
    $("#desc_ctl_txt").html("show text editor");
    $("#desc_help_txt").html("describe the scene");
    $("#scene_description_control").unbind(); 
    $("#scene_description_control").bind('click', function() { showDescriptionEditor(); }); 
    $('#scene_description').hide('slow');
    $("#desc_ctl_img").attr("src", "/images/grow.gif");
    $("#desc_ctl_img").attr("alt", "Image button to click to show text editor.");
    $("#scene_description_control").attr("title", "click to show text editor");
    $("#scene_description_control").tooltip({ showURL: false, delay: 0 });
}

$(document).ready(function() {
	$("#scenes_tab").addClass("here"); 
    $('#basic_tags').jqm({modal: true, trigger: '#basic_tags_control'});
    $('#basic_tags').jqmAddClose('#basic_tags_close_dialog'); 
    $('#deep_tags').jqm({modal: true, trigger: '#deep_tags_control'});
    $('#deep_tags').jqmAddClose('#deep_tags_close_dialog');  
    $('#comments').jqm({modal: true, trigger: '#comments_control'});
    $('#comments').jqmAddClose('#comments_close_dialog'); 
    $(".rte-zone").rte("/css/rte.css", "/images/");
    $('#update_title').bind('click', updateSceneTitle);
    $('#cancel_update_title').bind('click', function() {$('#title_change_input').hide()});
    $('#change_title_trigger').bind('click', showTitleChange);
    $('#pic_upload').jqm({modal: true, trigger: '#pic_upload_control'});
    $('#pic_upload').jqmAddClose('#pic_upload_close_dialog'); 
    $('#change_image_trigger').bind('click', function() {$('#image_change_input').toggle()});
    
    $('#change_title_popup').jqm({modal: true, onTop:true});
    $('#change_title_popup').jqmAddClose('#change_title_popup_close_dialog');
    $('#change_title_popup').jqmHide();
    $("#update_title_button").click(function() {updateSceneTitle()});
    $('#title_countdown').html("512");   
    $('#title').keydown(function(e) {
        if (e.keyCode == 13) {
            $("#update_title_button").click();
            return false;
        }
        limitText(document.forms.title_update.title, $('#title_countdown'), 512);
    }); 
    $('#title').keyup(function() {
        limitText(document.forms.title_update.title, $('#title_countdown'), 512);
    });
    $('#scene_description_control').bind('click', function() {
 		showDescriptionEditor();   	
    });
});