/*
Author: Paul Visco of http://elmwoodstrip.org?u=paul
Version: 2.10
*/

var sb = {
	debug : (typeof sbDebug == 'undefined') ? 0 : 1,
	base : (typeof sbBase == 'undefined') ? '../surebert' : sbBase,
	initialized : 0,
	uid : 0,
	ondomload : [],
	domLoaded : 0,
	onleavepage : [],
	uniqueID : function(){
		return 'uid_'+(sb.uid +=1);
	},
	keepTrying : function(){
		for(var x=0;x<arguments.length;x++){
			try{return arguments[x]();} catch(e){}
		}
	},
	widget : {},
	unixTime : function(){
		return parseInt(String(now.getTime()).substring(0,10), 10);
	},
	returnMe : function(){return this;}
};



var sc=sb;

sb.init = function(){

	if(this.initialized ===0){
		
		this.initialized=1;
		
		if(typeof sb.stickerMaker !='undefined'){
			sb.stickerMaker.init();
			
		}
		
		this.domLoaded = 1;
		
		if(typeof this.ondomload != 'undefined'){
			
			this.ondomload.forEach(function(v){
				if(typeof v == 'function'){
					v();
				}
			});
		
		}
		
		if(this.debug ===1 && this.debugMe){
			this.debugMe();
		}
	}
};

sb.objects = {
	
	isArray : function(it){
	
		return (sb.gettype(it) == 'array') ? true : false;
	},
	
	serialize : function(o){
		var prop,val, str, a=[];
		
		for(prop in o){
			if(sb.objects.isArray(o[prop])){
				o[prop].forEach(function(v,k){
					a.push(prop+'[]='+encodeURIComponent(v));
				});
				
			} else if(typeof o[prop] =='object' && !sb.objects.isArray(o[prop])){
				
				for(var p in o[prop]){
					if(typeof o[prop][p] == 'object'){
						str = sb.objects.serialize(o[prop][p]);
						var arr = str.split("&");
						str ='';
						arr.forEach(function(v,k){
							arr[k]= v.replace(/(.*?)=(.*?)/g, prop+"['"+p+"']['$1']=$2");
							
						});
						a.push(arr.join("&"));
					} else {
						a.push(prop+"['"+p+"']="+encodeURIComponent(o[prop][p]));
					}
				}
			} else {
				val = o[prop];
				a.push(prop+'='+encodeURIComponent(val));
			}
		}
		
		return a.join("&");
	},
	
	copyProtos : function(to, from) {
		from = from || {};
		for(var prop in from) {
			to.prototype[prop] = from[prop];
		}
		from = null;
		return to;
	},
	
	copyProps : function(to, from) {
		from = from || {};
		try{
			for(var prop in from) {
				to[prop] = from[prop];
			}
		}catch(e){}
		from = null;
		return to;
	},
	
	protosToProps : function(to, from){
		for(var prop in from) {
			to[prop] = from.prototype[prop];
		}
		from = null;
		return to;
	},
	
	extend : function(o){
		o = o || {};
		for(var prop in o) {
			this[prop] = o[prop];
		}
		o=null;
	},
	
	alert : function(obj){
		alert(sb.objects.dump(obj));
	},
	
	dump : function(obj, ret){
		
			ret = ret || 0;
			var prop,dat ='';
			for(prop in obj){
				dat+="\n"+prop+' = '+obj[prop];
			}
			
			if(ret !=1 ){ return dat;} else { return '<pre style="margin:5px;border:1px;padding:5px;">'+dat+'</pre>';}
	
	}
};

sb.gettype = function(o){
	if (!o) {return false;}
	var type = false;
	
	if (o instanceof Function) { 
		type = 'function'; 
	} else if (o.nodeType){
		if (o.nodeType == 3) {
			type = 'textnode';
		} else if (o.nodeType == 1) {
			type = 'element';
		}
	} else if (o instanceof Array) {
		type = 'array';
	} else if(typeof o == 'string'){
		type = 'string';
	} else if(type !='array' && typeof o.length !='undefined'){
		type = 'nodelist';
	} else {
		type = (typeof o).toLowerCase();
	}
	
	return type;
};

sb.extend = sb.objects.extend;

sb.object = function(){};

sb.object.prototype = {
	extend : sb.objects.extend
};

sb.element = function(o){
	var el;
	if(sb.gettype(o) == 'string'){
		el = sb.$(o);
	} else if(sb.gettype(o) == 'object' && typeof o.addClassName == 'undefined'){
		o.nodeName = o.nodeName || 'span';
		if(o.nodeName == 'input'){
			o.name = o.name || '';
			o.type = o.type || 'text';
			el = new sb.dom.createNamedElement(o.type, o.name);
		} else {
			el = document.createElement(o.nodeName);
		}
		
		delete o.nodeName;
	} else {
		el = o;
	}
	
	sb.objects.copyProps(el, this);
	
	if(typeof o.addAttributes !='undefined'){
		this.setAttributes.call(el, o.addAttributes);
		delete o.addAttributes;	
	}
	try{
	if(el !=o){
		el.extend(o);
	}
	} catch(e){o.toString();}
	return el;
};

sb.element.prototype = {
	
	addClassName : function(c){
		sb.dom.className.add.call(this, c);
	},
	
	setAttributes : function(o){
		
		for(var prop in o){
			this.setAttribute(prop, o[prop]);
		}
	},
	
	removeAttributes : function(o){
		for(var prop in o){
			this.setAttribute(prop) = '';
		}
	},
	
	append : function(el){return this.appendChild(sb.$(el));},
	
	appendTo : function(el){return sb.$(el).appendChild(this);},

	appendAfter : function(after){
		after = sb.$(after).nextSibling;
		return after.parentNode.insertBefore(this, after);
	},
	
	appendBefore : function(before){
		before = sb.$(before);
		return before.parentNode.insertBefore(this, before);
	},
	
	clearStyles : function(){
		for(var style in this.style){
			try{
				this.style[style] = '';
			}catch(e){}
		}
	},
	
	clone: function(){
		var el = sb.$(this.cloneNode(true));
		sb.objects.copyProps(el, this);
		return el;
	},
	
	css : function(prop, val){
		return sb.css(this, prop, val);
	},
	
	dump : function(){
		return sb.objects.dump(this);	
	},
	
	event : function (evt, func){
			return sb.events.add(this, evt, func);
	},
	
	extend : function(o){
		sb.objects.copyProps(this, o);
	},
	
	getBounds : function(params){
		params = params || {};
		params.pos = params.pos || 'abs';
		params.scroll = params.scroll || 0;
		var orig =this;
		var el=this,pos={top:0,left:0};
	
		do{
			pos.top += el.offsetTop;
			pos.left += el.offsetLeft;
			if(params.pos =='rel'){
				el = false;
			} else{
				try{el = el.offsetParent;}catch(e){el = false;}
				
			}
		} while(el);
		
		if(params.scroll ==1){
			if(sb.browser.scrollY){
				pos.top -=sb.browser.scrollY;
			}
			
			if(sb.browser.scrollX){
				pos.left -=sb.browser.scrollX;
			}
		}
		
		pos.bottom = pos.top+orig.offsetHeight;
		pos.right = pos.left+orig.offsetWidth;
		pos.h = orig.offsetHeight;
		pos.w = orig.offsetWidth;
		sc.objects.copyProps(this, pos);
		return pos;	

	},
	
	getBoundsRelative : function(){
			return this.getBounds({pos:'rel'});
	},
	
	getBoundsWithScroll : function(){
		return this.getBounds({scroll:1});
	},
	
	getNextSibling : function(){
		return this.getSibling('next');
	},
	
	getPreviousSibling : function(){
		return this.getSibling('previous');
	},
	
	getSibling : function(str){
		var el = this[str+'Sibling'];
		while (el.nodeType == 3) {
			el = el[str+'Sibling'];
		}
		return el;
	},
	
	hasClassName: function(c){
		return sb.dom.className.contains.call(this, c);
	},
	
	hide : function(){
		this.style.display = 'none';	
	},
	
	isChildOf : function (of) {
		var el = this;
		while(el = el.parentNode) {
			if(el == sb.$(of)) {return true;}
		}
		return false;
	},
	
	mv : function(x,y,z,pos){
		pos = pos ||'absolute';
		if(this.style.position===''){this.css('position', pos);}
		this.css('left', x);
		this.css('top', y);
		this.css('zIndex', z);
		this.getBounds();
	},
	
	oncontextmenu : function(func){
		if(typeof func == 'function'){
			this.oncontextmenu = function(){
				func.call(this);
				return false;
			}
		}
	},
	
	opacity : function(o){
		if(o){
			this.css('opacity', o);
			if(this.style.width === undefined){
				this.wh(this.offsetWidth, this.offsetHeight);
			}
		} else {
			return this.css('opacity');
		}
	},
	
	remove : function(){
		if(typeof this.parentNode !='undefined'){
			this.parentNode.removeChild(this);
		}
	},
	
	removeClassName : function(c){
		sb.dom.className.remove.call(this, c);
	},
	
	replace : function(node){
		var node = sb.$(node);
		if(typeof node.parentNode !='undefined'){
			node.parentNode.replaceChild(this, node);
		}
		node = null;
	},
	
	show : function(){
		this.style.display = 'block';
	},
	
	styles : function(params){
		try{
			sb.objects.copyProps(this.style, params);
		} catch(e){}
	},
	
	toggle : function(){
		if(this.style){
			this.style.display = (this.css('display') ==='none') ? 'block' : 'none';
		}
	},
	
	wh : function(w,h){
		this.css('width', w);
		this.css('height', h);
	},
	
	xy : function(x,y){
		this.style.left = x+'px';
		this.style.top = y+'px';
	},
	
	toString : function(){
		return 'sb.element';
	}
};

sb.dom = {

	$ : function(it, filt){
	
		if(it===null){return null;}
		if(typeof it=='object' && typeof filt == 'undefined'){return it;}
		
		var x,els,obj;
		
		if(typeof it =="string"){
			
			if(it.match(/#/)){
				it = it.replace("#", '');
				
				obj = document.getElementById(it);
				
			} else if(it.match(/\./)){
				
				obj = sb.dom.$('body', it);
				
				
			} else {
		
				obj = sb.dom.nodeListToArray(document.getElementsByTagName(it), it);
			}
			
		} else if(typeof it == "object" || typeof it == "function") {
			
			obj = it;
		} 
		
		//if there is a secondary filter
		if(typeof filt != 'undefined'){
			
			if(filt.match(/\./)){
				
				obj = sb.dom.nodeListToArray(obj.getElementsByTagName('*'), '*');
				
				obj = obj.filter(function(v){return v.className == filt.replace(".", '');});
			} else {
				obj = sb.dom.nodeListToArray(obj.getElementsByTagName(filt), filt);
			}
		}
		
		return obj;
	},
	
	nodeListToArray : function(obj, tag){
	
		if(sb.gettype(obj) == 'nodelist'){
			
			var x,nodes=[];
			for(x=0;x<obj.length;x++){
				nodes.push(obj[x]);
			}
				
			obj=(nodes.length ==1 && sb.arrays.inArray(sb.dom.singleTags, tag))? nodes[0] : nodes;
			nodes = null;
			
		}
		return obj;
	},

	ce : function(typ){
		var el = document.createElement(typ);
		return el;
	},
	
	importNode : function(node, deep){
		var nodeHTML = node.xml||node.outerHTML;
		if(!nodeHTML) {return false;}
		if(typeof deep == "undefined"){return false;}
		var tmpNode = document.createElement("div");
		tmpNode.innerHTML = nodeHTML;
		return tmpNode.firstChild.cloneNode(deep);
	},
	
	className : {
		
		toArray : function(){
			return this.className.split(' ');
		},
		
		contains : function(c){
			return sb.dom.className.toArray.call(this).inArray(c);
		},
		
		add : function(c){
			sb.dom.$(this).className += ' '+c;	
		},
		
		remove : function(c){
			var a = sb.dom.className.toArray.call(this);
			sb.dom.$(this).className = a.remove(c).join(' ');
		}
	},
	
	createNamedElement : function(t, n) {
		var el;
		
		try {
			el = document.createElement('<input type="'+t+'" name="'+n+'">');
		} catch (el) { }
			if (!el || !el.name) { 
			el = document.createElement('input');
			el.type=t;
			el.name=n;
		}
		
		return el;
	},
	
	remove : function(node){
		node = sb.$(node);
		if(typeof node.parentNode !='undefined'){
			node.parentNode.removeChild(node);
		}
	},
	
	replace : function(newNode, oldNode){
		newNode = sb.$(newNode);
		oldNode = sb.$(oldNode);
		if(typeof oldNode.parentNode !='undefined'){
			oldNode.parentNode.replaceChild(newNode, oldNode);
		}
	},
	
	s$ : function(obj){
		obj = new sb.element(obj);
		obj.getBounds();
		
		return obj;
	},
	
	singleTags : ['html', 'body', 'base', 'head', 'title'],
	toggle : function(node){
		var node = s$(node);
		if(node.style){
			node.style.display = (node.css('display') ==='none') ? 'block' : 'none';
		}
	},
	
	txt : function(str){
		return document.createTextNode(str);	
	}
	
};

sb.$=sb.dom.$;
sb.s$=sb.dom.s$;

sb.arrays = {
	combine : function(){
		var n=[];
		sb.arrays.forEach(arguments, function(a){
				sb.arrays.forEach(a, function(val){n.push(val);});
		});
		return n;
	},
	
	copy : function(arr){
		return sb.arrays.filter(arr, function(){return true;});
	},

	empty : function(arr){
		arr.length=0;
		return arr;
	},
	
	each : function(arr, func){
		sb.arrays.forEach(arr, func);
	},
	
	every : function(arr, func){
		if(typeof func == 'function'){
			for(var k=0;k<arr.length;k++){
				if(func(arr[k], k, arr) === false){
					return false;
				}
			}
			return true;
		}
	},
	
	filter : function(a, func){
		var n=[];
		if(typeof func == 'function'){
			sb.arrays.forEach(a, function(v,k,arr){
				if(func(arr[k], k, arr) === true){
					n.push(v);
				}
			});
		}
		return n;
	},
	
	forEach : function(arr, func){
		if(typeof func == 'function'){
			for(var k=0;k<arr.length;k++){
				func(arr[k], k, arr);
			}
		}
	},
	
	inArray : function(arr, val){
		return sb.arrays.some(arr, function(v){return v===val;});
	},
	
	indexOf : function(arr, val){
		for(var k=0;k<arr.length;k++){
			if(arr[k] == val){
				return k;
			}
		}
		return -1;
	},
	
	inject : function(arr, index, val){
		if(index <0){return arr;}
		var a = arr.slice(0, index), b = arr.splice(index, arr.length-index);
		a[index] = val;
		return sb.arrays.combine(a,b);
	},
	
	lastIndexOf : function(arr, val){
		var p=-1,k;
		for(k=0;k<arr.length;k++){
			if(arr[k] == val){
				p=k;
			}
		}
		return p;
	},
	
	map : function(arr, func){
		var n=[];
		if(typeof func == 'function'){
			sb.arrays.forEach(arr, function(v,k,a){n.push(func(v,k,a));});
		}
		return n;
	},
	
	max : function(arr){
		 var max=arr[0];
		 sb.arrays.forEach(arr, function(v){max=(v>max)?v:max;});
		 return max;
	},
	
	min : function(arr){
		 var min=arr[0];
		 sb.arrays.forEach(arr, function(v){min=(v<min)?v:min;});
		 return min;
	},
	
	random : function(arr){
 		return arr[sb.math.rand(0,arr.length)];
	},
	
	remove : function(arr, values){
		
		return sb.arrays.filter(arr, function(v){
			if(typeof values =='string'){
				return v != values;
			} else {
				return !sb.arrays.inArray(values, v);
			}
		});
	},
	
	unique : function(arr){
		var n=[];
		sb.arrays.forEach(arr, function(v){if(!sb.arrays.inArray(n, v)){n.push(v);}});
		return n;
	},
	
	regex: function(arr, expression) {
		
		var a = arr.filter(function(v, k, a) {
		 	if(v.v.toString().match(expression)){return true;}
		});
		
		return a;
	},

	some : function(arr, func){
		if(typeof func == 'function'){
			for(var k=0;k<arr.length;k++){
				if(func(arr[k], k, arr) === true){
					return true;
				}
			}
			return false;
		}
	}
	
};

sb.math = {

	rand : function(min,max){
		min = min || 0;
		max = max || 100;
		return Math.floor(Math.random()*max+min);
	},
	hex2dec : function(str){
		var val = parseInt(str,16);
		val = (typeof(val) =='number') ? val : 0;
		return val;
	},
	dec2hex: function(num){
		var hex = "0123456789ABCDEF",mask = 0xf,val='';
	
		while(num !== 0)
		{
			val = hex.charAt(num&mask) + val;
			num>>>=4;
		}
		
		return sb.strings.numpad(val);
	},
	round: function(val, precision){
		var x,dec = '1';
		for(x=1;x<=precision;x++){
			dec +='0';
		}
		dec = parseInt(dec, 10);
		return Math.round(val*dec)/dec;
	}
};

sb.strings = {
	basename : function(str){
		var re = new RegExp("/\\/", "g");
		str = str.replace(re, "/");
		var filename=str.split("/");
		return filename[(filename.length - 1)];
	},
	
	br2nl : function(str){
		var re = new RegExp("<[br /|br]>", "ig");
		return str.replace(re, "\n");
	},
	
	cleanFileName : function(str){
		var ext = str.match(/\.\w{2,3}$/);
		
		str = str.replace(/\.\w{2,3}$/, '');
		str = str.replace(/[^A-Z^a-z^0-9]+/g, ' ');
		str = str.ucwords();

		str = str.replace(/ /g, '');
		str +=String(ext).toLowerCase();
		return str;
	},

	empty : function(str){
		return (str ==='') ? true : false;
	},
	
	escapeHTML : function(str){
		str = str.replace(/</g, '&lt;');
		return str.replace(/>/g, '&gt;');
	},
	
	hex2rgb : function(hex, asArray){
		
		hex = sb.strings.stripWhitespace(hex).replace("#", "");
		var r= sb.math.hex2dec(hex.substr(0,2));
		var g = sb.math.hex2dec(hex.substr(2,2));
		var b = sb.math.hex2dec(hex.substr(4,2));
		if(asArray){
			return [r,g,b];
		} else {
			return 'rgb('+r+', '+g+', '+b+')';
		}
	},
	
	hilite : function(str, needle, className){
		className = className || 'hilite';
		//match all the instances of a text str within an HTML objects innerHTML
		var matches = new RegExp( "("+needle+")", "ig");
		//make it yellow and underlined with a class of markMe so further css can be applied
		return str.replace(matches, '<u class="'+className+'">$1</u>');
	},
	
	isNumeric : function(str){
		if(typeof str == 'number'){
			return 1;
		}
		var dat,valid = "0123456789.",x;
	
		for (x=0;x<str.length;x++){ 
			dat = str.charAt(x); 
			if (valid.indexOf(dat) == -1){
				 return false;
			}
		}
		return true;
	},
	
	linkify : function(str, target){
		target = target || '_blank';
		var match_url = new RegExp("(\s|\n|)([a-z]+?):\/\/([a-z0-9\-\.,\?!%\*_\#:;~\\&$@\/=\+]+)", "i");
		return str.replace(match_url, "<a href=\"$2://$3\" title=\"$2://$3\" target=\""+target+"\">::link::</a>");
		
	},
	
	ltrim : function(str){
		sb.strings.trim(str, 'l');
	},
	
	nl2br : function(str){
		var re = new RegExp("\n", "ig");
		return str.replace(re, "<br />");
	},
	
	numpad : function(num){
		return (num<=9) ? '0'+num : num;
	},
	
	px : function(str){
		if(!String(str).match(/px/)){
			str +='px';
			return str;
		} else {
			return str.replace('px', ''); 
		}
	},
		
	rgb2hex : function(rgb, asArray){
		if(!rgb.match(/^rgb/i)){return false;}
		
		var re = new RegExp('rgb\\((\\d{1,}),(\\d{1,}),(\\d{1,})\\)', "ig");
		var colors = re.exec(sb.strings.stripWhitespace(rgb));
		var r= sb.math.dec2hex(colors[1]);
		var g= sb.math.dec2hex(colors[2]);
		var b= sb.math.dec2hex(colors[3]);
		if(asArray){
			return [r,g,b];
		} else {
			return '#'+r+''+g+''+b;
		}
	},
	
	rtrim : function(str){
		sb.strings.trim(str, 'r');
	},
	
	substrCount : function(str, needle, caseInsensitive){
		var matches, ig = (caseInsensitive === undefined) ? 'g' : 'ig';
			
		var re = new RegExp(needle, ig);
		matches = str.match(re);
		if(matches !==null){
			return matches.length;
		} else {
		 	return false;
		}
	},

	strstr: function(str, needle, caseInsensitive){
		var ig = (caseInsensitive === undefined) ? 'g' : 'ig';
		var re = new RegExp(needle, ig);
		var matches = str.match(re);
		if(matches !==null){
			return true;
		} else {
		 	return false;
		}
	},
	
	stripHTML : function(str){
		var re = new RegExp("(<([^>]+)>)", "ig");
		str = str.replace(re, "");
		var amps = ["&nbsp;", "&amp;", "&quot;"];
		var replaceAmps =[" ", "&", '"'];
		for(var x=0;x<amps.length;x++){
			str = str.replace(amps[x], replaceAmps[x]);
		}
		
		re = new RegExp("(&(.*?);)", "ig");
		str = str.replace(re, "");
		
		return str;
	},
	
	stristr : function(str, needle){
		return sb.strings.strstr(str, needle, 1);
	},
	
	stripWhitespace : function(str){
		var spaces = "\\s";
		return str.replace(new RegExp("\\s", "g"), "");
	},
	
	toCamel : function(str){
		return str.replace(/-\D/gi, function(m){
			return m.charAt(m.length - 1).toUpperCase();
		});
	},

	trim : function(str, side) {
		side = side || 'lr';
	
		switch(side){
			case 'lr':
				return  str.replace(new RegExp("^\\s*|\\s*$", "g"),"");
			case 'l':
				return  str.replace(new RegExp("^\\s*(.*?)$", ""), "$1");
			case 'r':
				return  str.replace(new RegExp("^(.*?)\\s*$", ""), "$1");
		}
	},
	
	ucwords : function(str){
		var arr = str.split(' ');
		
		str ='';
		arr.forEach(function(v){
			str += v.charAt(0).toUpperCase()+v.slice(1,v.length)+' ';
		});
		return str;
	}
};

sb.ajax = function(params){ 
	
	//instantiate xmlhttp object
	try{this.o=new XMLHttpRequest();}catch(e){}
	try{this.o=new ActiveXObject("Msxml2.XMLHTTP");}catch(e){}
	try{this.o=new ActiveXObject("Microsoft.XMLHTTP");}catch(e){}
	if(!this.o){return null;}
	
	sb.objects.copyProps(this, params);
};

sb.ajax.extend = sb.objects.extend;
sb.ajax.extend({
	
	defaultMethod : 'get',
	defaultFormat : 'text',
	defaultURL : '',
	
	messages : {
		1:'This browser does not support surebert, please visit again with firefox, ie 5.5-7 for win, safari, netscape or opera.',
		2:'Page not found. status codes explained at http://surebert.com/errorCodes.html ',
		3:'page found but blank',
		4:'invalid xml',
		5:'log sent',
		6:'Data has arrived at the destination url',
		7:'Content Length exceed stated limit',
		8:'Error evaling javascript from server',
		9:'Dom node referenced by ajax object does not exist'
	}
});

sb.ajax.prototype = {
	debug : this.debug || 0,
	data : this.data || '',
	local : this.local || 0,
	format : this.format || '',
	async : this.async || 1,
	onlog :'',
	log : [],

	addToLog : function(log){
	
		if(typeof(log)=='number'){
			log = {data:sb.ajax.messages[log],code:log,type:'error'};
		} else if(typeof(log)!='object'){
			log = {data:log,code:5,type:'log'};
		} 
	
		if(typeof(this.onlog)=='function'){
			this.onlog(log);
		} else {
			try{
				if(this.debug == 1 || sb.ajax.debug == 1 && sb.consol){
					if(log.type =='error'){
						sb.consol.error(log.data, 1);
					} else {
						sb.consol.log(log.data, 1);
					}
				}
			}catch(e){}
		}
	},
	
	onreadystatechange : function() {
	
		switch(this.o.readyState){
			case 1:
				if(typeof(this.loading)=='function'){this.loading();} 
				return;
			case 2:
				if(typeof(this.loaded)=='function'){this.loaded();} 
				return;
			case 3:
				if(typeof(this.interactive)=='function'){this.interactive();} 
				return;
			case 4:
		}
		
		if (this.o.readyState != 4) {return; }
			if(this.method =='get'){
				this.addToLog('URL:url('+this.url+'?'+this.data+")\nDATA: "+this.data+'\nMETHOD:'+this.method+'\n');
			} else {
				
				this.addToLog('URL:url('+this.url+")\nDATA: "+this.data+'\nMETHOD:'+this.method+'\n');
			}
			
		try{
			if(this.o.status != 200 && this.local !==1){
				
				this.addToLog({'data':sb.ajax.messages[2]+"\nURL:url("+this.url+")\nDATA:("+this.data+")\nSTATUS: "+this.o.status+"\nSTATUS TEXT: "+this.o.statusText,'code':2,'type':'error'});
				return;
			}
		} catch(e){return;}
		
		if(this.format !='send'){
			if(this.o.responseText === ''){
				this.addToLog(3);
			} else{
				this.addToLog("HEADER: "+"\n"+this.o.getAllResponseHeaders()+"\n\nRECEIVED: \n"+this.o.responseText);
			}
		}
		
		if(typeof this.timer !='undefined'){
			this.timer.reset();
		}
		
		this.contentType = this.o.getResponseHeader("Content-Type");
		this.contentLength = this.o.getResponseHeader("Content-Length");
		
		if(this.contentLength > this.maxContentLength){
			
			this.addToLog(7);
			if(typeof this.onContentLengthExceeded == 'function'){
				this.onContentLengthExceeded();
			}
			this.o.abort();
			return;
		}
		
		if(this.format ===''){
			
		
			if(this.contentType.match('json')){
				this.format ='json';
			} else if (this.contentType.match('javascript')){
				this.format ='javascript';
			} else if (this.contentType.match('xml')){
				this.format ='xml';
			}
		}
				
		switch(this.format){
			
			case 'head':
				if(typeof this.header ==='undefined'){
					this.response = this.o.getAllResponseHeaders();
				} else {
					this.response = this.o.getResponseHeader(this.header);
				}
			break;
			
			case 'xml':
				if(this.o.responseXML !== null){ 
					this.response = this.o.responseXML.documentElement;
				} else { 
					this.addToLog(4);
				}
			break;
			
			case 'js':
				try{
					 this.response = this.o.responseText;
					eval(this.response); 
				}catch(e){
					this.addToLog(8);
				}
			break;
			
			case 'json':
				try{
					 eval('this.response='+this.o.responseText);
				}catch(e){
					this.addToLog(8);
				}
			break;
			
			case 'send':
				this.addToLog(6);
			break;
			
			default:
				this.response = this.o.responseText;
			break;
		}
		
		if(typeof(this.handler) =='function'){this.handler(this.response);}
		
		if(typeof this.node !='undefined'){
			
			if(sc.$(this.node)){
				var node = sc.$(this.node)
				if(typeof node.value !='undefined'){
					node.value = this.o.responseText;
				} else {
					node.innerHTML = this.o.responseText;
				}
				node = null;
			} else {
				this.addToLog(9);
			}
		}
				
		this.o.abort();
		return; 
	},
	
	fetch : function(url) {
		this.method = (typeof this.method !='undefined') ? this.method : sb.ajax.defaultMethod; 

		var t=this;
		url = url || t.url || sb.ajax.defaultURL;
		t.url =url;
		
		if(!t.o){t.addToLog(1);return;}
		
		t.o.onreadystatechange = function(){t.onreadystatechange();};
	
		if(t.method=='get' && t.data !== undefined){
			url = url+'?'+t.data;
		}
		
		if(typeof t.onmillisec =='function'){
			
			t.timer = new sb.timer(0.001, function(){t.onmillisec();});
			t.timer.begin();
		}
		
		if(typeof t.onfetch == 'function'){
			t.onfetch();
		}
		
		t.o.open(t.method, url, this.async);
	
		if(t.method=='post'){
			try{
				t.o.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			}catch(e){}
		}
		
		try{t.o.send(t.data); }catch(e){}
		
	},
	
	abort : function(){
		this.o.abort();
		
		if(typeof this.onmillisec !='undefined'){
			this.timer.reset();
		}
		
		if(typeof this.onabort =='function'){
			this.onabort();
		}
		
	},
	
	eatForm : function(form) { 
		if(this.data !==''){this.data +="&";}
		this.data += sb.forms.serialize(form);
	},
	
	extend : sb.objects.extend
};

sb.css = function(){
	
	var obj,prop,val=null,values,x;
	//arguments obj, prop, val
	if(typeof this.obj != 'undefined'){
		obj = this.obj;
		prop = arguments[0];
		val = (arguments[1] !== undefined) ? arguments[1]  :null;
	} else {
		obj = sb.$(arguments[0]);
		prop = arguments[1];
		val = (arguments[2] !== undefined) ? arguments[2] :null;
	}

	if(val === null){
		return sb.styles.read(obj, prop);

	} else {
		sb.styles.write(obj, prop, val);
	}
};

sb.styles = {
	
	newSheets : [],
	
	pxProps : ['fontSize', 'width', 'height', 'padding', 'border', 'margin', 'left', 'top'],
	
	writeRule : function(domEl, rule){
		
		if(typeof this.sheet ==='undefined'){
			if(document.createStyleSheet) {
				this.sheet = document.createStyleSheet('');
			} else {
			
				var sheet = document.createElement('style');
				sheet.type="text/css";
				sheet.appendChild(document.createTextNode(domEl+'{'+rule+'}'));
				this.sheet = sb.$('head').appendChild(sheet);
				sheet=null;
			}
		}
		
		if(this.sheet.insertRule){
			this.sheet.insertRule(domEl+'{'+rule+'}', this.numRules);
		} else if(this.sheet.addRule){
			this.sheet.addRule(domEl, rule);
		} else if (document.styleSheets.length >0){
			document.styleSheets[document.styleSheets.length-1].insertRule(domEl+'{'+rule+'}', this.numRules);
		}
		
		this.numRules++;
	},
	
	read : function(obj, prop){
		obj = sb.$(obj);
		
		var val;
		//use left properties if not specified
		if(prop.match(/^border$/)){
			prop = 'border-left-width';				
		} 
		
		if(prop.match(/^padding$/)){
			prop = 'padding-left';				
		}
		
		if(prop.match(/^margin$/)){
			prop = 'margin-left';				
		}
		
		if(prop.match(/^border-color$/)){
			prop = 'border-left-color';				
		}
				
		try{
			if (obj.style[prop]) {
				val = obj.style[prop];
				
			} else if (obj.currentStyle) {
				
				prop = sb.strings.toCamel(prop);
				val = obj.currentStyle[prop];
				
			} else if (document.defaultView && document.defaultView.getComputedStyle) {
					
				prop = prop.replace(/([A-Z])/g, "-$1");
				prop = prop.toLowerCase();
				
				val = document.defaultView.getComputedStyle(obj,"").getPropertyValue(prop);
				
			} else {
				val=null;
			}
			
			if(prop == 'opacity' && val === undefined){
				val = 1;
			}
			
			if(val){
				val = val.toLowerCase();
				if(val == 'rgba(0, 0, 0, 0)'){val = 'transparent';}
				
				if(typeof sb.colors !='undefined'){
					if(sb.colors.html[val]){
						val = sb.strings.hex2rgb(sb.colors.html[val]);
					}
				}
				
				if(val.match("^#")){
					val = sb.strings.hex2rgb(val);
				}
				
				return val;
			} else {
				return null;
			}
			
		} catch(e){}
		
	}, 

	write : function(obj,prop,val){
		obj = sb.$(obj);
		val = String(val);
		if(sb.styles.pxProps.inArray(prop) && val !=='' && !val.match(/em|cm|pt|px|%/)){
			val +='px';
		}
		
		prop = sb.strings.toCamel(prop);
		
		if(prop == 'opacity'){
			if(val <= 0){ val =0;}
			if(val >= 1){ val =1;}
			obj.style.opacity = val;
			
			if(typeof obj.style.filter == 'string'){
				obj.style.filter = "alpha(opacity:"+val*100+")";
			}
			
		} else {
			
			try{
			obj.style[prop] = val;
			}catch(e){}
		}
		
		return val;
	},

	load : function(href){

		var extSheet = document.createElement('link');
		extSheet.rel = 'stylesheet';
		extSheet.href = href;
		extSheet.type = 'text/css';
		this.newSheets.push(extSheet);
		return sb.$('head').appendChild(extSheet);
		
	},
	
	disable : function(sheet){
		if(typeof sheet !='undefined'){sheet.disabled=1;}
		
	},
	
	disableLoaded : function(){
		for(var x=0;x<this.newSheets;x++){
			this.disable(this.newSheets[x]);
		}
	},
	
	copy : function(from, to){
		from = sb.$(from);
		to = sb.$(to);
		
		for(var prop in from.style){
			try{to.style[prop] = from.style[prop];}catch(e){}
		}
	}
};

sb.styles.numRules =1;

sb.javascript = {

	load : function(src){
		var extScript = document.createElement('script');
		extScript.src = src;
		extScript.type = 'text/javascript';
		return sb.$('body').appendChild(extScript);	
	},
	
	loadAjax : function(src, func){
		
		var myJax = new ajax({
			url : src,
			format : 'text',
			async : true,
			handler : function(r){
				eval(r);
				if(typeof func == 'function'){
					func();
				}
			}
		}).fetch();
	}
};



sb.fileExists =function(file, handler){
	var sb_check = new sb.ajax({url : file});
	sb_check.onlog = function(e){
		if(typeof handler == 'function'){
			if(e.code ==2){handler();}
		}
	};
	sb_check.fetch();
};

sb.cookies={

	days : 7,
	path : '/',
	domain : '',
	onlog : '',
	
	recall : function(name){
		
		var i,n, parts = document.cookie.split(';');
		
		for(i=0;i<parts.length;i++){
			n = parts[i].split('=');
			n[0] = n[0].replace(/ /, "");
			
			if(name==n[0]){
				return unescape(n[1]);
			} 
		}
		return false;
	},
	
	listAll : function(){
		var i, c, list=[], parts = document.cookie.split(';');
		
		for(i=0;i<parts.length;i++){
			c = parts[i].split('=');
			list.push(c[0].replace(/ /, ""));
		}
		return list;
	},
	
	remember : function(name, value, days){

		days = days || sb.cookies.days;
	
	    var ck, date = new Date();
	
	    date.setTime(date.getTime()+(days*24*60*60*1000));
		 
		ck=name+'='+escape(value)+'; expires='+date.toGMTString()+'; path='+sb.cookies.path+';'+' host='+sb.cookies.domain;
		
		document.cookie =ck;
	},
	
	forget : function(name){
		
		this.remember(name, "", -1);
	},
	
	forgetAll : function(name){
	
		var n,i,deleted =[], parts = document.cookie.split(';');
		for(i=0;i<parts.length;i++){
			n = parts[i].split('=');
			
			if(n[0] !== undefined){
				deleted.push(n[0]);
				this.remember(n[0], "", -1);
			}
		}
	}
};

sb.events = {
	log : [],
	add: function(obj, event, handler){
		obj = sb.$(obj);
		
		if(obj.forEach){
			obj.forEach(function(v,k,a){sb.events.add(v, event, handler);});
		}
		
		if (obj.addEventListener){
			obj.addEventListener( event, handler, false );
		} else if (obj.attachEvent) {
			
			var uid = sb.uniqueID();
			obj['sce_'+uid] = handler;
			handler = function(){ 
				obj['sce_'+uid]( window.event ); 
			};
			obj.attachEvent( "on"+event, handler);
			
		}
		
		this.record(obj, event, handler);
		handler = null;
		return this.log.length-1;
	},
	
	remove: function(event){
		try{
			this.removeEvent(this.log[event][0], this.log[event][1], this.log[event][2]);
		} catch(e){}
	},
	
	removeAll: function(){
		var e;
		for(e in this.log){
			this.remove(e);
		}
		this.log =[];
	},

	removeEvent : function(obj, event, handler){
		if (obj.removeEventListener){
			obj.removeEventListener( event, handler, false );
		} else if (obj.detachEvent){
			obj.detachEvent( "on"+event, handler );
		}
	},
	
	record: function(obj, event, handler){
	
		this.log.push([obj, event, handler]);
	},
	
	stopAndPrevent : function(e){
		sb.events.stopPropagation(e);
		sb.events.preventDefault(e);
	},
	
	stopPropagation : function(e){
		 
		if(typeof e.stopPropagation == 'function'){
			e.stopPropagation();
		} else {
			e.cancelBubble = true;
		} 
	},
	
	preventDefault : function(e){
		 
		if(typeof e.stopPropagation == 'function'){
			e.preventDefault();
		} else {
			e.returnValue = false;
		} 
	},
	
	target : function(e){
	   var tar = (e.target !==undefined) ? e.target : e.srcElement;
	   if (tar.nodeType && tar.nodeType== 3){
	      tar = tar.parentNode;
	   }
	   return tar;
	},
	
	relatedTarget : function(e){
		var tar = false;
		switch(e.type){
			case 'mouseout':
			tar = e.relatedTarget || e.toElement;
			break;
			
			case 'mouseover':
			tar = e.relatedTarget || e.fromElement;
			break;
		}
		return tar;		
	},
	
	wheel : function(e){
		var delta = 0;
		if (e.wheelDelta) {
			delta = e.wheelDelta;
			if (window.opera) {delta = -delta;}
		} else if (e.detail) { delta = -e.detail;}
		delta = Math.round(delta);
		return (delta > 0 ) ? 1 : -1;
	},
	
	keys : function(e){
		
		var k, key, pressed, prop;
		key = e.keyCode;
		
		k = {};
		k.pressed ='';
		k.esc = (key == 27) ? 1 :0;
		k.ret = (key == 13) ? 1 :0;
		k.tab = (key ==9) ? 1 : 0;
		k.shift = (e.shiftKey) ? 1 :0;
		k.ctrl = (e.ctrlKey) ? 1 :0;
		k.alt = (e.altKey) ? 1 :0;
		k.home = (e.keyCode == 36) ? 1 : 0;
		k.up = (e.keyCode == 38) ? 1 : 0;
		k.down = (e.keyCode == 40) ? 1 : 0;
		k.left = (e.keyCode == 37) ? 1 : 0;
		k.right = (e.keyCode == 39) ? 1 : 0;
		k.pageUp = (e.keyCode == 33) ? 1 : 0;
		k.pageDown = (e.keyCode == 34) ? 1 : 0;
		k.space = (e.keyCode == 32) ? 1 : 0;
		k.letter = String.fromCharCode(key).toLowerCase();
		if(!k.letter.match(/\w/)){
			k.letter ='';
		}
		for(prop in k){
			if(k[prop] === 1){
				k.pressed = prop;
			}
		}
		k.pressed += ' '+k.letter;
		
		if(sb.debug ===1){
			sb.consol.log(sb.objects.dump(k));
		}
		return k;
	},
	
	oncontextmenu  : function(handler){
		sb.events.add('body', 'contextmenu', function(e){
			sb.events.preventDefault(e);
			if(typeof handler == 'function'){handler();}
		});
	}
};

$_GET = [];

sb.browser ={
	
	init : function(){
		if(window.location.search !==''){this.populateGET();}
		
		this.getAgent();
		this.measure();
	},
	
	populateGET : function (){
		var i,val,key;
		var q = window.location.search.substring(1);
		var v = q.split("&");
	
		for (i=0;i<v.length;i++) {
			var s = v[i].split("=");
			
			key = unescape(s[0]);
		
			val = unescape(s[1]);
			$_GET[key] = val.replace("+", " ");
		 }
	},
	
	measure : function(){
	
		if( typeof(window.innerWidth) == 'number' ) {
		    sb.browser.w = window.innerWidth;
		    sb.browser.h = window.innerHeight;
		} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {

		    sb.browser.w = document.documentElement.clientWidth;
		    sb.browser.h = document.documentElement.clientHeight;
		} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {

		    sb.browser.w = document.body.clientWidth;
		    sb.browser.h = document.body.clientHeight;
		}
		
		return [sb.browser.w, sb.browser.h];
	},
	
	win : function(url, w, h, sb){
		if(sb =='y' || sb === 1){sb ='yes';}
		if(sb =='n' || sb === 0){sb ='no';}
		if(sb != 'yes' && sb !='no'){sb ='yes';}
	
		var newWin = window.open(url,'name','height='+h+',width='+w+',menubar=no,resizable=yes,toolbar=no,scrollbars='+sb);
		
		try{newWin.focus();
		} catch(e){}
		return newWin;
	},
	
	scrollPos : function(){
		var x,y;
		if(window.pageYOffset){
			y = window.pageYOffset;
		} else if (document.documentElement && document.documentElement.scrollTop){
			y= document.documentElement.scrollTop;
		} else if (document.body && document.body.scrollTop){
			y= document.body.scrollTop;
		} else if (document.documentElement && !document.documentElement.scrollTop){
			y = 0;
		}
		sb.browser.scrollY = y;
	
		if(window.pageXSOffset){
			x = window.pageXOffset;
		} else if (document.documentElement && document.documentElement.scrollLeft){
			x = document.documentElement.scrollLeft;
		} else if (document.body && document.body.scrollLeft){
			x = document.body.scrollLeft;
		} else if (document.documentElement && !document.documentElement.scrollLeft){
			x = 0;
		}
		
		sb.browser.scrollX = x;
		return [sb.browser.scrollX, sb.browser.scrollY];
	},

	getAgent : function(){
		var opera = new RegExp("Opera/(\\d{1}\.\\d{1})", "i");
		var safari = new RegExp("safari/(\\d{3})", "i");
		var firefox = new RegExp("firefox/(\\d{1}\.\\d{1})", "i");
		var os,agent = navigator.userAgent;
		var str;
		
		if(window.opera && document.childNodes) {
			this.agent = 'op';
			this.version =7;
			str = navigator.userAgent.match(new RegExp("Opera/(\\d{1}\.\\d{1})", "i"));
			this.version = str[1];
			
		} else if (document.all && !window.XMLHttpRequest && document.compatMode){
			this.agent = 'ie';
			this.version = 6;
		} else if (document.all && window.XMLHttpRequest && document.compatMode){
			this.agent = 'ie';
			this.version = 7;
	
		} else if(agent.match(safari)){
			str = agent.match(safari);
			this.agent = 'sf';
			if(str[1] <= 100){
				this.version = 1;
			} else if(str[1] <= 200){
				this.version =1.2;
			} else if(str[1] < 400){
				this.version =1.3;
			} else if(str[1] > 400){
				this.version =2;
			}
		
		} else if(agent.match(firefox)){
			this.agent = 'ff';
			str = agent.match(firefox);
			this.version = str[1];
	
		} else {
			this.agent='other';
		}
	
		if(agent.match(/mac/i)){
			this.os = 'mac';
		} else if (agent.match(/window/i)){
			this.os = 'win';
		} else if (agent.match(/linux/i)){
			this.os = 'lin';
		}
		return this.agent;
	},
	
	removeSelection : function(){
		try{
			if(window.getSelection){
				window.getSelection().removeAllRanges();
			} else if(document.selection){
				document.selection.empty();
			}
		}catch(e){}
	}
};

sb.browser.init();

sb.swf = function(src, width, height, bgColor, version, alt){
	if(typeof arguments[0] == 'object'){
		sb.objects.copyProps(this, arguments[0]);
	} else {
		this.src = src;
		this.width = width || '150px';
		this.height = height || '105px';
		this.bgColor = bgColor || '#FFFFFF';
		this.id = 'sb_swf_'+sb.swf.instanceId;
		this.version = version || 5;
		this.alt = alt || '';
	}
	sb.swf.instanceId++;
};

sb.swf.version =4;
sb.swf.swfs=[];
sb.swf.instanceId=0;

sb.swf.prototype = {
	
	embed : function(obj){
		var dat;
		
		//embed flash move in all non IE browsers
		if(sb.swf.format=='embed'){
			
			dat = '<embed type="application/x-shockwave-flash" src="'+this.src+'"  id="'+this.id+'" allowScriptAccess="always" bgcolor="'+this.bgColor+'" ';
				
			if(typeof this.flashvars =='object'){
				
				dat +='FlashVars="'+sb.objects.serialize(this.flashvars)+'" ';
			
			}
			
			dat +=' width="'+this.width+'" height="'+this.height+'"  />';
		
		} else if(sb.swf.format=='object'){
				dat = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="'+this.width+'" height="'+this.height+'" id="'+this.id+'"><param name="movie" value="'+this.src+'" /><param name="bgcolor" value="'+this.bgColor+'" /><param name="allowScriptAccess" value="always" />';
				if(typeof this.flashvars =='object'){
					dat +='<param name="FlashVars" value="'+sb.objects.serialize(this.flashvars)+'">';
				}
				dat +='</object>';
		}
		
		if(this.version > sb.swf.version){
			dat =this.alt;
		}
		
		if(sb.strings.isNumeric(obj)){
			var swf = {};
			swf.dat = dat;
			swf.id = this.id;	
			return swf;
			
		} else if(sb.$(obj)){
			
			sb.$(obj).innerHTML =dat;
		} else {
			window.document.body.innerHTML +=dat;
		}
	
		return sb.$('#'+this.id);
	}
};

sb.swf.check= function(){
	try{
		var versionStr = new RegExp("\\d{1}\.\\d{0,5}", "i");
		var str = navigator.plugins["Shockwave Flash"].description;
		if(str.match(versionStr)){
			sb.swf.version = str.match(versionStr);
		}
	} catch(e){sb.swf.version=0;}
	return sb.swf.version;
};

sb.swf.testIe = function(){
	try{
		var x = new ActiveXObject("ShockwaveFlash.ShockwaveFlash." + sb.swf.version);
		if(x){
			return false;
		}
	} catch(e){return true;}
		
};

sb.swf.ieCheck= function(){	
	try{
		//THERE MUST BE A BETTER SOLUTION
		while(!sb.swf.testIe()){
			sb.swf.version++;
		}
		sb.swf.version--;
		return sb.swf.version;
	} catch(e){
		return true;
	}
};

sb.swf.cleanup = function() {
	sb.$('object').forEach(function(obj){
		obj.style.display='none';
		for(var prop in obj){
			if(typeof obj == 'function'){obj[prop] = function(){};}
		}
	});
};

sb.swf.unload = function() {
	__flash_unloadHandler = function(){};
	__flash_savedUnloadHandler = function(){};
	window.attachEvent( "onunload", sb.swf.cleanup );
	
};
	
sb.swf.detect = function(){
	if (navigator.plugins && navigator.plugins.length){
		sb.swf.format = 'embed';
		return sb.swf.check();
	} else {
		sb.swf.format = 'object';
		return sb.swf.ieCheck();
	}
};

sb.swf.detect();

sb.timer = function(sec, handler){
	var t =this;
	t.interval = (sec !== undefined) ? sec*1000 : 1000;
	if(handler !== undefined){t.handler=handler; }
	t.count=1;
};

sb.timer.wait = function(sec, func, beginHandler){
	if(typeof(beginHandler) == 'function'){beginHandler();}
	return window.setTimeout(func, sec*1000);
};

sb.timer.cancel = function(evt){
	window.clearTimeout(evt);
};
	
sb.timer.prototype = {

	begin : function() {
	
		var t = this;
		this.end();
		this.repeater = window.setInterval(function () {
			if (typeof t.handler  == "function"){
				
				t.handler();
				t.count++;
			}
		}, this.interval);
		
	},
	
	end : function (resetCount) {

		if (this.repeater !== null){window.clearInterval(this.repeater);}
		
		if(arguments.length !==0){this.count=0;}
		
		if (typeof(this.endHandler) == "function"){
			this.endHandler();
		}
	},
	
	reset : function(){
		this.end(1);
	},
	
	restart : function(){
		this.end(1);
		this.begin();
	},
	
	changeInterval : function(interval){
	
		this.interval = interval;
		this.end();
		this.begin();
	}
};

if(sb.browser.agent =='ie' && sb.swf.version >=9){
	//cleanup flash players for IE
	window.attachEvent( "onbeforeunload", sb.swf.unload);
}

sb.ln = function(i, o){
	if(!window[i] && o!==null){
		window[i] = o;
	}
};

sb.attachPrototype = function(obj, prop, sbMod){
	obj.prototype[prop] = function() {
		var a = [this];
		sb.arrays.forEach(arguments, function(v){a.push(v);});
		return sbMod[prop].apply(this, a);
	};
};

sb.attachProp = function(obj, prop, sbMod){
	obj[prop] = function() {
		return sbMod[prop](this, arguments[0], arguments[1]);
	};
};

sb.setGlobals = function(){
	var prop;
	for(prop in sb.strings){
		sb.attachPrototype(String, prop, sb.strings);	
	}
	
	for(prop in sb.arrays){
		sb.attachPrototype(Array, prop, sb.arrays);	
	}
	
	//add global links to internal sb functions
	sb.globals = {
		$ : sb.dom.$,
		s$ : sb.dom.s$,
		ajax: sb.ajax,
		arrays : sb.arrays,
		ce : sb.dom.ce,
		element : sb.element,
		gettype : sb.gettype,
		events: sb.events,
		forget: sb.cookies.forget,
		txt : sb.dom.txt,
		importNode : sb.dom.importNode,
		recall: sb.cookies.recall,
		remember: sb.cookies.remember,
		strings : sb.strings,
		swf : sb.swf,
		timer : sb.timer,
		wait : sb.timer.wait
	};
	
	for(var g in sb.globals){
		sb.ln(g, sb.globals[g]);
	}
	
	surebert = sb;
};

if(typeof sbNoGlobals === 'undefined'){
	sb.setGlobals();
	
	if(!document.importNode){
		document.importNode = sb.dom.importNode;
	}
}

if (sb.browser.agent == 'sf' || sb.browser.agent == 'op' && sb.browser.version <9){
	// runtime anonymous function
  (function(){

   // checks if document.readyState is loaded or complete
   /loaded|complete/.test(document.readyState) ?

    // then call __onContent__ , stopping internal loop
    window.sb.init() :

    // or loops itself with the faster timeout
    setTimeout(arguments.callee, 1);
  })();
} else if(document.addEventListener){
	//for Mozilla and opera >9
	 document.addEventListener("DOMContentLoaded", sb.init, false);
} else {
	
	
	//IE
	document.write('<script id="__ie_onload" defer src="https://javascript:void(0)"><\/script>');
	var script = document.getElementById("__ie_onload");
	script.onreadystatechange = function() {
	    if (this.readyState == "complete") {
	        sb.init(); // call the onload handler
	    }
	};
	
}




sb.events.add(window, 'load', function(){
	if(sb.initialized===0){sb.init();}
});

sb.events.add(window, 'resize', sb.browser.measure);
sb.events.add(window, 'scroll', sb.browser.scrollPos);
sb.events.add(window, 'unload', function(e){
	sb.onleavepage.forEach(function(v){
		if(typeof(v) =='function'){
			v(e);
		}
	});
	sb.events.removeAll();
});
