var buttonFrames=new Array();
var pre, post, cell, old, buttonCell, flyout, newMain, newSub, editEnabled, closeInterval, popupWin;


function setupFlyout(){

   for (i=1;i<=numFrames;i++){     // Pre-load button Animation Frames
     buttonFrames[i]=new Image;
     buttonFrames[i].src='templates/site'+tmpltID+'/images/button_f0' + i + '.gif';
   }

   if (document.layers){      //Netscape 4 specific code
      pre = 'document.';
      post = '';
   }
   
   if (document.getElementById){      //Netscape 6 specific code
      pre = 'document.getElementById("';
      post = '").style';
   }
   
   if (document.all){      //IE4+ specific code
      pre = 'document.all.';
      post = '.style';
   }


   if (!document.layers & mainIndex!=0) {
	  buttonCell=eval(pre + 'butCell' + mainIndex + post);
	  buttonCell.backgroundImage='url(templates/site'+tmpltID+'/images/button_f01.gif)';
	  buttonCell.backgroundColor=buttonBackClicked;//calcColor(color2dark,0.30);
	  buttonCell.color=buttonTextClicked;//color1dark;
   }
}



function overAction(cell){
   if(document.all && !window.opera && document.readyState!='complete') return;
   if (mainIndex!=cell && !document.layers) {
	 buttonCell=eval(pre + 'butCell' + cell + post);
     buttonCell.backgroundImage='url(templates/site'+tmpltID+'/images/button_f0' + numFrames + '.gif)';
     buttonCell.backgroundColor=buttonClrOver;
     buttonCell.color=buttonTxtOver;
   }
   if (document.layers) {
     if (!old) old=1;
	 flyout=eval(pre + "sub" + old + post);
	 flyout.visibility='hidden';
	 clearTimeout(closeInterval);
   }
   if (eval(pre + 'sub' + cell + post) && subCount[cell]>0){
	 flyout=eval(pre + 'sub' + cell + post);
     flyout.left=calcX(cell-1);
     flyout.top=calcY(cell-1);
     flyout.visibility='visible';
   }
}


function outAction(cell){
	if (document.all && !window.opera && document.readyState!='complete') return;
	flyout=eval(pre + "sub" + cell + post);
	flyout.visibility='hidden';
	if (mainIndex!=cell && !document.layers){
	    buttonCell=eval(pre + 'butCell' + cell + post);
		buttonCell.backgroundImage='url(templates/site'+tmpltID+'/images/button_f0' + midFrame + '.gif)';
		buttonCell.backgroundColor=buttonClrOff;
		buttonCell.color=buttonTxtOff;
	}		
}

function buttonClickAction(main, subdex){
  if (document.all && !window.opera && document.readyState!='complete') return;
  if( mainIndex!=cell){
	if (editEnabled) {
		newMain=main;
		newSub=subdex;
		uploadData();		
	} else {
		document.location.href='index.cfm?mainIdx='+main+'&subIdx='+subdex+'&WID='+WID;
	}
  }
}


function calcColor(hexColor,trans){
//	parse for RGB values of selected color, then calculate new RGB values for transparency where 'trans' is percent transparency
	var zero='0';
	
	var R=parseInt('0x' + hexColor.substr(1,2));
	var G=parseInt('0x' + hexColor.substr(3,2));
	var B=parseInt('0x' + hexColor.substr(5,2));

	var R1=zero.substring(0,Math.abs(Math.floor((R+(255-R)*trans))<16))+Math.floor((R+(255-R)*trans)).toString(16);
	var G1=zero.substring(0,Math.abs(Math.floor((G+(255-G)*trans))<16))+Math.floor((G+(255-G)*trans)).toString(16);
	var B1=zero.substring(0,Math.abs(Math.floor((B+(255-B)*trans))<16))+Math.floor((B+(255-B)*trans)).toString(16);
	var newColor=("#"+R1+G1+B1);
	return newColor
}

function popWin0(imgObjSrc){
popupWin=window.open(imgObjSrc,'popWin','left=0,top=0');
tempImg=new Image();
tempImg.src=imgObjSrc;
popupWin.resizeTo(tmpImg.width,tmpImg.height);
popupWin.moveTo(screen.availWidth/2-tmpImg.width/2,screen.availHeight/2-tmpImg.height/2);
popupWin.focus();
}

function popWin(imgObjSrc){
	tempImg=new Image();
	tempImg.src=imgObjSrc;
	popSrc=imgObjSrc;
	setTimeout('popWin2()',500);
}

function popWin2(){	
	imgWidth=tempImg.width;
	imgHeight=tempImg.height;
	popupWin=window.open('','','width='+imgWidth+',height='+imgHeight+',left='+(screen.availWidth/2-imgWidth/2)+',top='+(screen.availHeight/2-imgHeight/2));
	popupWin.document.write('<html><head><title>Full Size View</title><head>');
	popupWin.document.write('<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"><img src="'+popSrc+'"></body></html>');
	popupWin.document.close();
	popupWin.resizeTo(tempImg.width,tempImg.height+20);
	popupWin.moveTo(screen.availWidth/2-tempImg.width/2,screen.availHeight/2-tempImg.height/2);
	popupWin.focus();
}