// JavaScript Document

var myJavascriptObject;
var rpm;

var App = new Class({
    initialize: function(){
		this._animation = false;
		this.movieId = "flashMovie";
		// conversation variables
		this.currentSentence = 0;
		rpm=0;
		
		new Fx.Style('bubble','opacity', {duration:0}).start(0);
    }, // end constructor initialize
	
	getFlashMovieById: function(id){
		var isIE = navigator.appName.indexOf("Microsoft") != -1;
        var flashMovie = (isIE) ? window[this.movieId] : document[id];
		return flashMovie;
    }, // end function getFlashMovieById

	respond: function(data){
		this.talk(this.answers[data]);
    }, // end function talkToJavascript
    
	talkToFlash: function() {
		this.getFlashMovieById(this.movieId).respond(rpm);
		this.currentSentence++;
				
    }, // end function talkToFlash
    
	talk: function (theTalk) {
		var margin = 10;
		$('bubble').setStyle("opacity",0);
		$('bubble').innerHTML = theTalk;
		if ( navigator.appName.indexOf("Microsoft") != -1) {
			$('bubble').setStyle("background-color",'#fff');
			new Fx.Styles( $('bubble') , {duration: 1000, transition:Fx.Transitions.Quint.easeInOut, onComplete: function() { $('bubble').setStyle("background-color",'transparent'); } }).start({'opacity':[0,1], 'margin-top':[margin,0]});
		} else {
			new Fx.Styles( $('bubble') , {duration: 1000, transition:Fx.Transitions.Quint.easeInOut }).start({'opacity':[0,1], 'margin-top':[margin,0]});
		} 
	} // end function talk
    
});


window.addEvent('domready', function(){
	myJavascriptObject = new App();
});

function d_ChangeImage(money)
{
	switch (money)
	{
		case 25:
			rpm = 10;
			document["donateimg"].src="donate/25.jpg";
			d_changeText("Electric wiring for a house - lamps, wires and switches.");
			break;
		case 150:
			rpm = 20;
			document["donateimg"].src="donate/150.jpg";
			d_changeText("Specialized deep cycle battery.");
			break;
		case 250:
			rpm = 40;
			document["donateimg"].src="donate/250.jpg";
			d_changeText("Maintenance team training course.");
			break;
		case 400:
			rpm = 80;
			document["donateimg"].src="donate/400.jpg";
			d_changeText("A solar panel.");
			break;
		case 1500:
			rpm = 160;
			document["donateimg"].src="donate/1500.jpg";
			d_changeText("A complete renewable energy system for one family.");
			break;
		default:
			break;

	}
	myJavascriptObject.talkToFlash();
}

function d_changeText(txt){
	var textContent = document.getElementById('donateText');
	textContent.innerHTML=txt;
}

