
/*******************************************************************/
Class.inherits(adlib,{
	documentElement:((window.innerWidth||(document.documentElement&&(typeof document.documentElement.clientWidth!="undefined")))?document.documentElement:document.body),
	getDocumentWidth:function(){return adlib.documentElement.scrollWidth},
    getDocumentHeight:function(){return adlib.documentElement.scrollHeight}
});
// compliant browsers
Class.inherits(adlib,(window.innerWidth)?{
	    getViewWidth:function(){return window.innerWidth},
	    getViewHeight:function(){return window.innerHeight},
	    getScrollX:function(){return window.pageXOffset},
	    getScrollY:function(){return window.pageYOffset} 
	}:{
	    getViewWidth:function(){return adlib.documentElement.clientWidth},
	    getViewHeight:function(){return adlib.documentElement.clientHeight},
	    getScrollX:function(){return adlib.documentElement.scrollLeft},
	    getScrollY:function(){return adlib.documentElement.scrollTop} 
});

function getCenterX(name){
	var obj=$(name)||adlib.documentElement;
	var o=(obj==window||obj==document||obj==document.body)?adlib.documentElement:obj;
	if ((o==adlib.documentElement)&&(bis.safari)){
		o=document.body;
	}
    return Math.floor(((o==adlib.documentElement||o==document.body)?adlib.getViewWidth():o.getFullWidth())/2)+parseInt(o.scrollLeft);
}
function getCenterY(name){
	var obj=$(name)||adlib.documentElement;
	var o=(obj==window||obj==document||obj==document.body)?adlib.documentElement:obj;
	//alert(o==adlib.documentElement);
	if ((o==adlib.documentElement)&&(bis.safari)){
		o=document.body;
	}
    return Math.floor(((o==adlib.documentElement||o==document.body)?adlib.getViewHeight():o.getFullHeight())/2)+parseInt(o.scrollTop);
}
// gets the center point (x or y) of an element
// if targ is omitted, document is used.
function getCenter(xy, name){
	return (xy=="x")?getCenterX(name):getCenterY(name);
}

// Sets the Left location to move an object (name) to so that it will be centered to the target (targ) elements viewport
// if targ is omitted, document is used.
// Note: this function centers based on the target (targ) being the parent element.  It does not take the targets
// offset from the page into account.  Use centerOverX for that.
function centerX(name,targ){
	var obj=$(name);
	var mid=getCenter('x',targ);
	var wid=Math.floor(getWidth(name)/2);
	var out=mid-wid+"px";
	setStyle(obj,"left",out);			
}


// Sets the Left location to move an object (name) to so that it will be centered to the target (targ) elements viewport
// if targ is omitted, document is used.
// Note: this function centers based on the target (targ) being the parent element.  It does not take the targets
// offset from the page into account.  Use centerOverY for that.
function centerY(name,targ){
	var obj=$(name);
	var mid=((targ)?getCenter('y',targ):getCenter('y'));
	var hei=Math.floor(getHeight(name)/2);
	
	/* keeping the vertical centering from pushing a modal off the top of the page. */
	var out="0px";
	if (mid-hei < 0){
		//do nothing... take base case.
	}
	else{
		out = mid-hei+"px";
	}//end of if else
	
	setStyle(name,"top",out);
}

// Shortcut to centerX and centerY an element.
function centerXY(name,targ){
	centerX(name,targ);
	centerY(name,targ);
}


//horizontally centers an element (name) over another element (targ)
//if "name" is a child of "targ" use centerX instead
function centerOverX(name,targ){
	var obj=$(name);
	var tObj=$(targ)
	var wn=Math.floor(getWidth(name)/2);
	var lt=getLeft(targ);
	var wt=Math.floor(getWidth(targ)/2);
	setStyle(name,'left',(lt+wt-wn)+'px');
}

//Vertically centers an element (name) over another element (targ)
//if "name" is a child of "targ" use centerY instead
function centerOverY(name,targ){
	var obj=$(name);
	var tObj=$(targ)
	var wn=Math.floor(getHeight(name)/2);
	var lt=getTop(targ);
	var wt=Math.floor(getHeight(targ)/2);
	setStyle(name,'top',(lt+wt-wn)+'px');
}


// shortcut to centerOverX and centerOverY
function centerOverXY(name,targ){
	centerOverY(name,targ);
	centerOverX(name,targ);
}