/* Copyright (c) 2008 Akatoo Inc. */

function addEvent(C,B,A){if(C.addEventListener){C.addEventListener(B,A,false);EventCache.add(C,B,A)}else{if(C.attachEvent){C["e"+B+A]=A;C[B+A]=function(){C["e"+B+A](window.event)};C.attachEvent("on"+B,C[B+A]);EventCache.add(C,B,A)}else{C["on"+B]=C["e"+B+A]}}}var EventCache=function(){var A=[];return{listEvents:A,add:function(B,D,C){A.push(arguments)},flush:function(){var B,C;for(B=A.length-1;B>=0;B=B-1){C=A[B];if(C[0].removeEventListener){C[0].removeEventListener(C[1],C[2],C[3])}if(C[1].substring(0,2)!="on"){C[1]="on"+C[1]}if(C[0].detachEvent){C[0].detachEvent(C[1],C[2])}C[0][C[1]]=null}}}}();addEvent(window,"unload",EventCache.flush);function $(A){return document.getElementById(A)}function stopEventPropagation(A){if(!A){A=window.event}A.cancelBubble=true;if(A.stopPropagation){A.stopPropagation()}}function preventEventDefault(A){if(!A){A=window.event}if(A.preventDefault){A.preventDefault()}else{A.returnValue=false}}Function.prototype.bind=function(){var B=[],D=arguments[0],C=this,A;for(A=1;A<arguments.length;++A){B.push(arguments[A])}return function(){for(var E=0;E<arguments.length;++E){B.push(arguments[E])}return C.apply(D,B)}};function focusFirstEmptyAfterPageLoads(){var A=arguments;addEvent(window,"load",function(){focusFields(A)})}function focusFirstEmpty(){var A=arguments;focusFields(A)}function focusFields(B){var A=B.length,D,C,E;for(D=0;D<A;D++){C=null;E=$(B[D]);if(null!=E){if(E.style.display!="none"&&E.style.visibility!="hidden"){if("text"==E.type||"password"==E.type){C=E.value}else{if("textarea"==E.type){C=E.innerHTML}}if(null!=C){if(""==C){try{E.focus()}catch(E){}break}}}}}}function focusAfterPageLoads(A){addEvent(window,"load",function(){try{$(A).focus()}catch(B){}})};

/* Taken with modification from Alfred's "Pica". */

var instances = new Object();


// For JS and DOM.
function Lang(){
	
	// Browser
	
		/*public*/ this.isIE = function(){
			return this.findBrowserName("MSIE");
		}
		
		/*public*/ this.isIE7OrNewer = function(){
			return (
				this.findBrowserName("MSIE 7") ||
				this.findBrowserName("MSIE 8") ||
				this.findBrowserName("MSIE 9") );
		}
		
		/*public*/ this.isIE8 = function(){
			return this.findBrowserName("MSIE 8");
		}
		
		/*public*/ this.isIE7 = function(){
			return this.findBrowserName("MSIE 7");
		}
		
		/*public*/ this.isIE6 = function(){
			return this.findBrowserName("MSIE 6");
		}
		
		/*public*/ this.isIE6OrOlder = function(){
			return (
				this.findBrowserName("MSIE 6") ||
				this.findBrowserName("MSIE 5") ||
				this.findBrowserName("MSIE 4") );
		}
		
		/*public*/ this.isFirefox = function(){
			return this.findBrowserName("Firefox");
		}
		
		/*public*/ this.isSafari = function(){
			return this.findBrowserName("Safari") &&
				 ! this.findBrowserName("Chrome") ;
		}
		
		/*public*/ this.isChrome = function(){
			return this.findBrowserName("Chrome");
		}
		
		/*private*/ this.findBrowserName = function(/*string*/ text){
			var nav = navigator.userAgent ;
			return -1 != nav.indexOf( text ) ;
		}
		
	// Window
	
		/*public*/ this.getWindowWidth = function(){
			return window.innerWidth ? 
				window.innerWidth : 
				document.body.clientWidth ;
		}
		
		/*public*/ this.getWindowHeight = function(){
			return window.innerHeight ? 
				window.innerHeight : 
				document.body.clientHeight ;
		}
		
		/*public*/ this.getWindowScrollY = function(){
			var out = 0;
			if( lang.isIE() ){
				//document.compatMode;
				//out = document.documentElement.scrollTop;
				out = lang.b().scrollTop;
			}
			else out = lang.w().scrollY;
			return out;
		}
		
		/*public*/ this.getWindowScrollX = function(){
			var out = 0;
			if( lang.isIE() ){
				//document.compatMode;
				//out = lang.d().documentElement.scrollLeft; 
				out = lang.b().scrollLeft;
			}
			else out = lang.w().scrollX;
			return out;
		}
		
		/*public*/ this.center = function(/*Element*/ e){
			
			var wx = lang.getWindowScrollX();
			var wy = lang.getWindowScrollY();
			var ww = lang.getWindowWidth();
			var wh = lang.getWindowHeight();
			var ew = lang.getW( e );
			var eh = lang.getH( e );
			if( lang.isIE() ){
				// caution: may need to change if
				// not in IE Quirks mode.
				lang.setL( e, wx + ((ww-ew)/2) );
				lang.setT( e, wy + ((wh-eh)/2) );
			}
			else{
				lang.setL( e, wx + ((ww-ew)/2) );
				lang.setT( e, wy + ((wh-eh)/2) );
			}
		}
	
	// Common Elements.
	
		/*public*/ this.w = function(){ 
			return window; 
		}
		
		/*public*/ this.d = function(){ 
			return document; 
		}
		
		/*public*/ this.b = function(){ 
			return this.d().body; 
		}
		
		/*public*/ this.e = function( /*string*/ id ){ 
			var e = this.d().getElementById(id);
			if( !e ){
				var elms = this.d().getElementsByName(id);
				if( elms )
					if( elms.length )
						e = elms[0];
			}
			
			return e;
		}

	// Element ID's.
		
		/*private*/ this.defaultID = 0;
		
		/*public*/ this.id = function( /*Element*/ e ){ 
			if( e ){
				if( ! e.id ) 
					e.id = "ELEMENT" + (lang.defaultID++) ;
				return e.id;
			}
			return null;
		}
		
		/*public*/ this.getIDIndex = function( /*string*/ id, /*int*/ pos ){
			var a = 0;
			for(var p=0; p<=pos; p++){
				a = id.indexOf("[", a);
				if( -1 == a ) return -1;
				a += 1;
			}
			var b = id.indexOf("]", a);
			return lang.int( id.substr(a, b-a) );
		}
		
	// Creating new elements.
	
		/*public*/ this.newElement = function( /*string*/ tag ){ 
			return this.d().createElement(tag); 
		}
		
		/*public*/ this.newDiv	= function(){
			return this.newElement("div"); 
		}
		
		/*public*/ this.newScript = function(){ 
			return this.newElement("script"); 
		}
		
		/*public*/ this.newStyle = function(){ 
			return this.newElement("style"); 
		}
		
		/*public*/ this.newStyleSheet = function(){ 
			return this.newElement("styleSheet"); 
		}
		
		/*public*/ this.newLink = function(){ 
			return this.newElement("link"); 
		}
		
		/*public*/ this.newImg = function(){
			return this.newElement("img"); 
		}
	
	// Text
	
		/*public*/ this.setText	= function( /*Element*/ e, /*string*/ text ){ 
			var tag = e.tagName.toUpperCase();
			if( 	 tag == "INPUT" 	){ e.value = text; }
			else if( tag == "IMG"   	){ e.src   = text; }
			else if( tag == "TEXTAREA"	){ e.value = text; e.innerHTML = text; } // For Firefox & IE.
			else /*last attempt*/		 { e.innerHTML = text; }			
		}
		
		/*public*/ this.getText	= function( /*Element*/ e ){
			var tag = e.tagName.toUpperCase();
			if( 	 tag == "INPUT" 	){ 
				var t = e.type;
				if( "checkbox" == t ){
					if( e.checked ) return "on";
					else return "off";
				}
				else{
					return e.value;
				}
			}
			else if( tag == "IMG"   	){ return e.src; }
			else if( tag == "TEXTAREA"	){ return e.value ? e.value : e.innerHTML ; } // For Firefox & IE.
			else /*last attempt*/		 { return e.innerHTML; }
		}
		
	// Read / ReadWrite
	
		/*public*/ this.setRead = function( /*Element*/ e ){
			if( this.isIE() )
				 e.readOnly = true;
			else e.readOnly = "yes";
		}
		
		/*public*/ this.setReadWrite = function( /*Element*/ e ){
			if( this.isIE() )
				 e.readOnly = false;
			else e.readOnly = "";
		}
	
	// Checked
	
		/*public*/ this.setChecked = function( /*Element*/ e ){
			e.checked = true;
		}
		
		/*public*/ this.setUnChecked = function( /*Element*/ e ){	
			e.checked = false;
		}
		
		/*public*/ this.isChecked = function( /*Element*/ e ){
			return ( "yes"==e.check || true==e.checked );
		}
		
	// Visibility
	
		// Fixies IE visibility problems.
		/*public*/ this.show = function( /*Element*/ e, /*int*/ msBegin ){ 
			var id = lang.id(e);
			if( ! lang.isShown(e) ){
				if( msBegin )
					setTimeout( "lang.setL(lang.e('"+id+"'), lang.getL(lang.e('"+id+"')) + 10000);", msBegin);
				else
					lang.setL(e, lang.getL(e) + 10000 );
			}
		}
		
		/*public*/ this.hide = function( /*Element*/ e, /*int*/ msBegin ){ 
			var id = lang.id(e);
			if( lang.isShown(e) ){
				if( msBegin )
					setTimeout( "lang.setL(lang.e('"+id+"'), lang.getL(lang.e('"+id+"')) - 10000);", msBegin);
				else
					lang.setL(e, lang.getL(e) - 10000 );
			}
		}
		
		/*public*/ this.isShown = function( /*Element*/ e ){
			return ( -1000 < lang.getL(e) ) ;
		}
		
	// Opacity
	
		/*public*/ this.setOpacity = function( /*Element*/ e, /*float*/ alpha ){ 
			e.style.opacity=alpha; 
			e.style.filter = "alpha(opacity = " + 
				(alpha*100) + ")"; 
		}
		
		/*public*/ this.getOpacity = function( /*Element*/ e ){ 
			var o = e.style.opacity ? 
				e.style.opacity : e.style.filter ;
			if( !o ) o = -1;
			return this.float(o); 
		}
		
		/*public*/ this.fade = function( /*Element*/ e, /*float*/ alphaFrom, /*float*/ alphaTo, /*int*/ msBegin ){
			var id = lang.id(e);
			if( ! msBegin ) msBegin = 0;
			setTimeout("lang.fadeStep(lang.e('"+id+"'), "+alphaFrom+", "+alphaTo+");", msBegin);
		}
		
		/*private*/ this.fadeStep = function( /*Element*/ e, /*float*/ alphaFrom, /*float*/ alphaTo){
			if( e ){
				var id = lang.id(e);
				var ms = 100;
				var dt = alphaTo - alphaFrom;
				if( dt ){
					var a = alphaFrom ;
					if( alphaFrom < alphaTo ){
						
						a += 0.1;
						
						if( alphaTo < a ) a = alphaTo;
					}
					else{
						a -= 0.1;
						if( a > alphaFrom ) a = alphaFrom;
					}
					lang.setOpacity(e, a);
					if( a!=alphaFrom && a!=alphaTo ){
						alphaFrom = a;
						setTimeout("lang.fadeStep(lang.e('"+id+"'), "+alphaFrom+", "+alphaTo+");", 25);
					}
					else{ // Hack to fix an IE opacity bug
						if( 1 == lang.getOpacity(e) )
							if( e.style.filter )
								e.style.filter = "";
					}
				}
			}
		}
	
	// Event Handling.
	
		/*public*/ this.onEvent = function( /*Element*/ e, /*string*/ evt, /*Function*/ f ){ 
			// Hook 'em up!
			if( null != e && undefined != e ){
				if( e.addEventListener )
					 e.addEventListener(evt, f, false); 
				else e.attachEvent( "on" + evt, f );
			}
		}
		
		/*public*/ this.onLoad = function( /*Element*/ e, /*Function*/ f ){ 
			this.onEvent(e, 'load', f); 
		}
		
		/*public*/ this.onClick = function( /*Element*/ e, /*Function*/ f ){ 
			this.onEvent(e, 'click', f); 
		}	
		
		/*public*/ this.onDblClick = function( /*Element*/ e, /*Function*/ f ){ 
			this.onEvent(e, 'dblclick', f); 
		}	
		
		/*public*/ this.onMouseOver = function( /*Element*/ e, /*Function*/ f ){ 
			this.onEvent(e, 'mouseover', f); 
		}	
		
		/*public*/ this.onMouseOut = function( /*Element*/ e, /*Function*/ f ){ 
			this.onEvent(e, 'mouseout', f); 
		}	
		
		/*public*/ this.onMouseDown = function( /*Element*/ e, /*Function*/ f ){ 
			this.onEvent(e, 'mousedown', f); 
		}	
		
		/*public*/ this.onMouseUp = function( /*Element*/ e, /*Function*/ f ){ 
			this.onEvent(e, 'mouseup', f); 
		}	
		
		/*public*/ this.onFocus = function( /*Element*/ e, /*Function*/ f ){ 
			this.onEvent(e, 'focus', f); 
		}	
		
		/*public*/ this.onBlur = function( /*Element*/ e, /*Function*/ f ){ 
			this.onEvent(e, 'blur', f); 
		}
		
		/*public*/ this.onKeyDown = function( /*Element*/ e, /*Function*/ f ){ 
			this.onEvent(e, 'keydown', f); 
		}
		
		/*public*/ this.onKeyUp = function( /*Element*/ e, /*Function*/ f ){ 
			this.onEvent(e, 'keyup', f);
		}
		
		/*public*/ this.onType = function( /*Element*/ e, /*Function*/ f ){ 
			this.onEvent(e, 'keyup', f);
		}
		
		/*public*/ this.onChange = function( /*Element*/ e, /*Function*/ f ){
			this.onEvent(e, 'change', f);
		}
		
		/*public*/ this.onScroll = function( /*Element*/ e, /*Function*/ f ){
			this.onEvent(e, 'scroll', f);
		}
		
		/*public*/ this.target = function( /*Event*/   v ){ 
			return (v.target ? v.target : v.srcElement) ; 
		}
		
		// To revisit.
		/*public*/ this.originalTarget = function( /*Event*/ v ){
			return (v.originalTarget ? v.originalTarget : v.srcElement) ; 
		}
		
	// Casts.
	
		/*public*/ this.int = function( /*string*/ txt ){ 
			return parseInt(txt, 10); 
		}
		
		/*public*/ this.float = function( /*string*/ txt ){ 
			return parseFloat(txt, 10); 
		}
	
	// Positioning.
	
		/*public*/ this.getL = function( /*Element*/ e ){ 
			return this.int( e.style.left 	); 
		}
		
		/*public*/ this.getR = function( /*Element*/ e ){ 
			return this.int( e.style.right ); 
		}
		
		/*public*/ this.getT = function( /*Element*/ e ){ 
			return this.int( e.style.top 	); 
		}
		
		/*public*/ this.getB = function( /*Element*/ e ){ 
			return this.int( e.style.bottom ); 
		}
		
		/*public*/ this.getW = function( /*Element*/ e ){ 
			return this.int( e.style.width 	); 
		}
		
		/*public*/ this.getH = function( /*Element*/ e ){ 
			return this.int( e.style.height 	); 
		}
		
		/*public*/ this.getScreenL = function(/*Element*/ e){
			var l=0;
			while(true){
				if( null==e || undefined==e ) break;
				l+=e.offsetLeft;
				e = e.offsetParent;
			}
			return l;
		}
		
		/*public*/ this.getScreenT = function(/*Element*/ e){
			var t=0;
			while(true){
				if( null==e || undefined==e ) break;
				t+=e.offsetTop;
				e = e.offsetParent;
			}
			return t;
		}
		
		/*public*/ this.getViewportL = function(/*Element*/ e){
			var l=0;
			while(true){
				if( null==e || undefined==e ) break;
				l+=(e.offsetLeft-e.scrollLeft);
				e = e.offsetParent;
			}
			return l;
		}
		
		/*public*/ this.getViewportT = function(/*Element*/ e){
			var t=0;
			while(true){
				if( null==e || undefined==e ) break;
				t+=(e.offsetTop-e.scrollTop);
				e = e.offsetParent;
			}
			return t;
		}
		
		/*public*/ this.setL = function( /*Element*/ e, /*int*/ px, /*int*/ msBegin ){ 
			if( ! msBegin ){
				e.style.left = px + "px"; 
			}
			else{
				var id = lang.id( e );
				var js = "lang.e('" + id + "').style.left = \"" + px + "px\";" ;
				setTimeout( js, msBegin );
			}
		}
		
		/*public*/ this.setR = function( /*Element*/ e, /*int*/ px, /*int*/ msBegin ){ 
			if( ! msBegin ){
				e.style.right = px + "px"; 
			}
			else{
				var id = lang.id( e );
				var js = "lang.e('" + id + "').style.right = \"" + px + "px\";" ;
				setTimeout( js, msBegin );
			}
		}
		
		/*public*/ this.setT = function( /*Element*/ e, /*int*/ px, /*int*/ msBegin ){ 
			if( ! msBegin ){
				e.style.top = px + "px"; 
			}
			else{
				var id = lang.id( e );
				var js = "lang.e('" + id + "').style.top = \"" + px + "px\";" ;
				setTimeout( js, msBegin );
			}
		}
		
		/*public*/ this.setB = function( /*Element*/ e, /*int*/ px, /*int*/ msBegin ){ 
			if( ! msBegin ){
				e.style.bottom = px + "px"; 
			}
			else{
				var id = lang.id( e );
				var js = "lang.e('" + id + "').style.botttom = \"" + px + "px\";" ;
				setTimeout( js, msBegin );
			}
		}
		
		/*public*/ this.setW = function( /*Element*/ e, /*int*/ px, /*int*/ msBegin ){ 
			if( ! msBegin ){
				e.style.width = px + "px"; 
			}
			else{
				var id = lang.id( e );
				var js = "lang.e('" + id + "').style.width = \"" + px + "px\";" ;
				setTimeout( js, msBegin );
			}
		}
			
		/*public*/ this.setH = function( /*Element*/ e, /*int*/ px, /*int*/ msBegin ){ 
			if( ! msBegin ){
				e.style.height = px + "px"; 
			}
			else{
				var id = lang.id( e );
				var js = "lang.e('" + id + "').style.height = \"" + px + "px\";" ;
				setTimeout( js, msBegin );
			}
		}
		
		/*public*/ this.centerWithRespectTo = function( /*Element*/ toCenter, /*Element*/ withRespectTo ){
			var a = toCenter;
			var b = withRespectTo;
			
			var aL = lang.getL( a );
			var aT = lang.getT( a );
			var aW = lang.getW( a );
			var aH = lang.getH( a );
			
			var bL = lang.getL( b );
			var bT = lang.getT( b );
			var bW = lang.getW( b );
			var bH = lang.getH( b );
			
			lang.setL( a, bL + ((bW - aW)/2) );
			lang.setT( a, bT + ((bH - aH)/2) );
			lang.setW( a, aW );
			lang.setH( a, aH );
		}
		
	// Math.
	
		/*public*/ this.min	= function( /*number*/ lhs, /*number*/ rhs ){ 
			return Math.min( lhs, rhs ); 
		}
		
		/*public*/ this.max	= function( /*number*/ lhs, /*number*/ rhs ){ 
			return Math.max( lhs, rhs ); 
		}
		
		/*public*/ this.floor = function( /*number*/ n ){
			return Math.floor(n);
		}
		
		/*public*/ this.ceil = function( /*number*/ n ){
			return Math.ceil(n);
		}
		
		/*public*/ this.round = function( /*number*/ n ){ 
			return Math.round(n); 
		}
		
		/*public*/ this.abs	= function( /*number*/ n ){ 
			return Math.abs(n); 
		}
		
		/*public*/ this.pow = function( /*number*/ n, /*int*/ power ){
			return Math.pow(n, power);
		}
		
	// String
	
		/*public*/ this.replaceCaseSensitive = function( /*string*/ s, /*string*/ toReplace, /*string*/ replaceWith){
			return this.replace( s, toReplace, replaceWith, true );
		}
		
		/*public*/ this.replaceCaseInsensitive = function( /*string*/ s, /*string*/ toReplace, /*string*/ replaceWith){
			return this.replace( s, toReplace, replaceWith, false );
		}
		
		/*public*/ this.replace = function( /*string*/ s, /*string*/ toReplace, /*string*/ replaceWith, /*bool*/ caseSensitive){
			
			var f = caseSensitive ? "g" : "gi" ;
			if( this.isIE() ){
				var re = new RegExp( toReplace, f );
			 	s = s.replace(re, replaceWith);
			 	delete re;
		 	}
		 	else if( this.isFirefox() ){
			 	s = s.replace(toReplace, replaceWith, f);
		 	}
		 	else{
			 	var bef = s; var aft = s;
			 	for( var i=0; i<500; i++){
				 	bef = aft;
			 		aft = bef.replace( toReplace, replaceWith );
			 		if( bef == aft ) break;
		 		}
			 	s = aft;
		 	}
		 	return s;
		}
		
		/*public*/ this.strLeft = function( /*string*/ s, /*int*/ chars ){
			return s.substr(0, chars);
		}
		
		/*public*/ this.strRight = function( /*string*/ s, /*int*/ chars ){
			var l = this.strLength(s);
			var s = this.max( l-chars, 0 );
			return s.substr(s);
		}
		
		/*public*/ this.strLength = function( /*string*/ s ){
			return s.length;
		}
		
		/*public*/ this.strMid = function( /*string*/ s, /*int*/ start, /*int*/ chars ){
			if( chars ) return s.substr(start, chars);
			else return s.substr(start);
		}
		
		/*public*/ this.strToUpper = function(/*string*/ s){
			return s.toUpperCase();
		}
		
		/*public*/ this.strToLower = function(/*string*/ s){
			return s.toLowerCase();
		}
		
	// Ajax.
	
		/*public*/ this.sendAjax = function(/*string*/ method, /*string*/ url, /*Object*/ params, /*function*/ clbSuccess, /*function*/ clbFailure){
			var req = this.getAjaxRequest();
			req.onreadystatechange = function(){ 
			    if (req.readyState == 4) {
			        if (req.status == 200) {
			            if( clbSuccess ) clbSuccess(req.responseText);
			        } else {
				        //alert("There was a problem retrieving the XML data:\n" + req.statusText + "/" + req.responseText);
				        if( clbFailure ) clbFailure(req.responseText);
			            
			        }
			    }
			};			
			
			var body = "";
			for( key in params ){
				var val = params[key];
				if( body ) body += "&";
				body += key + "=" + encodeURI(val) ;
			}
			req.open("POST", url + "?" + body, true); // true means asynch, false means synch
			req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			req.send(body);
		}
		
		/*private*/ this.getAjaxRequest = function(){
			var req = null;
			if( this.isIE() ){
				try{ req = new ActiveXObject("Msxml2.XMLHTTP"); }
				catch(e){
				    try{ req =new ActiveXObject("Microsoft.XMLHTTP"); }
				    catch(e){}
				}
			}
			else{
				try{ req = new XMLHttpRequest(); }
				catch(e){}
			}
			return req;
		}
		
	// Date And Time.
		
		/*public*/ this.now = function(){
			var now = new Date();
			var nowMs = now.getTime();
			delete now;
			return nowMs;
		}
	
	// MsgBox
	
		/*public*/ this.msgBox = function( /*string*/ s0, /*string*/ s1, /*string*/ s2, /*string*/ s3, /*string*/ s4, /*string*/ s5, /*string*/ s6, /*string*/ s7, /*string*/ s8, /*string*/ s9 ){
			alert( "[" + s0 + "]\n[" + s1 + "]\n[" + s2 + "]\n[" + s3 + "]\n[" + s4 + "]\n[" + s5 + "]\n[" + s6 + "]\n[" + s7 + "]\n[" + s8 + "]\n[" + s9 + "]" ); 
		}
	
	/*public*/ this.trash = function( /*string*/ objectPath ){}
}
var lang = new Lang();



function AnimationSequence(/*string*/ eid, /*string*/ f){
	/*public*/ this.elementID = null;
	/*public*/ this.facet = ""; 		// L,T,W,H
	
	// Specifies the travelling path.
	/*public*/ this.deltaPx = -1;
	/*public*/ this.deltaMs = -1;
	/*public*/ this.curve 	= "";
	
	// Decided at runtime.
	/*public*/ this.startPx = -1;
	/*public*/ this.startMs = -1;
	
	// Implicit constructor.
	this.construct = function(){
		this.elementID = eid;
		this.facet = f;
	}
	this.construct();
	
	/*public*/ this.setTravellingPath = function(/*int*/ deltaPx, /*int*/ deltaMs, /*string*/ curve){
		this.deltaPx = deltaPx;
		this.deltaMs = deltaMs;
		this.curve 	 = curve;
	}
	
	/*public*/ this.startFrame = function(){
		var e = lang.e(this.elementID);
		if( 	"L" == this.facet ) this.startPx = lang.getL( e );
		else if("R" == this.facet ) this.startPx = lang.getR( e );
		else if("T" == this.facet ) this.startPx = lang.getT( e );
		else if("B" == this.facet ) this.startPx = lang.getB( e );
		else if("W" == this.facet ) this.startPx = lang.getW( e );
		else if("H" == this.facet ) this.startPx = lang.getH( e );
		this.startMs = lang.now();
	}
	
	/*public*/ this.drawFrame = function(){
		if( 	 "linear" 	 == this.curve ) return this.computeLinear();
		else if( "quadratic" == this.curve ) return this.computeQuadratic();
		else if( "cubic"	 == this.curve ) return this.computeCubic();
		else return this.computeLinear();
	}
	
	
	/*private*/ this.computeLinear = function(){
		var per = (lang.now() - this.startMs) / this.deltaMs;
		if( per < 0 ) per = 0;
		if( 1 < per ) per = 1;
		
		var px = lang.round( (per * this.deltaPx) + this.startPx );
		var e = lang.e(this.elementID);
		if( 	"L" == this.facet ) lang.setL( e, px );
		else if("R" == this.facet ) lang.setR( e, px );
		else if("T" == this.facet ) lang.setT( e, px );
		else if("B" == this.facet ) lang.setB( e, px );
		else if("W" == this.facet ) lang.setW( e, px );
		else if("H" == this.facet ) lang.setH( e, px );
		return (per != 1) ;
	}
	
	/*private*/ this.computeQuadratic = function(){
		var now = lang.now();
		var per = (now - this.startMs) / this.deltaMs;
		if( per < 0 ) per = 0;
		if( 1 < per ) per = 1;
		
		// Two quadratic formulas spliced together:
		// Left formula if a normal quadratic: y = a(x^2);
		// Right formula is an upside-down quadratic: y = -a((x-dx)^2) + dy
		
		// You really just have to trust me on this one...
		var dy = this.deltaPx;
		var dx = this.deltaMs;
		var a = (dy/2) / lang.pow( (dx/2), 2 ) ;
		
		var x = per * dx;
		var y = null;
		if( x < (dx/2) ) 		// Left formula.
			y = a*lang.pow(x, 2) ;
		else 					// Right formula.
			y = ( (-1*a)*lang.pow(x-dx,2) ) + dy ;
		
		var px = lang.round(y) + this.startPx;
		var e = lang.e(this.elementID);
		if( 	"L" == this.facet ) lang.setL( e, px );
		else if("R" == this.facet ) lang.setR( e, px );
		else if("T" == this.facet ) lang.setT( e, px );
		else if("B" == this.facet ) lang.setB( e, px );
		else if("W" == this.facet ) lang.setW( e, px );
		else if("H" == this.facet ) lang.setH( e, px );
		return (per != 1);
	}
	
	/*private*/ this.computeCubic = function(){
		
		var now = lang.now();
		var per = (now - this.startMs) / this.deltaMs;
		if( per < 0 ) per = 0;
		if( 1 < per ) per = 1;
		
		// Two cubic formulas spliced together:
		// Left formula if a normal cubic: y = a(x^3)
		// Right formula is an upside-down cubic: y = -a((x-dx)^3) + dy
		
		// You really just have to trust me on this one...
		var dy = this.deltaPx;
		var dx = this.deltaMs;
		var a = (dy/2) / lang.pow(dx/2, 3);
		
		var x = per * dx;
		var y = null;
		if( x < (dx/2) ) 		// Left formula.
			y = a*lang.pow(x, 3) ;
		else 					// Right formula.
			y = ( a*lang.pow(x-dx,3) ) + dy ;
		
		var px = lang.round(y) + this.startPx;
		var e = lang.e(this.elementID);
		if( 	"L" == this.facet ) lang.setL( e, px );
		else if("R" == this.facet ) lang.setR( e, px );
		else if("T" == this.facet ) lang.setT( e, px );
		else if("B" == this.facet ) lang.setB( e, px );
		else if("W" == this.facet ) lang.setW( e, px );
		else if("H" == this.facet ) lang.setH( e, px );
		return (per != 1);
	}
}




function AnimationSubject(){
	/*public*/ this.elementID = null;
	/*public*/ this.sequences = new Array();
	/*public*/ this.callback  = null;
	
	/*public*/ this.getSequence = function(/*string*/ facet){
		return this.sequences[facet];
	}
	
	/*public*/ this.addSequence = function(/*string*/ facet){
		var seq = new AnimationSequence( this.elementID, facet );
		this.sequences.push(seq);
		return seq;
	}
	
	/*public*/ this.clearSequences = function(){
		for( s in this.sequences ){
			for( m in this.sequences[s] )
				delete m;
			delete this.sequences[s];
		}
		delete this.sequences;
		this.sequences = new Array();
	}
	
	/*public*/ this.hasSequences = function(){
		return (i.sequences != 0) ;
	}
	
	/*public*/ this.addCallback = function(/*Object*/ clb){
		this.callback = clb;
	}
	
	// TODO:
	/*public*/ this.arrangeSequences = function(){}
	
	/*public*/ this.runSequences = function(/*int*/ msStartAnimation){
		if( ! msStartAnimation ) msStartAnimation = ani.msSequenceInterval;
		setTimeout( "ani.subjects['" + this.elementID + "'].runSequencesNow();", msStartAnimation);
	}
	
	/*private*/ this.runSequencesNow = function(){
		for( s in this.sequences )
			this.sequences[s].startFrame();
		setTimeout( "ani.subjects['" + this.elementID + "'].sequences_onTimer();" , 0);
	}
	
	/*public*/ this.sequences_onTimer = function(){
		var poll = false;
		for( s in this.sequences ){
			if( this.sequences[s].drawFrame() )
				poll = true;
		}
		
		if( poll ){
			var si = ani.msSequenceInterval;
			setTimeout( "ani.subjects['" + this.elementID + "'].sequences_onTimer();" , si);
		}
		else{
			if( this.callback )
				this.callback();
		}
	}
}




function Animation(){
	/*public*/ this.subjects = new Object();
	/*private*/ this.msSequenceInterval = 25;
	
	/*public*/ this.addSubject = function(/*Element*/ e){
		var sub = new AnimationSubject();
		var id = lang.id(e);
		sub.elementID = id;
		this.subjects[ id ] = sub;
		return sub;
	}
	
	/*public*/ this.getSubject = function(/*Element*/ e){
		var id = lang.id(e);
		if( this.subjects[id] )
			return this.subjects[id];
		else return null;
	}
	
	/*public*/ this.existSubject = function(/*Element*/ e){
		var id = lang.id(e);
		var sub = this.getSubject(e);
		if( ! sub ) sub = this.addSubject(e);
		return sub;
	}
	
	/*public*/ this.removeSubject = function(/*Element*/ e){
		var id = lang.id(e);
		if( this.getSubject(e) )
			lang.trash("ani.subjects." + id );
	}
	
	// Simple animations.
	
		/*public*/ this.runSingleSequence = function( /*Element*/ e, /*string*/ facet, /*int*/ deltaPx, /*int*/ deltaMs, /*string*/ curve, /*Object*/ callback, /*int*/ msStartAnimation){
			var sub = ani.existSubject( e );
			sub.clearSequences();
			var seq = sub.addSequence( facet );
			seq.setTravellingPath( deltaPx, deltaMs, curve);
			sub.addCallback(callback);
			sub.runSequences(msStartAnimation);
		}
		
		/*public*/ this.appearFrom = function( /*Element*/ toAppear, /*Element*/ from, /*int*/ deltaMs, /*string*/ curve, /*Object*/ callback, /*int*/ msStartAnimation ){
			var a = toAppear;
			var f = from;
			
			lang.show( a );
			a.style.overflow = "hidden";
			
			var aL = lang.getL(a);
			var aT = lang.getT(a);
			var aW = lang.getW(a);
			var aH = lang.getH(a);
			
			var fL = lang.getL(f);
			var fT = lang.getT(f);
			var fW = lang.getW(f);
			var fH = lang.getH(f);
			
			var cL = fL + (fW/2);
			var cT = fT + (fH/2);
			
			lang.setL( a, cL );
			lang.setT( a, cT );
			lang.setW( a, 0  );
			lang.setH( a, 0  );
			
			var sub = ani.existSubject( a );
			
			var seq = sub.addSequence( "L" );
			seq.setTravellingPath( aL-cL, deltaMs, curve );
			
			seq = sub.addSequence( "T" );
			seq.setTravellingPath( aT-cT, deltaMs, curve );
			
			seq = sub.addSequence( "W" );
			seq.setTravellingPath( aW, deltaMs, curve );
			
			seq = sub.addSequence( "H" );
			seq.setTravellingPath( aH, deltaMs, curve );
			
			sub.addCallback( callback );
			sub.runSequences( msStartAnimation );
		}
		
		/*public*/ this.disappearInto = function( /*Element*/ toDisappear, /*Element*/ into, /*int*/ deltaMs, /*string*/ curve, /*Object*/ callback, /*int*/ msStartAnimation ){
			var d = toDisappear;
			var i = into;
			
			lang.show( d );
			d.style.overflow = "hidden";
			
			var dL = lang.getL(d);		// toDisappear.
			var dT = lang.getT(d);
			var dW = lang.getW(d);
			var dH = lang.getH(d);
			
			var iL = lang.getL(i);		// into.
			var iT = lang.getT(i);
			var iW = lang.getW(i);
			var iH = lang.getH(i);
			
			var cL = iL + (iW/2);
			var cT = iT + (iH/2);
			
			var sub = ani.existSubject( d );
			var seq = sub.addSequence( "L" );
			seq.setTravellingPath( -(dL-cL), deltaMs, curve );
			
			seq = sub.addSequence( "T" );
			seq.setTravellingPath( -(dT-cT), deltaMs, curve );
			
			seq = sub.addSequence( "W" );
			seq.setTravellingPath( -dW, deltaMs, curve );
			
			seq = sub.addSequence( "H" );
			seq.setTravellingPath( -dH, deltaMs, curve );
			
			// HACK: Defer callback until after onDisappear().
			sub.addCallback( null ); 
			this.disappearCallback = callback;
			sub.runSequences( msStartAnimation );
			setTimeout( "ani.onDisappear( lang.e('" + lang.id(d) + "'), " + dL + ", " + dT + ", " + dW + ", " + dH + ");" , deltaMs+250 );
		}
		
		this.disappearCallback = null;
		
		/*public*/ this.onDisappear = function( /*Element*/ disappeared, /*int*/ l, /*int*/ t, /*int*/ w, /*int*/ h, /*Object*/ callback ){
			var d = disappeared;
			lang.show( d );
			lang.setL( d, l );
			lang.setT( d, t );
			lang.setW( d, w );
			lang.setH( d, h );
			lang.hide( d );
			if( this.disappearCallback )
				this.disappearCallback();
		}
		
}
var ani = new Animation();




function Timer(){
	/*public*/ this.timerID    	  = -1;
	/*public*/ this.callback   	  = null;
	/*public*/ this.msInterval 	  = -1;
	/*public*/ this.msLastStarted = -1;
	/*public*/ this.isStarted  	  = false;
	/*public*/ this.pollID		  = -1;
}




function Timers(){
	/*public*/ this.timers = new Array();
	
	/*public*/ this.addTimer = function(/*Object*/ callback, /*int*/ msInterval){
		var t = new Timer();
		var tid = this.timers.length;
		t.timerID = tid;
		t.callback = callback;
		t.msInterval = msInterval;
		this.timers[tid] = t;
		return tid;
	}
	
	/*private*/ this.isTimerReady = function(/*int*/ timerID){
		var out = false;
		var t = this.timers[timerID];
		if( t ){
			if( -1 	 != t.timerID 	 &&
				null != t.callback   &&
				-1 	 != t.msInterval ){
				out = true;
			}
		}
		return out;
	}
	
	/*public*/ this.getTimer = function(/*int*/ timerID ){
		var out = null;
		if( this.isTimerReady(timerID) )
			out = this.timers[timerID] ;
		return out;
	}
	
	/*public*/ this.start = function(/*int*/ timerID){
		var out = false;
		var t = this.getTimer(timerID);
		if( t ){
			if( ! t.isStarted ){
				t.isStarted = true;
				t.msLastStarted = lang.now();
				this.pollAfterMs( t.timerID, ++t.pollID, t.msInterval );
				out = true;
			}
		}
		return out;
	}
	
	/*public*/ this.stop  = function(/*int*/ timerID){
		var out = false;
		var t = this.getTimer(timerID);
		if( t ){
			if( t.isStarted ){
				t.isStarted = false;
				out = true;
			}
		}
		return out;
	}
	
	/*public*/ this.isStarted = function(/*int*/ timerID){
		var out = false;
		var t = this.getTimer(timerID);
		if( t ) out = t.isStarted;
		return out;
	}
	
	/*private*/ this.poll = function(/*int*/ timerID, /*int*/ pollID){
		var out = false;
		var t = this.getTimer(timerID);
		if( t ){
			if( pollID == t.pollID ){
				if( t.isStarted ){
					t.callback( timerID );
					this.pollAfterMs( timerID, pollID, t.msInterval );
				}
			}
		}
		return out;
	}
	
	/*private*/ this.pollAfterMs = function( /*int*/ timerID, /*int*/ pollID, /*int*/ ms ){
		setTimeout("timers.poll(" + timerID + ", " + pollID + ");", ms );
	}
	
	/*public*/ this.getElapsed = function(/*int*/ timerID){
		var out = -1;
		var t = this.getTimer(timerID);
		if( t ) out = lang.now() - t.msLastStarted ;
		return out;
	}
}
var timers = new Timers();




// For pica-style controls
function Control(){
	
	/*public*/ this.ieWrappingLinkFix = function(/*Element*/ parent ){
		if( lang.isIE() ){
			var a = this.getWrappingLink(parent);
			if( a && parent ){
				parent.style.cursor = "pointer";
				lang.onEvent( parent, "click", function(){control.onLinkClick(a)} );
			}
		}
	}
	
	/*private*/ this.getWrappingLink = function(/*Element*/ parent){
		var out = null;
		var p = parent;
		for(var i=0; i<4; i++){
			if( !p ) break;
			if( "A" == p.tagName ){
				out = p;
				break;
			}
			p = p.parentNode;
		}
		return out;
	}
	
	/*private*/ this.onLinkClick = function(/*Element*/ a){
		window.location = a.href;
	}
}
var control = new Control();function Index(){this.grpDialog=null;this.imgLightBulb=null;this.imgLogo=null;this.imgUnleash=null;this.frmSignIn=null;this.tboEmail=null;this.tboPassword=null;this.imgSignIn=null;this.imgSignInButton=null;this.imgLoading=null;this.imgBadgeUp=null;this.imgBadgeDown=null;this.bulb=null;this.badgeAnimationMs=1000;this.badgeOpacity=0.3;this.autoScrollBadgesMs=10000;this.dataHasLoaded=false;this.roundRobin=null;this.middleGroup=null;this.middleBadge=null;this.originalMiddleGroupT=-1;this.originalMiddleBoxL=-1;this.originalMiddleBoxT=-1;this.originalMiddleBoxW=-1;this.originalMiddleBoxH=-1;this.currentMiddleGroupT=-1;this.firstGroupBeforeScroll=null;this.lastGroupBeforeScroll=null;this.firstGroupTBeforeScroll=-1;this.lastGroupTBeforeScroll=-1;this.dataPos=0;this.direction="";this.isScrolling=false;this.numFinishedAnimation=0;this.badgeTimerID=-1;this.msLastMoved=-1;this.data=null;this.construct=function(){index.grpDialog=lang.e("grpDialog");index.imgLightBulb=lang.e("imgLightBulb");index.imgLogo=lang.e("imgLogo");index.imgUnleash=lang.e("imgUnleash");index.frmSignIn=lang.e("login_form");index.tboEmail=lang.e("tboEmail");index.tboPassword=lang.e("tboPassword");index.imgSignInButton=lang.e("imgSignInButton");index.imgLoading=lang.e("imgLoading");index.bulb=new IKULightBulb();index.bulb.construct("bulb");index.imgBadgeUp=lang.e("imgBadgeUp");index.imgBadgeDown=lang.e("imgBadgeDown");index.roundRobin=new Array();index.constructBadge(0);index.constructBadge(1);index.constructBadge(2);index.constructBadge(3);index.constructBadge(4);lang.onEvent(window,"load",index.onWindowLoad);lang.onEvent(window,"unload",index.onWindowUnload);lang.onEvent(window,"resize",index.onWindowResize);lang.onEvent(index.tboEmail,"keyup",index.onEmailKeyUp);lang.onEvent(index.tboPassword,"keyup",index.onPasswordKeyUp);lang.onEvent(index.imgSignInButton,"click",index.onSignInButtonClick);lang.onEvent(index.imgBadgeUp,"click",index.onBadgeUpClick);lang.onEvent(index.imgBadgeUp,"mousemove",index.onBadgeUpMouseMove);lang.onEvent(index.imgBadgeUp,"mouseout",index.onBadgeUpMouseOut);lang.onEvent(index.imgBadgeDown,"click",index.onBadgeDownClick);lang.onEvent(index.imgBadgeDown,"mousemove",index.onBadgeDownMouseMove);lang.onEvent(index.imgBadgeDown,"mouseout",index.onBadgeDownMouseOut);for(i in index.roundRobin){var B=index.roundRobin[i];var A=B.badge;var C=B.group;lang.onEvent(C,"mousemove",index.onBadgeMouseMove);lang.onEvent(C,"mouseout",index.onBadgeMouseOut);lang.onEvent(A.parent,"click",index.onBadgeClick);lang.onEvent(A.ticker.text,"click",index.onTickerClick)}index.autoScrollingStart()};this.constructBadge=function(C){var B=lang.e("grpBadge"+C);var A=new Badge();A.construct("badge"+C);index.roundRobin[C]={group:B,badge:A}};this.onWindowLoad=function(){index.onWindowResize();index.syncBadges();index.emphasizeOnlyMiddleBadge();index.loadData()};this.onWindowUnload=function(){};this.onWindowResize=function(){if(lang.isIE()){lang.setT(index.grpDialog,-5)}};this.onEmailKeyUp=function(A){if(13==A.keyCode){index.onSignInButtonClick()}};this.onPasswordKeyUp=function(A){if(13==A.keyCode){index.onSignInButtonClick()}};this.onSignInButtonClick=function(){index.frmSignIn.submit()};this.onBadgeUpClick=function(){if(index.dataHasLoaded){if(!index.isScrolling){index.showArrowDepressed("Up");index.direction="Up";index.scrollBadges()}}};this.onBadgeDownClick=function(){if(index.dataHasLoaded){if(!index.isScrolling){index.showArrowDepressed("Down");index.direction="Down";index.scrollBadges()}}};this.onBadgeUpMouseMove=function(){index.autoScrollingStop()};this.onBadgeUpMouseOut=function(){index.autoScrollingStart()};this.onBadgeDownMouseMove=function(){index.autoScrollingStop()};this.onBadgeDownMouseOut=function(){index.autoScrollingStart()};this.onBadgeMouseMove=function(A){if(index.isEventInMiddleBadge(A)){index.autoScrollingStop();index.msLastMoved=lang.now()}};this.isEventInMiddleBadge=function(B){var C=false;try{var D=lang.target(B);var G=lang.id(D);var A=lang.strLength(index.middleBadge.id);var F=lang.strLeft(G,A);if(F==index.middleBadge.id){C=true}}catch(E){}return C};this.onBadgeMouseOut=function(A){try{var B=lang.originalTarget(A);var D=lang.id(B);if(D==index.middleBadge.box.id||D==index.middleGroup.id){setTimeout("index.onBadgeMouseOutDelay();",800)}}catch(C){}};this.onBadgeMouseOutDelay=function(){var B=index.badgeTimerID;var A=timers.getTimer(B);var C=lang.now()-index.msLastMoved;if(500<C){index.autoScrollingStart()}};this.onBadgeClick=function(A){if(index.isEventInMiddleBadge(A)){if(index.dataHasLoaded){var C=lang.target(A);if(C.id==index.middleBadge.ticker.text.id){index.onTickerClick(A)}else{var B=index.middleBadge.userID;window.location="/public_profile.html?userid="+B}}}};this.onTickerClick=function(A){if(index.isEventInMiddleBadge(A)){if(index.dataHasLoaded){var B=index.middleBadge.questionID;window.location="/question.html?question_id="+B}}};this.getTimerID=function(){var A=index.badgeTimerID;if(-1==A){A=timers.addTimer(index.onAutoScrollingPoll,index.autoScrollBadgesMs);index.badgeTimerID=A}return A};this.autoScrollingStart=function(){var A=index.getTimerID();if(-1!=A){timers.start(A)}};this.autoScrollingStop=function(){var A=index.getTimerID();if(-1!=A){timers.stop(A)}};this.onAutoScrollingPoll=function(B){var A=timers.getElapsed(B);index.onBadgeDownClick()};this.loadData=function(){if(!window.data.isError){index.loadBulbColorsViaServerPage();index.showGreyBulbWhileLoadingBadges();if(null!=window.data.badges){index.loadBadgesViaServerPage()}else{index.loadBadgesViaAjax()}}else{index.goToHome()}};this.loadBulbColorsViaServerPage=function(){index.setBulbColors(window.data.bulbColors)};this.setBulbColors=function(B){index.bulb.addColor(0,"large/level1.jpg");for(m in B){var A=B[m];var C=A.MinPointsRequired;var D=A.UserLevelID;index.bulb.addColor(C,"large/level"+D+".jpg")}index.bulb.addColor(100000,"large/level9.jpg")};this.showGreyBulbWhileLoadingBadges=function(){index.bulb.setIKU(90);index.bulb.refresh(false)};this.loadBadgesViaServerPage=function(){index.setBadges(window.data.badges);index.setDataHasLoaded()};this.loadBadgesViaAjax=function(){cb={success:index.onAjaxSuccess,failure:index.onAjaxFail};YAHOO.util.Connect.asyncRequest("POST","/ajax/index.load.html",cb,null)};this.onAjaxSuccess=function(A){A=YAHOO.lang.JSON.parse(A.responseText);if(!A.isError){index.setBadges(A.badges);index.setDataHasLoaded()}else{index.goToHome()}};this.onAjaxFail=function(A){index.goToHome()};this.goToHome=function(){window.location="/home.html"};this.setBadges=function(A){index.data=A;index.bindData(0)};this.setDataHasLoaded=function(){lang.hide(index.imgLoading);index.dataHasLoaded=true};this.showArrowReset=function(A){if(!lang.isIE6()){if("Up"==A){lang.fade(index.imgBadgeUp,0.5,1)}else{if("Down"==A){lang.fade(index.imgBadgeDown,0.5,1)}}}};this.showArrowDepressed=function(A){if(!lang.isIE6()){if("Up"==A){lang.fade(index.imgBadgeUp,1,0.5)}else{if("Down"==A){lang.fade(index.imgBadgeDown,1,0.5)}}}};this.scrollBadges=function(){index.preScrollBadges();var A=index.originalMiddleGroupT-index.currentMiddleGroupT;this.numFinishedAnimation=0;for(i in index.roundRobin){ani.runSingleSequence(index.roundRobin[i].group,"T",A,index.badgeAnimationMs,"cubic",index.onFinishedAnimation,250)}};this.preScrollBadges=function(){index.syncBadgesBeforeScrolling();index.isScrolling=true;index.deEmphasizeMiddleBadge();var A=this.direction;if("Up"==A){index.roundRobinUp()}else{if("Down"==A){index.roundRobinDown()}}};this.onFinishedAnimation=function(){index.numFinishedAnimation++;var A=index.roundRobin.length;if(A==index.numFinishedAnimation){index.postScrollBadges()}};this.postScrollBadges=function(){var A=this.direction;if("Up"==A){index.shiftLastBadgeToTop()}else{if("Down"==A){index.shiftFirstBadgeToBottom()}}index.emphasizeMiddleBadge();index.bindData(0);setTimeout("index.isScrolling = false",500);index.showArrowReset("Up");index.showArrowReset("Down")};this.shiftFirstBadgeToBottom=function(){lang.setT(index.firstGroupBeforeScroll,index.lastGroupTBeforeScroll)};this.shiftLastBadgeToTop=function(){lang.setT(index.lastGroupBeforeScroll,index.firstGroupTBeforeScroll)};this.emphasizeMiddleBadge=function(){index.emphasizeBadge(2)};this.deEmphasizeMiddleBadge=function(){index.deEmphasizeBadge(2)};this.emphasizeOnlyMiddleBadge=function(){for(i in index.roundRobin){if(2==i){index.emphasizeBadge(i)}else{index.deEmphasizeBadge(i)}}};this.emphasizeBadge=function(A){index.fadeInBadge(A,0);index.expandBadgeBox(A,250);index.changeCursor(A,"pointer")};this.deEmphasizeBadge=function(A){index.collapseBadgeBox(A,0);index.fadeOutBadge(A,500);index.changeCursor(A,"default")};this.fadeInBadge=function(B,A){if(!lang.isIE()&&!lang.isChrome()){lang.fade(index.roundRobin[B].group,index.badgeOpacity,1,A)}};this.fadeOutBadge=function(B,A){if(!lang.isIE()&&!lang.isChrome()){lang.fade(index.roundRobin[B].group,1,index.badgeOpacity,A)}};this.setBadgeOpacity=function(B,A){lang.setOpacity(index.roundRobin[B].group,A)};this.expandBadgeBox=function(L,G){var H=index.roundRobin[L].badge.box;var K=index.originalMiddleBoxL;var F=index.originalMiddleBoxT;var E=index.originalMiddleBoxW;var M=index.originalMiddleBoxH;var I=K-lang.getL(H);var D=F-lang.getT(H);var B=E-lang.getW(H);var J=M-lang.getH(H);var C=150;if(lang.getW(H)<50){var A=ani.existSubject(H);A.clearSequences();var N=A.addSequence("L");N.setTravellingPath(I,C,"cubic");N=A.addSequence("T");N.setTravellingPath(D,C,"cubic");N=A.addSequence("W");N.setTravellingPath(B,C,"cubic");N=A.addSequence("H");N.setTravellingPath(J,C,"cubic");A.addCallback(null);A.runSequences(G)}};this.collapseBadgeBox=function(I,E){var F=index.roundRobin[I].badge.box;var G=lang.getW(F)/2;var D=lang.getH(F)/2;var B=-lang.getW(F);var H=-lang.getH(F);var C=150;if(50<lang.getW(F)){var A=ani.existSubject(F);A.clearSequences();var J=A.addSequence("L");J.setTravellingPath(G,C,"cubic");J=A.addSequence("T");J.setTravellingPath(D,C,"cubic");J=A.addSequence("W");J.setTravellingPath(B,C,"cubic");J=A.addSequence("H");J.setTravellingPath(H,C,"cubic");A.addCallback(null);A.runSequences(E)}};this.changeCursor=function(C,B){var A=this.roundRobin[C].badge;A.parent.style.cursor=B;A.ticker.text.style.cursor=B};this.roundRobinDown=function(){var A=index.roundRobin;if(A){var C=A[0];for(var B=1;B<A.length;B++){A[B-1]=A[B]}A[B-1]=C}index.dataPos=index.dataPosDown(index.dataPos);index.syncBadges()};this.roundRobinUp=function(){var A=index.roundRobin;if(A){if(1<A.length){var C=A[A.length-1];for(var B=A.length-2;B>=0;B--){A[B+1]=A[B]}A[0]=C}}index.dataPos=index.dataPosUp(index.dataPos);index.syncBadges()};this.syncBadges=function(){index.middleGroup=index.roundRobin[2].group;index.middleBadge=index.roundRobin[2].badge;if(-1==this.originalMiddleGroupT){this.originalMiddleGroupT=lang.getT(index.middleGroup);this.originalMiddleBoxL=lang.getL(index.middleBadge.box);this.originalMiddleBoxT=lang.getT(index.middleBadge.box);this.originalMiddleBoxW=lang.getW(index.middleBadge.box);this.originalMiddleBoxH=lang.getH(index.middleBadge.box)}index.currentMiddleGroupT=lang.getT(index.middleGroup)};this.syncBadgesBeforeScrolling=function(){index.firstGroupBeforeScroll=index.roundRobin[0].group;index.lastGroupBeforeScroll=index.roundRobin[4].group;index.firstGroupTBeforeScroll=lang.getT(index.firstGroupBeforeScroll);index.lastGroupTBeforeScroll=lang.getT(index.lastGroupBeforeScroll)};this.bindData=function(A){setTimeout("index.transferDataToGUI();",A)};this.transferDataToGUI=function(){p=index.dataPos;if(index.data){if(p<index.data.length){var D=p;for(var A=0;A<index.roundRobin.length;A++){var C=index.data[D];var B=index.roundRobin[A].badge;B.ticker.stop();index.transferDataToBadge(C,B);if(2==A){B.ticker.start();index.transferDataToBulb(C)}D=index.dataPosDown(D)}}}};this.addCommas=function(B){B+="";x=B.split(".");x1=x[0];x2=x.length>1?"."+x[1]:"";var A=/(\d+)(\d{3})/;while(A.test(x1)){x1=x1.replace(A,"$1,$2")}return x1+x2};this.transferDataToBadge=function(B,A){lang.setText(A.avatar,B.avatar.SmallAvatarExternalImageID);A.userID=B.userID;lang.setText(A.userName,B.userName);lang.setText(A.globalIKU,"IKU "+index.addCommas(B.globalIKU));index.transferDataToScale(B,A,0);index.transferDataToScale(B,A,1);index.transferDataToScale(B,A,2);A.ticker.setValue(B.text);A.questionID=B.questionID};this.transferDataToScale=function(C,A,E){var B=null;var D=C.categories[E];if(0==E){B=A.ikuScale0;lang.setText(A.categoryName0,D.name);A.categoryID0=D.id}else{if(1==E){B=A.ikuScale1;lang.setText(A.categoryName1,D.name);A.categoryID1=D.id}else{if(2==E){B=A.ikuScale2;lang.setText(A.categoryName2,D.name);A.categoryID2=D.id}}}B.setLimits(D.communityLo,D.communityHigh);B.setPointer(D.iku);B.setRange(D.probableLo,D.probableHigh);B.refresh()};this.transferDataToBulb=function(A){index.bulb.setIKU(A.globalIKU);index.bulb.refresh()};this.dataPosUp=function(A){if(0<index.data.length){A--;if(A<0){A=index.data.length-1}}return A};this.dataPosDown=function(A){if(0<index.data.length){A++;if(index.data.length<=A){A=0}}return A}}var index=new Index();index.construct();/* Copyright (c) 2008 Akatoo, Inc. */

function IKUScale(){
	// Id.
	this.id 		= "";
	
	// Elements.
	this.rainbow	= null;
	this.blur		= null;
	this.solid		= null;
	this.pointer 	= null;
	this.parent 	= null;
	
	// State.
	this.min 	= -1;
	this.val	= -1;
	this.max	= -1;
	this.rngMin = -1;
	this.rngMax = -1;
	this.pointerWidth 	= -1;
	this.parentWidth 	= -1;
	this.pointerHeight 	= -1;
	this.parentHeight 	= -1;
	
	// An explicit constructor.
	
	
	
	
		/*public*/ this.construct = function(/*string*/ id){
			this.id 		= id;
			
			this.rainbow = new IKUBarLayer();
			this.rainbow.construct( id + ".rainbow" );
			
			this.blur = new IKUBarLayer();
			this.blur.construct( id + ".blur" );
			
			this.solid = new IKUBarLayer();
			this.solid.construct( id + ".solid" );
			
			this.pointer 		= lang.e( id + ".pointer" );
			this.pointerWidth 	= lang.getW( this.pointer );
			this.pointerHeight 	= lang.getH( this.pointer );
			
			this.parent 		= this.pointer.parentNode;
			this.parentWidth 	= lang.getW( this.parent );
			this.parentHeight 	= lang.getH( this.parent );
			
			// IE hack.
			control.ieWrappingLinkFix( this.parent );
		}
		
		
		
		
	// Events.
	
	
	
	
		/*public*/ this.onRainbowViewerClick = function(/*Element*/ a){
			window.location = a.href;
		}
		
		/*public*/ this.onBlurViewerClick = function(/*Element*/ a){
			window.location = a.href;
		}
		
		/*public*/ this.onSolidViewerClick = function(/*Element*/ a){
			window.location = a.href;
		}
		
		
		
		
	/*public*/ this.setLimits = function(/*float*/ min, /*float*/ max){
		this.min = lang.float( min );
		this.max = lang.float( max );
	}
	
	/*public*/ this.setPointer = function(/*float*/ val){
		this.val = lang.float( val );
	}
	
	/*public*/ this.setRange = function(/*float*/ min, /*float*/ max){
		this.rngMin = lang.float(min);
		this.rngMax = lang.float(max);
		// TODO: fix the limits if need be.
		if( this.rngMin < this.min ) this.min = this.rngMin;
		if( this.max < this.rngMax ) this.max = this.rngMax;
	}
	
	/*public*/ this.refresh = function(){
		if( this.min 	!= -1 &&
			this.rngMin != -1 &&
			this.val	!= -1 &&
			this.rngMax != -1 &&
			this.max	!= -1 ){
			if( this.min 	<= this.rngMin 	&&
				this.rngMin <= this.val 	&&
				this.val 	<= this.rngMax  &&
				this.rngMax	<= this.max 	){
				this.showLayers();
				this.redraw();
			}
			else{ this.hideLayers(); }
		}
	}
	
	/*private*/ this.showLayers = function(){
		lang.show( this.rainbow.viewer );
		lang.show( this.blur.viewer );
		lang.show( this.solid.viewer );
	}
	
	/*private*/ this.hideLayers = function(){
		lang.hide( this.rainbow.viewer );
		lang.hide( this.blur.viewer );
		lang.hide( this.solid.viewer );
	}
	
	/*private*/ this.redraw = function(){
		this.fitLayersToParent();
		this.positionLayers();
		this.positionPointer();
	}
	
	/*private*/ this.fitLayersToParent = function(){
		this.rainbow.fitToParent(this.parentWidth);
		this.blur.fitToParent	(this.parentWidth);
		this.solid.fitToParent	(this.parentWidth);
	}
	
	/*private*/ this.positionLayers = function(){
		this.positionLayer( this.blur, 		this.min, 	 this.rngMin );
		this.positionLayer( this.rainbow, 	this.rngMin, this.rngMax );
		this.positionLayer( this.solid, 	this.rngMax, this.max );	
	}
	
	/*private*/ this.positionLayer = function(/*IKUBarLayer*/ layer, /*int*/ from, /*int*/ to ){
		layer.view(
			this.toPx(from),
			this.toPx(to));
	}
	
	/*private*/ this.positionPointer = function(){
		lang.setL( this.pointer, 
			this.toPx(this.val) -
			( this.pointerWidth / 2 ) );
			
		lang.setT( this.pointer, 
			this.parentHeight - 
			this.pointerHeight - 1 );
	}
	
	// Returns the px position of the pointer
	/*public*/ this.getPointerLPx = function(){
		var pl = lang.getL( this.pointer ) ;
		pl += ( this.pointerWidth / 2 ) ;
		return pl ;
	}
	
	// Get the px for a number on the scale.
	/*private*/ this.toPx = function(/*int*/ num){
		var px = (num - this.min) / (this.max-this.min) ;
		px *= this.parentWidth;
		return px;
	}
	
}




function IKUBarLayer(){
	// Elements.
	this.viewer 	= null;
	this.bar		= null;
	this.left		= null;
	this.center		= null;
	this.right		= null;
	
	// An explicit constructor.
	/*public*/ this.construct = function(/*string*/ id){
		this.viewer = lang.e( id + ".viewer" );
		this.bar 	= lang.e( id + ".bar" );
		this.left	= lang.e( id + ".left" );
		this.center	= lang.e( id + ".center" );
		this.right	= lang.e( id + ".right" );
	}
	
	/*public*/ this.fitToParent = function(/*int*/ parentWidth){
		var pw = parentWidth;
		var lw = lang.getW( this.left );
		var rw = lang.getW( this.right );
		
		lang.setL( this.viewer, 0);
		lang.setW( this.viewer, pw);
		lang.setL( this.left, 0 );
		lang.setL( this.center, lw );
		lang.setW( this.center, pw-lw-rw );
		lang.setL( this.right, pw-rw );
	}
	
	
	
	/*public*/ this.view = function(/*int*/ fromPx, /*int*/ toPx){
		lang.setL( this.bar, -fromPx );
		lang.setL( this.viewer, fromPx );
		lang.setW( this.viewer, toPx - fromPx );
	}
}function Badge(){this.id="";this.box=null;this.avatar=null;this.globalIKU=null;this.userName=null;this.ikuScale0=null;this.categoryName0=null;this.ikuScale1=null;this.categoryName1=null;this.ikuScale2=null;this.categoryName2=null;this.ticker=null;this.parent=null;this.userID=-1;this.questionID=-1;this.categoryID0=-1;this.categoryID1=-1;this.categoryID2=-1;this.construct=function(A){this.id=A;this.box=lang.e(A+"_box");this.avatar=lang.e(A+"_avatar");this.globalIKU=lang.e(A+"_globalIKU");this.userName=lang.e(A+"_userName");this.ikuScale0=new IKUScale();this.ikuScale0.construct(A+"_ikuScale0");this.categoryName0=lang.e(A+"_categoryName0");this.ikuScale1=new IKUScale();this.ikuScale1.construct(A+"_ikuScale1");this.categoryName1=lang.e(A+"_categoryName1");this.ikuScale2=new IKUScale();this.ikuScale2.construct(A+"_ikuScale2");this.categoryName2=lang.e(A+"_categoryName2");this.ticker=new TickerBox();this.ticker.construct(A+"_text");this.parent=this.globalIKU.parentNode}};function TickerBox(){this.id="";this.viewer=null;this.text=null;this.parent=null;this.value="";this.timerID=0;this.isStarted=false;this.isPaused=false;this.construct=function(A){this.id=A;this.viewer=lang.e(A+".viewer");this.text=lang.e(A+".text");this.face=lang.e(A+".face");this.parent=this.viewer.parentNode;instances[A]=this;addEvent(this.text,"mouseover",function(){instances[A].onTextMouseOver()});addEvent(this.text,"mouseout",function(){instances[A].onTextMouseOut()})};this.setValue=function(A){this.value=A;lang.setText(this.text,A)};this.start=function(){this.isStarted=true;this.isPaused=false;this.lengthenByRepeating();this.onScrollTimer(++this.timerID)};this.lengthenByRepeating=function(){var F="                                                    ";var C=F+this.value;var B=C.length;var A=lang.floor(500/B);var E=F+F+this.value;for(var D=0;D<A;D++){E+=C}lang.setText(this.text,E)};this.stop=function(){this.isStarted=false;lang.setText(this.text,this.value);lang.setL(this.text,0)};this.onScrollTimer=function(C){if(this.isStarted){if(!this.isPaused){if(C==this.timerID){var B=lang.getL(this.text);var A=lang.getW(this.text);if(B<=-A){lang.setL(this.text,0)}else{lang.setL(this.text,B-4)}setTimeout('instances["'+this.id+'"].onScrollTimer('+C+")",100)}}}};this.pause=function(){this.isPaused=true};this.resume=function(){this.isPaused=false;this.onScrollTimer(++this.timerID)};this.onTextMouseOver=function(){this.pause()};this.onTextMouseOut=function(){if(this.isStarted){if(this.isPaused){this.resume()}}}};/* Copyright (c) 2008 Akatoo, Inc. */

function IKULightBulb(){
	// Id.
	this.id 			= "";
	
	// Elements.
	this.imgLShade0	= null;
	this.imgRShade0	= null;
	this.imgLShade1	= null;
	this.imgRShade1	= null;
	this.parent		= null;
	
	// State.
	this.IKU			= 100;
	this.colors 		= new Array();
	this.leftColor		= null;					//
	this.rightColor		= null;
	this.roundRobin		= new Array();
	
	
	/*public*/ this.construct = function(/*string*/ id){
		this.id = id;
		this.imgLShade0 = lang.e( id + ".lShade0" );
		this.imgRShade0 = lang.e( id + ".rShade0" );
		this.imgLShade1 = lang.e( id + ".lShade1" );
		this.imgRShade1 = lang.e( id + ".rShade1" );
		this.parent 	= this.imgLShade0.parentNode;
		
		this.roundRobin[0] = { left: this.imgLShade0, right: this.imgRShade0 };
		this.roundRobin[1] = { left: this.imgLShade1, right: this.imgRShade1 };

		// IE hack.
		control.ieWrappingLinkFix( this.parent );
		
		instances[id] = this;
	}
	
	/*public*/ this.addColor = function(/*int*/ IKU, /*string*/ color){
		var o = new Object();
		o.IKU = IKU;
		o.color = color;
		this.colors.push(o);
	}
	
	/*public*/ this.setIKU = function(/*float*/ IKU){
		this.IKU = lang.float( IKU );
	}
	
	/*public*/ this.refresh = function(/*bool*/ fade){
		if( null == fade ) fade = true;
		this.leftColor = null;
		this.rightColor = null;
		for( i in this.colors ){
			var c = this.colors[i];
			if( c.IKU <= this.IKU )
				this.leftColor = c;
		
			if( null == this.rightColor ){
				if( this.IKU < c.IKU ){
					this.rightColor = c;
					break;
				}
			}
		}
		this.refreshImages(fade);
	}
	
	/*private*/ this.refreshImages = function(/*bool*/ fade){
		var l = this.leftColor;
		var r = this.rightColor;
		
		if( null != l && null != r ){
			var a = this.IKU - l.IKU ;
			var b = r.IKU - this.IKU ;
			var c = r.IKU - l.IKU ;
			var rightOpacity = lang.float(a/c);
			
			this.roundRobinDown();
			this.setImageSrc();
			this.changeImages(rightOpacity, fade);
		}
	}
	
	/*private*/ this.roundRobinDown = function(){
		var rr = this.roundRobin;
		if( rr ){
			var top = rr[0];
			for( var i=1; i<rr.length; i++)
				rr[i-1] = rr[i];
			rr[i-1] = top;
		}
	}
	
	/*private*/ this.setImageSrc = function(){
		this.roundRobin[0].left.src  = "/images/controls/IKULightBulb/" + this.leftColor.color ;
		this.roundRobin[0].right.src = "/images/controls/IKULightBulb/" + this.rightColor.color ;
	}
	
	/*private*/ this.changeImages = function(/*int*/ rightOpacity, /*bool*/ fade ){
		if( lang.isIE6() ) fade = false;
		if( fade ){
			r0 = lang.getOpacity(this.roundRobin[0].right);
			r1 = lang.getOpacity(this.roundRobin[1].right);
			lang.fade( this.roundRobin[0].left, 0.0, 1.0 );
			lang.fade( this.roundRobin[0].right, r0, rightOpacity );
			lang.fade( this.roundRobin[1].left, 1.0, 0.0 );
			lang.fade( this.roundRobin[1].right, r1, 0.0 );
		}
		else{
			lang.setOpacity( this.roundRobin[0].left, 1.0 );
			lang.setOpacity( this.roundRobin[0].right, rightOpacity );
			lang.setOpacity( this.roundRobin[1].left, 0.0 );
			lang.setOpacity( this.roundRobin[1].right, 0.0 );
		}
	}
	
}
