var RealTimeSearch=function() {
	if (typeof(Function.prototype.apply)=="undefined") {
		Function.prototype.apply = function(object, parameters) {
			var parameterStrings = new Array();
			if (!object)     object = window;
			if (!parameters) parameters = new Array();
			for (var i = 0; i < parameters.length; i++) parameterStrings[i] = 'parameters[' + i + ']';
			object.__apply__ = this;
			var result=eval('object.__apply__('+ parameterStrings.join(', ') +')');
			object.__apply__ = null;
			return result;
		}
	}
	if(typeof([].push) == "undefined") Array.prototype.push = function(v){return this[this.length] = v}	 
	if(typeof(Function.prototype.bind)=="undefined") { 
		Function.prototype.bind = function(object) { 
			var __method = this;
			return function() { 
				return __method.apply(object, arguments);
			}
		}
	}
	var __U2base_version__=0.2;
	var __U2base_use__=(typeof(U2)=="undefined" ? true : (__U2base_version__>U2.version ? true : false));
	if(__U2base_use__==true) {
		var U2={
			version : __U2base_version__,
			_Class : {},
			_Event : {},
			_Element : {},
			_Package : {}
		};
		U2._Class={
			Create : function() { 
				var Methods=arguments[0];
				var Extends=arguments;
				var returnObj=function(){
					if(this.Constructor) this.Constructor.apply(this,arguments);
				} 
				if(Extends.length>1) {for (var i=1;i<Extends.length;i++){returnObj=this.Extend(returnObj,Extends[i]);}}
				returnObj=this.Extend(returnObj,Methods);
				return returnObj;
			},
			Extend : function(returnObj/*, Define Method */) {
				var Methods=arguments[1];
				var methodName=null;
				if(typeof returnObj!="function") {throw new Error("[_Class Function] Arguments[0] is not Function");}
				if(typeof Methods!="object") {throw new Error("[_Class Function] Arguments[1] is not Object");} 		
				for(var methodName in Methods) {returnObj.prototype[methodName]=Methods[methodName];} 
				return returnObj;
			}
		};	 
		U2._Element={
			getBadBrowser : function() {
				if(navigator.userAgent.toLowerCase().indexOf("msie 5.0")>0 || navigator.userAgent.toLowerCase().indexOf("msie 5.5")>0) {return true;}else{return false;}
			},
			getBrowser : function() {
				if(navigator.userAgent.toLowerCase().indexOf("msie")>=0) {
					return "ie";
				}else if (navigator.userAgent.toLowerCase().indexOf("firefox")>=0) {
					return "ff";
				}else if (navigator.userAgent.toLowerCase().indexOf("opera")>=0) {
					return "op";
				}else if (navigator.userAgent.toLowerCase().indexOf("safari")>=0) {
					return "sf";
				}
			},
			getStyle : function(element, property) {
				if (element.style[property]) {
					return element.style[property]
				} else if (element.currentStyle) {
					return element.currentStyle[property]
				} else if (document.defaultView && document.defaultView.getComputedStyle) {
					var style = document.defaultView.getComputedStyle(element, null)
					return style.getPropertyValue(property)
				} else {
					return null
				}
			},
			setStyle : function(element, styles,sw) {
				var e;
				if(!sw) { // ie 5.0
					if(this.getBadBrowser()==true) {
						e=element.id!="" ? document.getElementById(element.id) : element;
					}else{
						e=element;
					}
				}else{
					e=element;
				}
	 
				for(var styleName in styles) {
					if(this.getBadBrowser()==true) {if(styleName=="cursor") styleName="hand";}
					e.style[styleName]=styles[styleName];
				} 
			},
			setStyles : function() {
				var aAs=arguments;
				for (var i=0;i<aAs.length;i++) {
					var sVarguments=aAs[i];
					U2._Element.setStyle(sVarguments[0],sVarguments[1]);
				}
			}
		};
	};
	var Rolling=U2._Class.Create({
		Constructor : function() {
			this._def={
				oP : arguments[0],
				iD : arguments[1],
				oFrame : {
					oDomUl : null,
					oDomLi01 : null,
					oDomLi02 : null
				},
				oTid : null,
				iHeight : 24,
				iMove : 0,
				iStatus : 0
			}
			this.Initialize();		
		},
		Initialize : function() {
			if(typeof(this._def.oUl)=="undefined") this.setDraw("newLine",this._def.oP);
		},
		setDraw : function() {
			var s=arguments[0],o=arguments[1];
			switch(s) {
				case "newLine" :
					var cUl=this._def.oFrame.oDomUl=document.createElement("ul");
					var cLi01=this._def.oFrame.oDomLi01=document.createElement("li");
					var cLi02=this._def.oFrame.oDomLi02=document.createElement("li");
					var iWidth=U2._Element.getBrowser()=="ie" ? "202" : "182";
					U2._Element.setStyles(
						[cUl,{position : "relative",height : this._def.iHeight+"px",overflow : "hidden"}],
						[cLi01,{position : "absolute",top : "0px",width : iWidth+"px"}],
						[cLi02,{position : "absolute",top : this._def.iHeight+"px",width : iWidth+"px"}]
					);
					cUl.appendChild(cLi01);
					cUl.appendChild(cLi02);
					o.appendChild(cUl);
				break;
			}
		},
		setChange : function() {
			if(this._def.iStatus==0) {this._def.oFrame.oDomLi01.innerHTML=this._def.oFrame.oDomLi02.innerHTML;}else{this._def.oFrame.oDomLi02.innerHTML=this._def.oFrame.oDomLi01.innerHTML;}
			this._def.iStatus=(this._def.iStatus==1 ? 0 : 1);
		},
		setValue : function() {
			var oValue=arguments[0];
			var flag=arguments[1];
			if(typeof(oValue)!="undefined") {
				
				if(oValue.status=="new" || oValue.status=="change_equal") {
					var sHtml="<div><a href=\""+oValue.href+"\">"+oValue.title+"</a> <p class=\""+oValue.status+"\"><span class=\""+oValue.status+"\"></span></p></div>";
				}else{
					var sHtml="<div><a href=\""+oValue.href+"\">"+oValue.title+"</a> <p><span class=\""+oValue.status+"\"></span><span class=\"num\">"+oValue.num+"</span></p></div>";
				}

				if(flag==1) {
					this._def.oFrame.oDomLi01.className=this._def.oFrame.oDomLi02.className=oValue.className;
					this._def.oFrame.oDomLi01.innerHTML=this._def.oFrame.oDomLi02.innerHTML=sHtml;
				}else{
					if(this._def.iStatus==0) {
						this._def.oFrame.oDomLi02.className=oValue.className;
						this._def.oFrame.oDomLi02.innerHTML=sHtml;
					}else{
						this._def.oFrame.oDomLi01.className=oValue.className;
						this._def.oFrame.oDomLi01.innerHTML=sHtml;
					}
				}
			}
		},
		onStarted : function() {},
		onFinished : function() {},
		doRolling : function() {
			var iTime=U2._Element.getBadBrowser()=="ff" ? 200 : 20;

			this.onStarted();
			this._def.oTid=setInterval(this._doMotion.bind(this),iTime);
		},
		_doMotion : function() {
			this._def.iMove++;

			if(this._def.iStatus==0) {
				U2._Element.setStyles(
					[this._def.oFrame.oDomLi01,{top:this._def.iMove+"px",filter:"alpha(opacity:60)",opacity:"0.6"}],
					[this._def.oFrame.oDomLi02,{top:(this._def.iMove-this._def.iHeight)+"px",filter:"",opacity:""}]
				);
			}else{
				U2._Element.setStyles(
					[this._def.oFrame.oDomLi02,{top:this._def.iMove+"px",filter:"alpha(opacity:60)",opacity:"0.6"}],
					[this._def.oFrame.oDomLi01,{top:(this._def.iMove-this._def.iHeight)+"px",filter:"",opacity:""}]
				);
			}

			if(this._def.iMove==this._def.iHeight) {
				this._def.iMove=0;
				clearInterval(this._def.oTid);
				this.setChange();
				this.onFinished();
			}
		}
	});
	var RollingAdmin=U2._Class.Create({
		Constructor : function() {
			var oId=document.getElementById(arguments[0]);
			var options=arguments[1];
			var sInitailizeValue=arguments[2];

			if(U2._Element.getBadBrowser()=="ff") options.loopWait *=10;
			if(U2._Element.getBadBrowser()=="ff") options.rollingWait *=10;

			this._def={
				oFrame : oId,
				oRolling : [],
				oData : [],
				oTid : null,
				oTid2 : null,
				aTmpValue : [],
				iRolling : 0,
				iCount : options.count,
				iLoopWait : options.loopWait,
				iRollingWait : options.rollingWait,
				iTimer : 0
			}

			this.Initialize(sInitailizeValue);
		},
		Initialize : function() {
			try {document.execCommand('BackgroundImageCache', false, true);} catch(e) {}
			var aValue=arguments[0];
			var oUls=this._def.oFrame.getElementsByTagName("ul");
			this._def.oFrame.innerHTML="";
			for(var i=0;i<this._def.iCount;i++) {
				this._def.oRolling[i]=new Rolling(this._def.oFrame,i);
				this._def.oRolling[i].setValue(aValue[i],1);
			}

			this.setTimer();
			this.doStart();
		},
		setApplyTmpValue : function() {
			for(var i=0;i<this._def.iCount;i++) {
				this._def.oRolling[i].setValue(this._def.aTmpValue[i]);
			}
		},
		setTmpValue : function() {
			this._def.aTmpValue=arguments[0];
		},
		setValue : function() { 
			var id=arguments[0]-1;	
			var oValue=arguments[1];
			this._def.oRolling[id].setValue(oValue);
		},
		getSleep : function (sec) {
			if(sec> 60*60) return 600;
			if(sec> 60*5) return 60;
			if(sec< 60*1) return 10;
			if(sec< 60*2) return 20;
			if(sec< 60*3) return 30;
			if(sec< 60*4) return 40;
			if(sec< 60*5) return 50;
		},
		setTimer : function () {},
		doStart : function() {
			this._def.oRolling[this._def.iRolling].onFinished=function() {
				this._def.iRolling++;
				if(this._def.iRolling==this._def.iCount) { 
					this._def.iRolling=0;
					if(this._def.oTid2==null) {
						this.setApplyTmpValue();
						this._def.oTid2=setTimeout(this.doStart.bind(this),this._def.iLoopWait);
					}
				}else{
					this._def.oTid2=null;
					this._def.oTid=setTimeout(this.doStart.bind(this),this._def.iRollingWait);
				}
			}.bind(this);
			this._def.oRolling[this._def.iRolling].doRolling();
		}
	});
	this.Admin=RollingAdmin;
}
