var ygPos=new function(){
	this.getPos=function(oEl){
		var pos=[oEl.offsetLeft,oEl.offsetTop];
		var parent=oEl.offsetParent;
		var tmp={x:null,y:null};
		if(parent!=oEl){
			while(parent){
			switch(browser){
				case'ie':
					if(_getStyle(parent,'position')=='relative'&&_getStyle(oEl,'width')=='auto'&&(_getStyle(oEl,'position')=='static')){
						return[oEl.offsetLeft,oEl.offsetTop];
					}else if(_getStyle(parent,'width')!='auto'||_getStyle(oEl.parentNode,'position')!='static'){
						tmp.x=parseInt(_getStyle(parent,'borderLeftWidth'));
						tmp.y=parseInt(_getStyle(parent,'borderTopWidth'));
						if(!isNaN(tmp.x))pos[0]+=tmp.x;
						if(!isNaN(tmp.y))pos[1]+=tmp.y;
					}
					break;
				case'gecko':
					if(_getStyle(parent,'position')=='relative'){
						tmp.x=parseInt(_getStyle(parent,'border-left-width'));
						tmp.y=parseInt(_getStyle(parent,'border-top-width'));
						if(!isNaN(tmp.x))pos[0]+=tmp.x;
						if(!isNaN(tmp.y))pos[1]+=tmp.y;
					}
					break;
			}
			pos[0]+=parent.offsetLeft;
			pos[1]+=parent.offsetTop;
			parent=parent.offsetParent;
		}
	}
	if(browser=='ie'&&_getStyle(oEl,'width')!='auto'&&_getStyle(oEl.offsetParent,'width')=='auto'&&_getStyle(oEl.offsetParent,'position')=='relative'){
		parent=oEl.parentNode;
		while(parent.tagName!='HTML'){
			tmp.x=parseInt(_getStyle(parent,'marginLeft'));
			tmp.y=parseInt(_getStyle(parent,'paddingLeft'));
			if(!isNaN(tmp.x))pos[0]-=tmp.x;
			if(!isNaN(tmp.y))pos[0]-=tmp.y;
			parent=parent.parentNode;
		}
	}
	return pos;
};
this.getX=function(oEl){
	return this.getPos(oEl)[0];
};
this.getY=function(oEl){
	return this.getPos(oEl)[1];
};
this.setPos=function(oEl,endPos){
	var offset=[0,0];
	var delta={x:0,y:0};
	var curStylePos=_getStyle(oEl,'position');
	if(curStylePos=='static'){oEl.style.position='relative';curStylePos='relative';}
	if(oEl.offsetWidth){
		if(curStylePos=='relative'){
			offset=this.getPos(oEl);
			var tmp={x:_getStyle(oEl,'left'),y:_getStyle(oEl,'top')};
			delta.x=(tmp.x&&tmp.x.indexOf('px')!=-1)?parseInt(tmp.x):0;
			delta.y=(tmp.y&&tmp.y.indexOf('px')!=-1)?parseInt(tmp.y):0;
		}else{
			offset=this.getPos(oEl.offsetParent);
			var tmp={x:_getStyle(oEl,'margin-left'),y:_getStyle(oEl,'margin-top')};
			delta.x=(tmp.x&&tmp.x.indexOf('px')!=-1)?0-parseInt(tmp.x):0;
			delta.y=(tmp.y&&tmp.y.indexOf('px')!=-1)?0-parseInt(tmp.y):0;
		}
	}
	if(browser=='safari'){
		if(oEl.offsetParent&&oEl.offsetParent.tagName=='BODY'){
			if(_getStyle(oEl,'position')=='relative'){
				delta.x-=document.body.offsetLeft;
				delta.y-=document.body.offsetTop;
			}else if(_getStyle(oEl,'position')=='absolute'||_getStyle(oEl,'position')=='fixed'){
				delta.x+=document.body.offsetLeft;
				delta.y+=document.body.offsetTop;
			}
		}
	}
	if(endPos[0]!==null)oEl.style.left=endPos[0]-offset[0]+delta.x+'px';
	if(endPos[1]!==null)oEl.style.top=endPos[1]-offset[1]+delta.y+'px';
};
this.setX=function(oEl,x){
	this.setPos(oEl,[x,null]);
};
this.setY=function(oEl,y){
	this.setPos(oEl,[null,y]);
};
this.getRegion=function(oEl){
	return new yui.Region.getRegion(oEl);
};
var _getStyle=function(oEl,property){
	var dv=document.defaultView;
	if(oEl.style[property])return oEl.style[property];
	else if(oEl.currentStyle){
		if(property.indexOf('-')!=-1){property=property.split('-');property[1]=property[1].toUpperCase().charAt(0)+property[1].substr(1);property=property.join('');
		}
	if(oEl.currentStyle[property])return oEl.currentStyle[property];}
	else if(dv&&dv.getComputedStyle(oEl,'')&&dv.getComputedStyle(oEl,'').getPropertyValue(property)){
		return dv.getComputedStyle(oEl,'').getPropertyValue(property);
	}
	return null;
};
var _getBrowser=function(){
	var ua=navigator.userAgent.toLowerCase();
	if(ua.indexOf('opera')!=-1)return'opera';
	else if(ua.indexOf('msie')!=-1)return'ie';
	else if(ua.indexOf('safari')!=-1)return'safari';
	else if(ua.indexOf('gecko')!=-1)return'gecko';
	else return false;};
	var browser=_getBrowser();
};
yui=window.yui||{};
yui.Region=function(t,r,b,l){
	this.top=t;
	this.right=r;
	this.bottom=b;
	this.left=l;
};
yui.Region.prototype.contains=function(region){
	return(region.left>=this.left&&region.right<=this.right&&region.top>=this.top&&region.bottom<=this.bottom);
};
yui.Region.prototype.getArea=function(){
	return((this.bottom-this.top)*(this.right-this.left));
};
yui.Region.prototype.intersect=function(region){
	var t=Math.max(this.top,region.top);
	var r=Math.min(this.right,region.right);
	var b=Math.min(this.bottom,region.bottom);
	var l=Math.max(this.left,region.left);
	if(b>=t&&r>=l){
		return new yui.Region(t,r,b,l);
	}else{
		return null;
	}
};
yui.Region.prototype.union=function(region){
	var t=Math.min(this.top,region.top);
	var r=Math.max(this.right,region.right);
	var b=Math.max(this.bottom,region.bottom);
	var l=Math.min(this.left,region.left);
	return new yui.Region(t,r,b,l);
};
yui.Region.prototype.toString=function(){
	return("Region {"+"  t: "+this.top+", r: "+this.right+", b: "+this.bottom+", l: "+this.left+"}");
}
yui.Region.getRegion=function(el){
	var p=ygPos.getPos(el);
	var t=p[1];
	var r=p[0]+el.offsetWidth;
	var b=p[1]+el.offsetHeight;
	var l=p[0];
	return new yui.Region(t,r,b,l);
};
yui.Point=function(x,y){
	this.x=x;
	this.y=y;
	this.top=y;
	this.right=x;
	this.bottom=y;
	this.left=x;
};
yui.Point.prototype=new yui.Region();