(function(){var setup = function(){	//start display setup	var _root = Stage.init({element : document.getElementById('main') ,fps : 24});		document.getElementById('container').style.display = 'block';		var loading = document.getElementById('loading');	loading.parentNode.removeChild(loading);		UITool.makeMenu(document.getElementById('menucontainer'), Stage.width , [{		label: 'Home',		action:function(){			location.href='../'		}	},{		label: 'Jump',		action:function(){			if(player.jump){				player.jump();			}		}	}]);		UITool.createModalPanelFromDOMElement({		target : document.getElementById('container'),		element : document.getElementById('help'),		width : 320,		height : 357,		margin : 5,		button : [{label: 'ok', func: function(){start();}}],		remove : true	});		document.getElementById('main').onclick = function(){		if(player.jump){			player.jump();		}	}		//end display setup		var energy;	var numberOfBanana = 5;	var incScore = 10;		var scr_txt = _root.createTextField('energy',_root.getNextHighestDepth(),170,4,148,24);	scr_txt._element.style.fontSize = 11;	scr_txt._element.style.color = 'white';		var player = _root.attachMovie('player','second',_root.getNextHighestDepth(),{_x:0,_y:0});	player.onLoad = function(){		this.stop();	}		var vitality = _root.attachMovie('vitality','vit',_root.getNextHighestDepth(),{_x:60,_y:5});	vitality.setVitality = function(num){		this._xscale = num>0 ? num : 1;		/*		if(this.vitality == num) return;		this.vitality = num>0 ? num : 1;		var scl = this._xscale;		if(scl == this.vitality){			delete this.onEnterFrame;		}else{			var v = scl > this.vitality ? -1 : 1;			var cnt = Math.ceil(Math.abs(this.vitality - scl));			this.onEnterFrame = function(){				scl += v;				this._xscale = scl;				if(--cnt==0){					this._xscale = this.vitality;					delete this.onEnterFrame;				}			}		}		*/	}		var vit_txt = _root.createTextField('vit_txt',_root.getNextHighestDepth(),6,4,60,24);	vit_txt._element.style.fontSize = 11;	vit_txt._element.style.color = 'white';	vit_txt.text = 'VITALITY';		var blinker = _root.createEmptyMovieClip('blk', _root.getNextHighestDepth());	blinker.blink = function(tgt, count){		if(this.target) this.target._visible = true;		this.target = tgt;		var c = count || 10;		this.onEnterFrame = function(){			tgt._visible = c%2;			if(c--==0){				tgt._visible = true;				delete this.onEnterFrame;			}		}	}		for(var i = 0 ;i<numberOfBanana;i++){		var banana = _root.attachMovie('banana','banana'+i,_root.getNextHighestDepth(),{_visible:false, _origin:'center'});	}		var incEnergy = function(num){		energy = Math.max(0,Math.min(100, energy+num));		vitality.setVitality(energy);	}		var xGet = function(){		var x = this._x;		var y = this._y;		var w = this._width;		var h = this._height;				switch(this._currentframe){			case 1:				incEnergy(0);			break;			case 2:				score+= incScore;				scr_txt.text = 'SCORE ' + score;				incEnergy(10);			break;			default:				blinker.blink(player, 16);				incEnergy(-30);			break;		}				this.onEnterFrame = (function(){			var count = 10;			var scl = 100;			var rot = 0;			var alph = 100;			return function(){				scl+=7;				rot += 30;				alph -= 10;				this._xscale = scl;				this._yscale = scl;				this._alpha = alph;				this._rotation = rot;				if(--count == 0){					this._visible = false;					this._x = -32;					delete this.onEnterFrame;				}			}		})();	}		var xShow = function(){		var flg;		do{			flg = false;			this._x = Math.floor(200*Math.random())+60;			this._y = Math.floor(140*Math.random())+40;			for(var i =0;i<numberOfBanana;i++){				var b = _root['banana' + i];				if(b != this){					if(this.hitTest(b)) flg = true;				}			}		}while(flg)				this._alpha = 100;		this._rotation = 0;		this._xscale=50;		this._yscale=50;		this._visible = false;				this.onEnterFrame = function(){			this._visible = true;			this.onEnterFrame = (function(){				var scl = 50;				var inc = 20;				return function(){					this._xscale = scl;					this._yscale = scl;					if(scl>140){						this._xscale = 100;						this._yscale = 100;						delete this.onEnterFrame;					}					scl+= inc;				}			})();		}		this.gotoAndStop('green');	}		var xGrow = function(){		for(var i = 0 ;i<numberOfBanana;i++){			var b = _root['banana'+ i];			if(b._visible){				if(b._alpha==100){					var cf = b._currentframe + 1;					if(cf==5){						b._visible = false;					}else{						b.gotoAndStop(cf);					}				}			}else{				b.xShow();			}		}	}		player.hitCheck = function(){		for(var i =0;i<numberOfBanana;i++){			var b = _root['banana'+i];			if(b._visible){				if(b._alpha == 100){					if(this.hitTest(b)){						b.xGet();					}				}			}		}	}		function makeJumpFunc(direction){		var d = direction;				if(energy==0){			return function(){				blinker.blink(vit_txt,12);			}		}else{			return function(){				incEnergy(-10);				var v = d * 9;				var cnt = 32;				var vy = -11;				var x = this._x;				var y = this._y;								this.jump = '';				this.gotoAndStop(d==1 ?  'jump_left' : 'jump_right');								this.onEnterFrame =  function(){					this.hitCheck();					this._x = x+=v;					vy += 0.5;					y+=vy;					if(y<19){						y=19;						vy =0;					}					this._y = y;					if(--cnt == 0){						this._x = d==1 ? Stage.width-this._width : 0;						this.vy = 0;						this.gotoAndStop(d==1 ? 'right' : 'left');						this.onEnterFrame = function(){							xGrow();							this.jump = makeJumpFunc(-(d));							this.onEnterFrame = this.drop;						}					}				}			}		}	}		player.drop = function(){			this.vy = Math.min(6,this.vy+0.2);			this._y += this.vy;			if(this._y > Stage.height-player._height-10){				delete this.onEnterFrame;				this._y = Stage.height-player._height-10;				if(energy==0){					//gameover					this._y = Stage.height-player._height					this.gotoAndStop(this._currentframe+4);					setTimeout(gameover, 1000);				}			}		}		function reset(){		score = 0;		energy = 100;		scr_txt.text = 'SCORE 0';				player.jump = makeJumpFunc(1);		player.gotoAndStop('left');		player._x = 0;		player._y = 32;		player.v=0;		player.vy = 0;				vitality._xscale = 100;		vitality.setVitality(100);				for(var i = 0 ;i<numberOfBanana;i++){			var banana = _root['banana' + i];			banana.xGet = xGet;			banana.xShow = xShow;			banana.xShow();			banana.gotoAndStop(i%3+1);		}	}		function start(){		player.onEnterFrame= player.drop;		reset();	}		function gameover(){		mrg = 40;		text = '<center><h3>GAME OVER</h3><br />Score ' + score + '</center><br />';		btn_array = [		{label: 'Try again', func: function(){start(); return false}},		{label: 'Other games', func: function(){document.location='http://www.grkt.com/iphone/'; return true}},		{label: 'Tell a friend', func: function(){document.location='mailto:?body=' + document.location; return true}}		]		UITool.createModalPanel(document.getElementById('container'), 320,357,{			margin: mrg,			text: text,			button: btn_array		});		for(var i = 0 ;i<numberOfBanana;i++){			_root['banana'+ i]._visible = false;		}	}}//window.addEventListener('load',setup,false);window.addEventListener(	'load',	function(){		var cnt = 10;		var loading = document.getElementById('loading');		loading.style.opacity = 1;		var id = setInterval(function(){			loading.style.opacity -= 0.1;			if(cnt--==0){				clearInterval(id);				setup();				window.scrollTo(0,1);			}		},50)},	false);})();