box = {
	
	object: null,
	type: null,
	zIndex: 10000,
	offsetX: 0,
	offsetY: 0,
	screenW: 0,
	screenH: 0,
	cursorX: 0,
	cursorY: 0,
	explorer: window.ActiveXObject ? true : false,
	assignBaseFunctions: function( classes ) {

		for( var a in document.getElementsByTagName('div') ) {

			boxElement = document.getElementsByTagName('div')[a];

			var Search = new RegExp(classes);

			if( Search.test(boxElement.className) ) {

				boxElement.onmousedown = function() { box.onTop(this.id) };
				
				boxElement.onclick = function() { clearTimeout(this['Timeout']) };

				for( b = 0; b < boxElement.childNodes.length; ++b ) if( boxElement.childNodes[b].className == 'Title' ) boxElement.childNodes[b].onmousedown = function() { box.drag(this.parentNode.id) };

			}

		}

	},
	centerPosition: function(o, w, t) {
		
		document.getElementById(o).style.visibility = 'hidden';
		document.getElementById(o).style.display = 'block';
		document.getElementById(o).style.left = (document.body.offsetWidth-document.getElementById(o).offsetWidth)/2+'px';
		document.getElementById(o).style.top = '150px';
		document.getElementById(o).style.display = 'none';
		document.getElementById(o).style.visibility = 'visible';

	},
	onTop: function(o) {

		box.object = document.getElementById(o);
		box.object.style.zIndex = box.zIndex;
		box.zIndex++;

	},
	enableSelection: function() {

		box.explorer ? document.onselectstart = new Function ('return true') : document.onmousedown = new Function ('return true');

	},
	disableSelection: function() {

		box.explorer ? document.onselectstart = new Function ('return false') : document.onmousedown = new Function ('return false');

	},
	drag: function(o) {

		box.object = document.getElementById(o);
		box.disableSelection();
		box.type = 'drag';

		box.offsetX = box.cursorX - box.object.offsetLeft;
		box.offsetY = box.cursorY - box.object.offsetTop;

		box.screenW = document.body.offsetWidth - box.object.offsetWidth;
		box.screenH = document.body.offsetHeight - box.object.offsetHeight;

	},
	capturePosition: function(e) {

		if( box.explorer ) e = window.event;

		box.cursorX = e.clientX;
		box.cursorY = e.clientY;

		if( box.type == 'drag' ) {
			
			box.object.style.right = 'auto';
			box.object.style.bottom = 'auto';

			if( box.cursorX - box.offsetX <= box.screenW ) box.object.style.left = ( box.cursorX - box.offsetX < 0 ? '0' : box.cursorX - box.offsetX ) + 'px';
			if( box.cursorY - box.offsetY <= box.screenH ) box.object.style.top = ( box.cursorY - box.offsetY < 0 ? '0' : box.cursorY - box.offsetY ) + 'px';

		}

	},
	drop: function() {
		box.object = null;
		box.type = null;
		box.enableSelection();

	}
	
}

document.onmousemove = box.capturePosition;
//document.onmouseup = box.drop;

