/******************************************
CM_ADD-IN - pagecheck (last updated: 08/02/02)

Simple code that *tries* to keep the menus inside the
bounderies of the page.

Code updated. It's still not perfect (obviosly)
but it will now do another check to try and place 
the menus inside.


Just add this code to the coolmenus js file
or link the cm_addins.js file to your page.
*****************************************/
makeCM.prototype.onshow+=";this.pagecheck(b,pm,pm.subx,pm.suby,maxw,maxh)"
makeCM.prototype.pagecheck=function(b,pm,x,y,w,h,n){  
  var l=pm.lev+1,a=b.align; if(!n) n=1
  var ok=1
  if(x<cmpage.x) {pm.align=1; ok=0;}
  else if(x+w>cmpage.x2){ pm.align=2; ok=0;}
  else if(y<cmpage.y) { pm.align=3; ok=0;}
  else if(h+y>cmpage.y2) {pm.align=4; ok=0;}
  if(!ok) this.getcoords(pm,this.l[l-1].borderX,this.l[l-1].borderY,pm.b.x,pm.b.y,w,h,this.l[l-1].offsetX,this.l[l-1].offsetY)
  x=pm.subx; y=pm.suby
	//Added check --- still not ok? --- part of the code by Denny Caldwell (thanks) -- badly immplemented by me though
  if(x<cmpage.x) {x += cmpage.x-x;}
  else if(x+w>cmpage.x2){ x = -(x+w-cmpage.x2);}
  else if(y<cmpage.y) { y = cmpage.y-y; }
  else if(h+y>cmpage.y2) {y = -(y+h-cmpage.y2);}
  if(x<cmpage.x) {x += cmpage.x-x;}
  else if(x+w>cmpage.x2){ x = -(x+w-cmpage.x2);}
  else if(y<cmpage.y) { y = cmpage.y-y;}
  else if(h+y>cmpage.y2) {y = -(y+h-cmpage.y2);}
	b.moveIt(x,y)  
}
