// ---------------------------------------------------------------------------
// Utility functions

function cleanSplit (str, separator) {
	if(!str)return new Array();
	var a=str.split(separator),i=a.length;
	while(i>=0){if(a[i]=='')a.splice(i,1);i--;}
	return a;
}
function scramble(s){
	var i,r='';
	for(i=0;i<s.length;i++)r+=String.fromCharCode(58)+(s.charCodeAt(i)+1);
	return r;
}
function descramble(s){
	var i,r='',l=s.split(s.charAt(0));
	for(i=1;i<l.length;i++)r+=String.fromCharCode(l[i]-1);
	return r;
}

// ---------------------------------------------------------------------------
// Utility functions for page parameters

function hasPageParams(){
	return _pageParams.length > 0;
}
function getPageParams(){
	return _pageParams.length ? _pageParams : null;
}
function getFirstPageParam(){
	return _pageParams.length ? _pageParams[0] : null;
}
function getLastPageParam(){
	return _pageParams.length ? _pageParams[_pageParams.length-1] : null;
}

// ---------------------------------------------------------------------------
// Tween

Tween = function (el, prop) {
	this.el = el;
	this.prop = prop;
	this.interval = null;
	this.onComplete = function(){};
	this.obj = "TweenInstance_" + (++ Tween.instance);
	eval(this.obj + "=this");
}
Tween.instance = 0;
Tween.prototype.start = function (current, end, duration, ease) {
	this.stop();
	if (current) this.current = current;
	else this.current = parseInt(this.el.style[this.prop]) || 0;
	this.end = end;
	this.duration = duration;
	this.ease = (ease && typeof(TweenEase[ease]) == 'function') ? ease : 'linear';
	this.elapsed = 0;
	this.difference = this.end - this.current;
	this.doTween();
	this.interval = setInterval(this.obj + ".doTween()", 50);
}
Tween.prototype.doTween = function(){
	if (this.elapsed ++ < this.duration) {
		var p = TweenEase[this.ease](this.elapsed, this.current, this.difference, this.duration);
		this.el.style[this.prop] = p + 'px';
	} else {
		this.el.style[this.prop] = this.end + 'px';
		this.stop();
		this.onComplete();
	}
}
Tween.prototype.stop = function(){
	clearInterval(this.interval);
	this.interval = null;
}
TweenEase = {
	linear : function (t, b, c, d) {
		return c*t/d+b;
	},
	easein : function (t, b, c, d) {
		return c*(t/=d)*t+b;
	},
	easeout : function (t, b, c, d) {
		return -c*(t/=d)*(t-2)+b;
	}
}

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