////////////////////////////////////////////////////////////////////////////////////////////////////
//
//	EFS Prototype-esque/reliant Scripts
//
//	Tj Eastmond <issuess@gmail.com>
//
////////////////////////////////////////////////////////////////////////////////////////////////////

function $T(tag,parent) {
	var tags;
	if(typeof parent == 'string') {
		parent = document.getElementById(parent);
		tags = parent.getElementsByTagName(tag);
	} else {
		tags = document.getElementsByTagName(tag);
	}
	return tags;
}

var Cookie = {
	set : function(name, value, days_to_expire) {
		var expire = '';
		if(days_to_expire != undefined) {
			var d = new Date();
			d.setTime(d.getTime() + (86400000 * parseFloat(days_to_expire)));
			expire = '; expires=' + d.toGMTString();
		}
		return (document.cookie = escape(name) + '=' + escape(value || '') + expire);
	},
	
	get : function(name) {
		var cookie = document.cookie.match(new RegExp('(^|;)\\s*' + escape(name) + '=([^;\\s]*)'));
		return (cookie ? unescape(cookie[2]) : null);
	},
	
	erase : function(name) {
		var cookie = Cookie.get(name) || true;
		Cookie.set(name, '', -1);
		return cookie;
	},
	
	accept : function() {
		if(typeof navigator.cookieEnabled == 'boolean') {
			return navigator.cookieEnabled;
		}
		Cookie.set('_test', '1');
		return (Cookie.erase('_test') = 1);
	}
};

var EFS = {};

EFS.onload = function(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

EFS.scroll = Class.create(); // Wrapper class for jsScroller
EFS.scroll.prototype = {
	initialize : function() {
		this.options = Object.extend({
			wrapper : '',
			scrollContainer : 'Scrollbar-Container',
			scrollDist : 10,
			width : 400,
			height : 200
		}, arguments[0] || {});
		this.setup();
	},
	
	setup : function() {
		wrapper = $(this.options.wrapper);
		this.scroller = new jsScroller(wrapper, this.options.width, this.options.height);
		this.scrollbar = new jsScrollbar(document.getElementById(this.options.scrollContainer), this.scroller, true);
		this.scrollTween = new jsScrollerTween(this.scrollbar,true);
		this.scrollbar._scrollDist = this.options.scrollDist;
	},
	
	getWidth : function() {
		alert(this.options.width);
	},
	
	move : function(to) {
		this.scrollbar.tweenTo(to);
	},
	
	top : function() {
		this.move(0);
	},
	
	swap : function(element) {
		this.scrollbar.swapContent($(element));
	}
};

EFS.blurlinks = function(parent) {
	var links = $T('a',parent);
	for(var i = 0; i < links.length; ++i) {
		var oldonfocus = links[i].onfocus;
		if(typeof links[i].onfocus != 'function') {
			links[i].onfocus = function() {
				this.blur();
			};
		} else {
			links[i].onfocus = function() {
				oldonfocus();
				this.blur();
			}
		}
	}
	return false;
}

EFS.qs = function(variable) {
	var query = window.location.search.substring(1);
	var vars = query.split("&");
	for(var i=0; i<vars.length; i++) {
		var pair = vars[i].split("=");
		if(pair[0] == variable) {
			return pair[1];
		}
	}
	return false;
};

////////////////////////////////////////////////////////////////////////////////////////////////////
