

var bgWindow;
var mouthWindow;
var bgWidth = 1020;//110;
var bgHeight = 750;//30;
var mouthWidth = 191;//110;
var mouthHeight = 100;

var version = "Pirate";

var hasPopped = false;
function launch(version,wide) {
  //  if(!hasPopped){
//	 hasPopped = true;
	 bgWidth = wide;
	 var winl =  (screen.width - bgWidth) / 2-15;
	 var wint =  (screen.height - bgHeight) / 2;
	 var winprops = 'height='+bgHeight+',width='+bgWidth+',top='+wint+',left='+winl+'resizable=0';
	 bgWindow = window.open( version+"/bg.html", "bg", winprops);
	 
	 winl =  (screen.width - mouthWidth) / 2;
     winprops = 'height='+mouthHeight+',width='+mouthWidth;
	 
     mouthWindow = window.open( version+"/mouth.html", "mouthWindow", winprops);
	
     mouthWindow.resizeTo(mouthWidth, mouthHeight);
	 mouthWindow.moveTo((screen.width ) / 2-mouthWidth/2,(screen.height ) / 2);
  //   mouthWindow.resizeTo(mouthWidth, mouthHeight);
	
	//}
//	 windows[0].moveTo(x*xSpace,y*ySpace);
		//	alert("woot");
			
		//    mouthWindow.moveTo((screen.width ) / 2-mouthWidth/2,(screen.height ) / 2);


	//set focus
	//alert("x: "+ windows.length+", "+"y: "+windows[2].length);

}

function center(){
	

	 mouthWindow.moveTo((screen.width ) / 2-mouthWidth/2,(screen.height ) / 2);
}
function closeWindows(){
	
 		bgWindow.close();
		mouthWindow.close();
		
	

}

var moved = false;
var centerCounter =0;
var maxMouth = screen.height/2-200;
function setWinSize(size){
			if(!moved){
				moved = true;
		   		//alert("d");
			    mouthWindow.moveTo((screen.width ) / 2-mouthWidth/2,(screen.height ) / 2);
			  
			}
			if(size > 5){
					var s = size*5;
					if(s>maxMouth) s = maxMouth; 
					mouthWindow.resizeTo(mouthWidth, mouthHeight+s);
					//mouthWindow.moveTo((screen.width ) / 2-mouthWidth/2,(screen.height ) / 2);
			//	windows[0].moveTo((screen.width - s) / 2,(screen.height - s) / 2);
				}else{
					mouthWindow.resizeTo(mouthWidth, mouthHeight);
					if(centerCounter > 30){
						centerCounter =0;
					mouthWindow.moveTo((screen.width ) / 2-mouthWidth/2,(screen.height ) / 2);
					}else{
					 	centerCounter ++;	
					}
		        //	mouthWindow.moveTo((screen.width ) / 2-mouthWidth/2,(screen.height ) / 2);
				}
			// var decColor = 65536 * (size/100);
		    // windows[0].setColor(decColor);
			// var decColor = red + 256 * green + 65536 * blue;
			//sendToActionScript("go");
}

function RGBToHex(rgb) { 
var char = "0123456789ABCDEF"; 
return String(char.charAt(Math.floor(rgb / 16))) + String(char.charAt(rgb - (Math.floor(rgb / 16) * 16))); 
} 



