GBS.media = { VERSION: 1.0 };

GBS.media.speech = { VERSION: 1.0 };
GBS.media.speech._api = '/Speech.php';



GBS.media.speech.synth = function(text){

    var cb = {
	success: function(d){

	    var r = YAHOO.lang.JSON.parse(d.responseText);
	    GBS.runCommand(r.cmd, r.data);

	},
	failure: function(){

	}
    };
    //var url = 'modules/speech/main.php?txt=' + text;
    var post = 'format=json&txt='+text;
    YAHOO.util.Connect.asyncRequest('POST', GBS.media.speech._api, cb, post);
}

GBS.media.speech.synthesize = function(text){

    var x = GBS.ui.Dialog();
    x.setHeader('Synthesizing dialog...');
    x.dialog.center();

    YAHOO.util.Connect.asyncRequest("GET", GBS.media.speech._api+'?format=json&txt='+ text, {
	    success: function(d){
		
		var r = YAHOO.lang.JSON.parse(d.responseText);
		x.setHeader('Synthesized dialog');
		x.setBody('<embed autoplay="true" src="'+r.url+'" height="50"></embed>');
		x.dialog.center();
	    },
	    failure: function(r){

		x.setHeader('Response');
		x.setBody("Failure");
		x.dialog.center();
	    }
	}
	);
}


GBS.media.speech.say = function(text, callback){


    GBS.media.speech.synthesize(text);


    /*
    GBS.util.Prompt('synthesize the text: ' + text, [
						    
{label:'Yes',onSelect: function(evt){	
	GBS.util.alert('ok');
	GBS.media.spech.synthesize(text);
    }
},
{label:'No',onSelect: function(evt){
	GBS.util.alert('ok');
    }
}
						    ]);
    */

}// end speech.say
    

// some convience mappings
GBS.say = GBS.media.speech.say;
