/*----------------------------------------------------------
| OLD: slider
+-----------------------------------------------------------
| [1] REWRITE THIS:
| Right now [sa] can't get the position of an anchor tag!!!
| Rewrite the getPos function in the future.
| [2] FIX THIS:
| Right now horizontal scolling cannot be used!!!
| this is because if the page fits in the window and the target object
| is not flush left the horizontal scoll can never reach the end scroll!
| Right now ePos.x is always 0
+-----------------------------------------------------------
| FIXES: [08.04.07]
| This version has the following fixes for rebuild "news" display
| This is a hack and slash patch - should use "smoothScroll.js" but would be a bitch to integrate it into this old framework.
| + uri verification includes the query (search) parameters as well - previously it only verified the full pathname.
| + added scroll canceling
+---------------------------------------------------------*/

$slide = {};
$slide.timer = null;
$slide.active = false;
$slide.decay = 6;
$slide.delay = 15;
$slide.yOffset = -4;
$slide.to = function(obj) {
	var sPos = getPageOffset();
	obj = $obj.get.byId(obj);
	if (obj && $envi.browser.sa) { //-- (see [1] above)
		if (obj.tagName.toLowerCase() == "a") { obj = obj.parentNode; }
	}
	var ePos = (obj) ? $obj.pos.get(obj) : { x:0, y:0 };
	ePos.x = 0; //-- (see [2] above)
	ePos.y += this.yOffset;
	this.active = true;
	this.go(sPos.x, sPos.y, ePos.x, ePos.y);
	return false;
};

$slide.go = function(curX, curY, endX, endY) {
	if (this.timer) { clearTimeout(this.timer); }
	if (!this.decay) { this.decay = 6; }
	if (!this.delay) { this.delay = 15; }
	if (!endX || endX < 0) { endX = 0; }
	if (!endY || endY < 0) { endY = 0; }
	if (!curX) { curX = getPageOffset().x; }
	if (!curY) { curY = getPageOffset().y; }

	var stepX = (endX - curX) / this.decay;
	var stepY = (endY - curY) / this.decay;
	curX += (stepX < 0) ? Math.floor(stepX) : Math.ceil(stepX);
	curY += (stepY < 0) ? Math.floor(stepY) : Math.ceil(stepY);

	window.scrollTo(curX,curY);

	if (curX != endX || curY != endY) {
		this.timer = setTimeout('$slide.go('+curX+','+curY+','+endX+','+endY+')',this.delay);
	} else {
		this.active = 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 { x:x, y:y };
}

$slide.autoCheck = function() {
	//NOTE: not compatable with [ie:mac]
	//NOTE: "cookie" functionality  not compatable with [sa]
	if ($envi("ie:mac")) { return; }
	var L = document.location, u, s, h;
	if (!(h = L.hash)) return;
	s = L.search;
	u = L.href.substr(0, L.href.length - s.length - h.length);
	if (!$envi.browser.sa && $cookie.enabled) $cookie.set("anchor", h.substr(1));
	else s += ((s) ? "&" : "?" ) + "anchor=" + h.substr(1);
	location.replace(u + s);
};

$slide.onload = function() {
	var aid;
	if (!$envi.browser.sa && $cookie.enabled) aid = $cookie.remove('anchor');
	else aid = (aid = document.location.search.match(/anchor=([^;]+)/)) ? aid[1] : '';
	if (aid) this.to(aid);
};

/*----------------------------------------------------------
| OLD: path/anchor tools
| added "NOSLIDE" ignore class label (I know it is a bad way to do it , but i was a quick solution!)
----------------------------------------------------------*/

function initAnchorLinks() {
	var links = document.links;
	for (var i = 0; i < links.length; i++) {
		var path = $file.split(links[i].href);
		if (path.file == $file.getFile() && links[i].className.indexOf('NOSLIDE') < 0) {
			var id = (path.hash) ? path.hash : "";
			$aqs.tasks.add(links[i],"onclick","$slide.to('" + id + "'); return false;");
			//alert(path.file +"\n"+ $file.path.getFile());
		}
	}
}
