function move(x,y){

	if(this.style){
		if(x!=null){
			this.style.pixelLeft	= x;
			this.tv['x'].cur		= x;
			this.tv['x'].dst		= x;
		}
		if(y!=null){
			this.style.pixelTop		= y;
			this.tv['y'].cur		= y;
			this.tv['y'].dst		= y;
		}
	}

}

function moveTo(dx,dy,type){

	var c = this.coords(); if(!c) return;

	this.tv['x'].typ = type;
	this.tv['y'].typ = type;

	this.tv['x'].cur = c.left;
	this.tv['y'].cur = c.top;
	this.tv['x'].dst = dx;
	this.tv['y'].dst = dy;

	this.tv['x'].sid = 0;
	this.tv['x'].fli = 0;
	this.tv['y'].sid = 0;
	this.tv['y'].fli = 0;

	this.tv['x'].on	 = true;
	this.tv['y'].on	 = true;

}

function size(w,h){

	if(this.style){
		if(w!=null){
			this.style.pixelWidth	= w;
			this.tv['w'].cur		= w;
			this.tv['w'].dst		= w;
		}
		if(h!=null){
			this.style.pixelHeight	= h;
			this.tv['h'].cur		= h;
			this.tv['h'].dst		= h;
		}
	}

}

function sizeTo(dw,dh,type){

	var c = this.coords(); if(!c) return;

	this.tv['w'].typ = type;
	this.tv['h'].typ = type;

	this.tv['w'].cur = c.width;
	this.tv['h'].cur = c.height;
	this.tv['w'].dst = dw;
	this.tv['h'].dst = dh;

	this.tv['w'].sid = 0;
	this.tv['w'].fli = 0;
	this.tv['h'].sid = 0;
	this.tv['h'].fli = 0;

	this.tv['w'].on	 = true;
	this.tv['h'].on	 = true;

}

function left(x){

	if(x!=null){
		this.style.pixelLeft = x;
	}else{
		return this.style.pixelLeft;
	}

}

function top(y){
	
	if(y!=null){
		this.style.pixelTop = y;
	}else{
		return this.style.pixelTop;
	}

}

function width(w){

	if(w!=null){
		if(w < 0) w = 0;
		this.style.width = w+'px';
	}else{
		return this.style.posWidth;
	}

}

function height(h){

	if(h!=null){
		if(h < 0) h = 0;
		this.style.height = h+'px';
	}else{
		return this.style.posHeight;
	}

}

function hide(oElm){

	if(!oElm) oElm = this;

	if(oElm.style){

		oElm.style.visibility = 'hidden';
		oElm.visible = false;

	}

	if(oElm.hideID){
		clearTimeout(oElm.hideID);
		oElm.hideID = null;
	}

}

function show(){

	if(this.style){

		this.style.visibility = 'visible';
		this.visible = true;

	}

}

function content(html){

	if(this.innerHTML!=null){

		this.innerHTML = html;

	}

}

function coords(oElm){

	if(!oElm) oElm = this;

	if(oElm.getBoundingClientRect){

		var a = oElm.getBoundingClientRect();
		var b = new Array();

		b.left   = a.left;
		b.right  = a.right;
		b.top    = a.top;
		b.bottom = a.bottom;
		b.width  = a.right - a.left;
		b.height = a.bottom - a.top;

		return b;

	}

	return false;

}

function transProps(){

	this.sid = 0;
	this.fli = 0;
	this.cur = 0;
	this.dst = 0;
	this.spd = 1;
	this.on  = false;

}

function still(){

	if(!this.tv) this.tv = new Array();

	this.tv['x'] = new transProps();
	this.tv['y'] = new transProps();
	this.tv['w'] = new transProps();
	this.tv['h'] = new transProps();

}

function enableTrans(oElm){

	if(!oElm.style) return;

	page.objects[page.objects.length] = oElm;

	oElm.style.position = 'absolute';

	oElm._left		= left;
	oElm._top		= top;
	oElm._width		= width;
	oElm._height	= height;

	oElm.content	= content;
	oElm.show		= show;
	oElm.hide		= hide;
	oElm.move		= move;
	oElm.moveTo		= moveTo;
	oElm.size		= size;
	oElm.sizeTo		= sizeTo;
	oElm.coords		= coords;
	oElm.still		= still;
	oElm.transport	= transport;

	oElm.hide();
	oElm.still();

}

function unLoad(targetURL){

	if(targetURL){

		var oImg = document.getElementById('hUnLoad');

		if(oImg){

			oImg.targetURL			= targetURL;
			oImg.src				= 'scripts/pixel.php?ses='+escape(ses)+'&url='+escape(targetURL);
			oImg.onload				= function temp(){ window.location = this.targetURL; }

			// just incase onload fails.
			setTimeout('window.location = "'+targetURL+'";',1000);

		}

	}

	return false;

}

function page(){

	page.win = window;
	page.doc = page.win.document;
	page.bod = page.doc.body;

	page.objects = new Array();

	page.event	= getEvent;

	page.create =	function c(sElm){

						if(page.doc.createElement) return page.doc.createElement(sElm);

					}

	page.bod.onmouseover	= mouseHandler;
	page.bod.onmouseout		= mouseHandler;
	page.bod.onmousedown	= mouseHandler;
	page.bod.onmousemove	= mouseHandler;

	page.bod.onselectstart	= selectionHandler;
	//page.bod.oncontextmenu	= contextHandler;

	//------------------------------------------
	// Menu Creation
	//------------------------------------------

		page.menu = page.create('DIV');

		page.menu.className	= 'menu';
		page.menu.hideWait	= 50;
		page.menu.my		= 'menu';

		page.bod.insertAdjacentElement('beforeEnd', page.menu);

		enableTrans(page.menu);

		page.menu.content('');
		page.menu.move(-100,-100);
		page.menu.size(10,10);
		page.menu.hide();

	//------------------------------------------

	page.loopID = setInterval('loop()',1);

	if(window.locInit) window.locInit();

}

function loop(){

	if(!page.objects) return;

	for(var i = 0; i < page.objects.length; i++){

		if(page.objects[i]){

			page.objects[i].transport('x');
			page.objects[i].transport('y');
			page.objects[i].transport('w');
			page.objects[i].transport('h');

		}

	}

}

function transport(t){

	if(this.tv[t].on){

		switch(t){
		case 'x':	this.mimic = this._left;	break;
		case 'y':	this.mimic = this._top;		break;
		case 'w':	this.mimic = this._width;	break;
		case 'h':	this.mimic = this._height;	break;
		}

		this.tv[t].cur = this.mimic();

		var cur = this.tv[t].cur;
		var dst = this.tv[t].dst;
		var spd = this.tv[t].spd;
		var sid = this.tv[t].sid;
		var fli = this.tv[t].fli;

		var _add = 1;
		var _max = 10 - (fli * 3);		if(_max < 1) _max = 1;
		var _min = -10 + (fli * 3);		if(_min > -1) _min = -1;

		var dif = (dst - cur);

		if(this.onTransLoop) eval(this.onTransLoop);

		if((dif >= -1 && dif <= 1) && _max==1 && _min==-1){

			this.tv[t].on = false;
			this.mimic(dst);
			return;

		}else{

			if(cur < dst){

				if(sid != -1){
					if(sid) fli++;
					sid = -1;
				}

				if(spd < _max){ spd += _add; }

			}else if(cur >= dst){

				if(sid != 1){
					if(sid) fli++;
					sid = 1;
				}
				if(spd > _min){ spd -= _add; }

			}

			cur += spd;

			this.tv[t].fli = fli;
			this.tv[t].sid = sid;
			this.tv[t].cur = cur;
			this.tv[t].dst = dst;
			this.tv[t].spd = spd;

			this.mimic(cur);

		}

	}

}

function timeStamp(){
	var d = new Date();
	return d.getTime();
}

function contextHandler(){

	var e	= page.event(); if(!e) return;

	e.obj.returnValue = false;

}

function selectionHandler(){

	var e	= page.event(); if(!e) return;
	var src	= e.src;		if(!src) return;

	if(!src.isTextEdit && !src.contentEditable){

		e.obj.returnValue = false;

	}

}

function mouseHandler(){

	var e	= page.event(); if(!e) return;
	var src	= e.src;		if(!src) return;
	var my	= src.my;
	var c	= coords(src);

	switch(e.type){
	case 'mousemove':


	break;
	case 'mouseover':

		if(src.note){

			if(page.menu.hideID){
				clearTimeout(page.menu.hideID);
				page.menu.hideID = null;
			}

			page.menu.content(src.note);
			page.menu.size(90,10);

			var mc = page.menu.coords();

			page.menu.move(c.left - mc.width + 6,c.top - mc.height + 6);
			page.menu.show();

			window.status = page.menu.innerText;
			return true;

		}

		if(src.className=="icon"){
			src.className="icon_o";
		}

		if(my=='zoom'){

			if(!page.zoomImage){
				page.zoomImage	= new Image();
				page.zoomInsert	= true;
			}

			page.zoomImage.className	= 'zoom-image';
			page.zoomImage.src			= src.src;

			var x = 0;
			var y = 0;
			var w = parseInt(src.myWidth);
			var h = parseInt(src.myHeight);
			var oy = page.bod.clientHeight;

			if(src.myX){
				x = c.left + (c.width / 2) + parseInt(src.myX);
			}else{
				x = c.left - w - 10;
			}

			if(src.myY){
				y = c.top + (c.height / 2) + parseInt(src.myY);
			}else{
				y = c.top + (c.height / 2) - (h / 2);
			}

			if((y + h) > oy){ y = oy - h - 10; }

			page.zoomImage.style.left	= x + page.bod.scrollLeft;
			page.zoomImage.style.top	= y + page.bod.scrollTop;
			page.zoomImage.width		= w;
			page.zoomImage.height		= h;

			if(page.zoomInsert){

				document.body.insertAdjacentElement('beforeEnd',page.zoomImage);
				page.zoomInsert = false;

			}

			if(page.zoomImage.filters && page.zoomImage.filters[0]){

				page.zoomImage.filters[0].stop();
				page.zoomImage.style.visibility = 'visible';

			}

		}

		if(my=='menu' || page.menu.contains(src)){

			if(page.menu.hideID){
				clearTimeout(page.menu.hideID);
				page.menu.hideID = null;
			}

		}

		switch(my){
		case 'm1':

			src.alt = '';

			if(page.menu.hideID){
				clearTimeout(page.menu.hideID);
				page.menu.hideID = null;
			}

			page.menu.hide();
			page.menu.content('<b>Welcome<br></b><font size=1>Information about this site, its contents and its overall purpose in the grand scheme of things...</font>');
			page.menu.move(c.left - 90,c.top+10);
			page.menu.size(100,50);
			page.menu.show();

			window.status = 'Welcome';
			return true;

		break;
		case 'm2':

			src.alt = '';

			if(page.menu.hideID){
				clearTimeout(page.menu.hideID);
				page.menu.hideID = null;
			}

			page.menu.hide();
			page.menu.content('<b>Portfolio<br></b><font size=1>The section that is dedicated to work that i have accomplished - and liked... :)</font>');
			page.menu.move(c.left - 90,c.top+10);
			page.menu.size(100,50);
			page.menu.show();

			window.status = 'Portfolio';
			return true;

		break;
		case 'm3':

			src.alt = '';

			if(page.menu.hideID){
				clearTimeout(page.menu.hideID);
				page.menu.hideID = null;
			}

			page.menu.hide();
			page.menu.content('<b>Ideas & Projects<br></b><font size=1>Information about my current schemes, plans and hair brained ideas!</font>');
			page.menu.move(c.left - 90,c.top+10);
			page.menu.size(100,50);
			page.menu.show();

			window.status = 'Ideas & Projects';
			return true;

		break;
		case 'm4':

			src.alt = '';

			if(page.menu.hideID){
				clearTimeout(page.menu.hideID);
				page.menu.hideID = null;
			}

			page.menu.hide();
			page.menu.content('<b>Intoddid<br></b><font size=1>Just some stuff that i find interesting & odd that just really wouldn\'t have fitted in Projects & Ideas!</font>');
			page.menu.move(c.left - 90,c.top+10);
			page.menu.size(100,50);
			page.menu.show();

			window.status = 'Interesting!';
			return true;

		break;
		case 'm5':

			src.alt = '';

			if(page.menu.hideID){
				clearTimeout(page.menu.hideID);
				page.menu.hideID = null;
			}

			page.menu.hide();
			page.menu.content('<b>Remember Login?<br></b><font size=1>Tick this box if you want your login remembered for next time...</font>');
			page.menu.move(c.left - 93,c.top+13);
			page.menu.size(100,50);
			page.menu.show();

			window.status = 'Interesting!';
			return true;

		break;
		}

	break;
	case 'mouseout':

		if(src.note){

			page.menu.hide();
			window.status = ' ';
			return true;

		}

		if(src.className=="icon_o"){
			src.className="icon";
		}

		if(my=='zoom' && page.zoomImage){

			if(page.zoomImage.filters)	page.zoomImage.filters[0].apply();
			if(page.zoomImage.style)	page.zoomImage.style.visibility = 'hidden';
			if(page.zoomImage.filters)	page.zoomImage.filters[0].play();

		}

		if(my=='menu' || page.menu.contains(src)){

			page.menu.hideID = setTimeout('page.menu.hide()',page.menu.hideWait);

		}

		switch(my){
		case 'm1':
		case 'm2':
		case 'm3':
		case 'm4':
		case 'm5':
		case 'm6':
		case 'm7':

			page.menu.hideID = setTimeout('page.menu.hide()',page.menu.hideWait);

		break;
		}

		window.status = ' ';
		return true;

	break;
	case 'mousedown':

		page.menu.hide();

	break;

	}

}

function re2member(oChk){

	if(!document.getElementById) return;

	var oElm = document.getElementById('hLoginTitle');	if(!oElm) return;

	if(re2member.arguments.length==0){

		oElm.width	= re2member.width;
		oElm.height	= re2member.height;

	}else{

		if(oChk){

			if(oChk.checked){

				re2member.width		= 63;
				re2member.height	= 9
				oElm.onload			= re2member;
				oElm.src			= 'images/t_rememberlogin.gif';

			}else{

				re2member.width		= 55;
				re2member.height	= 9;
				oElm.onload			= re2member;
				oElm.src			= 'images/t_memberlogin.gif';

			}

		}

	}

}

function object(){}

function getEvent(win){

	if(!getEvent.str) getEvent.str = '';

	if(!win) win = window;

	var e = win.event;
	var r = new object();

	if(!e) return false;

	r.propertyName	= e.propertyName;
	r.src			= e.srcElement;
	r.tag			= (r.src?e.srcElement.tagName:false);
	r.type			= e.type;
	r.to			= e.toElement;
	r.from			= e.fromElement;
	r.button		= e.button;
	r.kc			= e.keyCode;
	r.shiftKey		= e.shiftKey;
	r.ctrlKey		= e.ctrlKey;
	r.altKey		= e.altKey;
	r.repeat		= e.repeat;

	if(r.button==1){
		
		r.leftClick		= true;
		r.rightClick	= false;

	}else if(r.button==2){
		
		r.leftClick		= false;
		r.rightClick	= true;

	}else if(r.button==3){
	
		r.leftClick		= true;
		r.rightClick	= true;

	}else{

		r.leftClick		= false;
		r.rightClick	= false;

	}

	r.screenX		= e.screenX;
	r.screenY		= e.screenY;
	r.x				= e.x;
	r.y				= e.y;
	r.obj			= e;

	return r;

}

function findParent(oObj, sType, tValue){

	if(!oObj) return false;

	if(sType == 'id'){

		if(oObj.id == tValue) return oObj;

	}else if(sType == 'name'){

		if(oObj.name == tValue) return oObj;

	}else if(sType == 'tag'){

		if(oObj.tagName == tValue) return oObj;

	}

	return findParent(oObj.parentElement, sType, tValue);

}

function findChild(oObj, sType, tValue){

	if(!oObj) return false;

	if(sType == 'id'){

		if(oObj.id == tValue) return oObj;

	}else if(sType == 'name'){

		if(oObj.name == tValue) return oObj;

	}else if(sType == 'tag'){

		if(oObj.tagName == tValue) return oObj;

	}else if(sType == 'value'){

		if(oObj.value == tValue) return oObj;

	}

	var temp, i;

	if(oObj.children && oObj.children.length){

		for(i=0; i<oObj.children.length; i++){

			temp = findChild(oObj.children[i], sType, tValue);

			if(temp) return temp;

		}

	}

	return false;

}

window.onload = page;

function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" + 
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}
