/*---< core.js >----------------------[04.02.19]
|
| System information and
| core methods/constructors for js components
|
+----< dependencies >----------------------------
|
| >> none
|
+----< contents >--------------------------------
|
| +-system info
| | getSysInfo() --method
| | browserIs(pStr) -->> ("ie:win:>=3.0,ns:*:>5,sa")
|
| +-document info
| | getModDate() <PENDING>
|
| +-object <HTML element>
| | getById(who)
| | \findChild(who)
| | \findById(who[,verified{bool}])
| | getProps(who[,detailed{bool}])
| | getPos(who)
| | setClass(who,nClass)
| | setAttribute(who,attName,nValue)
| | setDisplay(pStr) -->> ("item1:y,item2:n,item3:y")
|
| +-math
| | vector_2d() <constructor>
| | vector_3d() <constructor>
| | ease_cubic() <PENDING>
|
| +-core
| | removeWhiteSpace(str)
| | extractParam(pStr, pId[,dlm])
|
| +-slider
| | slideTo(who)
| | goSlide(curX, curY, endX, endY, steps)
| | getPageOffset()
|
+----< notes >-----------------------------------
|
| Javascript 1.3 compliant
| removed --> object initialization
|
+------------------------------------------------
| (c)2003,2004 Inter-Planning Inc.
| http://www.inter-garden.com
+----------------------------------------------*/

//---------- containers ----------[begin]
var sysInfo = {};
var taskDB = {};
//---------- containers ----------[end]

//---------- system info ----------[begin]

function initSysInfo() { //-- v1.11[03.12.14]
	var platform = {};
	var browser = {};
	browser.name = "";
	browser.ver = 0;
	var agt = navigator.userAgent.toLowerCase();
	if (agt.indexOf("mac") >= 0) {
		platform.mac = true; platform.name = "mac";
	} else if (agt.indexOf("win") >= 0) {
		platform.win = true; platform.name = "win";
	}
	if (agt.indexOf("netscape") >= 0) {
		browser.ns = true; browser.name = "ns";
		browser.ver = parseFloat(agt.substring(agt.indexOf("netscape/") + 9));
	} else if (agt.indexOf("omniweb") >= 0) {
		browser.ow = true; browser.name = "ow";
		if (agt.indexOf("omniweb/v496") >= 0) { browser.ver = 4.5 };
	} else if (agt.indexOf("opera") >= 0) {
		browser.op = true; browser.name = "op";
		browser.ver = parseFloat(agt.substring(agt.indexOf("opera ") + 6));
	} else if (agt.indexOf("msie") >= 0) {
		browser.ie = true; browser.name = "ie";
		browser.ver = parseFloat(agt.substring(agt.indexOf("msie ") + 5));
	} else if (agt.indexOf("safari") >= 0) {
		browser.sa = true; browser.name = "sa";
		if (agt.indexOf("safari/85") >= 0) { browser.ver = 1 };
	} else if (agt.indexOf("mozilla") >= 0 && agt.indexOf("rv:") >= 0) {
		browser.mz = true; browser.name = "mz";
		browser.ver = parseFloat(agt.substring(agt.indexOf("rv:") + 3));
	}
	if (agt.indexOf("mozilla") >= 0) {
		browser.moz = true;
		browser.engine = "moz";
		browser.moz_ver = parseFloat(navigator.appVersion);
		if (!browser.name && document.layers) {
			browser.ns = true; browser.name = "ns";
			browser.ver = browser.moz_ver;
		}
	}
	delete agt;
	sysInfo.platform = platform;
	sysInfo.browser = browser;
}
initSysInfo();

function browserIs(pStr) { //-- v2.02[04.02.20]
//-- example -->>  browserIs("ie:win:>=3.0,ns:*:>5,sa");
	var pArr, pList, b, s, c, v, i;
	pArr = removeWhiteSpace(pStr).toLowerCase().split(',');
	pList = [];
	for(i = 0; i < pArr.length; i++) { pList[i] = pArr[i].split(":") }
	for(i = 0; i < pList.length; i++) {
		b = (pList[i][0] == null || pList[i][0] == "") ? "*" : pList[i][0];
		s = (pList[i][1] == null || pList[i][1] == "") ? "*" : pList[i][1];
		v = (pList[i][2] == null || pList[i][2] == "") ? "*" : pList[i][2];
		if (v == "*") { c = "*" }
		else {
			c = v.replace(/[\d\.]+/g,"");
			v = parseFloat(v.replace(/[^\d\.]+/g,""));
			if (c == "=") { c = "==" }
			if (c == "") { c = (isNaN(v)) ? "*" : "==" }
		}
		if (b == sysInfo.browser.name || b == "*") {
			if (s == sysInfo.platform.name || s == "*") {
				if (c == "*" ) { return true }
				else { if (eval(sysInfo.browser.ver+c+v)) { return true } }
			}
		}
	}
	return false;
}

//---------- system info ----------[end]

//---------- object <HTML element> ----------[begin]

function getById(who) { //-- v2.01 [04.02.18]
	if (typeof who == "object") { return who }
	who = (typeof who != "string") ? who.toString() : who;
	return ((who.indexOf('.')<0) ? findById(who, true) : findChild(who));
}

function findChild(who) { //-- v1.01 [04.02.18]
	var us = who.split('.');
	us[0] = findById(us[0],true);
	var walkTree = function (who, walkSiblings) {
		if (who.id==us[i+1]) { us[i+1]=who; cycleDone=true }
		if (cycleDone) { return }
		if (who.firstChild != null) { walkTree(who.firstChild, true) }
		if (walkSiblings==true && who.nextSibling != null) { walkTree(who.nextSibling, true) }
	};
	for (var i=0; i<us.length-1; i++) {
		var cycleDone = false;
		if (typeof us[i]=='object') { walkTree(us[i]) }
	}
	return ((typeof us[us.length-1]=='object') ? us[us.length-1] : null);
}

function findById(who, verified) { //-- v1.13 [04.02.18]
	if (verified != true) {
		if (typeof who == "object") { return who }
		who = (typeof who != "string") ? who.toString() : who;
	}
	if (document.getElementById) { return document.getElementById(who) }
	else if (document.all) { return document.all[who] }
	return ((document.layers) ? document.layers[who] : null);
}

function getProps(who, detailed) { //-- v1.01 [03.09.15]
	var dlm = " | ";
	var props = "";
	who = getById(who);
	if (detailed == true) {
		props += "ID: "+who.id;
		props += "\nTag Name: "+who.tagName;
		props += "\nObject Type: "+who;
		props += "\nProperties: ";
	}
	for (var prop in who) { props += prop+dlm }
	return props;
}

function getPos(who) { //-- v1.0 [03.09.13]
	who = getById(who);
	var offX = who.offsetLeft;
	var offY = who.offsetTop;
	var tempMe = who;
	while (tempMe.offsetParent != null) {
		tempMe = tempMe.offsetParent;
		offX += tempMe.offsetLeft;
		offY += tempMe.offsetTop;
	}
	return new vector_2d(offX,offY);
}

function setClass(who,newCls) { //-- v1.0 [03.12.07]
	setAttribute(who,'class',newCls)
}
function setAttribute(who,attName,newVal) { //-- v1.0 [03.12.07]
	who = getById(who);
	if (sysInfo.browser.name == 'ie') { who.attributes.getNamedItem(attName).value = newVal }
	else { who.setAttribute(attName,newVal) }
}

function setDisplay(pStr) { //-- v1.11 [04.02.20]
//-- example -->>  setDisplay("item1:y,item2:n,item3:y");
	var pArr, i, j, p, who, s;
	pArr = removeWhiteSpace(pStr).split(',');
	for (i=0; i<pArr.length; i++) {
		p = pArr[i];
		j = p.indexOf(':');
		who = getById(p.substring(0,j));
		s = p.substring(j+1);
		who.style.display= (s == "y") ? "block" : "none";
	}
}

//---------- object <HTML element> ----------[end]

//---------- math ----------[begin]

vector_2d = function (x, y) { //-- v1.0[03.09.14]
	this.x = x; this.y = y;
}

vector_3d = function (x, y, z) { //-- v1.0[03.09.14]
	this.x = x; this.y = y; this.z = z;
}

function ease_cubic() {
	return false;
}

//---------- math ----------[end]

//---------- core ----------[begin]

function removeWhiteSpace(str){ //-- v1.0[03.04.20]
	return str.replace(/\s+/g,"");
}

function extractParam(pStr, pId, dlm) { //-- v1.1[03.08.23]
	var si, ei;
	if (pId.indexOf("=") < 0) { pId += "=" }
	if (dlm == null) { dlm = "," }
	si = pStr.indexOf(pId);
	if(si >= 0) {
		si += pId.length;
		ei = pStr.indexOf(dlm, si);
		if (ei < 0) { ei = pStr.length }
		return pStr.slice(si, ei);
	} else { return null }
}

//---------- core ----------[end]

//---------- slider ----------[begin]
var slideTimer;
var sliding = false;

function slideTo(who){
	var sPos = getPageOffset();
	var ePos = getPos(who);
	var steps = 4;
	sliding = true;
	ePos.y -= 5;
	goSlide(sPos.x, sPos.y, 0, ePos.y, steps);
}

function goSlide(curX, curY, endX, endY, steps){
	var newX, newY;
	if (slideTimer) { clearTimeout(slideTimer) }
	if (!endX || endX < 0) { endX = 0 }
	if (!endY || endY < 0) { endY = 0 }
	if (!curX) { curX = getPageOffset().x }
	if (!curY) { curY = getPageOffset().y }
	if (!steps) { steps = 6 }
	curX += (endX - curX) / steps;
	curY += (endY - curY) / steps;
	if (curX < 0) { curX = 0 }
	if (curY < 0) { curY = 0 }
	newX = Math.round(curX);
	newY = Math.round(curY);
	window.scrollTo(newX, newY);
	if (newX != endX || newY != endY) {
		slideTimer = setTimeout("goSlide("+curX+","+curY+","+endX+","+endY+","+steps+")",15);
	} else {
		sliding = false;
	}
}
function getPageOffset() {
	var x, y;
	x = (document.body.scrollLeft) ? document.body.scrollLeft : ((window.pageXOffset) ? window.pageXOffset : 0 );
	y = (document.body.scrollTop) ? document.body.scrollTop : ((window.pageYOffset) ? window.pageYOffset : 0 );
	return new vector(x,y);
}
//---------- slider ----------[end]
