	jQuery.fn.position= function()
	{
		return this.each
		(
			function()
			{
 				this.position = _mk_Position(this);
			},
			arguments
		);
	};


	
		
	jQuery.fn.bottom = function() 
	{
		var coord = (arguments.length) ? normalizeCoordinates( this, 0, arguments[0]) : {x: null, y:null};
		
		this.each
		(
			function()
			{
				rv = spriteDelta( this, "bottom", coord.x, coord.y);
			},
			arguments
		);
	    return  (!arguments.length) ? rv : this;
	};
	

	
	
	
	jQuery.fn.right = function() 
	{
		var coord = (arguments.length) ? normalizeCoordinates( this, arguments[0],0) : {x: null, y:null};
		
		this.each
		(
			function()
			{
				rv = spriteDelta( this, "right",  coord.x, coord.y);
			},
			arguments
		);		
	    return  (!arguments.length) ? rv : this;
	};
	
	jQuery.fn.top = function() 
	{
		var coord = (arguments.length) ? normalizeCoordinates( this,0, arguments[0]) : {x: null, y:null};
		
		this.each
		(
			function()
			{
				rv = spriteDelta( this, "top",  coord.x, coord.y);
			},
			arguments
		);
		
	    return  (!arguments.length) ? rv : this;
	};
	
	jQuery.fn.left = function( ) 
	{
		var coord = (arguments.length) ? normalizeCoordinates( this, arguments[0],0) : {x: null, y:null};
		
		this.each
		(
			function()
			{
				rv = spriteDelta( this, "left",  coord.x, coord.y);
			},
			arguments
		);
		
	    return  (!arguments.length) ? rv : this;
	};
	

	jQuery.fn.width = function() 
	{ 
		var coord = (arguments.length) ? normalizeCoordinates( this, arguments[0],0) : {x: null, y:null};

		this.each
		(
			function()
			{
				rv = spriteDelta( this, "width", coord.x, coord.y);
			},
			arguments
		);
		
	    return  (!arguments.length) ? rv : this;
	}

	jQuery.fn.height= function() 
	{
		var coord = (arguments.length) ? normalizeCoordinates( this,0, arguments[0]) : {x: null, y:null};

		this.each
		(
			function()
			{
				rv = spriteDelta( this, "height",  coord.x, coord.y);
			},
			arguments
		);
		
	    return  (!arguments.length) ? rv : this;
	};





	jQuery.fn.center = function() 
	{
		if ( typeof(arguments[0]) == "object")
		{
			var y = arguments[0].y;
			var x = arguments[0].x
		}
		else
		{
			var y = arguments[1];
			var x = arguments[0];
		}
		
		var coord = (arguments.length) ? normalizeCoordinates( this, x,y) : {x: null, y:null};
		this.each
		(
			function()
			{
				rv = spriteDelta( this, "center", coord.x, coord.y);
			},
			arguments
		);
	    return  (!arguments.length)  ? rv : this;
	};


	
	jQuery.fn.thatIntersectSet = function( ) 
	{
		var resultSet=[], set2 = jQuery( arguments[0]).each(  function() { ( typeof( this.position) == "undefined") ?  jQuery( this).position() : null; }).get();

		this.each
		(    
			function()
			{

				( typeof( this.position) == "undefined") ?  jQuery( this).position() : null;
		
				for ( var x=0; x< set2.length;x++)
				{
					if ( findIntersection(this, set2[x]))
					{
						resultSet.push( this);
					}
				
				}
			},
			arguments
		);

		return jQuery( resultSet);
	};

	jQuery.fn.thatBoundSet = function( ) 
	{
		var resultSet=[], set2 = jQuery( arguments[0]).each( function() { ( typeof( this.position) == "undefined") ?  jQuery( this).position() : null; } ).get();

		this.each
		(
			function()
			{
				 ( typeof( this.position) == "undefined") ?  jQuery( this).position() : null;
		
				for ( var x=0; x< set2.length;x++)
				{

					if ( isBound( this,  set2[x]))
					{
						resultSet.push( this);
					}
				}
			},
			arguments
		);
		return jQuery( resultSet);
	};
	









// functions
	function _mk_Position(o) 
	{
		var fixBrowserQuirks = true;
    
		if (o==null) 
		{
			return null;
		}
    
		var left = 0, top = 0, width = 0, height = 0, parentNode = null, offsetParent = null;
  
    		offsetParent = o.offsetParent;
		var originalObject = o;
		var el = o; // "el" will be nodes as we walk up, "o" will be saved for offsetParent references

		while (el.parentNode!=null) 
		{

			el = el.parentNode;
			if (el.offsetParent==null) 
			{
			}
			else 
			{
				var considerScroll = true;
				/*
					In Opera, if parentNode of the first object is scrollable, then offsetLeft/offsetTop already 
					take its scroll position into account. If elements further up the chain are scrollable, their 
					scroll offsets still need to be added in. And for some reason, TR nodes have a scrolltop value
					which must be ignored.
				*/

				if (fixBrowserQuirks && window.opera) 
				{
					if (el==originalObject.parentNode || el.nodeName=="TR") 
					{
						considerScroll = false;
					}
				}
				if (considerScroll)
				{
					if (el.scrollTop && el.scrollTop>0)
					{
						top -= el.scrollTop;
					}
					if (el.scrollLeft && el.scrollLeft>0) 
					{
						left -= el.scrollLeft;
					}
				}
			}

			// If this node is also the offsetParent, add on the offsets and reset to the new offsetParent

			if (el == offsetParent) 
			{
				left += o.offsetLeft;
				if (el.clientLeft && el.nodeName!="TABLE") 
				{
					left += el.clientLeft;
				}
        			top += o.offsetTop;
        			if (el.clientTop && el.nodeName!="TABLE") 
				{
					top += el.clientTop;
				}
				o = el;
				if (o.offsetParent==null) 
				{
					if (o.offsetLeft) 
					{
						left += o.offsetLeft;
					}
					if (o.offsetTop) 
					{
						top += o.offsetTop;
					}
				}
				offsetParent = o.offsetParent;
			}
		}
		if (originalObject.offsetWidth) 
		{
			width = originalObject.offsetWidth;
		}
		if (originalObject.offsetHeight) 
		{
			height = originalObject.offsetHeight;
		}
		
		return {
			'left':left,
			'top':top,
			'width':width,
			'height':height,
			'center': 
					{
						x: (left + Math.max(width/2)),
						y: (top + Math.max(height/2))
					},
			'right': (left+width),
			'bottom': (top+height)
		};
	};



	jQuery.fn.simpleBoundry = jQuery.fn.thatBoundSet;
	jQuery.fn.simpleIntersect = jQuery.fn.thatIntersectSet;
	jQuery.fn.boundryBox = jQuery.fn.thatBoundSet;
	jQuery.fn.intersectBox = jQuery.fn.thatIntersectSet;
	
	function findIntersection(o1,o2)
	{
		x1 = intersectX( o1.position.left, o2);
		x2 = intersectX( o1.position.right, o2);

		y1 = intersectY( o1.position.top, o2);
		y2 = intersectY( o1.position.bottom, o2);


		return ((x1 && y1) || (x1 && y2) || (x2 && y1) || (x2 && y2));
	}


	function intersectX( px, o)
	{
		return (( px >= o.position.left) && ( px <= o.position.right));
	}
	function intersectY(  py, o)
	{
		return (( py >= o.position.top) && ( py <= o.position.bottom ));
	}


	function isBound( o1, o2)
	{
		return ((o1.position.left <= o2.position.left) && (o1.position.right >= o2.position.right) && (o1.position.top <= o2.position.top) && (o1.position.bottom >= o2.position.bottom));
	}





	function spriteDelta(obj,  fn, cx, cy)
	{
		if (!obj || !fn) return false;
		
		var rv = 0;

		if (cx != null )
		{
	
			switch(fn)
			{
				case "top":		obj.style.top		= ( cy +  "px"); break;
				case "height":	obj.style.height	= ( cy +  "px"); break;		
				case "bottom":	obj.style.top		= ( cy - ( jQuery( obj).height() ) +  "px"); break;						
				case "left":	obj.style.left		= ( cx +  "px"); break;
				case "width":	obj.style.width		= ( cx +  "px"); break;
				case "right":	obj.style.left		= ( cx - ( jQuery( obj).width()  ) +  "px");	 break;
				case "center":
								obj.style.left = ( cx - ( jQuery( obj).width()/2  )) +  "px";
								obj.style.top =  ( cy - ( jQuery( obj).height()/2 )) +  "px";
								
								
								break;
				default:
			}
		}
		else
		{
			obj.position = _mk_Position( obj);
			switch(fn)
			{
				case "top":		rv = obj.position.top; break;
				case "left":	rv = obj.position.left; break;
				case "height":	rv = obj.position.height; break;
				case "width":	rv = obj.position.width; break;
				case "bottom":	rv = obj.position.bottom; break;
				case "right":	rv = obj.position.right; break;
				case "center":	rv = obj.position.center; break;
				default:
				
			}
		}
		return rv;
	}

	function normalizeCoordinates( obj, cx, cy)
	{
		if ( typeof(cx) == "string" ||  typeof(cy) == "string")
		{
			var rv = {x:0,y:0}
			var fakeDiv = jQuery("<div class='fake'></div>").insertAfter(obj).css({left: cx,top: cy,position: "absolute"});
		
			rv =
			{
				x:  _mk_Position( fakeDiv.get(0)).left,
				y:  _mk_Position( fakeDiv.get(0)).top 
			}
			fakeDiv.remove(); fakeDiv = null;
		}
		else
		{
			rv =
			{
				x:  cx,
				y:  cy 
			}
		}
		return rv;
	}