// Strategy page prompt
var promptText = 'Select a strategy and type response here';

// On strategy page: remove the prompt text from response box
function removePrompt() {
    var box = $('textarea');
    if (box.val()==promptText) {
        box.val('');
        // No longer need binding
        box.unbind('focus');
    }
}

// On strategy page: insert the prompt text into the response box
function insertPrompt() {
    var box = $('textarea');
    if (box.val() == '') {
        box.val(promptText);
        box.focus(removePrompt);
    }
}

function removeConfirmation() {
    $('#confirmation').html('');
}

function sentenceStarter() {
    removePrompt();

    var form = document.forms[0];
    if ( form['form.response'].value == '' ) {

        var strategy = form['form.strategy'].value;
        var starter = '';

        switch ( strategy ) {
        case 'summarize':
            starter = "This text was mostly about...";
            break;
        case 'predict':
            starter = "I predict this will be about...";
            break;
        case 'clarify':
            starter = "A confusing part of this text is...";
            break;
        case 'question':
            starter = "Why does...";
            break;
        case 'visualize':
            starter = "I see...";
            break;
        case 'feeling':
            starter = "This text makes me feel...";
            break;
        case 'reflect':
            starter = "So far...";
            break;
        case 'web-eval':
            starter = "My overall rating of this web site is...";
            break;
        case 'media-lit':
            starter = "Media is being used to...";
            break;
        case 'journal':
            starter = "My notes, thoughts, ideas: ";
            break;
        }

        form['form.response'].value = starter;
        removeConfirmation();
    }
}

function choiceChanged(obj) {
    removeConfirmation();
    if (obj.value == 'none') {
        indiraSetMode('form.agent-1', 'g');
        indiraSetMode('form.agent-2', 'g');
        indiraSetMode('form.agent-3', 'g');
        indiraSetMode('starter', 'g');
        indiraSetMode('form.save', 'g');
    } else {
        indiraSetMode('form.agent-1', '');
        indiraSetMode('form.agent-2', '');
        indiraSetMode('form.agent-3', '');
        indiraSetMode('starter', '');
        indiraSetMode('form.save', '');
    }
}

// Runs agent script in a dragBox
function runAgent (n, path) {
	var agent = createAgent (n, path);
	agent.autoplay = true;
	agent.setOnPlayStop (function () { agent.dragBox.hide(); });
	if (agent.dragBox == null) {
		agent.createDragBox();
	}
	agent.dragBox.show();
}

// Runs agent replacing content of element ID
function runAgentInline (n, path, id) {
	var agent = AgentItem[n];
	if (agent == null) {
		agent = createAgent (n, path);
	}
	agent.autoplay = true;
	agent.setSize (250, 250);
	var previousContents = document.getElementById(id).innerHTML;
	agent.setOnPlayStop (function () { document.getElementById(id).innerHTML = previousContents; });
    //    agent.setOnLeftClick (function () { alert ("noticed click"); });
	agent.insertTag (id);
}

function createAgent (n, path) {
	var a = new FlashAgent(n,
						 'http://agents.cast.org/v5/',
						 'http://agents.cast.org/shared/',
						 path);
	a.cssPath = '/cst/indira/css/_bzudn_agentStyle.css';
	return a;
}

/// Below here, not updated for CST 3

// Call to create an agent and have it speak.
//  If last 2 arguments are omitted, will use the standard speech; if they are
// supplied, will get speech from database.
// function agentSpeak (genre, strat, coach, assignmentId, subAssignmentId ) {
// 	if (assignmentId) {
// 		runAgentInline (1, 'CUSTOM-AGENT,'+genre+','+strat+','+coach
// 						+','+assignmentId+','+subAssignmentId, 'agent_location');
// 	} else {
// 		runAgentInline (1, 'STRAT-AGENT,'+genre+','+strat+','+coach, 'agent_location');
// 	}
// }

// function agentFeedback (page, status) {
// 	runAgentInline (2, 'FEEDBACK-AGENT,'+page+','+status, 'feedback_location');
// }

