//\/////
//\  overLIB positionMod Plugin
//\  This file requires overLIB 4.14 or later.
//\
//\  overLIB 4.10  - You may not remove or change this notice.
//\  Copyright Erik Bosrup 1998-2003. All rights reserved.
//\  Last modified 2004-01-03. Contributors are listed on the homepage.
//\  See http://www.bosrup.com/web/overlib/ for details.
//\/////
////////
// PRE-INIT
// Ignore these lines, configuration is below.
////////
if (typeof olInfo == 'undefined' || typeof olInfo.meets == 'undefined' || !olInfo.meets(4.14)) alert('overLIB 4.14 or later is required for the positionMod Plugin.');
else {
registerCommands('nojustx,nojusty');
////////
// DEFAULT CONFIGURATION
// Settings you want everywhere are set here. All of this can also be
// changed on your html page or through an overLIB call.
////////
if (typeof ol_nojustx=='undefined') var ol_nojustx=0;
if (typeof ol_nojusty=='undefined') var ol_nojusty=0;
////////
// END OF CONFIGURATION
// Don't change anything below this line, all configuration is above.
////////
////////
// INIT
////////
// Runtime variables init. Don't change for config!
var o3_nojustx=0;
var o3_nojusty=0;
// PLUGIN FUNCTIONS
////////
// Set runtime variables
function setPositionModVariables() {
	o3_nojustx = ol_nojustx;
	o3_nojusty = ol_nojusty;
}
// Parses positionMod Parameters
function parsePositionModExtras(pf,i,ar) {
	var k=i,v;
	if (k < ar.length) {
		if (ar[k]==NOJUSTX) { eval(pf +'nojustx=('+pf+'nojustx==0) ? 1 : 0'); return k; }
		if (ar[k]==NOJUSTY) { eval(pf +'nojusty=('+pf+'nojusty==0) ? 1 : 0'); return k; }
	}
	return -1;
}
// Was originally in the placeLayer() routine; separated out for future ease
function hModPlacement(browserWidth, horizontalScrollAmount, widthFix) {
	if ( hasCmdReference('centerpopup') || hasCmdReference('anchor')) return void(0);
	var placeX, iwidth, nojustx, winoffset, widthFix = (!olIe4) ? 20 : widthFix;
	iwidth = (o3_frame.innerWidth) ?  o3_frame.innerWidth : eval('o3_frame.'+docRoot+'.clientWidth');
	winoffset = (olIe4) ? eval('o3_frame.'+docRoot+'.scrollLeft') : o3_frame.pageXOffset;
	// HORIZONTAL PLACEMENT
	var parsedWidth = hasCmdReference('shadow') ? parseInt(o3_width) : ((olIe4) ? o3_frame.document.all['overDiv'].scrollWidth : (olNs4 ? over.clip.width : over.offsetWidth));
	if (o3_fixx > -1||o3_relx!=null) {
		// Fixed position
		placeX=(o3_relx!=null ? ( o3_relx < 0 ? winoffset +o3_relx+ iwidth - parsedWidth - widthFix : winoffset+o3_relx) : o3_fixx);
	} else {  
    if(o3_hauto == 1){
    	o3_offsetx=Math.abs(o3_offsetx)
    	if((o3_x-winoffset)>(iwidth / 2))o3_hpos=LEFT; else o3_hpos=RIGHT;
		}
    nojustx = (o3_nojustx || o3_offsetx!=ol_offsetx) ?  1 : 0;
    if(o3_hpos == CENTER)placeX=o3_x-parsedWidth/2+(nojustx?o3_offsetx:0);
    if(o3_hpos == RIGHT)placeX=o3_x+o3_offsetx;
    if(o3_hpos == RIGHT || o3_hpos == CENTER ){
      if(o3_snapx > 1)placeX=placeX +(o3_snapx-placeX % o3_snapx);
      if(!nojustx&&((placeX+parsedWidth)>(winoffset+iwidth-widthFix))){
        placeX=iwidth+winoffset-parsedWidth-widthFix ;
      }
    }
    if(o3_hpos == LEFT){
      placeX=o3_x-o3_offsetx-parsedWidth;
      if(o3_snapx > 1)placeX=placeX-(o3_x % o3_snapx);
    }
    if(!nojustx&&(placeX<winoffset))placeX=winoffset;
  }	
  return placeX;
}
// was originally in the placeLayer() routine; separated out for future ease
function vModPlacement(browserHeight,verticalScrollAmount) {
	if ( hasCmdReference('centerpopup') || hasCmdReference('anchor')) return void(0);
	var placeY, iheight, nojusty, scrolloffset, parsedHeight;
	iheight = (o3_frame.innerHeight) ? o3_frame.innerHeight : eval('o3_frame.'+docRoot+'.clientHeight');
	scrolloffset = (olIe4) ? eval('o3_frame.'+docRoot+'.scrollTop') : o3_frame.pageYOffset;
	// VERTICAL PLACEMENT
	parsedHeight = o3_aboveheight ? parseInt(o3_aboveheight) : ((olIe4) ? o3_frame.document.all['overDiv'].scrollHeight : (olNs4 ? over.clip.height : over.offsetHeight));
	if (o3_fixy > -1||o3_rely!=null) {
		// Fixed position
		placeY=(o3_rely!=null ? (o3_rely < 0 ? scrolloffset+o3_rely+iheight - parsedHeight : scrolloffset+o3_rely) : o3_fixy);
	} else {
    if(o3_vauto == 1){
    	o3_offsety=Math.abs(o3_offsety);
      if((o3_y-scrolloffset)> iheight/2)o3_vpos=ABOVE; else o3_vpos=BELOW;
    }
    nojusty = (o3_nojusty || o3_offsety!=ol_offsety) ?  1 : 0;
    if(parsedHeight > 0 && o3_vpos == ABOVE){
      placeY=o3_y -(parsedHeight+o3_offsety);
      if(o3_snapy > 1)placeY=placeY-(o3_y % o3_snapy);
    } else {
      placeY=o3_y+o3_offsety;
      if(o3_snapy > 1)placeY=placeY +(o3_snapy-placeY % o3_snapy);
      if(!nojusty&&((placeY+parsedHeight)>(scrolloffset+iheight)))placeY=scrolloffset+iheight-parsedHeight;
    }
    if(!nojusty&&(placeY<scrolloffset))placeY=scrolloffset;
  }
  return placeY;
}
function hasCmdReference(command) {
	var pf = (typeof over.pop != 'undefined') ? 'over.pop.' : 'o3_';
	return ( eval('typeof '+ pf+command + '!= "undefined"') && eval(pf+command)) ? true : false;
}
////////
// PLUGIN REGISTRATIONS
////////
registerRunTimeFunction(setPositionModVariables);
registerCmdLineFunction(parsePositionModExtras);
if (olInfo.simpleversion >= 410) {
	registerHook("horizontalPlacement", hModPlacement, FCHAIN);
	registerHook("verticalPlacement", vModPlacement, FCHAIN);
}
}

