<!--
var self = null;
function ColorDrop ()
{
	this.colorObj = null;
	this.HITPOS = 270;
	this.lastColor=0;this.pickColor=0;
	this.wScr = 0; this.cScr = 0;this.speed=80;this.tmID=null;
	this.hitTile = null;this.sBtn = null;this.missHits=10;
	
	this.tileClass  = ['whitebowl','greenbowl','redbowl','yellowbowl','bluebowl'];
	this.dropClass  = ['','grndrop','reddrop','ylwdrop','bludrop'];
	this.callBackFunc = null;
	self = this;
	
	this.setFinishCallBack = function(cbFunc) {this.callBackFunc = cbFunc;}
	
	this.clearBoard = function()
	{
	    this.initDrop(false);
	    if (this.hitTile == null) {this.hitTile  = document.getElementById('hitid');}	 
	    if (this.hitTile != null) {this.hitTile.className = this.tileClass[0];}
	    
	    if (this.tmID != null) {clearInterval(this.tmID);}
	    
	    this.wScr = 0; this.cScr = 0;this.speed=80;this.tmID=null;
	    
		var o = document.getElementById("grnscr"); if (o != null) {o.innerHTML = this.cScr;}
		o = document.getElementById("redscr"); if (o != null) {o.innerHTML = this.wScr;}
		
		if (this.colorObj == null) {this.colorObj = document.getElementById('dropobj');}
	}
	
	
	this.startGame = function(mh)
	{
		this.missHits = mh;
	    this.clearBoard();
	    
		var str = '<div class="greenpad" onClick="self.changeColor(1);"></div><div class="redpad" onClick="self.changeColor(2);"></div><div class="yellowpad" onClick="self.changeColor(3);"></div><div class="bluepad" onClick="self.changeColor(4);"></div>';
		var o = document.getElementById('touchpad'); if (o != null) {o.innerHTML = str;}
				
		o = document.getElementById("scene");
		if (o != null)
		{
			this.sBtn = document.createElement("div");
			if (this.sBtn != null)
			{
				this.sBtn.className = "strtbtn";
				this.sBtn.style.visibility = "visible";
				this.sBtn.innerHTML = "Start";
				this.sBtn.onclick = function() {self.initDrop(true);}
				o.appendChild(this.sBtn);
			}
		}
	}

	this.initDrop = function(flg)
	{
	    if (this.sBtn != null) {this.sBtn.style.visibility = "hidden";}
		var o = document.getElementById("scene");
		if (o != null && this.sBtn != null)
		{
	        o.removeChild(this.sBtn);
		}
		this.sBtn = null;
		if (flg) {this.setPick();}
	}
	
	
	this.changeColor = function(clr)
	{
		if (this.hitTile != null) {this.hitTile.className = this.tileClass[clr];}
		this.lastColor = clr;
	}

	this.setPick = function()
	{
		var newClr = this.getRandom(1,4); while (this.pickColor == newClr) {newClr = this.getRandom(1,4);}
		this.pickColor = newClr;
		if (this.colorObj != null)
		{
			this.colorObj.style.top = '0px';
			this.colorObj.className = this.dropClass[newClr];
			this.tmID = setInterval('self.moveDown()', this.speed);
		}
	}

	this.getRandom = function (min,max)
	{
    	return min + Math.floor(Math.random()*(max-min+1))
	}


	this.moveDown = function () 
	{
		if (this.colorObj == null) {return;}
		var pos = parseInt(this.colorObj.style.top);
		if (pos >= this.HITPOS) { return; }
		this.colorObj.style.top = pos+10+'px';
		pos = parseInt(this.colorObj.style.top);
		if (pos >= this.HITPOS)
		{
			clearInterval(this.tmID);
			this.checkColor();
		}
	}


	this.checkColor = function()
	{
		if (this.lastColor == this.pickColor) {this.cScr++} else {this.wScr++}
		var o = document.getElementById("grnscr"); if (o != null) {o.innerHTML = this.cScr;}
		o = document.getElementById("redscr"); if (o != null) {o.innerHTML = this.wScr;}
		if (this.cScr > 50) {this.speed=10;}
		else if (this.cScr > 40) {speed=15;}
		else if (this.cScr > 30) {this.speed=20;}
		else if (this.cScr > 20) {this.speed=30;}
		else if (this.cScr > 15) {this.speed=40;}
		else if (this.cScr > 10) {this.speed=50;}
		else if (this.cScr > 5)  {this.speed=60;}

		if (this.wScr >= this.missHits) {this.finishgame(Math.floor(this.cScr*100/(this.cScr+this.wScr)));} else {this.setPick();}
	}
	
	this.finishgame = function(scr)
	{
		var str = '<div style="height:36px;float:right;"><div style="float:left;padding-top:10px;font-family:verdana, arial,helvetica;font-size:20px;color:#ffffff;">Game Over</div><div id="lbtn"></div><div id="mbtn" onClick="self.submitfrm(' + scr + ');">OK</div><div id="rbtn"></div></div>';
		var f = document.getElementById("touchpad"); if (f != null) {f.innerHTML = str;}        
	}
	
	
	this.submitfrm = function(score)
	{
		var f = document.getElementById("colordropbrd");
		if (f != null) 
		{
			f.innerHTML = "";
			var str = "Congratulations!!<br>Your score is " + score + "%";
			var o = f.appendChild(document.createElement('div'));
			o.innerHTML='<input type="hidden" name="helppage" value="colordrophelp.html" />';
			var o = f.appendChild(document.createElement('div'));
			o.innerHTML='<input type="hidden" name="gamepage" value="colordrop.html" />';
			o = f.appendChild(document.createElement('div'));
			o.innerHTML='<input type="hidden" name="msg" value="' + str + '" />';
		}

		document.colordrop_frm.submit();
	}
	

}

//-->
