// JavaScript Document

var myJavascriptObject;

var App = new Class({
    initialize: function(){
		this._animation = false;
		this.movieId = "flashMovie";
		// conversation variables
		this.currentSentence = 0;
		this.sentences = {0:"Hey Actionscript! How r u?",1:"Nice helmet, dude!"};
		this.answers = {0:"Oh I'm fine, thankx!",1:"No, thankx. I'll stay clean!"};

		// event registration
		$('talk').onclick = function(event){
			var e = new Event(event);
			this.talkToFlash();
			e.stop();
		}.bind(this);
		
		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)
	{
	    callFromFlash();
		//this.talk(this.answers[data]);
    }, // end function talkToJavascript
    
	talkToFlash: function() {
		this.talk(this.sentences[this.currentSentence%2]);
		// Get the movie and call the ActionScript
		this.getFlashMovieById(this.movieId).respond("mein Test");//this.currentSentence%2);
		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();
});


/** init on screen keyboard on load */
window.addEvent("domready", function () {
	$$("#fgraph tr").addEvents({"mouseover":function () {
		if (this.className != "description1" && this.className != "description2" && this.className != "header" && this.className != "border-bottom-grey-light-bold notab" && this.className != "border-bottom-grey-bold year") {
			
			var cells = this.cells;
			var values = new Array(cells.length);
			for (i = 0; i < cells.length; i++) {
				values[i] = removeHTMLTags(cells[i].innerHTML);				
			}
			var valstring = (implode("|", values));
			showRowDiagram(valstring, this);
		}
	}, "mouseout":function () {
		hideRowDiagram();
	}});
});
function removeHTMLTags(strInputCode) {
	var strTagStrippedText = strInputCode.replace(/(<([^>]+)>)/ig, "");
	strTagStrippedText = strTagStrippedText.replace(/&nbsp;+/ig, "");
	return strTagStrippedText;
}
function implode(glue, pieces) {
	return ((pieces instanceof Array) ? pieces.join(glue) : pieces);
}


