// JavaScript Document

var myJavascriptObject;

var App = new Class({
    initialize: function(){
		this._animation = false;
		this.movieId = "flashcatalogo";
		// 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){
		this.talk(data);
		
    }, // end function talkToJavascript
    
    remove360: function(data){
		this.rem();
		
    }, // end function talkToJavascript

	talkToFlash: function() {
		this.talk(this.sentences[this.currentSentence%2]);
		// Get the movie and call the ActionScript
		this.getFlashMovieById(this.movieId).respond(this.currentSentence%2);
		this.currentSentence++;
				
    }, // end function talkToFlash
    
    rem: function () {
    	$('bubble').setStyle("opacity",0);
		$('bubble').innerHTML = "";
    }, 
    
	talk: function (theTalk) {
		$('bubble').setStyle("opacity",0);
		$('bubble').innerHTML = "<iframe id=\"fsi\" src=\"" + theTalk + "\" frameborder=\"0\" scrolling=\"no\"></iframe>";
		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]});
		} else {
			new Fx.Styles( $('bubble') , {duration: 1000, transition:Fx.Transitions.Quint.easeInOut }).start({'opacity':[0,1]});
		} 
	} // end function talk
    
});


window.addEvent('domready', function(){
	myJavascriptObject = new App();
});
