(function(){
	if(window.sb){return;}
	var document = window.document;
	
	
	var sb = {
		
		
		
		$ : function() {
			//return items that are already objects
			if((typeof arguments[0] == 'object' || typeof arguments[0] == 'function') && arguments.length ==1){return arguments[0];}
			
			//handle legacy dollarsign stuff
			if(arguments.length ==2 && typeof arguments[1] == 'string'){
				return sb.$.legacy.apply(this, arguments);
			}
			
			var selectors = sb.strings.trim.call(arguments[0]);
			var selector = selectors.split(",");
			var inheriters, nodes = [];
			var within = arguments[1];
			
			for(var s=0;s<selector.length;s++){
				selector[s] = selector[s].replace(/\s?([>\+\~])\s?/, "$1");
				inheriters = selector[s].split(" ");
				nodes = nodes.concat(sb.$.parseInheritors(inheriters, within));
			}
			
			//if there is only one match and there was only one requested or the request and match were for a single style HTML tag (head, body) then return only that match
			
			if(nodes.length ==1  && (!selectors.match(/,/) && selectors.match(/^\#\w+$/)) || sb.arrays.inArray.call(sb.dom.singleTags, selectors)){
				
				return nodes[0];
			} else if(selectors.match(/^\#\w+$/) && nodes.length === 0){
				return null;
			} else {
				return nodes;
			}
			
		},
	
		
		addGlobals : function(){
			var prop;
			
			for(prop in sb.strings){
				if(typeof String.prototype[prop] =='undefined'){
					String.prototype[prop] = sb.strings[prop];
				}
			}
		
			for(prop in sb.arrays){
				if(typeof Array.prototype[prop] =='undefined'){
					Array.prototype[prop] = sb.arrays[prop];
				}	
			}
			
			//Object.prototype.infuse = sb.objects.infuse;
			//Object.prototype.forEach = sb.objects.forEach;
			
			
			//add global links to internal sb functions
			sb.globals = {
				$ : sb.$,
				s$ : sb.s$
			};
			
			sb.objects.forEach.call(sb.globals, function(v,k,o){
				sb.createIfNotExists(k, v);
			});
	
		},
		
		
		base : (typeof window.sbBase !='undefined') ? window.sbBase : '/surebert',
		
		
		consol : {
			log : function(){},
			write : function(){},
			error : function(){}
		},
	
		
		createIfNotExists : function(i, o){
			if(!window[i] && o!==null){
				window[i] = o;
			}
		},
		
		
		css : {},
		
		
		included : [],
		
		include : function(module){
			
			var mods = module.split('.');
			var path ='', file, unit=sb,m;
			
			for(m=0;m<mods.length;m++){
				
				if(m !==0 && m < mods.length && mods.length >1){
					path +='.';
				}
				path +=mods[m];
				
				try{
					unit = unit[mods[m]];
				} catch(e){}
			
				if(typeof unit == 'undefined'){
						
					this.included.push(path);
					file = path.replace(/\./g, "/");
					sb.load(sb.base+'/'+file+'.js');
				
				}
			}
		},
		
		
		load : function(url){
			var evaled = 0;
	
			(function(){
				var load = new sb.ajax({
					url : url,
					async : 0,
					method : 'get',
					format : 'js',
					debug : sb.loadDebug ? 1 : 0,
					handler: function(r){
					//#######look into this 
						try{
							evaled=1;
						}catch(e){
								
							evaled=0;
							delete e.stack;
							sb.consol.error(sb.messages[13]+"\nURL: "+url+"\n"+sb.objects.dump(e));
							
						}
						load=null;
					}
				}).fetch();}());
			return evaled;
		},
		
	
		messages : [],
		
		
		onbodyload : [],
		
		
		onleavepage : [],
		
		
		
		s$ : function(el, fil){
			
			var retVal = sb.$.apply(this, sb.toArray(arguments));
			
			if(sb.typeOf(retVal) == 'array'){
			
				retVal = retVal.map(function(node){
					return sb.s$helper(node, el);
				});
			
				//REMOVEME
				
				retVal = new sb.nodeList(retVal);
				
				
			}  else {
				retVal = sb.s$helper(retVal, el); 
			}
			
			return retVal;
	
		},
		
		
		s$helper : function(node, el){
			if(sb.typeOf(node) == 'element'){
				sb.objects.infuse(sb.element.prototype, node);
				
			} else if (sb.typeOf(node) != 'sb.element'){
				sb.consol.error('"'+el+'" of object type ' +sb.typeOf(node)+sb.messages[14]);
			}
			
			return node;
					
		},
		
		
		toArray : function(o){
			var a=[];
			for(var x=0;x<o.length;x++){
				a.push(o[x]);
			}
			return a;
		},
		
		
		typeOf : function(o){
			var type='';
			
			if(o === null){
				return 'null';
			} else if (o instanceof Function) { 
				type = 'function'; 
			} else if (o instanceof Array) {
				type = 'array';
			} else if(typeof o == 'number'){
				type = 'number';
				if(String(o).match(/\./)){
					type = 'float';
				}
			} else if(typeof o == 'string'){
				type = 'string';
			} else if(o === true || o === false){
				type='boolean';
			} else {
				type = (typeof o).toLowerCase();
			}
			
			if(typeof o =='object' ){
			
				if(typeof o.typeOf == 'function'){
					type = o.typeOf();
				} else if (o.nodeType){
					if (o.nodeType == 3) {
						type = 'textnode';
						
					} else if (o.nodeType == 1) {
						type = 'element';
					}
				} else if(typeof o.length !='undefined' && type !='array'){
					type = 'nodelist';
				} 
			}
			
			return type;
		},
		
		
		uid : 0,
		
		
		uniqueID : function(){
			return 'uid_'+(sb.uid +=1);
		},
		
		
		
		unixTime : function(){
			return parseInt(String(new Date().getTime()).substring(0,10), 10);
		},
		
		
		functions : {},
		
		
		utils : {},
		
		
		widget : {},
		
		
		forms : {}
		
	};
	
	
	sb.browser ={
		
		
		ie6 : 0,
		
		
		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 agent = window.navigator.userAgent;
			var str;
			
			if(window.opera && window.document.childNodes) {
				this.agent = 'op';
				str = agent.match(opera);
				this.version = str[1];
				
			} else if (document.all && !window.XMLHttpRequest && document.compatMode){
				this.agent = 'ie';
				this.version = 6;
				sb.browser.ie6 =1;
			}  else if (document.all && window.XMLHttpRequest && document.compatMode){
				this.agent = 'ie';
				this.version = 7;
		
			} else if(agent.match(firefox)){
				this.agent = 'ff';
				str = agent.match(firefox);
				this.version = str[1];
			} else if(agent.match(safari)){
				
				str = agent.match(safari);
				
				this.agent = 'sf';
				if(agent.match(/iphone/i)){
					this.agent += '_iphone';
				} else if(agent.match(/ipod/i)){
					this.agent += '_ipod';
				}
				
				if(str[1] < 400){
					this.version =1;
				} else if(str[1] < 500){
					this.version =2;
				} else if(str[1] < 600){
					this.version =3;
				}
				
			} else {
				this.agent='other';
			}
		
			return this.agent;
		},
		
		
		measure : function(){
			sb.browser.w=0; sb.browser.h =0;
			if( typeof window.innerWidth == 'number' ) {
			    sb.browser.w = window.innerWidth;
			    sb.browser.h = window.innerHeight;
			} else if( window.document.documentElement && ( window.document.documentElement.clientWidth || window.document.documentElement.clientHeight ) ) {
			    sb.browser.w = document.documentElement.clientWidth;
			    sb.browser.h = document.documentElement.clientHeight;
			}
			
			return [sb.browser.w, sb.browser.h];
		},
		
		
		getScrollPosition : function(){
			var x=0,y=0;
			if(window.pageYOffset){
				y = window.pageYOffset;
			} else if (document.documentElement && document.documentElement.scrollTop){
				y= document.documentElement.scrollTop;
			} 
			sb.browser.scrollY = y;
		
			if(window.pageXSOffset){
				x = window.pageXOffset;
			} else if (document.documentElement && document.documentElement.scrollLeft){
				x = document.documentElement.scrollLeft;
			} 
			
			sb.browser.scrollX = x;
			return [sb.browser.scrollX, sb.browser.scrollY];
		},
		
		
		init : function(){
		
			this.getAgent();
			this.measure();
		}
	};
	
	sb.browser.init();
		
	
	sb.$.getElementById = function(selector){
		
		var parts = selector.split("#");
		var tag = parts[0];
		var id = parts[1];
		var el = document.getElementById(id);
		
		return el;
		
	};
	
	
	sb.$.getElementByClassName = function(within, selector){
	
		var parts = selector.split('.');
		var tag = parts[0];
		var class_name = parts[1];
		
		var elements = sb.$.getElementsByTagName(within, tag);
		
		within = elements.filter(function(node,k,a){
			
			//var classMatch = node.className && node.className.match(new RegExp("\s?("+class_name+")\s?"));
			var classMatch = node.className && node.className.match(new RegExp("\\b("+class_name+")\\b"));
			if(classMatch && classMatch[0] == class_name){
				
				return true;
			}
			
		});
		
		return within;
		
	};
	
	
	sb.$.getElementsByTagName = function(within, tag) {
		
		tag = tag || '*';
		
		var matches = [];
		
		within.forEach(function(node,k,a){
			
			var elements = sb.toArray(node.getElementsByTagName(tag));
			matches = matches.concat(elements);
		});
	
		
		return matches;
	};
	
	
	sb.$.getElementsByAttributes = function(within, selector){
		
		var tag,attr,operator,value;
		if (selector.match(/^(?:(\w*|\*))\[(\w+)([=~\|\^\$\*]?)=?['"]?([^\]'"]*)['"]?\]$/)) {
			tag = RegExp.$1;
			attr = (typeof sb.$.attrConvert =='function') ? sb.$.attrConvert(RegExp.$2) : RegExp.$2;
			
			operator = RegExp.$3;
			value = RegExp.$4 ||'';
		}
		
		var elements = sb.$.getElementsByTagName(within, tag);
		
		within = elements.filter(function(el,k,a){
		
		el.attrVal = el.getAttribute(attr, 2);
		
		//if attribute is null
		if(!el.attrVal){
			return false;
		}
		
		switch(operator){
			case '=':
				if(el.attrVal != value){
					return false;
				}
				break;
				
			case '~':
				
				if(!el.attrVal.match(new RegExp('(^|\\s)'+value+'(\\s|$)'))){
					return false;
				}
				break;
				
			case '|':
				if(!el.attrVal.match(new RegExp('^'+value+'-?'))) {
					return false;
				}
				break;
				
			case '^':
				if(el.attrVal.indexOf(value) !== 0){
					return false;
				}
				break;
				
			case '$':
				if(el.attrVal.lastIndexOf(value)!=(el.attrVal.length-value.length)){
					return false;
				}
				break;
				
			case '*':
				if(!(el.attrVal.indexOf(value)+1)){
					return false;
				}
				break;
				
			default:
				if(!el.getAttribute(attr)){
					return false;
				}
		}
		
		return true;
			
		});
		
		return within;
		
	};
	
	
	sb.$.getNextSibling = function(node){
		while((node = node.nextSibling) && node.nodeType != 1){}
		return node;
	};
	
	
	sb.$.getPreviousSibling = function(node){
		while((node = node.previousSibling) && node.nodeType != 1){}
		return node;
	};
	
	
	sb.$.getFirstChild = function(node){
		node = node.firstChild;
		while (sb.typeOf(node) == 'textnode') {
			node = sb.$.getNextSibling(node);
		}
		return node;	
	};
	
	
	sb.$.getLastChild = function(node){
		
		node = node.lastChild;
		while (sb.typeOf(node) == 'textnode') {
			node = sb.$.getPreviousSibling(node);
		}
		return node;
	};
	
	
	sb.$.getElementsByParent = function(within, selector){
		var parts = selector.split(">");
				
		var par =parts[0];
		var chld = parts[1];
		
		var elements = sb.$(chld);
		elements = (!elements.length) ? [elements] : elements;
		
		elements = elements.filter(function(el,k,a){
		
			if(!par.indexOf('#')+1 && el.parentNode.nodeName.toLowerCase() == par){
					
				return true;
			} else if(par.indexOf('#')+1 && par.replace(/\#/, '') == el.parentNode.id){
				return true;
			}
			
			return false;
		});
		
		return elements;
	};
	
	
	sb.$.getElementsByAdjacentSibling = function(within, selector){
		var parts = selector.split("+");
				
		var nodeName =parts[0];
		var adjacentNodeName = parts[1];
		
		var elements = sb.$(nodeName);
		elements = (!elements.length) ? [elements] : elements;
		//put in the proper adajcent siblings
		elements = elements.map(function(el,k,a){
			
			var node = sb.$.getNextSibling(el);
			if(node && node.nodeName.toLowerCase() == adjacentNodeName){
				return node;
			} 
			
			return false;
			
		});
		
		//remove any false eones
		elements = elements.filter(function(v){
			if(!v){
				return false;
			} else {
				return true;
			}
		});
		return elements;
				
	};
	
	
	sb.$.parsePseudoSelectors = function(within, selector){
	
		var nth,notSelector,elements = [],parts = selector.split(":");
		
		selector =parts[0];
		var pseudo = parts[1];
		
		var nodes = sb.$(selector, within);
		
		nodes.forEach(function(node,k,a){
			
			switch(pseudo){
				
				case 'before':
			
					var bf = new sb.element({
						nodeName : 'span',
						innerHTML : 'ddd'
					}).appendToTop(node);
					elements.push(bf);
				
					break;
					
				case 'first-child':
					
					if(node.parentNode && node == sb.$.getFirstChild(node.parentNode)){
						elements.push(node);
					}
					break;
					
				case 'last-child':
					if(node.parentNode && node == sb.$.getLastChild(node.parentNode)){
						elements.push(node);
					}
					break;
				
				case 'empty':
					if(node.innerHTML ===''){
						elements.push(node);
					}
					break;
					
				case 'only-child':
					
					if(node.parentNode.childNodes.length ==1){
						elements.push(node);
					}
					break;
					
				default: 
					
				if(pseudo.indexOf('not')+1){
					notSelector = pseudo.match(/not\((.*?)\)/);
					
					if(node.nodeName.toLowerCase() != notSelector[1]){
						elements.push(node);
					}
				} else if(pseudo.indexOf('nth-child')+1){
					nth = pseudo.match(/nth\-child\((.*?)\)/);
					if(sb.strings.isNumeric.call(nth[1])){
						nth = parseInt(nth[1],10)-1;
						
						if(nth == k){
							elements.push(node);
						}
					} else {
						switch(nth[1]){
							case 'odd':
								if(k %2 !==0){
									elements.push(node);
								}
								break;
								
							case 'even':
								if(k %2 ===0){
									elements.push(node);
								}
								break;
						}
					}
						
					
				}
				
			}
			
			 
		});
	
		return elements;
	};
	
	
	sb.$.parseInheritors = function(inheriters, within){
		
		var matches = [];
		
		//within = (typeof within !='undefined') ? within : [document];
		within = within || [document];
		
		inheriters.within = within;
		inheriters.forEach(function(selector,k,a){
		
			var element;
			
				///we have just an id///
				if((selector.indexOf("#") === 0 && selector.match(/^\#\w+$/)) || selector.match(/\w+\#\w+/)) {
					
					element = sb.$.getElementById(selector);
				
					if(element){
						inheriters.within = [element];
						if(k+1 == a.length){
							matches = matches.concat(inheriters.within);
						}
					}
					
					return true; 
				}
			
			if(selector.indexOf(">")+1){
				inheriters.within = sb.$.getElementsByParent(inheriters.within, selector);
				
				if(k+1 == a.length){
					matches = matches.concat(inheriters.within);
					
				}
				
				return true;
				
			}
			
			if(selector.indexOf("+")+1){
				
				inheriters.within = sb.$.getElementsByAdjacentSibling(inheriters.within, selector);
				
				if(k+1 == a.length){
					matches = matches.concat(inheriters.within);
					
				}
				
				return true;
		
			}
			
			///look for attribute's by searching for sqaure brackets //
			if(selector.indexOf('[')+1){
				
				inheriters.within = sb.$.getElementsByAttributes(inheriters.within, selector);
			
				if(k+1 == a.length){
					matches = matches.concat(inheriters.within);
				}
				
				return true;
			}
			
			//look for pseudo selectors
			if(selector.indexOf(":")+1){
				
				inheriters.within = sb.$.parsePseudoSelectors(inheriters.within, selector);
				
				if(k+1 == a.length){
					matches = matches.concat(inheriters.within);
				}
				
				return true;
				
			}
			
			
			///look for classNames///
			var period_pos = selector.indexOf(".");
			//check for position of css attribute selectors to make sure period isn't in them
			var left_bracket_pos = selector.indexOf("[");
			var right_bracket_pos = selector.indexOf("]");
			
			if(period_pos+1 && !(period_pos > left_bracket_pos && period_pos < right_bracket_pos)) {
				
				inheriters.within = sb.$.getElementByClassName(inheriters.within, selector);
				if(k+1 == a.length){
					matches = matches.concat(inheriters.within);
				}
				
				return true;
				
			}
			
			if(selector.match(/\w+\#\w+/)){
			
				inheriters.within = [sb.$.getElementById(selector)];
			
				if(k+1 == a.length){
					matches = matches.concat(inheriters.within);
				}
				
				return true;
			}
			
			//Tag selectors - no class or id specified.
			inheriters.within = sb.$.getElementsByTagName(inheriters.within, selector);
		
			if(k+1 == a.length){
				matches = matches.concat(inheriters.within);
			}
			return true;
				
		});
		
		return matches;
	};
	
	
	sb.$.legacy = function(){
		
		var hasAttr=0, obj = arguments[0], filt =  arguments[1];
			
		if(filt.indexOf('@')+1){
		
			filt = filt.replace(new RegExp("=(.*?)$","flags"), "=\"$1\"");
			
			filt = '['+filt.replace('@', '')+']';
			hasAttr=1;
		}
			
		//if first arg is an object
		if(obj.getElementsByTagName){
			
			//convert old sb @ to new attribute selector style - get rid of this soon
			
			return sb.$(filt, [obj]);
			
		//if both arguments are strings join and send to sb.$
		} else if (typeof obj =='string' && typeof filt =='string') {
			
			if(hasAttr){
			//	alert(obj+filt);
				return sb.$(obj+filt);
			} else { 
				return sb.$(sb.toArray(arguments).join(' '));
			}
		}
		
	};
	
	sb.objects = {
			
		
		serialize : function(o){
			var str, arr, a=[];
		
			sb.objects.forEach.call(o, function(value, prop, object){
				
				if(sb.typeOf(value) == 'array'){
					
					value.forEach(function(v, k){
						a.push(prop+'[]='+encodeURIComponent(v));
					});
					
				} else if(typeof value =='object'){
					
					sb.objects.forEach.call(value, function(v2, k2, o2){
				
						if(typeof v2 == 'object' || sb.typeOf(v2) == 'array'){
							
							str = sb.objects.serialize(v2);
							arr = str.split("&");
							str ='';
							arr.forEach(function(v3, k3, a3){
								arr[k3]= v3.replace(/(.*?)=(.*?)/g, prop+"['"+k2+"']['$1']=$2");
								
							});
					
							a.push(arr.join("&"));
							
						} else {
							a.push(prop+"['"+k2+"']="+encodeURIComponent(v2));
						}
					});
				} else {
					a.push(prop+'='+encodeURIComponent(value));
				}
			});
				
			return a.join("&");
		},
		
		
		infuse : function(from, to){
			
			to = to || this;
			from = from || {};
			sb.objects.forEach.call(from, function(val,prop,o){
			
				try{ to[prop] = val;} catch(e){}
			});
			from = null;
			return to;
		},
		
		
		
		copy : function(o){
			var copy = {};
			
			sb.objects.forEach.call(o, function(val,prop,obj){
				copy[prop] = val;
			});
			
			return copy;
		},
		
		
		dump : function(o, pre){
				var prop,str ='';
				sb.objects.forEach.call(o, function(v,p,o){
					try{
						str+="\n\n"+p+' = '+v;
					} catch(e){
						str += "\n"+p+' = CANNOT PROCESS VALUE!';
					}
				});
				
				if(!pre){ return str;} else { return '<pre style="margin:5px;border:1px;padding:5px;">'+str+'</pre>';}
		
		},
		
		forEach : function(func){
			for(var prop in this){
				if(this.hasOwnProperty(prop) && !sb.objects[prop] || prop =='infuse'){
					func(this[prop], prop, this);
				}
			}
		}
	};
	
	
	sb.infuse = sb.objects.infuse;
	
	
	sb.ajax = function(params){ 
		
		try{this.o=new window.XMLHttpRequest();}catch(e){
			try{this.o=new window.ActiveXObject("Microsoft.XMLHTTP");}catch(e3){
				throw('This browser does not support surebert');
			}
		}
		
		sb.objects.infuse(params, this);
		
		if(sb.typeOf(params.data) == 'object'){
			this.data = sb.objects.serialize(params.data);
		}
	};
	
	
	sb.ajax.infuse = sb.objects.infuse;
	
	sb.ajax.infuse({
		
		log : function(){},
		
		
		defaultMethod : 'post',
		
		
		defaultFormat : 'text',
		
		
		defaultURL : ''
		
	});
	
	sb.ajax.prototype = {
		
		
		completed : 0,
		
		
		debug : this.debug || 0,
		
		
		data : this.data || '',
		
		
		format : this.format || '',
		
		
		async : this.async,
		
		
		local : this.local || 0,
		
		
		onreadystatechange : function() {
			var message = '';
			var js='';
			
			if (this.o.readyState != 4 || this.completed == 1) {return true; }
			
			this.completed =1;
	
			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){
					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';
					} else if(this.contentType.match('boolean')){
						this.format = 'boolean';
					}
				} else {
					this.format = sb.ajax.defaultFormat;
				}
			} 
			
			this.log(2, "\nHEADERS\nStatus: "+this.o.status+"\nStatus Text: "+this.o.statusText+"\n"+this.o.getAllResponseHeaders()+"\nRESPONSE: \n"+(sb.strings.escapeHTML.call(this.o.responseText) ||'PAGE WAS BLANK ;(')+"\n");
			
			//page status other than 200
			if(this.o.status != 200 && this.local !==1){
				return false;
			}
		
			
			if(typeof this.timer !='undefined'){
				window.clearInterval(this.timer);
			}
			
			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.log(3);
					}
					break;
				
				case 'js':
					js =  this.o.responseText;
					break;
					
				case 'json':
					js = 'this.response='+this.o.responseText;
					break;
					
				case 'boolean':
					this.response = (this.o.responseText === 0) ? 0 : 1;
					break;
				
				default:
					this.response = this.o.responseText;
			}
		
			if(js !==''){
				try{
					 eval(js);
				}catch(e2){
					this.log(4);
				}
			}
			
			if(typeof this.handler =='function'){this.handler(this.response);}
			
			if(typeof this.node !='undefined'){
				
				if(sb.$(this.node)){
					this.node = sb.$(this.node);
					if(typeof this.node.value !='undefined'){
						this.node.value = this.o.responseText;
					} else {
						this.node.innerHTML = this.o.responseText;
					}
				} else {
					this.addToLog(5);
				}
			}
			
			this.o.abort();
			return this; 
		},
	
		log : function(logId, message){
			if(this.debug ==1){
				
				var info = (message || '')+"\nSENT\nURL: ";
				if(this.method == 'get'){
					info += '<a href="'+this.url+'?'+this.data+'">'+this.url+'?'+this.data+'</a>';
				} else {
					info += this.url;
				}
				
				info += "\nMETHOD: "+this.method+"\nFORMAT: "+this.format+"\nASYNC: "+this.async+"\nDATA: "+this.data;
				
				sb.ajax.log(logId, info);
				if(typeof this.onLog == 'function'){
					
					this.onLog(logId, info);
				}
			}
		},
		
		
		timeout : 0,
		
		
		fetch : function(url) {
			this.completed =0;
			
			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){
				return false;
			}
			
			if(typeof t.async =='undefined'){
				t.async=true;
			}
			
			t.log(1);
			
			t.o.onreadystatechange = function(){t.onreadystatechange();};
		
			if(sb.typeOf(t.data) == 'object'){
				t.data = sb.objects.serialize(t.data);
			}
		
			if(t.method=='get' && t.data !== undefined){
				url = url+'?'+t.data;
			}
			
			if(t.timeout){
				
				t.count = 0;
				
				t.timer = window.setInterval(function(){
					if(t.count >= t.timeout){
						t.abort();
						t.count = 0;
						
						if(typeof t.onTimeout == 'function'){
							t.timeout();
						}
						
						window.clearInterval(t.timer);
					} else {
					
						t.count++;
					}
				}, 1);
			}
			
			t.o.open(t.method, url, t.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(e1){}
			
			if (!t.async ){ t.onreadystatechange();}
			
		},
		
		
		abort : function(){
			this.o.abort();
			
			if(typeof this.onmillisec !='undefined'){
				this.timer.reset();
			}
			
			if(typeof this.onabort =='function'){
				this.onabort();
			}
			
		},
		
		
		infuse : sb.objects.infuse
	};
	
	sb.dom = {
	
		
		
		onReady : function(o){
			var found =0, timer, count=0;
			o.args = o.args || [];
			o.interval = o.interval || 10;
			
			o.tries = o.tries || 600;
			if(o.tries == -1){o.tries =99999999;}
			
			if(typeof o.onReady=='function'){
				
				timer = window.setInterval(function(){
					
					count +=1;
					
					if(count >= o.tries){
						window.clearTimeout(timer);
						
						if(typeof o.onTimeout=='function'){
							o.onTimeout(o.id);
						}
						return;
					}
					
					if(o.id == 'body' && document.body){
						window.clearTimeout(timer);
						found=1;
						o.id = document.body;
					} else if(o.id !='body' && sb.$(o.id)){
						
						window.clearTimeout(timer);
						found=1;
					}
					
					if(found ==1){
						o.onReady.apply(sb.$(o.id), o.args);
						
					}
					
				}, o.interval);
				
			} else {
				throw('sb.dom.onReady: You object argument must have a onReady property that runs when the dom element "'+o.id+'" is available');
			}
		},
		
		
		singleTags : ['html', 'body', 'base', 'head', 'title']
		
	};
	
	
		
	sb.arrays = {
		
		
		inArray : function(val){
			return this.some(function(v){return v===val;});
		},
		
		remove : function(values){
			
			return this.filter(function(v){
				if(sb.typeOf(values) !='array'){
					return v != values;
				} else {
					return !sb.arrays.inArray.call(values, v);
				}
			});
		}
	};
	
	
	sb.colors =  {
		
		
		dec2hex : function(dec){
			return(this.hexDigit[dec>>4]+this.hexDigit[dec&15]);
		},
		
		hexDigit : ["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"],
		
		
		hex2dec : function(hex){
			return parseInt(hex,16);
		}
	};
	
	
	sb.strings = {
		
		
		escapeHTML : function(){
			var str = this.replace(/</g, '&lt;');
			return str.replace(/>/g, '&gt;');
		},
		
		isNumeric : function(){
			return /^\d+?(\.\d+)?$/.test(this);
		},
		
		
		hex2rgb : function(asArray){
			var hex = sb.strings.trim.call(this).replace("#", "");
			var rgb = parseInt(hex, 16); 
			var r   = (rgb >> 16) & 0xFF;
			var g = (rgb >> 8) & 0xFF; 
			var b  = rgb & 0xFF;
			
			if(asArray){
				return [r,g,b];
			} else {
				return 'rgb('+r+', '+g+', '+b+')';
			}
		},
		
		
		toCamel : function(){
			return String(this).replace(/-\D/gi, function(m){
				return m.charAt(m.length - 1).toUpperCase();
			});
		},
		
		
		toElement : function(parentNodeType){
			parentNodeType = parentNodeType || 'span';
			
			var temp = new sb.element({
				nodeName : parentNodeType,
				innerHTML : this
			});
			
			if(temp.childNodes.length > 1){
				return sb.s$(temp);
			} else {
				return sb.s$(temp.firstChild);	
			}
			
		},
	
		
		trim : function() {
			var str = this.replace(/^\s+/, '');
			return str.replace(/\s+$/, '');
		}
		
	};
	
	
	
	sb.styles = {
		
		
		numRules : 1,
		
		
		sheets : [],
		
		
		
		pxProps : ['fontSize', 'width', 'height', 'padding', 'border', 'margin', 'left', 'top']
		
	};
	
	
	sb.events = {
		
		
		
		add : function() {
			
		    if(window.addEventListener){
		   
		        return function(el, type, fn) {
		        	el = sb.$(el);
		        	var evt = {el:el, type:type, fn:fn};
		            el.addEventListener(type, fn, false);
		            return sb.events.record(evt);
		        };
		    } else if ( window.attachEvent){
		        return function(el, type, fn) {
		        	el = sb.$(el);
		        	
		            var f = function() {
		                fn.call(el, window.event);
		            };
		            var evt = {el:el, type:type, fn:f};
		            el.attachEvent('on'+type, f);
		             return sb.events.record(evt);
		        };
		    }
		}(),
		
		
		log : [],
		
		
		preventDefault : function(e){
			 
			if(typeof e.stopPropagation == 'function'){
				e.preventDefault();
			} else {
				e.returnValue = false;
			} 
		},
		
		record : function(evt){
			sb.events.log.push(evt);
			return evt;
		},
		
		
		
		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;
			}
			
			try{
				
				if (tar.nodeType && (tar.nodeType== 3 || tar.nodeName == 'EMBED')){
				  tar = tar.parentNode;
				}
				
			} catch(error){
				
				tar = sb.events.target(e);
				
			}
			return sb.s$(tar);
		},
			
		
		remove : function(evt){
		
			if (evt.el.removeEventListener){
				evt.el.removeEventListener( evt.type, evt.fn, false );
			} else if (evt.el.detachEvent){
				evt.el.detachEvent( "on"+evt.type, evt.fn );
			}
			
		},
		
		
		removeAll: function(){
			sb.events.log.forEach(function(evt){
				sb.events.remove(evt);
			});
			sb.events.log=[];
		},
	
		
		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;
			} 
		},
		
		
		target : function(e){
			var tar = (e.target !==undefined) ? e.target : e.srcElement;
		   
		   if (tar.nodeType && (tar.nodeType== 3 || tar.nodeName == 'EMBED')){
		      tar = tar.parentNode;
		   }
		
		   return sb.s$(tar);
		}
		
	};
	
	
	sb.element = function(o){
		var el,c;
	
		if(sb.typeOf(o) == 'sb.element'){
			return o;
		}
		if(sb.typeOf(o)=='object' ){
			if(o.tag == 'input' && sb.dom.createNamedElement){
				el = new sb.dom.createNamedElement(o.type, o.name);
			} else {
				el = document.createElement(o.tag);
			}
		}
		
		//copy properties from the sb.element prototype
		sb.objects.infuse(sb.element.prototype, el);
		o = sb.objects.copy(o);
		 
		if(typeof o.addAttributes !='undefined'){
			this.setAttributes.call(el, o.addAttributes);
			delete o.addAttributes;	
		}
		
		if(typeof o.styles !='undefined'){
			this.styles.call(el, o.styles);
			delete o.styles;	
		}
		
		if(typeof o.children !='undefined'){
			for(c=0;c<o.children.length;c++){
				el.appendChild(new sb.element(o.children[c]));
			}
			delete o.children;
		}
		
		if(typeof o.events !='undefined'){
			sb.objects.forEach.call(o.events, function(func,event,obj){
				el.event(event, func);
			});
			
			delete o.events;
		}
		
		//copy additional props from o
		sb.objects.infuse(o, el);
		
		try{
			//remove attributes for ie's sake
			el.removeAttribute('tag');
		}catch(e){
			sb.consol.log("Error building new sb.element: "+sb.objects.dump(o));
		}
		return el;
	};
	
	
	
	sb.element.prototype = {
		
		s$ : function(pattern){
			return sb.s$(this, pattern);	
		},
		
		addClassName : function(className){
			this.className += ' '+className;
			
			return this;
		},
	  
		
		setAttributes : function(o){
			var t=this;
			sb.objects.forEach.call(o, function(val,prop,o){
				t.setAttribute(prop, val);
			});
			return this;
		},
		
		
		append : function(el){return this.appendChild(sb.$(el));},
		
		
		appendTo : function(el){
			return sb.$(el).appendChild(this);
		},
		
			
		appendToTop : function(el){
			el = sb.$(el);
		
			if(el.childNodes.length ===0){
				return this.appendTo(el);
			} else {
				return this.appendBefore(el.firstChild);
			}
		},
	
		
		appendAfter : function(after){
			
			var el = sb.s$(after);
			
			var nxtSib = el.getNextSibling();
			
			if(nxtSib){
				return nxtSib.parentNode.insertBefore(this, nxtSib);
			} else {
				return this.appendTo(el.parentNode);
			}
			
		},
		
		
		appendBefore : function(before){
			before = sb.$(before);
			return before.parentNode.insertBefore(this, before);
		},
		
		
		event : function (evt, func){
			
			var event = sb.events.add(this, evt, func);
			this.eventsAdded.push(event);
			this.lastEventAdded = event;
			return this;
			
		},
		
		
		lastEventAdded : [],
		
		
		eventsAdded : [],
		
		
		events : function(events){
			for(var event in events){
				if(typeof events[event] =='function'){
					this.event(event, events[event]);
				}
			}
			
			return this;
		},
		
		
		eventRemove : function (evt){
			sb.events.remove(evt);
			return this;
		},
		
		
		eventsRemoveAll : function(){
			this.eventsAdded.forEach(function(evt){
				sb.events.remove(evt);
			});
			this.eventsAdded = [];
			return this;
		},
		
		
		infuse : function(o){
			sb.objects.infuse(o, this);
			
			return this;
		},
		
		
		
		getPosition : function(params){
			params = params || {};
			var orig = this;
		
			var el=this;
			
			orig.top =0;
			orig.left =0;
			
			do{
				orig.top += el.offsetTop;
				orig.left += el.offsetLeft;
				
				if(params.pos =='rel'){
					el = false;
				} else{
					try{el = el.offsetParent;}catch(e){el = false;}
					
				}
			} while(el);
			
			if(params.accountForScrollBar){
				sb.browser.getScrollPosition();
				if(sb.browser.scrollY){
					orig.top -=sb.browser.scrollY;
				}
				
				if(sb.browser.scrollX){
					orig.left -=sb.browser.scrollX;
				}
			}
			
			orig.getDimensions();
			
			//alias for w and h
			orig.w = orig.width;
			orig.h = orig.height;
			orig.bottom = orig.top+orig.width;
			orig.right = orig.left+orig.height;
			
			return orig;	
		},
	
		
		getDimensions : function() {
			
		    var display = this.getStyle('display');
		    // Safari bug
		    if (display != 'none' && display !== null) {
		    	this.width = this.offsetWidth;
		    	this.height = this.offsetHeight;
		     
		    } else {
		    	
			    // All *Width and *Height properties give 0 on els with display none,so enable the el temporarily
			
			    var origStyles = {
			    	visibility : this.style.visibility,
			    	position : this.style.position,
			    	display : this.style.display
			    };
			    
			    this.styles({
			    	visibility : 'hidden',
			    	position : 'absolute',
			    	display : 'block'
			    });
				
			  	this.width = this.clientWidth;
			  	this.height = this.clientHeight;
			  	this.styles(origStyles);
		    }
		    return this;
		},
		
		getFirstChild : function(){
			return sb.$.getFirstChild(this);
		},
		
		
		getLastChild : function(){
			return sb.$.getLastChild(this);
		},
		
		
		getWidth : function(){
			return this.getDimensions(this).width;
		},
			  
		
		getHeight : function(){
			return this.getDimensions(this).height;
		},
	
		
		getNextSibling : function(){
			return sb.s$(sb.$.getNextSibling(this));
		},
		
		
		getPreviousSibling : function(){
			return sb.s$(sb.$.getPreviousSibling(this));
		},
		
		
		getX : function(){
			var x = 0, el=this;
			while(el !== null){
				x += el.offsetLeft;
				el = el.offsetParent;
			}
			return x;
		},
		
		
		getY : function(){
			var y = 0, el=this;
			while(el !== null){
				y += el.offsetTop;
				el = el.offsetParent;
			}
			return y;
		},
		
		
		hasClassName: function(c){
			return sb.arrays.inArray.call(this.className.split(' '), c);
		},
		
		
		hide : function(){
			this.style.display = 'none';
			return this;
		},
		
		
		mv : function(x,y,z){
			
			this.style.left = x+'px';
			this.style.top = y+'px';
			if(z){
				this.style.zIndex = z;
			}
			
			if(this.getStyle('position') == 'static'){this.style.position = 'absolute';}
			
			this.getPosition();
			return this;
		},
		
		
		remove : function(){
			if(typeof this.parentNode !='undefined'){
				this.parentNode.removeChild(this);
			}
			return this;
		},
		
		
		removeClassName : function(className){
			var a = this.className.split(' ');
			this.className = sb.arrays.remove.call(a, className).join(' ');
			return this;
		},
		
		
		replace : function(node){
			node = sb.$(node);
			if(typeof node.parentNode !='undefined'){
				node.parentNode.replaceChild(this, node);
			}
			node = null;
			return this;
		},
		
		
		show : function(){
			try{
			this.style.display = (this.getStyle('display')=='none') ? 'block' : this.getStyle('display'); 
			} catch(e){
				this.style.display='block';
			}
			return this;
		},
		
		
		styles : function(params){
			
			for(var prop in params){
				
				this.setStyle(prop, params[prop]);
			}
			
			return this;
		},
		
		
		getStyle : function(prop){
			var val;
			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 (this.style[prop]) {
					val = this.style[prop];
					
				} else if (this.currentStyle) {
					
					prop = sb.strings.toCamel.call(prop);
					val = this.currentStyle[prop];
					
				} else if (document.defaultView && document.defaultView.getComputedStyle) {
						
					prop = prop.replace(/([A-Z])/g, "-$1");
					prop = prop.toLowerCase();
					
					val = document.defaultView.getComputedStyle(this,"").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.html !='undefined'){
						if(sb.colors.html[val]){
							val = sb.strings.hex2rgb.call(sb.colors.html[val]);
						}
					}
					
					if(val.match("^#")){
						val = sb.strings.hex2rgb.call(val);
					}
				
					return val;
				} else {
					return null;
				}
				
			} catch(e){
				sb.consol.log(sb.messages[18]+prop+"\nID: #"+this.id+"\nError: "+e);
			}
		},
		
		setStyle : function(prop, val){
			
				if(sb.arrays.inArray.call(sb.styles.pxProps, prop) && val !=='' && !val.match(/em|cm|pt|px|%/)){
					val +='px';
				}
				
				prop = sb.strings.toCamel.call(prop);
			
				if(prop == 'opacity'){
					if(val <= 0){ val =0;}
					if(val >= 1){ val =1;}
					this.style.opacity = val;
					
					if(typeof this.style.filter == 'string' && sb.browser.ie6===1){
						this.style.filter = "alpha(opacity:"+val*100+")";
					}
					
				} else {
					
					try{
						this.style[prop] = val;
					}catch(e){}
				}
		},
		
		
		toggle : function(){
			if(this.style){
				this.style.display = (this.getStyle('display') ==='none') ? '' : 'none';
			}
			return this;
		},
		
		typeOf : function(){
			return 'sb.element';
		},
		
		
		unsetAttributes : function(a){
			var t=this;
			a.forEach(function(v){
				t.setAttribute(v, '');
			});
			return this;
		},
		
		
		wh : function(w,h){
			this.style.width = w+'px';
			this.style.height = h+'px';
			return this;
		}
	};
	
	
	
	sb.nodeList = function(nodes){
			
		this.nodes = nodes;
		
		for(var prop in sb.element.prototype){
			if (sb.typeOf(sb.element.prototype[prop]) == 'function') {
				this[prop] = this.addElementPrototypes(prop);
			}
			
		}
		
	};
	
	sb.nodeList.prototype  = {
		
		
		add : function(el){
			el = sb.s$(el);
			if(sb.typeOf(el) == 'array'){
				for(var i=0;i<el.length;i++){
					this.nodes.push(el[i]);
				}
			} else {
				this.nodes.push(el);
			}	
			
			return this;
		},
		
		
		drop : function(el){
			
			var t = this;
			el = sb.s$(el);
			
			this.nodes = t.nodes.filter(function(v){
				if(sb.typeOf(el) == 'sb.element'){
					return v != el;
				} else {
					return !el.nodes.some(function(v1){return v===v1;});
					
				}
				
			});
			return this;
		},
		
		
		nodes : [],
		
		
		addElementPrototypes : function(func){
			var t = this;
			return function(){
				
				var args = arguments;
				
				t.nodes.forEach(function(node){
					if(sb.typeOf(node) == 'sb.element'){
						node[func].apply(node, args);
					}
			
				});
				return this;
	
			};
		},
		
		
		typeOf : function(){
			
			return 'sb.nodeList';
		}
	};
	
	
	sb.math = {
		
		flip : function(a){
			return (a===1) ? 0 : 1;	
		}
	};
		
	(function(){
		if(!Array.prototype.forEach){
			sb.include('arrays.js1_5');
		}
		if(sb.browser.ie6){
			sb.include('ie6');
		} else {
			
			sb.ie6 = {
				pngFix: function(){},
				pngFixBg: function(el){}
			};
		}
		
		if(typeof window.sbNoGlobals === 'undefined'){
			//if globals are enabled add them
			sb.addGlobals();
			
		}
		
	})();
		
	sb.dom.onReady({
		id : 'body',
		onReady : function(){
			sb.onbodyload.forEach(function(v){
				if(typeof v == 'function'){
					v();
				}
			});
		},
		tries : 600,
		ontimeout : function(){
			if(typeof sb.onbodynotready =='function'){
				sb.onbodynotready();
			}
		}
	});
	
	sb.events.add(window, 'resize', sb.browser.measure);
	sb.events.add(window, 'scroll', sb.browser.getScrollPosition);
	sb.events.add(window, 'unload', function(e){
		sb.onleavepage.forEach(function(v){
			if(typeof(v) =='function'){v(e);}
		});
		sb.events.removeAll();
	});
	window.sb = sb;
	window.Sb = sb;
})();