
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.functions){
			Function.prototype[prop] = sb.functions[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];
			}	
		}
		
		if(typeof Element !='undefined' && typeof sbSuperElements !='undefined'){
			for(prop in sb.element.prototype){
				Element.prototype[prop] = sb.element.prototype[prop];
			}
		}
		
		//add global links to internal sb functions
		sb.globals = {
			$ : sb.$,
			s$ : sb.s$,
			$_GET : sb.$_GET,
			ajax : sb.ajax,
			events : sb.events,
			forget: sb.cookies.forget,
			importNode : sb.dom.importNode,
			recall: sb.cookies.recall,
			remove : sb.dom.remove,
			replace : sb.dom.replace,
			remember: sb.cookies.remember,
			txt : sb.dom.txt,
			typeOf : sb.typeOf
		};
		
		for(var g in sb.globals){
			sb.createIfNotExists(g, sb.globals[g]);
		}
		
		if(!document.importNode){
			document.importNode = sb.dom.importNode;
		}	
	},
	
	
	$_GET : [],
	
	
	base : (typeof sbBase !='undefined') ? sbBase : '../surebert',
	
	
	consol : {
		log : function(){},
		write : function(){},
		error : function(){},
		dump : function(){},
		swfDebug : function(){}
	},

	
	createIfNotExists : function(i, o){
		if(!window[i] && o!==null){
			window[i] = o;
		}
	},
	
	
	include : function(module){
		return sb.load(sb.base+'/'+module+'.js');
	},
	
	
	keepTrying : function(){
		for(var x=0;x<arguments.length;x++){
			try{return arguments[x]();} catch(e){}
		}
	},
	
	
	load : function(url){
		var evaled = 0;
		
		(function(){
			var load = new sb.ajax({
				url : url,
				async : 0,
				method : 'get',
				handler: function(r){
			
					try{
						eval(r);
						evaled=1;
					}catch(e){
						evaled=0;
						delete e.stack;
						sb.consol.error(url+ sb.messages[13]+"\n"+sb.objects.dump(e));
						
					}
					load=null;
				}
			}).fetch();}());
		return evaled;
	},
	

	messages : new Array(50),
	
	
	onbodyload : [],
	
	
	onleavepage : [],
	
	
	s$ : function(el, fil){
		
		var nodes;
		try{
		
			nodes = sb.$.apply(this, sb.toArray(arguments));
			
			if(sb.typeOf(nodes) == 'array'){
				nodes = nodes.map(function(node){
					
					sb.objects.importPrototypesAsProperties(sb.element, node);
					return node;
				});
				
				nodes = new sb.nodeList(nodes);
			} else {
				sb.objects.importPrototypesAsProperties(sb.element, nodes);
			}
			
			
			return nodes;
		} catch(e){
			//throw('s$ node "'+el+'" does not exist');
			
			sb.consol.error('"'+el+'"' +sb.messages[14]+sb.objects.dump(e));
			return false;
		}
	},
	
	
	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);
	},
	
	
	widget : {}
	
};


sb.ie6 = {
	pngFix: function(){},
	pngFixBg: function(){}
};


sb.browser ={
	
	
	ie6 : 0,
	
	
	getAgent : function(){
		var outdated = (typeof sbOutdatedBrowser == 'function') ? sbOutdatedBrowser : 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 = window.navigator.userAgent;
		var str;
		
		if(window.opera && document.childNodes) {
			this.agent = 'op';
			this.version =7;
			str = window.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;
			sb.browser.ie6 =1;
		} 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';
		}
		
		if((this.agent.match(/ff/) && this.version < 1.5) || (this.agent.match(/ie/) && this.version < 6) || (this.agent.match(/sf/) && this.version < 1.3) || (this.agent.match(/op/) && this.version < 9)){
		
			outdated({agent : this.agent,version:this.version,os:this.os});
		}
		
		return this.agent;
	},
	
	
	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];
	},
	
	
	removeSelection : function(){
		try{
			if(window.getSelection){
				window.getSelection().removeAllRanges();
			} else if(document.selection){
				document.selection.empty();
			}
		}catch(e){}
	},
	
	
	populateGET : function (){
		var i,s,val,key;
		var q = window.location.search.substring(1);
		var v = q.split("&");
	
		for (i=0;i<v.length;i++) {
			s = v[i].split("=");
			key = unescape(s[0]);
			val = unescape(s[1]);
			sb.$_GET[key] = val.replace("+", " ");
		 }
	},
	
	
	init : function(){
		if(window.location.search !==''){this.populateGET();}
		
		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?'));
		
		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 = sb.$.attrConvert(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(nth[1].isNumeric()){
					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 = 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.$.attrConvert = function(attr){
	
	if(sb.browser.agent=='ie'){
		switch(attr){
			
			case 'cellindex':
				attr = 'cellIndex';
				break;
			case 'class':
				attr = 'className';
				break;
			case 'colspan':
				attr = 'colSpan';
				break;
			case 'for':
				attr = 'htmlFor';
				break;
			case 'rowspan':
				attr = 'rowSpan';
				break;
			case 'valign':
				attr = 'vAlign';
				break;
		}
	}
	return attr;
};


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 prop,val, str, arr, a=[];
		
		for(prop in o){
			if(sb.typeOf(o[prop]) == 'array'){
				o[prop].forEach(function(v,k){
					a.push(prop+'[]='+encodeURIComponent(v));
				});
				
			} else if(typeof o[prop] =='object' && !sb.typeOf(o[prop]) =='array'){
				
				for(var p in o[prop]){
					if(typeof o[prop][p] == 'object'){
						str = sb.objects.serialize(o[prop][p]);
						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("&");
	},
	
	importPrototypes : function(from, toObj){
		from = from || {};
		for(var prop in from.prototype) {
			toObj.prototype[prop] = from.prototype[prop];
		}
		from = null;
		return toObj;
	},
	
	
	importProperties : function(from, toObj){
		
		from = from || {};
		for(var prop in from) {
			try{ toObj[prop] = from[prop];} catch(e){}
		}
		from = null;
		return toObj;
	},
	
	
	importPrototypesAsProperties : function(from, toObj){
		from = from || {};
		for(var prop in from.prototype) {
			toObj[prop] = from.prototype[prop];
		}
		from = null;
		return toObj;
	},
	
	
	importPropertiesAsPrototypes : function(from, toObj){
		from = from || {};
		for(var prop in from) {
			toObj.prototype[prop] = from[prop];
		}
		from = null;
		return toObj;
	},
	
	
	extend : function(from){
		return sb.objects.importProperties(from, this);
	},
	
	
	
	copy : function(o){
		var copy = {};
		for(var prop in o){
			copy[prop] = o[prop];
		}
		return copy;
	},
	
	
	alert : function(o){
		alert(sb.objects.dump(o));
	},
	
	
	dump : function(o, pre){
			var prop,str ='';
			for(prop in o){
				try{
					str+="\n"+prop+' = '+o[prop];
				} catch(e){
					str += "\n"+prop+' = CANNOT PROCESS VALUE!';
				}
			}
			
			if(!pre){ return str;} else { return '<pre style="margin:5px;border:1px;padding:5px;">'+str+'</pre>';}
	
	}
};


sb.ajax = function(params){ 
	
	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.importProperties(params, this);
};


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 = {
	
	
	completed : 0,
	
	
	debug : this.debug || 0,
	
	
	data : this.data || '',
	
	
	format : this.format || '',
	
	
	async : this.async,
	
	
	onlog :'',
	
	
	local : this.local || 0,
	
	
	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() {
		
		if (this.o.readyState != 4 || this.completed == 1) {return; }
			this.completed =1;
			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(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(9);
			}
		}
		
		this.o.abort();
		return; 
	},
	
	
	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){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'){
			if(typeof sb.timer =='undefined'){sb.include('sb.timer');alert(sb.timer);}
			
			t.timer = new sb.timer({
				milliseconds : 1,
				handler :  function(){t.onmillisec();}
			});
		
			t.timer.begin();
		}
		
		if(typeof t.onfetch == 'function'){
			t.onfetch();
		}
		
		if(typeof(t.async) =='undefined'){
			t.async=true;
		}
		
		
		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(e){}
		
		
		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();
		}
		
	},
	
	
	extend : sb.objects.extend
};


sb.css = function(prop, val){

	if(val){
		sb.styles.write(this, prop, val);
	} else {
		return sb.styles.read(this, prop);
	}
};

sb.dom = {

	
	
	addPosition : function(params){
		params = params || {};
		var orig = params.el || 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.scroll){
			sb.browser.scrollPos();
			if(sb.browser.scrollY){
				orig.top -=sb.browser.scrollY;
			}
			
			if(sb.browser.scrollX){
				orig.left -=sb.browser.scrollX;
			}
		}
		
		orig.addDimensions();
		
		//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;	
	},
	
	
	addDimensions : function(el) {
		
	    var display = el.css('display');
	    // Safari bug
	    if (display != 'none' && display != null) {
	    	el.width = el.offsetWidth;
	    	el.height = el.offsetHeight;
	     
	    } else {
	    	
		    // All *Width and *Height properties give 0 on els with display none,so enable the el temporarily
		
		    var origStyles = {
		    	visibility : el.style.visibility,
		    	position : el.style.position,
		    	display : el.style.display
		    };
		    
		    sb.element.prototype.styles.call(el, {
		    	visibility : 'hidden',
		    	position : 'absolute',
		    	display : 'block'
		    });
		    
		  	el.width = el.clientWidth;
		  	el.height = el.clientHeight;
		  	
		  	sb.element.prototype.styles.call(el, origStyles);
	    }
	    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){
			this.className += ' '+c;	
		},
		
		remove : function(c){
			var a = sb.dom.className.toArray.call(this);
			this.className = a.remove(c).join(' ');
		},
		
		toggle : function(c){
			
			if(sb.dom.className.contains.call(this, c)){
				sb.dom.className.remove.call(this, c);
			} else {
				sb.dom.className.add.call(this, c);
			}
		}
	},
	
	
	createNamedElement : function(t, n) {
		var el;
		
		try {
			el = document.createElement('<input type="'+t+'" name="'+n+'">');
		} catch (e) { }
			if (!el || !el.name) { 
			el = document.createElement('input');
			el.type=t;
			el.name=n;
		}
		
		return el;
	},
	
	
	
	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 func property that runs when the dom element '+o.id+' is available');
		}
	},
	
	
	remove : function(node){
		node = sb.$(node);
		if(typeof node.parentNode !='undefined'){
			return node.parentNode.removeChild(node);
		}
	},
	
	
	replace : function(newNode, oldNode){
	
		newNode = sb.$(newNode);
		oldNode = sb.$(oldNode);
		if(typeof oldNode.parentNode !='undefined'){
			return oldNode.parentNode.replaceChild(newNode, oldNode);
		}
	},
	
	
	singleTags : ['html', 'body', 'base', 'head', 'title'],
	
	
	toggle : function(node){
		node = sb.s$(node);
		if(node.style){
			node.style.display = (node.css('display') ==='none') ? 'block' : 'none';
		}
	},
	
	
	txt : function(s){
		return document.createTextNode(s);	
	}
	
};


sb.element = function(o){
	var el,c;
	
	if(typeof o.nodeName =='undefined'){
		o.nodeName = o.nodeName || o.tag;
	}
	
	if(sb.typeOf(o) == 'string'){
		
		return new sb.element(o);
	} else if(sb.typeOf(o)=='object' || sb.typeOf(o) == 'sb.element'){
		if(typeof o.nodeName =='undefined') {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.importProperties(this, el);
	
	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'){
		for(var ev in o.events){
			el.event(ev, o.events[ev]);
		}
		//delete o.events;
	}
	
	
	if(el !=o){
		el.extend(o);
	}
	
	//remove attributes for ie or the props turn to attributes
	el.removeAttribute('tag');
	
	return el;
};



sb.element.prototype = {

	
	addClassName : sb.dom.className.add,
	
	
	addDimensions : function(){
		return sb.dom.addDimensions(this);
	},
  
	
	setAttributes : function(o){
		
		for(var prop in o){
			this.setAttribute(prop, o[prop]);
		}
	},
	
	
	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);
	},

	
	clearPosition : function(){
		
		this.styles({
			position : '',
			zIndex: '',
			left : '',
			top: ''
		});	
	},
	
	
	clearStyles : function(){
		for(var style in this.style){
			try{
				this.style[style] = '';
			}catch(e){}
		}
	},
	
	
	
	css : sb.css,
	
	
	event : function (evt, func){
		//this.events[evt] = func;
		
		var event = sb.events.add(this, evt, func);
		this.eventsAdded.push(event);
		return event;
	},
	
	
	eventsAdded : [],
	
	
	events : function(events){
		for(var ev in events){
			this.event(ev, events[ev]);
		}
	},
	
	
	eventRemove : function (evt){
		return sb.events.remove(evt);
	},
	
	
	eventsRemoveAll : function(){
		this.eventsAdded.forEach(function(evt){
			sb.events.remove(evt);
		});
		this.eventsAdded = [];
	},
	
	
	extend : function(o){
		sb.objects.importProperties(o, this);
	},
	
	
	
	
	addPosition : function(params){
		return sb.dom.addPosition.call(this, params);
	},
	
	
	addPositionRelative : function(params){
		params = params || {};
		params.pos = 'rel';
		return sb.dom.addPosition.call(this, params);
	},
	
	
	addPositionMinusScroll : function(params){
		params = params || {};
		params.scroll = 1;
		return sb.dom.addPosition.call(this, params);
	
	},

	
	getAncestors : function(within){
		if(within){
			within = sb.s$(within);
		}
		
		var ancestors =[], el=this;
		
		do{
			if(typeof el =='object' && el.parentNode && el.parentNode.nodeName !='HTML' && el.parentNode !=document && el.parentNode != within){
				el = el.parentNode;
				ancestors.push(sb.s$(el));
			} else {
				el = false;
			}
			
		} while(el);
		
		return ancestors;
	},
	
	
	getDescendants : function(){
		return sb.s$(this, '*');
	},
	
	
	getFirstChild : function(){
		return sb.$.getFirstChild(this);
	},
	
	
	getLastChild : function(){
		return sb.$.getLastChild(this);
	},
	
	
	
	getWidth : function(){
		return sb.dom.addDimensions(this).width;
	},
		  
	
	getHeight : function(){
		return sb.dom.addDimensions(this).height;
	},
	
	
	getElementsByClassName : function(className){
		var children = this.getElementsByTagName('*');
		
		children = sb.toArray(children);
		children = children.filter(function(child){
			if(child.nodeType !=1){
				return false;
			}
			//new RegExp('(^|\s)'+className+'(\s|$)')
			if(child.className.match(new RegExp("(^|\\s)"+className+"(\\s|$)"))){
				return true;
			}
			return false;
		});
		
		return children;
	},
	
	
	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.dom.className.contains.call(this, c);
	},
	
	
	hide : function(){
		this.style.display = 'none';
	},
	
	
	html : function(html){
		if(html){
			this.innerHTML = html;
		} else {
			return this.innerHTML;
		}
	},
	
	
	
	isDescendantOf : function(el){
	
		return sb.s$(el).getDescendants().inArray(this);
	},
	
	
	mv : function(x,y,z,pos){
		pos = pos ||'absolute';
		if(this.style.position===''){this.style.position= pos;}
		this.style.left = x+'px';
		this.style.top = y+'px';
		this.style.zIndex = z;
		this.addPosition();
	},
	
	
	opacity : function(o){
		if(String(o).isNumeric()){
			sb.styles.write(this, 'opacity', o);
			
		} else {
			
			return this.css('opacity') || 1;
		}
	},
	
	
	remove : function(){
		if(typeof this.parentNode !='undefined'){
			this.parentNode.removeChild(this);
		}
	},
	
	
	removeClassName : function(c){
		sb.dom.className.remove.call(this, c);
	},
	
	
	replace : function(node){
		node = sb.$(node);
		if(typeof node.parentNode !='undefined'){
			node.parentNode.replaceChild(this, node);
		}
		node = null;
	},
	
	
	show : function(){
		try{
			this.style.display = (this.css('display')=='none') ? 'block' : this.css('display'); 
		} catch(e){
			this.style.display='block';
		}
	},
	
	
	styles : function(params){
		try{
			sb.objects.importProperties(params, this.style);
		} catch(e){}
	},
	
	
	toggle : function(){
		if(this.style){
			this.style.display = (this.css('display') ==='none') ? '' : 'none';
		}
	},
	
	
	toggleClassName : sb.dom.className.toggle,
	
	typeOf : function(){
		return 'sb.element';
	},
	
	
	unsetAttributes : function(a){
		var t=this;
		a.forEach(function(v){
			t.setAttribute(v, '');
		});
	},
	
	
	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';
	}
};


sb.functions = {
	
	
	fireAfterDelay : function(o){
		
		o.func = this;
		return new sb.fireAfterDelay(o);
		
	},
	
	
	fireRepeatedly : function(o){
		var milliseconds =1000;
		
		if(typeof o == 'object'){
			milliseconds = o.milliseconds || milliseconds;
			if(o.seconds){
				milliseconds = o.seconds*1000;
			}
		} else if(typeof o == 'number'){
			milliseconds = o;
		}
		
		var evt = window.setInterval(this, milliseconds);
	 	return {
	 		abort : function(){window.clearInterval(evt);}
	 	};
	},
	
	
	
	extend: function(o){
		sb.objects.importProperties(o, this);
	},
	
	
	extendInstances : function(o){
		sb.objects.importPropertiesAsPrototypes(o, this);
	},
	
	
	setThis : function(){
		var func = this, args = sb.toArray(arguments), obj = args.shift();
		  return function() {
		    return func.apply(obj, args);
		  };
	}
		
};


	
sb.arrays = {
	
	
	avg : function(){
		var tl = sb.arrays.sum.call(this);
		return tl/this.length;
	},

	
	copy : function(){
		return this.filter(function(){return true;});
	},

	
	empty : function(){
		this.length =0;
		return this;
	},
	
	
	every : function(func){
		var k;
		if(typeof func == 'function'){
			for(k=0;k<this.length;k++){
				
				if(func(this[k], k, this) !== true){
					
					return false;
				}
			}
			return true;
		}
	},
	
	
	filter : function(func){
		var n=[];
		if(typeof func == 'function'){
			this.forEach(function(v,k,arr){
				if(func(arr[k], k, arr) === true){
					n.push(v);
				}
			});
		}
		
		return n;
		
	},
	
	
	forEach : function(func){
		var k;
		if(typeof func == 'function'){
			for(k=0;k<this.length;k++){
				func(this[k], k, this);
			}
		}
	},
	
	
	inArray : function(val){
		return this.some(function(v){return v===val;});
	},
	
	
	indexOf : function(val){
		for(var k=0;k<this.length;k++){
			if(this[k] == val){
				return k;
			}
		}
		return -1;
	},
	
	
	inject : function(index, val){
		if(index <0){return this;}
		var a = this.slice(0, index), b = this.splice(index, this.length-index);
		
		a[index] = val;
		return a.concat(b);
	},
	
	
	lastIndexOf : function(val){
		var p=-1,k;
		for(k=0;k<this.length;k++){
			if(this[k] == val){
				p=k;
			}
		}
		return p;
	},
	
	
	map : function(func){
		var n=[];
		if(typeof func == 'function'){
			this.forEach(function(v,k,a){n.push(func(v,k,a));});
		}
		return n;
	},
	
	
	max : function(){
		 var max=this[0];
		 this.forEach(function(v){max=(v>max)?v:max;});
		 return max;
	},
	
	
	min : function(){
		 var min=this[0];
		 this.forEach(function(v){min=(v<min)?v:min;});
		 return min;
	},
	
	
	mostCommon : function(){
		var count=0,max=0,num=0,mode=0;
		this.sort();
		this.forEach(function(v){
			
			if(num != v){
				num=v;
				count=1;
			} else {
				count++;
			}
			
			if(count > max){
				max = count;
				mode = num;
			}
		});
		if(max ==1){mode = false;}
		return mode;
	},
	
	
	natsort : function(direction){
		direction = (direction ==-1) ? -1 : 1;
		if(direction == -1){
			this.sort(function(a,b){return (b-a);});
		} else {
			this.sort(function(a,b){return (a-b);});
		}
		return this;
	},
	
	
	pointer : 0,
	
	
	current : function(){
		return this[this.pointer];
	},
	
	
	end : function(){
		this.pointer = this.length-1;
		return this[this.pointer];
	},
	
	
	first : function(){
		return this[0];
	},
	
	//ADD DOCS
	cycle : function(){
		var next = this.next();
		if(typeof next == 'undefined'){
			return this.rewind();
		} else {
			return next;
		}
	},
	
	
	last : function(){
		return this[this.length-1];
	},

	
	next : function(){
		this.pointer +=1;
		return this[this.pointer];
	},
	
	
	rewind : function(){
		this.pointer=0;
		return this[this.pointer];
	},

	
	prev : function(){
		this.pointer -=1;
		return this[this.pointer];
	},
	
	
	random : function(){
 		return this[sb.math.rand(0,this.length)];
	},
	
	
	range : function(){
		var a = this.natsort();
		return this[a.length-1]-a[0];
	},
	
	
	remove : function(values){
		
		return this.filter(function(v){
			if(sb.typeOf(values) !='array'){
				return v != values;
			} else {
				return !sb.arrays.inArray.call(values, v);
			}
		});
	},
	
	
	shuffle : function(){
		var i=this.length,j,t;
		
		while(i--)
		{
			j=Math.floor((i+1)*Math.random());
			t=this[i];
			this[i]=this[j];
			this[j]=t;
		}
		return this;
	},
	
	
	sum : function(){
		var val = 0;
		sb.arrays.forEach.call(this, function(v){
			val +=v;
		});
		return val;
	},
	
	
	unique : function(){
		var n=[];
		sb.arrays.forEach.call(this, function(v){if(!sb.arrays.inArray.call(n, v)){n.push(v);}});
		return n;
	},
	
	
	regex: function(expression) {
		
		return sb.arrays.filter.call(this, function(v, k, a) {
		 	if(v.toString().match(expression)){return true;}
		});
		
	},

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


sb.arrays.each = sb.arrays.forEach;



sb.nodeList = function(nodes){
	
	if(!nodes && typeof nodes !='object'){
		nodes = [];
	}

	sb.objects.importProperties(sb.nodeList.methods, nodes);
	
	return nodes;
}

sb.nodeList.methods = {
	
	
	add : function(el){
		el = sb.s$(el);
		if(sb.typeOf(el) == 'array'){
			for(var i=0;i<el.length;i++){
				this.push(el[i]);
			}
		} else {
			this.push(el);
		}	
		
		return this;
	},
	
	
	addClassName : function(name){
		this.forEach(function(node){
			node.addClassName(name);
		});
		return this;
	},
	
	
	
	setAttribute : function(a,v){
		this.forEach(function(node){
			node.setAttribute(a,v);
		});
		return this;
	},
	
	
	css : function(p,v){
		this.forEach(function(node){
			node.css(p,v);
		});
		return this;
	},
	
	
	hide : function(){
		this.forEach(function(node){
			node.hide();
		});
		return this;
	},
	
	
	html : function(html){
		this.forEach(function(node){
			node.html(html);
		});
		return this;
	},
	
	
	parents : function(){
		var parents = [];
		this.forEach(function(node){
			parents.push(node.parentNode);
		});
		return sb.s$(parents);
	},
	
	
	removeClassName : function(name){
		this.forEach(function(node){
			node.removeClassName(name);
		});
		return this;
	},
	
	
	show : function(){
		this.forEach(function(node){
			node.show();
		});
		return this;
	},
	
	
	toggle : function(){
		this.forEach(function(node){
			node.toggle();
		});
		return this;
	}
	
};


sb.nodeList.prototype.addClass = sb.nodeList.prototype.addClassName;


sb.nodeList.prototype.attr = sb.nodeList.prototype.setAttribute;


sb.nodeList.prototype.removeClass = sb.nodeList.prototype.removeClassName;


sb.math = {

	
	rand : function(min,max){
		min = min || 0;
		max = max || 100;
		return Math.floor(Math.random()*max+min);
	},
	
	
	hex2dec : function(hex){
		var val = parseInt(hex,16);
		val = (typeof(val) =='number') ? val : 0;
		return val;
	},
	
	
	dec2hex: function(dec){
		var hex =  dec.toString(16);
		hex = (hex.length <2)? hex+hex : hex;
		return hex;
	}
};


sb.strings = {
	
	
	basename : function(){
		var re = new RegExp("/\\/", "g");
		var str = this.replace(re, "/");
		var filename=str.split("/");
		return filename[(filename.length - 1)];
	},
	
	
	br2nl : function(){
		var re = new RegExp("<[br /|br]>", "ig");
		return this.replace(re, "\n");
	},
	
	
	cleanFileName : function(){
		var ext = this.match(/\.\w{2,3}$/);
		var str = this.replace(/ext/, '');
		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(){
		return (this ==='') ? true : false;
	},
	
	
	escapeHTML : function(){
		var str = this.replace(/</g, '&lt;');
		return str.replace(/>/g, '&gt;');
	},
	
	
	hex2rgb : function(asArray){
		var hex = sb.strings.stripWhitespace.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+')';
		}
	},
	
	
	hilite : function(needle, className){
		className = (typeof className != 'undefined') ? ' class="'+className+'" ' : ' style="background-color:yellow;" ';
		
		var matches = new RegExp( "("+needle+")", "ig");
		return this.replace(matches, "<u "+className+">$1</u>");
	},
	
	
	isNumeric : function(){
		if(sb.typeOf(this) == 'number'){
			return 1;
		}
		var dat,valid = "0123456789.",x;
	
		for (x=0;x<this.length;x++){ 
			dat = this.charAt(x); 
			if (valid.indexOf(dat) == -1){
				 return false;
			}
		}
		return true;
	},
	
	
	linkify : function(target){
		target = target || '_blank';
		var match_url = new RegExp("(\s|\n|)([a-z]+?):\/\/([a-z0-9\-\.,\?!%\*_\#:;~\\&$@\/=\+]+)", "i");
		return this.replace(match_url, "<a href=\"$2://$3\" title=\"$2://$3\" target=\""+target+"\">::link::</a>");
		
	},
	
	
	ltrim : function(){
		return sb.strings.trim.call(this, 'l');
	},
	
	
	nl2br : function(){
		var re = new RegExp("\n", "ig");
		return this.replace(re, "<br />");
	},
	
	
	numpad : function(){
		return (this<=9) ? '0'+this : this;
	},
	
	
	rgb2hex : function(asArray){
		if(!this.match(/^rgb/i)){return false;}
		
		var re = new RegExp('rgb\\((\\d{1,}),(\\d{1,}),(\\d{1,})\\)', "ig");
		var colors = re.exec(sb.strings.stripWhitespace.call(this));
		var r= parseInt(colors[1], 10).toString(16);
		var g= parseInt(colors[2], 10).toString(16);
		var b= parseInt(colors[3], 10).toString(16);
		
		r = (r.length<2) ? r+r : r;
		g = (g.length<2) ? g+g : g;
		b = (b.length<2) ? b+b : b;
		
		if(asArray){
			return [r,g,b];
		} else {
			return '#'+r+''+g+''+b;
		}
	},
	
	
	rtrim : function(){
		return sb.strings.trim.call(this, 'r');
	},
	
	
	substrCount : function(needle, caseInsensitive){
		var matches, ig = (caseInsensitive === undefined) ? 'g' : 'ig';
			
		var re = new RegExp(needle, ig);
		matches = this.match(re);
		if(matches !==null){
			return matches.length;
		} else {
		 	return false;
		}
	},
	
	
	substrReplace : function(replaceWith, start, length){
		return this.replace(this.substring(start, (start+length)), replaceWith );
	},

	
	strstr: function(needle){
		var f= this.indexOf(needle)+1;
		return (f===0) ? 0 :1;
	},
	
	
	stripHTML : function(){
		var re = new RegExp("(<([^>]+)>)", "ig");
		var str = this.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(needle){
		return sb.strings.strstr.call(this, needle, 1);
	},
	
	
	stripWhitespace : function(){
	
		return this.replace(new RegExp("\\s", "g"), "");
		
	},
	
	
	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);	
		}
		
	},
	
	
	toFile : function(params){
		if(typeof params.url =='undefined'){return;}
		
		params.debug = params.debug || 0;
		params.onpass= params.onpass || function(){};
		params.onfail= params.onfail || function(){};
		
		params.handler = params.handler || function(){};
		var xfer = new sb.ajax({
			url:params.url,
			debug:params.debug,
			format :'text',
			method:'post',
			data:'data='+escape(this),
			handler:function(r){
				if(r==1){
					params.onpass();
				} else {
					params.onfail();
				}
			
			}
			
		});
	
		xfer.fetch();
	},
	
	
	toNumber : function(){
		if(this.match(/\./)){
			return parseFloat(this, 10);
		} else {
			return parseInt(this, 10);
		}
	},

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



sb.styles = {
	
	
	
	numRules : 1,
	
	
	sheets : [],
	
	
	
	pxProps : ['fontSize', 'width', 'height', 'padding', 'border', 'margin', 'left', 'top'],
	
	
	writeRule : function(domEl, rule){
		var sheet;
		if(typeof this.sheet ==='undefined'){
			if(document.createStyleSheet) {
				this.sheet = document.createStyleSheet('');
			} else {
			
				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(node, prop){
		node = sb.$(node);
		
		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 (node.style[prop]) {
				val = node.style[prop];
				
			} else if (node.currentStyle) {
				
				prop = sb.strings.toCamel.call(prop);
				val = node.currentStyle[prop];
				
			} else if (document.defaultView && document.defaultView.getComputedStyle) {
					
				prop = prop.replace(/([A-Z])/g, "-$1");
				prop = prop.toLowerCase();
				
				val = document.defaultView.getComputedStyle(node,"").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.call(sb.colors.html[val]);
					}
				}
				
				if(val.match("^#")){
					val = sb.strings.hex2rgb.call(val);
				}
				
				return val;
			} else {
				return null;
			}
			
		} catch(e){}
		
	}, 

	
	write : function(obj,prop,val){
		obj = sb.$(obj);
		val = String(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;}
			obj.style.opacity = val;
			
			if(typeof obj.style.filter == 'string' && sb.browser.ie6===1){
				obj.style.filter = "alpha(opacity:"+val*100+")";
			}
			
		} else {
			
			try{
			obj.style[prop] = val;
			}catch(e){}
		}
		
		return val;
	},
	
	
	copy : function(from, toObj){
		from = sb.$(from);
		toObj = sb.$(toObj);
		
		for(var prop in from.style){
			try{toObj.style[prop] = from.style[prop];}catch(e){}
		}
	}
};


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;
	},
	
	
	
	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(){
	
		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);
			}
		}
	},
	
	
	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;
	}
	
};


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);
	        };
	    }
	}(),
	
	
	getWheelDirection : 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;
		
		return k;
	},
	
	
	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;
		}
		
		return sb.s$(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;
		}
		
		try{
			tar.nodeName;
		} 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 = tar.parentNode;
	   }
	   return tar;
	}
	
};


sb.fireAfterDelay = function(o){
	sb.objects.importProperties(o, this);
	this.milliseconds = this.milliseconds || 1000;
	if(typeof this.seconds!='undefined'){
		this.milliseconds = this.seconds*1000;
	}
	var t=this,a;
	if(typeof o.args !='undefined'){
		a = (o.args.length) ? o.args : []; 
	}
	this.evt = window.setTimeout(function(){t.func.apply(t.func, a);}, this.milliseconds);
};

sb.fireAfterDelay.prototype = {
		
	
	abort : function(){
		window.clearTimeout(this.evt);
	}
};

//###EVERYTHING BELOW THIS POINT IS FOR INTERNAL SETUP###
(function(){

	if(typeof sbNoGlobals === 'undefined'){
		//if gloabls are enabled add them
		sb.addGlobals();
	} else {
		
		//add only javascript 1.6-1.8 array globals
		for(var prop in sb.arrays){
			
			if(typeof Array.prototype[prop] =='undefined' && prop.match(/indexOf|lastIndexOf|filter|forEach|every|map|some|reduce|reduceRight/)){
				
				Array.prototype[prop] = sb.arrays[prop];
			}
		}
	}
})();

sb.dom.onready({
	id : 'body',
	onready : function(){
		sb.onbodyload.forEach(function(v){
			if(typeof v == 'function'){
				v();
			}
		});
		if(sb.browser.ie6===1){
			sb.include('sb.ie6');
		}
	},
	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.scrollPos);
sb.events.add(window, 'unload', function(e){
	sb.onleavepage.forEach(function(v){
		if(typeof(v) =='function'){
			v(e);
		}
	});
	sb.events.removeAll();
});
sb.swf = function(params){
	if(typeof params == 'object'){
		sb.objects.importProperties(params, this);
	} 
	this.width = this.width || '400px';
	this.height = this.height || '300px';
	this.bgColor = this.bgColor || '#FFFFFF';
	this.version = this.version || 5;
	this.alt = this.alt || '';
	this.src = this.src || '';
	this.wmode = this.wmode || '';
	if(typeof this.id =='undefined'){
		this.id = 'sb_swf_'+sb.swf.instanceId;
		sb.swf.instanceId++;
	}
};


sb.swf.prototype = {
	
	
	toHTML : function(){
		var html='';
		
		if(this.version > sb.swf.version){
			return this.alt;
		}
		
		if(sb.swf.format=='embed'){
			
			html = '<embed type="application/x-shockwave-flash" src="'+this.src+'"  id="'+this.id+'" wmode="'+this.wmode+'" allowScriptAccess="always" bgcolor="'+this.bgColor+'" ';
				
			if(typeof this.flashvars =='object'){
				
				html +='FlashVars="'+sb.objects.serialize(this.flashvars)+'" ';
			
			}
			
			html +=' width="'+this.width+'" height="'+this.height+'"  />';
		
		} else if(sb.swf.format=='object'){
				html = '<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="wmode" value="'+this.wmode+'" /><param name="allowScriptAccess" value="always" />';
				if(typeof this.flashvars =='object'){
					html +='<param name="FlashVars" value="'+sb.objects.serialize(this.flashvars)+'">';
				}
				html +='</object>';
		}
		return html;
		
	},
	
	
	embed : function(el){
		sb.$(el).innerHTML =this.toHTML();
		return sb.$('#'+this.id);
		
	}
};

sb.swf.extend = sb.objects.extend;

sb.swf.extend({
	
	version : 4,
	
	
	swfs : [],

	
	instanceId : 0,
	
	
	check : function(){
		var version, description;
		try{
			version = new RegExp("\\d{1}\.\\d{0,5}", "i");
			if(navigator.plugins["Shockwave Flash"]){
				description = navigator.plugins["Shockwave Flash"].description;
				if(description.match(version)){
					sb.swf.version = description.match(version);
				}
				
			}
		} catch(e){sb.swf.version=0;}
		return sb.swf.version;
	},
	
	
	testIe : function(){
		try{
			
			if(new ActiveXObject("ShockwaveFlash.ShockwaveFlash." + sb.swf.version)){
				return false;
			}
		} catch(e){return true;}
			
	},
	
	
	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;
		}
	},
	
	
	cleanup : function() {
		try{
		sb.$('object').forEach(function(obj){
			obj.style.display='none';
			for(var prop in obj){
				if(typeof obj == 'function'){obj[prop] = function(){};}
			}
		});
		}catch(e){}
	},
	
	
	unload : function() {
		__flash_unloadHandler = function(){};
		__flash_savedUnloadHandler = function(){};
		window.attachEvent( "onunload", sb.swf.cleanup );
		
	},
	
	
	detect : function(){
		for(var x=0;x<navigator.plugins.length;x++){
		//	sb.objects.alert(navigator.plugins[x]);
		}
		if (navigator.plugins && navigator.plugins.length){
			sb.swf.format = 'embed';
			return sb.swf.check();
		} else if(sb.browser.agent =='ie'){
			sb.swf.format = 'object';
			return sb.swf.ieCheck();
		} 
	}
	
});

sb.swf.detect();

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


if(typeof sb.swf =='undefined'){
	sb.include('sb.swf');
}


sb.stickerDebug = 0;


sb.onstickerload = [];



sb.sound = function(url, vol){
	
	if(typeof url == 'undefined'){return;}
	this.url = url;
	this.vol = vol || sb.sound.globalVolume;
	sb.sound.sounds.push(this);
}; 

//add extend if globals are turned off
if(typeof sb.sound.extend == 'undefined'){
	sb.sound.extend = function(from){
		return sb.objects.importProperties(from, this);
	};
}
	
sb.sound.extend({
	
	
	stopAll : function(){
		sb.sound.sounds.forEach(function(v){
			v.stop();
		});
	},
	
	
	muteAll : function(){
		sb.sound.sounds.forEach(function(v){
			v.setVolume(0);
		});
	},
	
	
	globalVolume : 50,

	
	
	sounds : [],
	
	
	muted : 0,
	
	
	handlers : {
		
		oncomplete : function(info){
			if(typeof sb.sound.sounds[info.id].oncomplete=='function'){
				sb.sound.sounds[info.id].oncomplete(info);
			}
		},
		
		onid3 : function(info){
			if(typeof sb.sound.sounds[info.id].onid3=='function'){
				sb.sound.sounds[info.id].onid3(info);
			}
		},
		
		onload : function(info){
			if(typeof sb.sound.sounds[info.id].onload=='function'){
				sb.sound.sounds[info.id].onload(info);
			}
		}
	}
});



sb.sound.prototype = {
	
	
	playing :0,
	
	
	play : function(vol){
		if(typeof sb.stickerInit=='undefined'){
			
			if(typeof this.interval !='undefined'){return;}
			
			var t=this;
			this.tries = 0;
			this.interval = window.setInterval(function(){
				if(typeof sb.stickerInit !='undefined'){
					t.play();
					window.clearInterval(t.interval);
				}
				this.tries++;
				
				if(this.tries > 10){
					window.clearInterval(t.interval);
					sb.consol.error(sb.messages[16]+t.url);
				}
			}, 100);
			
			return;
		}
		
		if(sb.sound.muted===1){return;}
		vol = vol || this.vol;
		if(typeof this.id == 'undefined'){
			
			this.id = sb.sticker.soundCreate(this.url, vol);
		} else {
			this.setVolume(vol);
			this.start();
		}
		return this.id;
	},
	
	
	start : function(){
		this.playing =1;
		sb.sticker.soundStart(this.id);
	},
	
	
	stop : function(){
		this.playing =0;
		sb.sticker.soundStop(this.id);
	},
	
	
	setVolume : function(vol){
		sb.sticker.soundSetVolume(this.id, vol);
	},
	
	
	mute : function(){
		this.setVolume(0);
	},
	
	
	setPan : function(pan){
		switch(pan){
			case 'left':
				pan = -100;
				break;
			case 'right':
				pan = 100;
				break;
			case 'middle':
				pan = 0;
				break;
		}
		
		sb.sticker.soundSetPan(this.id, pan);
	},
	
	
	getPan : function(){
		return sb.sticker.soundGetPan(this.id);
	},
	
	
	setPosition : function(position){
		sb.sticker.soundSetPosition(this.id, position);
	},
	
	
	getPosition : function(){
		return sb.sticker.soundGetPosition(this.id);
	}
	
};


sb.sharedObject = {

	
	remember :function(key, v){
	
		try{
			sb.sticker.remember(key,escape(v));
		} catch(e){
			window.setTimeout(function(){sb.sharedObject.remember(key,v);}, 1000);
		}
	},
	
	
	recall : function(key){
		try{
			var val = unescape(sb.sticker.recall(key));
			if(val == 'null'){return false;} else {return val;}
		} catch(e){return false;}
	},
	
	
	forget : function(key){
		try{
			sb.sticker.forget(key);
		} catch(e){return false;}
		return true;
	}
};


sb.persistentData = {
	remember : function(name, value){
		sb.cookies.remember(name, value);
		if(sb.cookies.recall(name) != value){
			
			sb.sharedObject.remember(name, value);
		}
	},

	recall : function(name){
		
		if(sb.cookies.recall(name)){
			return sb.cookies.recall(name);
		} else {
			return sb.sharedObject.recall(name);
		}
	},

	forget : function(name){
		if(sb.cookies.recall(name)){
			sb.cookies.forget(name);
		}
		
		if(sb.sharedObject.recall(name)){
			sb.sharedObject.forget(name);
		}
	}
};


sb.uploadHandlers = {
	
	
	onSelect : function(total){
		
	},
	
	
	onAllComplete : function(data){},
	
	
	onAllProgress : function(files){},
	
	
	onCancel : function(){},
	
	
	onStart : function(file){},
	
	
	onComplete : function(file){},
	
	
	onProgress : function(file, files){},
	
	
	onReturnData : function(data){},
	
	
	onError : function(e){},
	
	
	onExceedsMaxFileSizeK : function(info){},
	
		
	onExceedsMaxFiles : function(info){
		alert("You have chosen "+info.chosen+".  Please select only "+info.limit);
	}
};




sb.upload = function(param){
	sb.consol.error(sb.messages[15]);
};


sb.stickerloaded = function(){
	setTimeout(
		function(){
		
			if(sb.stickerInit == undefined){
				sb.upload = function(params){
					sb.sticker.upload(params);
				};
				
				sb.upload.cancel = function(){
					sb.sticker.cancel();
				};
				
				sb.setStickerDebug = function(state){
					
					sb.stickerDebug = state;
					sb.sticker.setDebug(state);
				};
				
				sb.onstickerload.forEach(function(v){
					if(typeof v =='function'){v();}
				});
				
				sb.stickerInit=1;
				
				if(sb.stickerDebug ==1){
					
					sb.setStickerDebug(1);
				}
			}
	}, 5);
	
	
};

sb.stickerInclude = function(){
	
	var surebertSwf = new sb.element({
		id : 'surebertSwf',
		nodeName : 'div',
		styles : {
			width : '1px',height : '1px'
		}
		
	});
	surebertSwf.appendToTop(document.body);
	
	if(sb.browser.agent =='ff'){
		
		if(window.screenX < 0){
			var screenX =(window.screenX*-1)+20;
			surebertSwf.mv((window.screenX*-1)+20,0,999);
		}
	}
	
	sb.swfBox = new sb.swf({
		src : sb.base+'/surebert.swf',
		width : 1,
		height : 1,
		bgColor :'#000000',
		wmode: 'transparent'
	});
	
	sb.swfBox.id = 'sb_sticker';
	sb.sticker = sb.swfBox.embed(surebertSwf);
	
	
};


sb.soundCheck = function(mp3){
	new sb.sound(mp3 || 'http://surebert.com/song.mp3').play();
};

sb.onbodyload.push(sb.stickerInclude);

if(typeof sbNoGlobals === 'undefined'){
	remember = sb.persistentData.remember;
	recall = sb.persistentData.recall;
	forget = sb.persistentData.forget;
}


sb.element.prototype.cssTransition = function(changes, duration){
	var el = this;
	
	var transitions = {
		
		effects : [],
		
		
		start : function(){
			this.effects.forEach(function(effect){
				effect.start();
			});
		},
		
		
		stop : function(){
			this.effects.forEach(function(effect){
				effect.stop();
			});
		},
		
		
		reset : function(){
			this.effects.forEach(function(effect){
				effect.reset();
			});
		},
		
		
		restart : function(){
			this.effects.forEach(function(effect){
				effect.restart();
			});
		}
		
	};
	
	changes.forEach(function(change){
		var effect =  new sb.effect({
			el : el
		});
		
		effect.prop = change.prop;
		effect.unit = change.unit ||'';
		
		effect.duration = change.duration || duration || 24;
		effect.type = change.type || 'outQuad';
		if(change.prop =='backgroundColor' || change.prop =='color'){
			effect.beginColor = change.begin;
			effect.endColor = change.end;
			
			effect.begin =  0;
			effect.change = 100;
			effect.end = change.end;
		} else {
			effect.begin =  change.begin;
			effect.change = change.change;
		}
		effect.onTween = change.onTween || 0;
		effect.onEnd = change.onEnd || 0;
		if(typeof change.handler =='function'){
			
			effect.handler = function(){
				change.handler.call(effect);
			}
		} else {
			effect.handler = function(){
			
				//fix stupid IE height 0px prob
				if (this.prop =='height' && sb.browser.agent =='ie' && sb.browser.version==6 && this.value<1){
					
					this.value=1;
				}
				
				if(this.prop =='backgroundColor' || this.prop =='color'){
					
					this.el.style[change.prop] = sb.colors.getTweenColor(this.beginColor, this.endColor, this.value);
					
				
				} else  {
					try{
					//this.el.style[change.prop] = String(this.value.toFixed(2))+this.unit;
					this.el.css(change.prop, String(this.value.toFixed(2))+this.unit);
					} catch(e){
					//	alert(this.prop);
					}
				} 
			}
			
		}
		
		transitions.effects.push(effect);
	});
	
	
	return transitions;
};



sb.effect = function(params){
	
	this.setParams(params ||{});
	
	sb.effects.register(this);
	
};


sb.effect.prototype = {
	
	
	time : 0,
	
	
	duration :24, 
	
	
	count :1,
	
	
	type : 'inQuart',
	
	
	setParams : function(params){
		
		sb.objects.importProperties(params, this);
		if(typeof params.el !='undefined'){
			this.el = sb.s$(this.el);
		} 
		
	},
	
	
	start : function(){
		
		var t=this;
	
		this.repeater = window.setInterval(
		function(){
		
			if(t.time < t.duration){
				
				t.time++;
				t.value = sb.effects.tween[t.type](t.time,t.begin,t.change,t.duration);
				t.valueRounded = Math.round(t.value);
				if(typeof t.onTween=='function'){
					t.onTween(t.value);
				}
				t.handler();
				
			} else {
				t.count++;
				if(typeof t.onEnd =='function'){t.onEnd();}
				t.stop();
			}
		}, 12);
		
	},

	
	stop : function(){
		if(typeof this.onStop == 'function'){this.onStop();}
		window.clearInterval(this.repeater);
	},
	
	
	reset : function(){
		if(typeof this.onReset == 'function'){this.onReset();}
		this.count=0;
		this.value = this.begin;
		this.valueRounded = this.begin;
		this.time=0;
		this.stop();
	},
	
	
	restart : function(){
		if(typeof this.onRestart == 'function'){this.onRestart();}
		this.reset();
		this.start();
	}
};



sb.effects = {
	
	
	registered : [],
	
	
	register : function(effect){
		this.registered.push(effect);
	},
	
	
	stopAll : function(){
		sb.effects.registered.forEach(function(v){v.stop();});
	},
	
	
	startAll : function(){
		sb.effects.registered.forEach(function(v){v.start();});
	}
};


sb.effects.tween = {

	
	linear : function(t,b,c,d) {
	    return c*t/d + b;
	},
	
	
	outQuint : function(t,b,c,d) {
	    return c*(Math.pow(t/d-1,5)+1)+b;
	},
	
	
	inOutQuint : function(t,b,c,d) {
	    if ((t/=d/2)<1){
	        return c/2*Math.pow(t,5)+b;
	    }
	    return c/2*(Math.pow(t-2,5)+2)+b;
	},
	
	
	inQuad : function(t,b,c,d) {
	    return c*(t/=d)*t + b;
	},
	
	
	outQuad : function(t,b,c,d) {
	    return -c*(t/=d)*(t-2) + b;
	},
	
	
	inOutQuad : function(t,b,c,d) {
	    if ((t/=d/2) < 1) {
	    	return c/2*t*t + b;
	    }
	    return -c/2 * ((--t)*(t-2)-1)+b;
	},
	
	
	inCubic : function(t,b,c,d) {
	    return c*Math.pow(t/d,3)+b;
	},
	
	
	outCubic : function(t,b,c,d) {
	    return c*(Math.pow(t/d-1,3)+1)+b;
	},
	
	
	inOutCubic : function(t,b,c,d) {
	    if ((t/=d/2)<1){
	        return c/2*Math.pow(t,3)+b;
	    }
	    return c/2*(Math.pow(t-2,3)+2)+b;
	},
	
	
	inQuart : function(t,b,c,d) {
	    return c* Math.pow(t/d,4) + b;
	},
	
	
	outQuart : function(t,b,c,d) {
	    return -c*(Math.pow(t/d-1,4)-1)+b;
	},
	
	
	inOutQuart : function(t,b,c,d) {
		if ((t/=d/2)<1){
		    return c/2*Math.pow(t,4)+b;
		}
		return -c/2*(Math.pow(t-2,4)-2)+b;
	},
	
	
	inSine : function(t,b,c,d) {
	    return c* (1 - Math.cos(t/d*(Math.PI/2))) + b;
	},
	
	
	outSine : function(t,b,c,d) {
	    return c* Math.sin(t/d*(Math.PI/2)) + b;
	},
	
	
	inOutSine : function(t,b,c,d) {
	    return c/2* (1-Math.cos(Math.PI*t/d)) +b;
	},
	
	
	inExpo : function(t,b,c,d) {
	    return c* Math.pow(2,10*(t/d - 1)) +b;
	},
	
	
	outExpo : function(t,b,c,d) {
	    return c* (-Math.pow(2,-10*t/d) + 1) + b;
	},
	
	
	inOutExpo : function(t,b,c,d) {
	    if ((t/=d/2) < 1){
	        return c/2 * Math.pow(2, 10*(t-1))+b;
	    }
	    return c/2 * (-Math.pow(2, -10 * --t) + 2) +b;
	},
	
	
	inCirc : function(t,b,c,d) {
	    return c* (1-Math.sqrt(1- (t/=d)*t)) + b;
	},
	
	
	outCirc : function(t,b,c,d) {
	    return c* Math.sqrt(1-(t=t/d-1)*t) + b;
	},
	
	
	inOutCirc : function(t,b,c,d) {
		if ((t/=d/2) < 1){
			return c/2 * (1-Math.sqrt(1-t*t))+b;
		}
	    return c/2 * (Math.sqrt(1- (t-=2)*t)+1) +b;
	},
	
	
	extend : sb.objects.extend
};


sb.effects.fade = function(o){
	var effect = new sb.effect(o);
	
	effect.duration = o.duration || 24;
	effect.type = o.type || 'inQuart';
	
	effect.handler = function(){
		this.el.opacity(Math.round(this.value)/100);
	}
	return effect;
};

sb.effects.scale = function(o){
	
	var effect = new sb.effect(o);
	
	effect.dir = o.dir || 'xy';
	effect.duration = o.duration || 24;
	effect.type = o.type || 'inSine';
	
	effect.handler = function(){
		try{
		if(this.dir =='x' || this.dir =='xy'){
			this.el.style.width = Math.round(this.el.w*this.value)+'px';
		}
		
		if(this.dir =='y' || this.dir =='xy'){
			this.el.style.height=Math.round(this.el.h*this.value)+'px';;
		}
		
		this.el.style.fontSize=this.value+'em';
		}catch(e){
			sb.consol.error(this.value);
		}
	}
	return effect;
};

sb.effects.moveY =  function(obj){
	var effect = new sb.effect(o);
	
	effect.duration = o.duration || 24;
	effect.type = o.type || 'inQuart';
	
	effect.handler = function(){
		obj.mv(this.el.offsetleft, this.value, this.el.css('zIndex'));
	}
	return effect;
	
};

//requires sb.colors.js
sb.effects.warmToRed = function(o){
	
	if(typeof sb.colors =='undefined'){sb.include('sb.colors');}
	
	var effect = new sb.effect(o);
	
	effect.duration = o.duration || 24;
	effect.type = o.type || 'inQuart';
	effect.origBgColor = effect.el.css('backgroundColor');
	
	effect.origBgColorArr = sb.colors.toArray(effect.origBgColor);
	effect.begin = 0;
	effect.change = 255;
	effect.handler = function(){
			
		var val = Math.round(this.value);
		var r=this.origBgColorArr[0] +val;
		var g=this.origBgColorArr[1] -val;
		var b=this.origBgColorArr[2] -val;
		this.el.style.backgroundColor = 'rgb('+r+','+g+','+b+')';
	
	}
	return effect;
};

sb.effects.rollUp = function(o){
	
	var effect = new sb.effect(o);
	
	effect.duration = o.duration || 24;
	effect.type = o.type || 'outQuart';
	
	var border = effect.el.css('border').toNumber();
	var padding = effect.el.css('padding').toNumber();
	var height = effect.el.offsetHeight;
	$(effect.el, '*').forEach(function(v){
		if(v.nodeName =='EMBED' || v.nodeName =='OBJECT'){
			sb.dom.remove(v);
		}
	})
	effect.begin = height
	effect.change = height*-1;
	effect.el.style.overflow ='hidden';
	effect.handler = function(){
	
		var val = Math.round(this.value);
		if(val < border){
			this.el.style.border = val+'px';
		}
		
		if(val < padding){
			this.el.style.padding = val+'px';
		}
		
		this.el.style.height = val+'px';
		
		
	}
	return effect;
};

sb.effects.flash = function(o){
	
	var effect = new sb.effect(o);

	effect.duration = o.duration || 24;
	effect.type = o.type || 'outQuad';
	effect.flashes = o.flashes || 3;
	effect.begin =  parseFloat(effect.el.opacity()).toFixed(3);
	effect.change = effect.begin;
	
	effect.onEnd = function(){
		
		if(this.count <= this.flashes){
			this.time =0;
			this.start();
		} else {
			this.onEnd='';
			this.stop();
			if(typeof o.onEnd == 'function'){o.onEnd();}
			this.el.opacity(effect.begin);
		}
	}
	
	effect.handler = function(){
		//document.title = parseFloat(this.value).toFixed(2);
		this.el.opacity(parseFloat(this.value).toFixed(3));
		
	}
	return effect;
};


sb.effects.scrollTo = function(o){
	
	var effect = new sb.effect(o);

	effect.duration = o.duration || 45;
	effect.type = o.type || 'outQuart';
	
	sb.events.add(document, 'DOMMouseScroll', function(){effect.stop();});
	sb.events.add(document, 'mousewheel', function(){effect.stop();});
	
	effect.handler = function(){
		window.scrollTo(0, this.value);
		
	}
	return effect;
};

sb.element.prototype.makeDraggable = function(){

	sb.$(this, '*').forEach(function(v){
		if(v.className.match(/dragHandle/i)){
			v.style.cursor = 'move';
		}
	});
	if(this.className.match(/dragHandle/)){
		this.style.cursor = 'move';
	}
	this.sbDraggable = this.event('mousedown', sb.drag.start);
};


sb.element.prototype.makeUnDraggable = function(){
	
	sb.$(this, '*').forEach(function(v){
		if(v.className.match(/dragHandle/i)){
			v.style.cursor = '';
		}
	});
	if(this.className.match(/dragHandle/)){
		this.style.cursor = '';
	}
	this.eventRemove(this.sbDraggable);
};



sb.drag = {
	
	debug : 0,
	zIndex : 0,
	el : {},
	
	move : function(e){
		
		sb.events.preventDefault(e);
		var scroll = sb.browser.scrollPos();
		var x = e.clientX, y = e.clientY, el = sb.drag.el;
		
		if(typeof sb.drag.el.lockX =='undefined'){
			x=el.x.estart + x + scroll[0] - el.x.cstart;
			el.style.left = x+'px';
		}
		if(typeof sb.drag.el.lockY =='undefined'){
			y = el.y.estart + y + scroll[1] - el.y.cstart;
			el.style.top = y+'px';
		}
		
		sb.browser.removeSelection();
		
		if(typeof sb.drag.ondrag == 'function'){
			
			sb.drag.ondrag.call(sb.drag.el, e, {x:x,y:y});	
		}
	},
	
	stop : function(e){
		
		sb.events.preventDefault(e);
		if(sb.drag.mmove){
			sb.events.remove(sb.drag.mmove);
		}
		if(sb.drag.mup){
			sb.events.remove(sb.drag.mup);
		}
		//sb.drag.el.opacity(sb.drag.el.origOpacity||1);
		
		if(typeof sb.drag.ondragstop == 'function'){
			sb.drag.ondragstop.call(sb.drag.el, e);	
		}
		 
	},
	
	start : function(e, id){
		
		var x=e.clientX, y=e.clientY, el;
		var scroll = sb.browser.scrollPos();
		
		el = s$(this);
		//el.origOpacity = el.css('opacity');
		//set handlers
		if(typeof this.ondrag == 'function'){
			sb.drag.ondrag = this.ondrag;	
		}
		
		if(typeof this.ondragstart == 'function'){
			sb.drag.ondragstart = this.ondragstart;	
			sb.drag.ondragstart.apply(sb.drag.el);
		}
		
		if(typeof this.ondragstop == 'function'){
			sb.drag.ondragstop = this.ondragstop;	
		}
		
		
		if(el.css('position') == 'static' && sb.drag.debug ==1){
			alert('You need to set position style on elemement');
		}
		
		while(el.nodeType == 3 || sb.css(el, 'position') == 'static'){
			el = s$(el.parentNode)	
		}
		
		el.x = {
			cstart : x+scroll[0],
			estart : parseInt(el.css('left'), 10)
		};
		
		el.y = {
			cstart : y+scroll[1],
			estart : parseInt(el.css('top'), 10)
		};
		
		if (isNaN(el.x.estart)) {el.x.estart = 0;}
	  	if (isNaN(el.y.estart)) {el.y.estart = 0;}
	 

		el.style.zIndex = ++sb.drag.zIndex;
		
		//set as global dragable element
		sb.drag.el = el;
		
		if(sb.dom.className.contains.call(sb.events.target(e), 'dragHandle')){
			sb.drag.mmove = sb.events.add(document, 'mousemove', sb.drag.move);
			//el.opacity(0.3);
		} 
		sb.drag.mup = sb.events.add(document, 'mouseup', sb.drag.stop);
	
  }
	
};



sb.md5 = {
	
	
	hexcase : 0,
	
	
	b64pad : '',
	
	
	chrsz : 8,
	
	
	
	
	test : function (){
	  return this.hex("abc") == "900150983cd24fb0d6963f7d28e17f72";
	},
	
	
	binl2hex : function(binarray){
		
	  var hex_tab = this.hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
	  var str = "";
	  for(var i = 0; i < binarray.length * 4; i++)
	  {
	    str += hex_tab.charAt((binarray[i>>2] >> ((i%4)*8+4)) & 0xF) +
	           hex_tab.charAt((binarray[i>>2] >> ((i%4)*8  )) & 0xF);
	  }
	  return str;
	},
	
	
	hex : function(s){ 
		return this.binl2hex(this.core(this.str2binl(s), s.length * this.chrsz));
	},
	
	
	b64 : function(s){
		return this.binl2b64(this.core(this.str2binl(s), s.length * this.chrsz));
	},
	
	
	str : function(s){
		return this.binl2str(this.core(this.str2binl(s), s.length * this.chrsz));
	},
	
	
	hex_hmac : function(key, data){ 
		return this.binl2hex(this.core_hmac(key, data));
	},
	
	
	b64_hmac : function(key, data) {
		return this.binl2b64(this.core_hmac(key, data));
	},
	
	
	str_hmac : function(key, data) {
		return this.binl2str(this.core_hmac(key, data));
	},
	
	
	core : function(x, len){
		
	  
	  x[len >> 5] |= 0x80 << ((len) % 32);
	  x[(((len + 64) >>> 9) << 4) + 14] = len;
	
	  var a =  1732584193;
	  var b = -271733879;
	  var c = -1732584194;
	  var d =  271733878;
	
	  for(var i = 0; i < x.length; i += 16){
	    var olda = a;
	    var oldb = b;
	    var oldc = c;
	    var oldd = d;
	
	    a = this.ff(a, b, c, d, x[i+ 0], 7 , -680876936);
	    d = this.ff(d, a, b, c, x[i+ 1], 12, -389564586);
	    c = this.ff(c, d, a, b, x[i+ 2], 17,  606105819);
	    b = this.ff(b, c, d, a, x[i+ 3], 22, -1044525330);
	    a = this.ff(a, b, c, d, x[i+ 4], 7 , -176418897);
	    d = this.ff(d, a, b, c, x[i+ 5], 12,  1200080426);
	    c = this.ff(c, d, a, b, x[i+ 6], 17, -1473231341);
	    b = this.ff(b, c, d, a, x[i+ 7], 22, -45705983);
	    a = this.ff(a, b, c, d, x[i+ 8], 7 ,  1770035416);
	    d = this.ff(d, a, b, c, x[i+ 9], 12, -1958414417);
	    c = this.ff(c, d, a, b, x[i+10], 17, -42063);
	    b = this.ff(b, c, d, a, x[i+11], 22, -1990404162);
	    a = this.ff(a, b, c, d, x[i+12], 7 ,  1804603682);
	    d = this.ff(d, a, b, c, x[i+13], 12, -40341101);
	    c = this.ff(c, d, a, b, x[i+14], 17, -1502002290);
	    b = this.ff(b, c, d, a, x[i+15], 22,  1236535329);
	
	    a = this.gg(a, b, c, d, x[i+ 1], 5 , -165796510);
	    d = this.gg(d, a, b, c, x[i+ 6], 9 , -1069501632);
	    c = this.gg(c, d, a, b, x[i+11], 14,  643717713);
	    b = this.gg(b, c, d, a, x[i+ 0], 20, -373897302);
	    a = this.gg(a, b, c, d, x[i+ 5], 5 , -701558691);
	    d = this.gg(d, a, b, c, x[i+10], 9 ,  38016083);
	    c = this.gg(c, d, a, b, x[i+15], 14, -660478335);
	    b = this.gg(b, c, d, a, x[i+ 4], 20, -405537848);
	    a = this.gg(a, b, c, d, x[i+ 9], 5 ,  568446438);
	    d = this.gg(d, a, b, c, x[i+14], 9 , -1019803690);
	    c = this.gg(c, d, a, b, x[i+ 3], 14, -187363961);
	    b = this.gg(b, c, d, a, x[i+ 8], 20,  1163531501);
	    a = this.gg(a, b, c, d, x[i+13], 5 , -1444681467);
	    d = this.gg(d, a, b, c, x[i+ 2], 9 , -51403784);
	    c = this.gg(c, d, a, b, x[i+ 7], 14,  1735328473);
	    b = this.gg(b, c, d, a, x[i+12], 20, -1926607734);
	
	    a = this.hh(a, b, c, d, x[i+ 5], 4 , -378558);
	    d = this.hh(d, a, b, c, x[i+ 8], 11, -2022574463);
	    c = this.hh(c, d, a, b, x[i+11], 16,  1839030562);
	    b = this.hh(b, c, d, a, x[i+14], 23, -35309556);
	    a = this.hh(a, b, c, d, x[i+ 1], 4 , -1530992060);
	    d = this.hh(d, a, b, c, x[i+ 4], 11,  1272893353);
	    c = this.hh(c, d, a, b, x[i+ 7], 16, -155497632);
	    b = this.hh(b, c, d, a, x[i+10], 23, -1094730640);
	    a = this.hh(a, b, c, d, x[i+13], 4 ,  681279174);
	    d = this.hh(d, a, b, c, x[i+ 0], 11, -358537222);
	    c = this.hh(c, d, a, b, x[i+ 3], 16, -722521979);
	    b = this.hh(b, c, d, a, x[i+ 6], 23,  76029189);
	    a = this.hh(a, b, c, d, x[i+ 9], 4 , -640364487);
	    d = this.hh(d, a, b, c, x[i+12], 11, -421815835);
	    c = this.hh(c, d, a, b, x[i+15], 16,  530742520);
	    b = this.hh(b, c, d, a, x[i+ 2], 23, -995338651);
	
	    a = this.ii(a, b, c, d, x[i+ 0], 6 , -198630844);
	    d = this.ii(d, a, b, c, x[i+ 7], 10,  1126891415);
	    c = this.ii(c, d, a, b, x[i+14], 15, -1416354905);
	    b = this.ii(b, c, d, a, x[i+ 5], 21, -57434055);
	    a = this.ii(a, b, c, d, x[i+12], 6 ,  1700485571);
	    d = this.ii(d, a, b, c, x[i+ 3], 10, -1894986606);
	    c = this.ii(c, d, a, b, x[i+10], 15, -1051523);
	    b = this.ii(b, c, d, a, x[i+ 1], 21, -2054922799);
	    a = this.ii(a, b, c, d, x[i+ 8], 6 ,  1873313359);
	    d = this.ii(d, a, b, c, x[i+15], 10, -30611744);
	    c = this.ii(c, d, a, b, x[i+ 6], 15, -1560198380);
	    b = this.ii(b, c, d, a, x[i+13], 21,  1309151649);
	    a = this.ii(a, b, c, d, x[i+ 4], 6 , -145523070);
	    d = this.ii(d, a, b, c, x[i+11], 10, -1120210379);
	    c = this.ii(c, d, a, b, x[i+ 2], 15,  718787259);
	    b = this.ii(b, c, d, a, x[i+ 9], 21, -343485551);
	
	    a = this.safe_add(a, olda);
	    b = this.safe_add(b, oldb);
	    c = this.safe_add(c, oldc);
	    d = this.safe_add(d, oldd);
	  }
	  return [a, b, c, d];
	
	},
	
	
	cmn : function(q, a, b, x, s, t){
	  return this.safe_add(this.bit_rol(this.safe_add(this.safe_add(a, q), this.safe_add(x, t)), s),b);
	},
	
	
	ff : function(a, b, c, d, x, s, t){
	  return this.cmn((b & c) | ((~b) & d), a, b, x, s, t);
	},
	
	
	gg : function(a, b, c, d, x, s, t){
	  return this.cmn((b & d) | (c & (~d)), a, b, x, s, t);
	},
	
	
	hh : function(a, b, c, d, x, s, t){
	  return this.cmn(b ^ c ^ d, a, b, x, s, t);
	},
	
	
	ii : function(a, b, c, d, x, s, t){
	  return this.cmn(c ^ (b | (~d)), a, b, x, s, t);
	},
	
	
	core_hmac : function(key, data){
		
	  var bkey = this.str2binl(key);
	  if(bkey.length > 16) bkey = this.core(bkey, key.length * this.chrsz);
	
	  var ipad = Array(16), opad = Array(16);
	  for(var i = 0; i < 16; i++){
	    ipad[i] = bkey[i] ^ 0x36363636;
	    opad[i] = bkey[i] ^ 0x5C5C5C5C;
	  }
	
	  var hash = this.core(ipad.concat(this.str2binl(data)), 512 + data.length * this.chrsz);
	  return this.core(opad.concat(hash), 512 + 128);
	},
	
	
	safe_add : function (x, y){
	  var lsw = (x & 0xFFFF) + (y & 0xFFFF);
	  var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
	  return (msw << 16) | (lsw & 0xFFFF);
	},
	
	
	bit_rol : function(num, cnt){
	  return (num << cnt) | (num >>> (32 - cnt));
	},
		
	
	str2binl : function (str){
		var bin = [];
		var mask = (1 << this.chrsz) - 1;
		for(var i = 0; i < str.length * this.chrsz; i += this.chrsz)
		bin[i>>5] |= (str.charCodeAt(i / this.chrsz) & mask) << (i%32);
		return bin;
	},
	
	
	binl2str : function (bin){
		var str = "";
		var mask = (1 << this.chrsz) - 1;
		for(var i = 0; i < bin.length * 32; i += this.chrsz)
		str += String.fromCharCode((bin[i>>5] >>> (i % 32)) & mask);
		return str;
	},
	
	
	binl2b64 : function(binarray){
		var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
		var str = "";
		for(var i = 0; i < binarray.length * 4; i += 3){
			var triplet = (((binarray[i   >> 2] >> 8 * ( i   %4)) & 0xFF) << 16)
			            | (((binarray[i+1 >> 2] >> 8 * ((i+1)%4)) & 0xFF) << 8 )
			            |  ((binarray[i+2 >> 2] >> 8 * ((i+2)%4)) & 0xFF);
			            
			for(var j = 0; j < 4; j++){
				
			  if(i * 8 + j * 6 > binarray.length * 32) {
			  	str += b64pad;
			  } else {
			  	str += tab.charAt((triplet >> 6*(3-j)) & 0x3F);
			  }
		
			}
			return str;
		}

	}	
	
};


String.prototype.md5 = function(){
	return sb.md5.hex(this);
}

















sb.ie6 = {
	
	
	pngFix : function(obj){
		var i,im,images,src,st;
		if(sb.browser.agent == 'ie' && sb.browser.version <7){
			obj = sb.$(obj);
			if(typeof obj.src !='undefined'){
				images = [obj];
			} else {
				images = $(obj, 'img');
			}
			
			for(i=0;i<images.length;i++){	
				im = images[i];
				src = im.src;
				st = im.style;
				if( src.substr((src.length -3),3)== "png"){
					if(im.width==0 || im.height==0){
						//sb.consol.error(sb.messages[17]+im.src+"\nwidth:"+im.width+"\n"+"height:"+im.height)
					}
					st.width = im.width + 'px';
					st.height = im.height + 'px';
				
					im.src = sb.base+'/spacer.gif';
					st.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='image')";
		
				}
			}
		}
	},
	
	
	
	pngFixBg : function(el){
		if(sb.browser.agent == 'ie' && sb.browser.version <7){
			el = s$(el);
			if(el.css('background-image').match(/\w\.png/) && sb.browser.agent =='ie' && sb.browser.version <= 6){
				
				el.style.backgroundImage = 'none';
				el.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=scale src='"+el.css('background-image').match(/http:\/\/.*?png/)+"')";
			}
		}
	}

};

//for backwards compatibility, eventually this will go away

sb.browser.pngFixBg = sb.ie6.pngFixBg;
sb.browser.pngFix = sb.ie6.pngFix;