//v 1.45
//10/03/06


//tweens Math adapted from http://www.synthesisters.com/hypermail/max-msp/Nov05/34305.html
// t = time (elapsed since tween began),
// b = beginning (value),
// c = change (in value),
// d = duration

sc.tween = {
	//LINEAR CURVE: 
	linear : function(t,b,c,d) {
	    return c*t/d + b;
	},
	
	//POWER CURVES:
	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;
	},

	inQuint : function(t,b,c,d) {
	    return c* Math.pow(t/d,5) + 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;
	},
	
	// SINE CURVES:
	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;
	},
	
	// EXPONENTIAL CURVES:
	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;
	},
	
	// CIRCULAR CURVES
	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;
	} 

};

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

sc.effect = function(params){
	
	if(typeof params == 'object'){
		this.setParams(params);
	}
	
	sc.effects.register(this);
	
};

sc.effect.prototype = {
	
	time : 0,
	duration :18, 
	
	start : function(){
		var t=this;
		
		if(typeof this.onBegin =='function'){this.onBegin();}
	
		this.repeater = window.setInterval(
		function(){
			if(t.time < t.duration){
				t.time++;
				
				t.value = sc.tween[t.type](t.time,t.begin,t.change,t.duration);
				t.valueRounded = Math.round(t.value);
				t.handler();
			} else {
				if(typeof t.onEnd =='function'){t.onEnd();}
				t.stop();
			}
		}, 41);
		
	},
	
	setParams : function(params){
		if(typeof params =='object'){
			sc.objects.addProps(this, params);
		}
	},
	
	stop : function(){
		
		window.clearInterval(this.repeater);
	},
	
	reset : function(){
		this.value = 0;
		this.valueRounded = 0;
		this.time=0;
		this.stop();
	}
};

sc.effects.fade =  function(obj){
	this.obj = obj = sc.dom.s$(obj);
	
	this.effect = new sc.effect({
		type : 'inQuart',
		handler : function(){
			obj.css('opacity', this.valueRounded/100);
		}
	});
};

sc.effects.fade.prototype = {
	
	duration :24,
	
	start : function(from, to){
		
		this.effect.begin = from;
		this.effect.change = to-from;
		this.effect.duration = this.duration;
		//sc.consol.dump(this.effect);
		this.effect.start();
	},
	
	stop : function(){
		this.effect.stop();
	}
};

sc.effects.scale =  function(obj){
	this.obj = obj =  sc.dom.s$(obj);
	
	this.effect = new sc.effect({
		type : 'inQuart',
		handler : function(){
			obj.wh(obj.w*this.value, obj.h*this.value);
			obj.css('font-size', this.value+'em');
		}
	});
};

sc.effects.scale.prototype = {
	
	duration :24,
	
	start : function(from, to){
		
		this.effect.stop();
		this.effect.begin = from;
		this.effect.change = to-from;
		this.effect.duration = this.duration;
		//sc.consol.dump(this.effect);
		this.effect.start();
	},
	
	stop : function(){
		this.effect.stop();
	}
};


sc.effects.blink =  function(obj){
	this.obj = obj =  sc.dom.s$(obj);
	
	this.fade = new sc.effect({
		type : 'outCirc',
		handler : function(){
			document.title = this.valueRounded/100;
			obj.opacity(this.valueRounded/100);
		}
	});

};

sc.effects.blink.prototype = {
	start : function(){
		
		this.stop();
		this.fade.begin = 100;
		this.fade.change = -100;
		this.fade.duration = 24;
		this.fade.onEnd = function(){
			this.time = 0;
			this.start();
		};
		this.fade.start();
		
		
	},
	
	stop : function(){
		this.fade.stop();
	}
};




sc.effects.beat =  function(obj){
	this.obj = obj =  sc.dom.s$(obj);
	
	this.grow = new sc.effect({
		type : 'inQuart',
		handler : function(){
			obj.wh(obj.w*this.value, obj.h*this.value);
			obj.css('font-size', this.value+'em');
		}
	});

};

sc.effects.beat.prototype = {
	start : function(from, to){
		
		this.stop();
		this.grow.begin = from;
		this.grow.change = to-from;
		this.grow.duration = 10;
		this.grow.onEnd = function(){
			this.time = 0;
			this.start();
		};
		this.grow.start();
		
		
	},
	
	stop : function(){
		this.grow.stop();
	}
};


sc.effects.vaporize =  function(obj){
	this.obj = obj =  sc.dom.s$(obj);
	
	this.effect = new sc.effect({
		type : 'inQuart',
		onEnd : function(){
			sc.dom.remove(obj);
		},
		handler : function(){
			obj.wh(obj.w*this.value, obj.h*this.value);
			obj.css('font-size', this.value+'em');
		}
	});
};

sc.effects.vaporize.prototype = {
	
	duration :24,
	
	start : function(from, to){
		var scrollTop;
		if(typeof this.obj.parentNode.scrollTop !='undefined'){
			scrollTop = this.obj.parentNode.scrollTop;
		} else {
			scrollTop = 0;
		}
		this.obj.mv(this.obj.left, this.obj.top-scrollTop, 999);
		var n = new sc.effects.fade(this.obj).start(100,0);
		this.effect.stop();
		this.effect.begin = from;
		this.effect.change = to-from;
		this.effect.duration = this.duration;
		//sc.consol.dump(this.effect);
		this.effect.start();
	},
	
	stop : function(){
		this.effect.stop();
	}
};


sc.dragger = function(obj){
	var t=this;
	t.obj=sc.$(obj);
	sc.stylify(t.obj);
	t.obj.css('cursor', 'move');
	
	t.obj.dragging = sc.events.add(t.obj, 'mousedown', function(e){sc.events.preventDefault(e);return t.setDragging(e);});
	

	sc.events.add(document, 'mouseup', function(e){
		for(var d in sc.dragger.draggers){
			try{
				sc.dragger.draggers[d].stop(e);
			}catch(e){}
		}
	});
	
	t.obj.ondragstart=function(e){	return t.setDragging(e);};
	t.obj.ondragstop=function(e){t.stop(e);};
	
	if(sc.browser.agent =='sf'){
		
		document.onmousedown = function(){return false;}; 
	}
	
	sc.dragger.draggers.push(this);
	
	this.x = {};
	this.y = {};
	this.z = {};
	this.x.orig = sc.dom.x(this.obj);
	this.y.orig = sc.dom.y(this.obj);
	this.x.current = this.x.orig;
	this.y.current = this.y.orig;
	this.x.origRel = this.obj.offsetLeft;
	this.y.origRel = this.obj.offsetTop;
	this.className = this.obj.className;

};

sc.dragger.draggers = [];

sc.dragger.prototype = {
	restrictToParent : 0,
	
	setDragging : function(e){
		var t=this;
		this.x.onDragObj = sc.dom.x(this.obj);
		this.y.onDragObj = sc.dom.y(this.obj);
	
		this.x.onDragMouse =e.clientX;
		this.y.onDragMouse =e.clientY;
	
		this.dragable=1; 
		if(typeof this.onstartdrag == 'function'){this.onstartdrag(e);}
		if(this.onmousemoving !==undefined){sc.events.remove(this.onmousemoving);}
		this.onmousemoving = sc.events.add(document, 'mousemove', function(e){return t.drag(e);});
		return false;
	},
	
	mv : function(x,y,z){
		this.obj.mv(x, y, z);
	},
	
	drag : function(e){
		var t=this,x;
		
		if (t.dragable === 1){
			
			sc.browser.removeSelection();
			this.x.rel= t.x.onDragObj+e.clientX-(t.x.onDragMouse+t.x.orig);
			this.y.rel = t.y.onDragObj+e.clientY-(t.y.onDragMouse+t.y.orig);
			this.z.rel = this.obj.css('zIndex');
			
			this.x.mouse = e.clientX;
			this.y.mouse = e.clientX;
			
			this.x.current = this.x.orig+this.x.rel;
			this.y.current  = this.y.orig+this.y.rel;
			
			if(this.restrictToParent !== 0){
				this.restrictTo(t.obj.parentNode);
			} else if(typeof this.container != "undefined"){
				this.restrictTo(this.container);
			}
			
			if(sc.isArray(this.collideWith)){
				this.detectCollision();
				
			}
			
			
			this.y.rel+=this.y.origRel;
			this.x.rel+=this.x.origRel;
			this.mv(this.x.rel, this.y.rel, 999);
		
			for(x=0;x<sc.dragger.draggers.length;x++){
				if(sc.dragger.draggers[x] !=this){
					sc.dragger.draggers[x].obj.style.zIndex=100;
				}
			}
		
			this.left = this.x.current; 
			this.right = this.x.current+this.obj.offsetWidth;
			this.top = this.y.current;
			this.bottom = this.top+this.obj.offsetHeight;
				
			if(this.debug ==1){this.obj.dump();}
			
			if(typeof this.ondrag == "function"){
				this.ondrag();
			}
			
			this.obj.css('opacity', 0.5);
			
		} 
		
		return false;
	},
	
	
	reset : function(e){
		this.obj.mv(e.clientX, e.clientY, 999);
	},
	
	remove : function(){
		sc.dom.remove(this.obj);
		sc.events.remove(this.onmousemoving);
		if(typeof this.onstartdrag == 'function'){delete this.onstartdrag;}
		if(typeof this.ondrag == 'function'){delete this.ondrag;}
		if(typeof this.onstopdrag == 'function'){delete this.onstopdrag;}
	},
	
	stop : function(e){
		this.dragable=0;
		sc.events.remove(this.onmousemoving);
		this.obj.css('opacity', 1.0);
		if(typeof this.onstopdrag == 'function'){this.onstopdrag(e);}
		
	},
	
	reset : function(){
		this.obj.style.left='';
		this.obj.style.top='';
	},
	
	detectCollision : function(){
		this.collidingWith = [];
		for(var x=0;x<this.collideWith.length;x++){
			if(this.collideWith[x].bottom >= this.top && this.collideWith[x].top <=this.bottom && this.collideWith[x].right >= this.left && this.collideWith[x].left <=this.right){
				this.collidingWith.push(this.collideWith[x]);
			}
		}
		
		if(typeof this.oncollide == 'function'){
			this.oncollide(this.collidingWith);
		}
				
	},
	
	restrictTo : function(obj){
		var x,y,border = sc.styles.read(obj, 'border') || 0;
		
		var container = sc.$(obj);
		
		container.left = sc.dom.x(container);
	
		container.right = container.left+container.offsetWidth-(border*2);
		container.top = sc.dom.y(container);
		container.bottom = container.top+container.offsetHeight-(border*2);
		
		x = this.x.rel;
		y= this.y.rel;
		if(this.x.current <= container.left){
			x=container.left-this.x.orig;
		} 
		
		if(this.x.current >=(container.right-this.obj.offsetWidth)){
			x= (container.right-this.obj.offsetWidth)-this.x.orig;
		}
		
		if(this.y.current <=(container.top)){
			y=container.top-this.y.orig;
		}
		
		if(this.y.current+this.obj.offsetHeight >= container.bottom){
			y=(container.bottom-this.obj.offsetHeight)-this.y.orig;
		}
	
		if(typeof this.onhitboundary == "function"){
			if(x != this.x.rel || y !=this.y.rel){
				this.onhitboundary(true);
				
				this.x.rel=x;
				this.y.rel=y;
			} else {
				this.onhitboundary(false);
			}
		}
	}
	
};


sc.slider = function(name, min, max, width, defaultValue){
	this.name = name;
	this.min = min || 0;
	this.max = max || 100;
	this.width = width || 100;
	this.defaultValue =(defaultValue !==undefined) ? defaultValue : (this.max-this.min)/2;
	this.floatValues = 0;
};

sc.slider.prototype = {
	value :0,
	displayName : 1,
	displayValue : 1,
	
	setX : function(x, ignoreHandler){
			var nonRoundX = x,str;
			x = Math.round(x);
			if(isNaN(x)){x=this.defaultValue;}
			
			if(x < 0){
				x=0;
				this.value=this.min;
				this.valueToPos(this.value, 1);
			} else if (x > this.width){
				this.value=this.max;
				x=this.width;
				this.valueToPos(this.value, 1);
			} else {
				this.value = this.posToValue(nonRoundX);
				this.getPercentage();
			}
			
			this.nob.title = this.value;
			
			this.nob.style.left=x+'px';
			if(this.display){
				
				if(this.displayName===1){str = this.name;}
				if(this.displayValue===1){str += ' '+this.value;}
				if(this.measurement !== undefined){str += this.measurement;}
				this.display.firstChild.data=str;
			}
			if(typeof(this.onchangevalue)=='function' && ignoreHandler!==1 && this.value !=8){
				this.onchangevalue();
			}
	},
	
	getX : function(){
		return sc.dom.x(this.nob);
	},
	
	getPercentage : function(){
		
		this.percentage = (this.value ===0)? 0 :Math.round((this.value*100)/this.max);
		return this.percentage;
	},
	
	posToValue : function(val){
		val= this.min+(val*(this.max-this.min))/this.width;
		
		val= (this.floatValues) ? val : Math.round(val);
		if(isNaN(val)){val =this.min+1;}
		return val;
	},
	
	valueToPos : function(val, mv){
		var x;
		if(val===0 && this.min ===0){
			 x=0;
		} else {
			x= (this.width*(val-this.min))/(this.max-this.min);
			x=Math.round(x);
		}
	
		if(mv == 1){this.setX(x);}
		return x;
	},
	
	drag : function(e){
		var t=this,x;
		if(this.draggable === 1){
			
			x=this.valueToPos(this.defaultValue)+e.clientX-this.origX-this.nob.offsetWidth/2;
			this.setX(x);
			sc.browser.removeSelection();
		}
	},
	
	dragStop : function(){
		this.draggable = 0;
		document.onmousemove = null;
		document.onmouseup = null;
	},
	
	events : [],
	
	dragStart : function(){
		var t=this;
		this.origX=this.getX();
		
		sc.events.add(t.nob, 'mousedown',  
			function(e){
				
				t.draggable=1;
				t.events.mousemove = sc.events.add(document, 'mousemove', function(e){t.drag(e);return false;});
				
				t.events.onmouseup = sc.events.add(document, 'mouseup', function(e){
					if(typeof t.onmouseup =='function'){t.onmouseup();}
					t.dragStop();
					return false;
				});
		
				sc.events.preventDefault(e);
				return false;
			}
		);
		
	},
	
	calibrate : function(){
		
		var oldValue = this.value;
		this.valueToPos(this.defaultValue, 1);
		this.dragStart();
		this.valueToPos(oldValue, 1);
	},
	
	basicStyle : function(){
		sc.stylify(this.track);
	
		this.track.css('margin',10);
		this.track.css('border', '1px solid white');
		this.track.css('backgroundColor', 'red');
		this.track.css('height','16px');
		sc.stylify(this.nob);
		this.nob.css('backgroundColor', '#ACACAC');
		this.nob.css('border', '1px solid white');
		
		this.display.style.fontSize='12px';
		this.display.style.color='white';
		
	},
	
	toHTML : function(container, defaultStyle){
		
		var t=this;
		t.container = sc.$(container);
	
		
		this.nob = document.createElement('span');
		this.nob.style.height=(this.height === undefined) ?'16px' :this.height+'px';
		this.nob.style.width='10px';
		
		this.nob.style.cursor='pointer';
		this.nob.style.position='absolute';
		this.nob.style.zIndex=1;
		this.nob.className = 'sc_slider_nob';
		sc.css(this.nob, 'opacity', 0.5);
	
		this.track = document.createElement('div');
		this.track.className ='sc_slider';
		this.track.style.fontSize='10px';
		this.track.style.position='relative';
	
		this.track.appendChild(this.nob);
		this.container.appendChild(t.track);
	
		if(this.displayName ==1){
			this.display = document.createElement('span');
			this.display.appendChild(document.createTextNode(''));
			
			
			this.track.appendChild(this.display);
			this.display.className = 'sc_slider_display';
			this.display.style.position="relative";
			this.display.style.zIndex=0;
			
			this.display.style.margin='0px 5px 0px 5px';
			this.display.style.height=this.nob.offsetHeight+'px';
			
		}
		
		sc.events.add(this.track, 'mousedown', 
			function(e){
				if(typeof t.onmousedown =='function'){t.onmousedown();}
				t.setX(t.valueToPos(t.defaultValue)+e.clientX-t.origX-t.nob.offsetWidth/2);
			}
		);
	
		this.track.style.fontSize='1px'; //required for IE
		t.track.style.width=t.width+t.nob.offsetWidth+'px';
		t.track.style.height=(t.nob.offsetHeight)+'px';

		this.valueToPos(this.defaultValue, 1);
	
		sc.events.add(window, 'resize', function(){t.calibrate();});
	
		this.calibrate();
		if(defaultStyle ==1){
			this.basicStyle();
		}
	},
	
	reset : function(){
		this.valueToPos(this.defaultValue,1);
	}, 
	
	toString : function(){
		return '[sc slider]';
	}
		
};


sc.privacyScreen = function(){

	this.show = function(){
		sc.screen.style.backgroundColor='black';
		sc.screen.style.width =sc.browser.w+'px';
		sc.screen.style.height =sc.browser.h+'px';
		sc.screen.style.fontSize ='0px';
		sc.screen.style.zIndex ='400';
		sc.screen.style.position ='absolute';
		sc.screen.style.top ='0px';
		sc.screen.style.left ='0px';
	};
	
	this.hide = function(){
		sc.screen.style.width ='0px';
		sc.screen.style.height ='0px';
	};
	
	if(this.screen === undefined){
	
		this.screen = sc.dom.create('div', '', 'scPrivacyScreen');
		sc.$('body').appendChild(this.screen);
		
		
		sc.privacyScreen.hider = sc.events.add(sc.screen, 'mousedown', this.hide);
		
		this.show();
		
	} else {
		this.show();
	}
	
};


sc.spelling = {
	mistakes : ["Teh", "teh", "adn", "ahve", "ahd", "alot", "amke", "arent", "beleif", "beleive", "cant", "couldnt", "didnt", "ehr", "esle", "workign", "agian", "doesnt", "doens't", "hadnt", "hasnt", "eyt", "hed", "hel", "heres", "hes", "hows", "hsa", "hte", "htere", "i'll", "isnt", "ive", "mkae", "peice", "peices", "seh", "shouldnt", "shouldve", "taht", "tahn", "dont", "i'm", "broswer", "emlwood", "shoudl", "taht", "infromation", "comming", "i", "thier", "cheif", "feild", "itll", "itsa", "weve", "somethign", "hers", "n;t", "goign"],
	
	corrections : ["The", "the", "and", "have", "had", "a lot", "make", "aren't", "belief", "believe", "can't", "couldn't", "didn't", "her", "else", "working", "again", "doesn't", "doesn't", "hadn't", "hasn't", "yet", "he'd", "he'll"," here's", "he's", "how's", "has", "the", "there", "I'll", "isn't", "I've", "make", "piece", "pieces", "she", "shouldn't", "should've", "that", "than", "don't", "I'm",  "browser", "elmwood", "should", "that", "information", "coming", "I", "their", "cheif", "field", "it'll", "it's a", "we've", "something", "her's", "n't", "going"],
	
	typoFix: function(str){

		var i,mistake,correction,errorsFound =[];
		
		for (i=0;i<this.mistakes.length;i++){
		
			mistake = new RegExp( "\\b"+this.mistakes[i]+"\\b", "g");
			correction = this.corrections[i];
			if(str.match(mistake)){
			  	errorsFound.push("\n"+this.mistakes[i]+"=>"+correction);
			}
			str = str.replace(mistake, correction);
			
		}
		alert("Found "+errorsFound.length+" typos: "+errorsFound);
		return str;
	}
	
};

sc.math.plotArc = function(){};

sc.math.plotArc.prototype = {
	y : 0,//-2447
	steps : 100,
	alias :1,
	create : function(){
		this.points=[];
		var y=this.y,x=0;
		
		while(y<=this.steps){
			x=Math.sqrt(this.steps-Math.pow(y,2));
			
			if(!isNaN(x)){
				this.points.push(Math.round(x));
			} else {
				break;
			}
			
			y+=this.alias;
		}
		return this.points;
	}
};

sc.roundedCorners = function(obj){
	
	this.obj = sc.$(obj);
	
	this.round();
};

sc.roundedCorners.bevels = new sc.math.plotArc();
sc.roundedCorners.bevels = sc.roundedCorners.bevels.create().reverse();

sc.roundedCorners.prototype = {
	
	round : function(){
		var color,bgColor,bevel,bevels,btmBevels,factor,max,topBevels,wrapper,wrapperBody,wrapperTitle,x;
		wrapper = document.createElement('div');
		wrapper.className='sb_rounded';
		wrapper.id = this.obj.id;
		wrapper.style.backgroundColor='transparent';
		
		bevels = sc.arrays.copy(sc.roundedCorners.bevels);
		max = sc.arrays.max(bevels);
		//bevels = [10,8,6,5,4,3,2,2,1,1,1,0,0,0];
		/*
		bevels = new sc.arc();
		bevels = bevels.create().reverse();
		max = bevels.max();
		*/
	//	bevels = [0,0,0,1,1,1,2,2,3,4,5,6,8,10];
		factor =1;
		if(factor !=1){
			sc.arrays.walk(function(key, val){return val*factor;}, bevels);
		}
		
		topBevels = document.createElement('div');
		topBevels.style.display='block';
		topBevels.style.height=(factor*bevels.length)+'px';
		topBevels.style.backgroundColor='transparent';
		topBevels.style.overflow='hidden';
		
		for(x=0;x<bevels.length;x++){
			
			bevel = document.createElement('span');
			bevel.style.display ='block';
			bevel.style.height =factor+'px';
			bevel.style.overflow ='hidden';
			
			bevel.className = 'sb_rounded_bgcolor sb_rounded_top';
			bevel.style.margin ='0 '+(max-bevels[x])+'px';
			if(this.obj.getAttribute('rounded') !==null){
				if(this.obj.getAttribute('rounded').match(/tl:none;/)){
					bevel.style.marginLeft ='0px';
				}
				
				if(this.obj.getAttribute('rounded').match(/tr:none;/)){
					bevel.style.marginRight ='0px';
				}
			}
			topBevels.appendChild(bevel);
			bevel=null;
		}
		
		wrapper.appendChild(topBevels);
		
		if(this.obj.title !==''){
			wrapperTitle = document.createElement('div');
			wrapperTitle.style.cursor ='pointer';
			wrapperTitle.innerHTML=this.obj.title;
			wrapperTitle.className ='sb_rounded_bgcolor sb_rounded_top sb_rounded_title';
			wrapperTitle.style.textAlign ='center';
			wrapperTitle.onclick = function(){
				sc.dom.toggle(this.nextSibling);
			};
			sc.roundedCorners.titles.push(wrapperTitle);
			wrapper.appendChild(wrapperTitle);
		}
		
		wrapperBody = document.createElement('div');
		wrapperBody.innerHTML=this.obj.innerHTML;
		wrapperBody.className='sb_rounded_body';
		if(this.obj.getAttribute("bgColor") !==null){
			wrapperBody.style.backgroundColor= this.obj.getAttribute("bodyColor");
		} else {
			wrapperBody.style.backgroundColor= sc.css(this.obj, 'backgroundColor');
		}
		wrapper.appendChild(wrapperBody);
		
		btmBevels = document.createElement('div');
		btmBevels.style.height=(factor*bevels.length)+'px';
		btmBevels.style.backgroundColor='transparent';
		btmBevels.style.overflow='hidden';
		
		bevels.reverse();
		for(x=0;x<bevels.length;x++){
			
			bevel = document.createElement('span');
			bevel.style.display ='block';
			bevel.style.height =factor+'px';
			bevel.style.overflow ='hidden';
			bevel.className = 'sb_rounded_bgcolor sb_rounded_btm';
			bevel.style.margin ='0 '+(max-bevels[x])+'px';
			if(this.obj.getAttribute('rounded') !==null){
				if(this.obj.getAttribute('rounded').match(/bl:none;/)){
					bevel.style.marginLeft ='0px';
				}
				
				if(this.obj.getAttribute('rounded').match(/br:none;/)){
					bevel.style.marginRight ='0px';
				}
			}
			btmBevels.appendChild(bevel);
			bevel=null;
		}
		
		wrapper.appendChild(btmBevels);
		this.obj.parentNode.replaceChild(wrapper, this.obj);

		this.obj=null;
		topBevels=null;
		btmBevels=null;
		wrapperBody=null;
		wrapperTitle=null;
		wrapper=null;
		bevels=null;
	}
};

sc.roundedCorners.find = function(toggleAll){
	
	var d,divs = document.getElementsByTagName('div'),x;
	
	for(x=0;x<divs.length;x++){
		if(divs[x].className=='sb_rounded'){
			d = new sc.roundedCorners(divs[x]);
		}
	}
	
	divs=d=null;
	if(toggleAll === 1){this.toggleAll();}
};

sc.roundedCorners.titles=[];

sc.roundedCorners.closeAll = function(){
	
	for(var x=0;x<this.titles.length;x++){
		this.titles[x].nextSibling.style.display='none';
	}
};

sc.roundedCorners.openAll = function(){
	for(var x=0;x<this.titles.length;x++){
		this.titles[x].nextSibling.style.display='';
	}
};

sc.roundedCorners.toggler = function(v,k,a){

	surebertCom.events.add(v, 'click',function(){sc.roundedCorners.closeAll();sc.roundedCorners.toggle(k);});

};

sc.roundedCorners.toggle = function(x){

	sc.dom.toggle(this.titles[x].nextSibling);
};

sc.roundedCorners.toggleAll = function(){
	surebertCom.events.add(window, 'load', function(){
		sc.roundedCorners.closeAll();
		sc.roundedCorners.toggle(0);
		sc.roundedCorners.titles.forEach(sc.roundedCorners.toggler);
	});
	
};

sc.returnToTop = function(src){
	sc.events.add(window, 'load', function(){
	
		var toTop, timer;
		toTop = document.createElement('img');
		
		toTop.id = 'scToTop';
		toTop.src = src;
		toTop.style.width='auto';
		toTop.style.height='auto';
		toTop.style.position='absolute';
		toTop.style.left='0px';
		sc.browser.pngFix(toTop);
		toTop.style.cursor='pointer';
		toTop.style.display='none';
		toTop.title='return to top of page';
		sc.events.add(toTop, 'mousedown', function (e){
			this.style.top='0px';window.scrollTo(0,0);}
			);
		window.document.body.appendChild(toTop);
	
		sc.events.add(window, 'scroll', function(){
			var y =sc.browser.scrollPos()[1];
			if(y <100){
				sc.$('scToTop').style.display="none";
			}else {
				sc.$('scToTop').style.display='block';	
			}
			
			if(y !== ''){
				sc.$('scToTop').style.top = (y+200)+"px";	
			}
		});
		
		toTop = null;
		
	});
	
	
};

sc.findText = function(obj, handler){

	this.obj = obj;
	if(typeof(handler) == 'function'){
		this.handler = handler; 
	}
	this.getAll();
};

sc.findText.prototype = {

	textNodes : [],
	getAll : function(){
		
		var i,x,allTags = this.obj.getElementsByTagName("*");
		
		for(i=0;i<allTags.length;i++){
	
			for(x=0;x<allTags[i].childNodes.length;x++){
				
				switch(allTags[i].nodeName){
					case "IMG":
					case "SCRIPT":
					case "STYLE":
					break;
					default:
					
						if(allTags[i].childNodes[x].nodeType ==3 ){
							if(!allTags[i].childNodes[x].data.match(/^[\n|\s]$/,''))
							{
								this.textNodes.push(allTags[i].childNodes[x]);
							}
						}	
					break;
				}
			}
		}
		
		this.handleText();
	},
	
	handleText : function(){
	
		if(typeof(this.handler) == 'function'){
			for(var x=0;x<this.textNodes.length;x++){
				this.handler(this.textNodes[x]);
			}	
		}
	}
		
};

sc.performance = function(func){
    var t0 = new Date().getTime();
    func();
    return new Date().getTime() - t0;
};

/**
Instantiates HTML tooltips
@param object obj - the object that the tooltip is attached to
@param string txt - the innerHTML of the tooltip
@param string className - the className of the tooltip for css styling - overrides default styles
e.g.
myTip = new surebertCom.toolTip('tester', 'This can <b>also</b> be HTML', 'className');
$('tester').onmouseover = function(){
	this.tip.show();
}
surebertCom.events.add('my', 'click', function(){myTip.show();});
*/
surebertCom.toolTip = function(txt, className){
	var t= this;
	this.className = className || 'surebertComToolTip';
	this.txt =txt;
	this.state=0;
	this.fadein=1;
	this.setup();
	
};

surebertCom.toolTip.prototype = {

	setup : function(){
		var t=this,tip = sc.dom.ce('div');
		
		this.tip = sc.$('body').lastChild.appendChild(tip);
		
		var hide = this.tip.appendChild(sc.dom.create('div', '::close me::'));
		hide.style.cursor='pointer';
		if(this.className == 'surebertComToolTip'){
			hide.style.display='block';
			hide.style.backgroundColor ='red';
			hide.style.width='100%';
			hide.style.textAlign='center';
			hide.style.height='20px';
		} else {
			hide.className = 'surebertComToolTipHide '+this.className+'Hide';
		}
		
		this.tipData = tip.appendChild(sc.dom.create('div', this.txt));

		
		this.tip = sc.dom.s$(tip);
		this.tip.css('display', 'none');
		
		if(this.className == 'surebertComToolTip'){
			this.tip.css('width', 200);
			this.tip.css('padding', '10px');
			this.tip.css('color', 'black');
			this.tip.css('backgroundColor', '#e9f289');
			this.tip.css('border', '2px dotted #d1dd4f');
			
		} else {
			this.tip.className = 'surebertComToolTip '+this.className;
		}
		
		this.tipData.className = 'surebertComToolTipData '+this.className+'Data';
		hide.onmousedown = function(){
			t.hide();
			return false;
		};
		
		this.dragger = new sc.dragger(this.tip);
		
	//	surebertCom.events.remove(drag.onmousemoving);
		
	},
	update : function(dat){
		//i realize this is lame but its the only way it will work in IE
		
		this.tipData = this.tip.replaceChild(sc.create('div', dat, '', this.tipData.className ),this.tip.lastChild);
		//this.tip.height = this.tip.offsetHeight;
	},
	
	show : function(e){
	
		e = e || window.event;
		
		if(this.state !==1){
			if(e !==undefined){

				this.tip.mv(e.clientX+30,e.clientY-40,600);
			}
			this.tip.css('display', 'block');
			
			this.state=1;
		}
		
	},
	
	hide : function(){
		if(this.state !==0){
			this.state=0;
			this.tip.css('display', 'none');
			
		}
	},
	
	fetch : function(url, tag){
		var t=this;
		if(this.sb_load === undefined){
			this.sb_load = new sc.ajax();
			this.sb_load.handler = function(response){
				if(tag !==undefined){
					t.update('<'+tag+'/>'+response+'<'+tag+'/>');
				} else {
					t.update(response);
				}
			};
		}
		this.sb_load.fetch(url);
	},
	
	toggle : function(){
		if(this.state ===0 || this.state ===undefined){
			this.show();
		} else {
			this.hide();
		}
	},
	
	attach : function(obj, className){
		this.obj = sc.$(obj);
		
		if(this.className !='surebertComToolTip'){
			this.obj.className = 'surebertComToolTipAttached '+this.className+'Attached';
		}
		var t=this;
		sc.events.add(this.obj, 'mouseover', 
			function(e){
				t.show(e);
			}
		);
	}
};

sc.progressBar = function(id, width, height, color){
	var progressBar = sc.dom.ce('div');
	width = width || 100;
	height = height || 10;
	color = color || 'green';
	progressBar.css('height', height);
	progressBar.css('backgroundColor', color);
	sc.$(id).appendChild(progressBar);
	this.progressBar = progressBar;
	
	this.timer = new sc.timer (0.01, function(){
	
		if(progressBar.offsetWidth > width){
			progressBar.style.width='0px';
		} else {
			progressBar.style.width = (progressBar.offsetWidth+5)+'px';
		}
	});
};

sc.progressBar.prototype = {
	
	start : function(){
		this.timer.begin();
	},
	
	stop : function(){
		this.progressBar.style.width='0px';
		this.timer.end();
	}
};

sc.warning = {
	height : 50,
	visible : 0,
	message : 'This is the default warning!',
	
	closeEffect : new sc.effect({
		begin : 0,
		time :0,
		duration : 18,
		type : 'inQuart',
		
		handler : function(){
			sc.warning.box.style.height = this.valueRounded+'px';
			sc.warning.box.style.backgroundColor = 'rgb('+Math.round(Math.pow(this.valueRounded,1.4))+',100,0)';	
		},
		
		onEnd : function(){
			//sc.warning.debug("Closing Ended :\n");
			sc.warning.box.style.display='none';
		}
	}),
	
	openEffect : new sc.effect({
		begin : 0,
		duration : 18,
		type : 'outQuart',
		
		handler : function(){
			sc.warning.box.style.height = this.valueRounded+'px';
			sc.warning.box.style.backgroundColor = 'rgb('+Math.round(Math.pow(this.valueRounded,1.4))+',50,50)';	
		},
		
		onEnd : function(){
			this.clickme = sc.events.add(sc.warning.box, 'click', function(e){
				sc.warning.close();
			});
		}
	}),
			
	
	close : function(){
		this.visible= 0;
		this.closeEffect.reset();
		this.closeEffect.begin  = sc.warning.height;
		this.closeEffect.change  = -sc.warning.height;
		this.openEffect.stop();
		this.closeEffect.start();
	},
		
	open : function(){
		this.box.style.display = 'block';
		this.visible= 1;
		this.openEffect.reset();
		this.openEffect.change  = sc.warning.height;
		this.closeEffect.stop();
		this.openEffect.start();
	},
	
			
	warn : function(message){
		this.message = message || this.message;
		
		if(this.visible === 1){
			this.open();
			this.box.innerHTML = this.message;
			
		} else {
			
			if(typeof this.box === 'undefined'){
				var body = sc.$('body');
					
				this.box = sc.dom.create('div', this.message, 'scWarning');
				this.box.style.display='none';
				this.box.style.overflow='hidden';
				this.box.style.height='0px';
				body.insertBefore(this.box, body.firstChild);
			}
		
				this.box.style.display='none';
				this.box.style.cursor ='pointer';
		
			
			this.open();
		}
		
		sc.browser.pngFix(this.box);
	}
};


sc.firefox ={
	warned : 0,
	
	checkBuild : function(){
		
		this.warn = sc.dom.ce('div');
		this.warn = sc.dom.s$(this.warn);
		this.warn.styles({
			padding :'15px',
			fontWeight : 'bold',
			backgroundColor : 'orange',
			border : '2px solid red',
			color : 'white',
			position : 'absolute',
			left : '20px',
			top : '20px',
			zIndex : 999,
			opacity : 0.9,
			width : '200px',
			fontFamily : 'tahoma, verdana, sans',
			fontSize : '0.8em'
			
		});
		
		this.warn.id = 'scFirefoxUpgrade';
		
		this.im = sc.dom.ce('img');
		this.im = sc.dom.s$(this.im);
		this.im.styles({
			cssFloat :'left',
			margin : '10px 10px 160px 10px'
			
		});
		
		this.im.src='http://www.mozilla.com/images/firefox-logo-64x64.png';
		
		this.warn.appendChild(this.im);
		this.warn.appendChild(create('p', 'Your firefox browser is out of date.  You are currently running version '+sc.browser.version+' while version '+scLatestFirefox+' is available!  You should upgrade for best performance and the latest security.<br /><br />'));
		
		this.upgrade = sc.dom.ce('a');
		this.upgrade.href='http://www.mozilla.com/firefox/';
		this.upgrade.innerHTML = 'upgrade!';
		this.upgrade.style.color='blue';
		this.upgrade.style.textDecoration='underline';
		this.upgrade.style.marginRight = '5px';
		
		this.cancel = sc.dom.ce('a');
		this.cancel.href='#';
		this.cancel.onclick = function(){
			
			sc.cookies.remember('FIREFOXNOUPGRADE', 1);
			sc.dom.remove(this.parentNode);
			
		}
		this.cancel.style.textDecoration='underline';
		this.cancel.style.color='red';
		this.cancel.innerHTML = 'cancel';
		
		this.warn.a(this.upgrade);
		this.warn.a(this.cancel);
		
		sc.dom.insertBefore(this.warn, $('body').firstChild);
		this.warned =1;
	}
}
//window events
events.add(window, 'load', function(){
	
	if(typeof scLatestFirefox !='undefined' && sc.browser.agent =='ff' && sc.cookies.recall('FIREFOXNOUPGRADE') !=1 && sc.firefox.warned === 0){
		
		if(sc.browser.version < scLatestFirefox  ){
			
			sc.firefox.checkBuild();
		}
	}
	
	//check textareas for allowtabs=1 attribute
	sc.$('textarea').forEach(function(v){
		if(v.getAttribute('allowtabs')==1 || v.getAttribute('allowtabs')=="yes"){
			sc.forms.allowTabs(v);
		}
	});
	
});
