


function libObj(){}
libObj.prototype.init = function( objId ){
	this.evnt=document.getElementById(objId);
	this.css=this.evnt.style;
	this.x=parseInt(this.css.left)||this.css.pixelLeft||this.evnt.offsetLeft||0;
	this.y=parseInt(this.css.top)||this.css.pixelTop||this.evnt.offsetTop||0;
	this.w=this.evnt.offsetWidth||this.css.clip.width||this.css.pixelWidth||0; 
	this.h=this.evnt.offsetHeight||this.css.clip.height||this.css.pixelHeight||0;
	this.obj = objId + "Object";
	eval(this.obj + "=this");
	return this
}

libObj.prototype.moveIt 		= function(x,y){ 	if(x!=null){this.x=x;this.css.left=x;} if(y!=null){this.y=y;this.css.top=y;}}
libObj.prototype.moveBy 		= function(x,y){ 	this.css.left=this.x+=x; this.css.top=this.y+=y; }
libObj.prototype.showIt 		= function(){		this.css.visibility="visible"}
libObj.prototype.hideIt 		= function(){		this.css.visibility="hidden"}
libObj.prototype.displayIt	= function(){		this.css.display="block"}
libObj.prototype.noneIt 		= function(){		this.css.display="none"}
libObj.prototype.sizeIt 		= function(w,h){ 	if(w!=null){this.css.pixelWidth=this.css.width=w;} if(h!=null){this.css.pixelHeight=this.css.height=h;}}

/*
 *
 *
 *	Slide animation
 * * * * * * * * * * * * * * * * * * * * * * */
libObj.prototype.slideIt = function(endx,endy,inc,speed,fn,wh){
  if(!this.slideactive){
    var distx = endx - this.x;
    var disty = endy - this.y
    var num = Math.sqrt(Math.pow(distx,2)+Math.pow(disty,2))/inc
    var dx = distx/num; var dy = disty/num
    this.slideactive = 1;
    if(!wh) wh=0; if(!fn) fn=0
    this.slide(dx,dy,endx,endy,speed,fn,wh)
    }
}
libObj.prototype.slide = function(dx,dy,endx,endy,speed,fn,wh) {
  if(this.slideactive&&
  (Math.floor(Math.abs(dx))<Math.floor(Math.abs(endx-this.x))|| 
    Math.floor(Math.abs(dy))<Math.floor(Math.abs(endy-this.y)))){
    this.moveBy(dx,dy); 
    if(wh) eval(wh)
    setTimeout(this.obj+".slide("+dx+","+dy+","+endx+","+endy+","+speed+",'"
    +fn+"','"+wh+"')",speed)
  }else{
    this.slideactive = 0; 
    this.moveIt(endx,endy);
    if(fn) eval(fn)
	if(this.fnProp) {
		this.slipSlideIt("mouseup");
		this.fnProp=false;
	}
  }
}




/*
 *
 *
 *	slipSlide animation
 * * * * * * * * * * * * * * * * * * * * * * */
libObj.prototype.slipSlideIt = function(eType){
	if(!this.slideactive){
		var endx = this.x;
		var endy = (eType=="mouseout")?6:(eType=="mouseup")?0:3;
		var inc = 2;
		var speed = 5;
		var distx = 0;
		var disty = endy - this.y;
		var num = Math.sqrt(Math.pow(distx,2)+Math.pow(disty,2))/inc
		var dx = distx/num; var dy = disty/num
		this.slipSlideactive = 1;
		this.slipSlide(dx,dy,endx,endy,speed,eType)
	}else{
		// slideUpWhenReady
		if(this.evnt.selected)this.fnProp = true;
	}
}
libObj.prototype.slipSlide = function(dx,dy,endx,endy,speed,eType) {
	if(!this.slideactive && this.slipSlideactive){
		var endy = (eType=="mouseout")?6:(eType=="mouseup")?0:3;
		if(	this.slipSlideactive&&
			(Math.floor(Math.abs(dx))<Math.floor(Math.abs(endx-this.x))|| 
			Math.floor(Math.abs(dy))<Math.floor(Math.abs(endy-this.y)))) {
			this.moveBy(dx,dy); 
			setTimeout(this.obj+".slipSlide("+dx+","+dy+","+endx+","+endy+","+speed+",'"+eType+"')",speed)
		}else{
			this.slipSlideactive = 0;
			this.moveIt(this.x,endy);
		}
	}
}




/*
 *
 *
 *	drang and drop
 * * * * * * * * * * * * * * * * * * * * * * */
var dd_is_active=0;
var dd_obj=0;
var dd_mobj=0;

function lib_dd(){
  dd_is_active=1
  document.onmousemove=lib_dd_move
  document.onmousedown=lib_dd_down
  document.onmouseup=lib_dd_up
}


libObj.prototype.hasTheTarget = function(e){
	if ( !e ) e = window.event;
	if ( e.target ) var trg = e.target;
	else if ( e.srcElement ) var trg = e.srcElement;
	if ( trg!=this.evnt ) return false;
	return true;
}
function checkTheTarget(e, element){
	if( element.length && element.length>1 ){
		var result = false;
		for( var i=0;i<element.length;i++ ){
			result = result || element[i].hasTheTarget(e);
		}
		return result;
	} else {
		return element.hasTheTarget(e);
	}
}

libObj.prototype.dragdrop = function(dragMode, minBorder, maxBorder, targetObj, wn, fn ){
	if(!dd_is_active) lib_dd();
	this.dragMode=dragMode;
	if(fn)this.fn=fn;
	if(wn)this.wn=wn;
	this.targetObj=targetObj;
	this.minBorder=(minBorder!=null)?minBorder:0;
	this.maxBorder=maxBorder;
	this.evnt.obj = this;
	this.evnt.fn = fn;
	this.evnt.onmouseover=function(e){ 
		if(( this.obj.targetObj )&&( !checkTheTarget(e, this.obj.targetObj) )) return;
		lib_dd_over(this.obj);
	}
	this.evnt.onmouseout=function(e){ 
		if(( this.obj.targetObj )&&( !checkTheTarget(e, this.obj.targetObj) )) return;
		dd_mobj=0;
	}
}
libObj.prototype.nodragdrop = function(){
	this.evnt.onmouseover=""; this.evnt.onmouseout=""
	dd_obj=0; dd_mobj=0
}

function lib_dd_over(obj){dd_mobj=obj}
function lib_dd_up(e){
	if(dd_obj.fn)eval(dd_obj.fn);
	dd_obj=0;
}
function lib_dd_down(e){
	if(dd_mobj){
		if (!e) var e = window.event;
		if (e.pageX || e.pageY){ x=e.pageX; y=e.pageY; }
		else if (e.clientX || e.clientY){ x = e.clientX; y = e.clientY; }
		dd_obj=dd_mobj
		dd_obj.clX=x-dd_obj.x; 
		dd_obj.clY=y-dd_obj.y;
	}
}
function lib_dd_move(e){
	if (!e) var e = window.event;
	if (e.pageX || e.pageY){ x=e.pageX; y=e.pageY; }
	else if (e.clientX || e.clientY){ x = e.clientX; y = e.clientY; }
	if(dd_obj){
		nx=x-dd_obj.clX;
		ny=y-dd_obj.clY;
		ny=(ny<=dd_obj.minBorder)?dd_obj.minBorder:ny;
		if(( dd_obj.maxBorder!=null )&&( ny>=dd_obj.maxBorder )){ ny=dd_obj.maxBorder}
		dd_obj.moveIt( ((dd_obj.dragMode=="move-y")?null:nx), ((dd_obj.dragMode=="move-x")?null:ny) );
		if(dd_obj.wn)eval(dd_obj.wn);
	}
}




/*
 *
 *
 *	unrelated yet frequently used functions
 * * * * * * * * * * * * * * * * * * * * * * * * * */
Array.prototype.contains = function( element ){
	for(var i=0;i<this.length;i++){if( this[i]==element ) return true;}
	return false;
}

function findPosX(obj) {
	var curleft = 0;
	if (obj.offsetParent){while (obj.offsetParent){curleft += obj.offsetLeft; obj = obj.offsetParent;}}
	else if (obj.x) curleft += obj.x;
	return curleft;
}

function findPosY(obj) {
	var curtop = 0;
	if (obj.offsetParent){while (obj.offsetParent){curtop += obj.offsetTop; obj = obj.offsetParent;}}
	else if (obj.y) curtop += obj.y;
	return curtop;
}

function clock() {
	var digital = new Date();
	var year = digital.getYear();
	var month = digital.getMonth()+1;	 	if(month<=9)month="0"+month;
	var day = digital.getDate();					if(day<=9)day="0"+day;
	var hours = digital.getHours();
	var minutes = digital.getMinutes();		if(minutes<=9)minutes = "0"+minutes;
	dispTime = year + "-" + month + "-" + day+" <b>"+hours + ":" + minutes+"</b>";
	document.getElementById("ClockBox").innerHTML = dispTime;
	setTimeout("clock()", 1000);
}

function getThePage( wSubtrahend, hSubtrahend ){
	page = {
		w 		: window.innerWidth,
		h 		: window.innerHeight
	}
	if(wSubtrahend)page.w-=wSubtrahend;
	if(hSubtrahend)page.w-=hSubtrahend;
}

function getTheWin(){
	win = {
		x		: window.screenX,
		y		: window.screenY
	}
}