window.cyui={};
cyui.browser={};
cyui.browser.userAgent=navigator.userAgent.toLowerCase();
cyui.browser.isOpera=(cyui.browser.userAgent.indexOf('opera')!=-1);
cyui.browser.isSafari=(cyui.browser.userAgent.indexOf('safari')!=-1);
cyui.browser.isIE=(cyui.browser.userAgent.indexOf('msie')!=-1&&!cyui.browser.isOpera);
cyui.browser.isFF=(cyui.browser.userAgent.indexOf('firefox')!=-1);
cyui.$=function(id){
	return document.getElementById(id);
};
cyui.event={};
cyui.event.hnd=[];
cyui.event.Dispatcher=function(){
	var q={};
	this.addListener=function(evt, fnc, tar, args){
		if(!q[evt]) q[evt]=[];
		q[evt].push([fnc,tar,args]);
		return true;
	};
	this.removeListener=function(evt, fnc){
		if(!q[evt]) return false;
		var l=q[evt].length;
		for(var i=0;i<l;i++){
			if(q[evt][i][0]==fnc){
				q[evt].splice(i, 1);
				return true;
			}
		}
	};
	this.dispatch=function(evt){
		if(!q[evt]) return false;
		var l=q[evt].length;
		for(var i=0;i<l;i++){
			if(q[evt][i][1]&&q[evt][i][2]) q[evt][i][0].apply(q[evt][i][1], q[evt][i][2]);
			else q[evt][i][0]();
		}
		return true;
	};
};
cyui.event.remove=function(hnd){
	if (window.removeEventListener) hnd[0].removeEventListener(hnd[1], hnd[2], false);
	else if (window.detachEvent) hnd[0].detachEvent('on'+hnd[1], hnd[2]);
};
cyui.event.TweenEvent={
	TWEEN_COMPLETE:'tweenComplete'
};
cyui.event.add=function(obj, evt, fnc){
	if (window.addEventListener) obj.addEventListener(evt, fnc, false);
	else if (window.attachEvent) obj.attachEvent( 'on'+evt, fnc );
	return [obj, evt, fnc];
};
cyui.event.SliderEvent={
	SLIDE_NEXT:'slideNext',
	SLIDE_PREVIOUS:'slidePrevious',
	SLIDE_ADDED:'sliderAdded',
	BEGIN_OF_SLIDE:'beginOfSlide',
	MIDDLE_OF_SLIDE:'middleOfSlide',
	END_OF_SLIDE:'endOfSlide',
	REQURE_SLIDE:'requireSlide'
};
cyui.transition={};
cyui.transition.ease={
	easeNone:function(t, b, c, d){
		return c*t/d+b;
	},
	easeInQuad:function(t, b, c, d){
		return c*(t/=d)*t+b;
	},
	easeOutQuad:function(t, b, c, d){
		return -c *(t/=d)*(t-2)+b;
	},
	easeInOutQuad:function(t, b, c, d){
		if ((t/=d/2) < 1) return c/2*t*t+b;
		return -c/2*((--t)*(t-2)-1)+b;
	},
	easeOutInQuad:function(t, b, c, d){
		if (t < d/2) return ease.easeOutQuad (t*2, b, c/2, d);
		return ease.easeInQuad((t*2)-d, b+c/2, c/2, d);
	},
	easeInCubic:function(t, b, c, d){
		return c*(t/=d)*t*t+b;
	},
	easeOutCubic:function(t, b, c, d){
		return c*((t=t/d-1)*t*t+1)+b;
	},
	easeInOutCubic:function(t, b, c, d){
		if ((t/=d/2) < 1) return c/2*t*t*t+b;
		return c/2*((t-=2)*t*t+2)+b;
	},
	easeOutInCubic:function(t, b, c, d){
		if (t < d/2) return ease.easeOutCubic (t*2, b, c/2, d);
		return ease.easeInCubic((t*2)-d, b+c/2, c/2, d);
	},
	easeInQuart:function(t, b, c, d){
		return c*(t/=d)*t*t*t+b;
	},
	easeOutQuart:function(t, b, c, d){
		return -c*((t=t/d-1)*t*t*t-1)+b;
	},
	easeInOutQuart:function(t, b, c, d){
		if ((t/=d/2) < 1) return c/2*t*t*t*t+b;
		return -c/2*((t-=2)*t*t*t-2)+b;
	},
	easeOutInQuart:function(t, b, c, d){
		if (t < d/2) return ease.easeOutQuart (t*2, b, c/2, d);
		return ease.easeInQuart((t*2)-d, b+c/2, c/2, d);
	},
	easeInQuint:function(t, b, c, d){
		return c*(t/=d)*t*t*t*t+b;
	},
	easeOutQuint:function(t, b, c, d){
		return c*((t=t/d-1)*t*t*t*t+1)+b;
	},
	easeInOutQuint:function(t, b, c, d){
		if ((t/=d/2) < 1) return c/2*t*t*t*t*t+b;
		return c/2*((t-=2)*t*t*t*t+2)+b;
	},
	easeOutInQuint:function(t, b, c, d){
		if (t < d/2) return ease.easeOutQuint (t*2, b, c/2, d);
		return ease.easeInQuint((t*2)-d, b+c/2, c/2, d);
	},
	easeInSine:function(t, b, c, d){
		return -c*Math.cos(t/d*(Math.PI/2))+c+b;
	},
	easeOutSine:function(t, b, c, d){
		return c*Math.sin(t/d*(Math.PI/2))+b;
	},
	easeInOutSine:function(t, b, c, d){
		return -c/2*(Math.cos(Math.PI*t/d)-1)+b;
	},
	easeOutInSine:function(t, b, c, d){
		if (t < d/2) return ease.easeOutSine (t*2, b, c/2, d);
		return ease.easeInSine((t*2)-d, b+c/2, c/2, d);
	},
	easeInExpo:function(t, b, c, d){
		return (t==0) ? b : c*Math.pow(2, 10*(t/d-1))+b-c*0.001;
	},
	easeOutExpo:function(t, b, c, d){
		return (t==d) ? b+c : c*1.001*(-Math.pow(2, -10*t/d)+1)+b;
	},
	easeInOutExpo:function(t, b, c, d){
		if (t==0) return b;
		if (t==d) return b+c;
		if ((t/=d/2) < 1) return c/2*Math.pow(2, 10*(t-1))+b-c*0.0005;
		return c/2*1.0005*(-Math.pow(2, -10*--t)+2)+b;
	},
	easeOutInExpo:function(t, b, c, d){
		if (t < d/2) return ease.easeOutExpo (t*2, b, c/2, d);
		return ease.easeInExpo((t*2)-d, b+c/2, c/2, d);
	},
	easeInCirc:function(t, b, c, d){
		return -c*(Math.sqrt(1-(t/=d)*t)-1)+b;
	},
	easeOutCirc:function(t, b, c, d){
		return c*Math.sqrt(1-(t=t/d-1)*t)+b;
	},
	easeInOutCirc:function(t, b, c, d){
		if ((t/=d/2) < 1) return -c/2*(Math.sqrt(1-t*t)-1)+b;
		return c/2*(Math.sqrt(1-(t-=2)*t)+1)+b;
	},
	easeOutInCirc:function(t, b, c, d){
		if (t < d/2) return ease.easeOutCirc (t*2, b, c/2, d);
		return ease.easeInCirc((t*2)-d, b+c/2, c/2, d);
	},
	easeInElastic:function(t, b, c, d){
		var p;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		var s, a;
		if (!a || a < Math.abs(c)) { a=c; s=p/4; }
		else s = p/(2*Math.PI)*Math.asin (c/a);
		return -(a*Math.pow(2,10*(t-=1))*Math.sin( (t*d-s)*(2*Math.PI)/p ))+b;
	},
	easeOutElastic:function(t, b, c, d){
		var p;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		var s, a;
		if (!a || a < Math.abs(c)) { a=c; s=p/4; }
		else s = p/(2*Math.PI)*Math.asin (c/a);
		return (a*Math.pow(2,-10*t)*Math.sin( (t*d-s)*(2*Math.PI)/p )+c+b);
	},
	easeInOutElastic:function(t, b, c, d){
		var p;
		if (t==0) return b;  if ((t/=d/2)==2) return b+c;  if (!p) p=d*(.3*1.5);
		var s;
		var a;
		if (!a || a < Math.abs(c)) { a=c; s=p/4; }
		else s = p/(2*Math.PI)*Math.asin (c/a);
		if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1))*Math.sin( (t*d-s)*(2*Math.PI)/p ))+b;
		return a*Math.pow(2,-10*(t-=1))*Math.sin( (t*d-s)*(2*Math.PI)/p )*.5+c+b;
	},
	easeOutInElastic:function(t, b, c, d){
		if (t < d/2) return ease.easeOutElastic (t*2, b, c/2, d, a, p);
		return ease.easeInElastic((t*2)-d, b+c/2, c/2, d, a, p);
	},
	easeInBack:function(t, b, c, d){
		var s;
		if (!s) s = 1.70158;
		return c*(t/=d)*t*((s+1)*t-s)+b;
	},
	easeOutBack:function(t, b, c, d){
		var s;
		if (!s) s = 1.70158;
		return c*((t=t/d-1)*t*((s+1)*t+s)+1)+b;
	},
	easeInOutBack:function(t, b, c, d){
		var s;
		if (!s) s = 1.70158;
		if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t-s))+b;
		return c/2*((t-=2)*t*(((s*=(1.525))+1)*t+s)+2)+b;
	},
	easeOutInBack:function(t, b, c, d){
		if (t < d/2) return ease.easeOutBack (t*2, b, c/2, d, s);
		return ease.easeInBack((t*2)-d, b+c/2, c/2, d, s);
	},
	easeInBounce:function(t, b, c, d){
		return c-ease.easeOutBounce (d-t, 0, c, d)+b;
	},
	easeOutBounce:function(t, b, c, d){
		if ((t/=d) < (1/2.75)) {
			return c*(7.5625*t*t)+b;
		} else if (t < (2/2.75)) {
			return c*(7.5625*(t-=(1.5/2.75))*t+.75)+b;
		} else if (t < (2.5/2.75)) {
			return c*(7.5625*(t-=(2.25/2.75))*t+.9375)+b;
		} else {
			return c*(7.5625*(t-=(2.625/2.75))*t+.984375)+b;
		}
	},
	easeInOutBounce:function(t, b, c, d){
		if (t < d/2) return ease.easeInBounce (t*2, 0, c, d)*.5+b;
		else return ease.easeOutBounce (t*2-d, 0, c, d)*.5+c*.5+b;
	},
	easeOutInBounce:function(t, b, c, d){
		if (t < d/2) return ease.easeOutBounce (t*2, b, c/2, d);
		return ease.easeInBounce((t*2)-d, b+c/2, c/2, d);
	}
};
cyui.transition.MultiTween=function(_iDuration, _iFrameRate){
	var _aoTweenData=null;
	var _iCount=null;
	var _iIndex=null;
	var _iTweenLength=null;
	var _iFrameSecond=null;
	var _hndTimer=null;
	var _aValue=[];
	var _hndListener=[];
	var _hndEventQueue={};
	var _evtDispatcher=null;
	// Constructor
	var init=function(){
		// Check arguments
		if(!_iDuration||!_iFrameRate){
			alert('Any argument is not input.');
			return false;
		}else if((typeof _iDuration!='number')||(typeof _iFrameRate!='number')){
			alert('Any argument is not correct.');
			return false;
		}
		_evtDispatcher=new cyui.event.Dispatcher();
		vInitalize();
	};
	// Initalize
	var vInitalize=function(){
		_aoTweenData=[];
		_iIndex=-1;
		_iCount=0;
		_iFrameSecond=1000/_iFrameRate;
		_iTweenLength=_iFrameRate*_iDuration;
	};
	// Get values
	var aGetValue=function(sEaseType, iBegin, iFinish){
		var rtn=[];
		var dist=iFinish-iBegin;
		for(var i=1; i <= _iTweenLength; i++) rtn.push(Math.round(cyui.transition.ease[sEaseType](i, iBegin, dist, _iTweenLength)));
		return rtn;
	};
	// Add tween
	this.add=function(oTarget, sProperty, iBegin, iFinish, sUnit, sEaseType){
		// Check arguments
		if(oTarget==null||sProperty==null||iBegin==null||iFinish==null||sUnit==null||!!!sEaseType){
			alert('Any argument is not input.');
			return false;
		}else if((typeof oTarget!='object')||(typeof sProperty!='string')||(typeof iBegin!='number')||(typeof iFinish!='number')||(typeof sUnit!='string')||(typeof sEaseType!='string')){
			alert('Any argument is not correct.');
			return false;
		}
		_aoTweenData[_iCount]=[oTarget, sProperty, iBegin, iFinish, sUnit, sEaseType, aGetValue(sEaseType, iBegin, iFinish)];
		var iIdx=_iCount;
		_iCount=_iCount+1;
		return iIdx;
	};
	// Get target
	this.getTarget=function(iIdx){
		if(!_aoTweenData[iIdx]) return false;
		return _aoTweenData[iIdx][1];
	};
	// Set target
	this.setTarget=function(iIdx, oTarget){
		if(typeof oTarget!='object') return false;
		if(_hndTimer==null&&_aoTweenData[iIdx]&&_aoTweenData[iIdx][0]!=oTarget){
			_aoTweenData[iIdx][0]=oTarget;
			return true;
		}
	};
	// Get property
	this.getProperty=function(iIdx){
		if(!_aoTweenData[iIdx]) return false;
		return _aoTweenData[iIdx][1];
	};
	// Set property
	this.setProperty=function(iIdx, sProperty){
		if(typeof sProperty!='string') return false;
		if(_hndTimer==null&&_aoTweenData[iIdx]&&_aoTweenData[iIdx][1]!=sProperty){
			_aoTweenData[iIdx][1]=sProperty;
			return true;
		}
	};
	// Get begin
	this.getBegin=function(iIdx){
		if(!_aoTweenData[iIdx]) return false;
		return _aoTweenData[iIdx][2];
	};
	// Set begin
	this.setBegin=function(iIdx, iBegin){
		if(typeof iBegin!='number') return false;
		if(_hndTimer==null&&_aoTweenData[iIdx]&&_aoTweenData[iIdx][2]!=iBegin){
			_aoTweenData[iIdx][2]=iBegin;
			_aoTweenData[iIdx][6]=aGetValue(_aoTweenData[iIdx][5], _aoTweenData[iIdx][2], _aoTweenData[iIdx][3]);
			return true;
		}
	};
	// Get finish
	this.getFinish=function(iIdx){
		if(!_aoTweenData[iIdx]) return false;
		return _aoTweenData[iIdx][3];
	};
	// Set finish
	this.setFinish=function(iIdx, iFinish){
		if(typeof iFinish!='number') return false;
		if(_hndTimer==null&&_aoTweenData[iIdx]&&_aoTweenData[iIdx][3]!=iFinish){
			_aoTweenData[iIdx][3]=iFinish;
			_aoTweenData[iIdx][6]=aGetValue(_aoTweenData[iIdx][5], _aoTweenData[iIdx][2], _aoTweenData[iIdx][3]);
			return true;
		}
	};
	// Get unit
	this.getUnit=function(iIdx){
		if(!_aoTweenData[iIdx]) return false;
		return _aoTweenData[iIdx][4];
	};
	// Set unit
	this.setUnit=function(iIdx, sUnit){
		if(typeof sUnit!='string') return false;
		_aoTweenData[iIdx][4]=sProperty;
		return true;
	};
	// Get position
	this.getPosition=function(iIdx){
		if(!_aoTweenData[iIdx]) return false;
		return _aoTweenData[iIdx][6][_iIndex];
	};
	// Set position
	this.setPosition=function(iIndex){
		if(typeof iIndex!='number') return false;
		if(_hndTimer==null&&_iIndex!=iIndex&&iIndex<_aValue.length) _iIndex=iIndex;
		return true;
	};
	// Tween
	var vTween=function(){
		var l=_aoTweenData.length;
		if(_iIndex+1<_iTweenLength){
			var aData=null;
			_iIndex++;
			for(var i=0;i<l;i++){
				aData=_aoTweenData[i];
				aData[0][aData[1]]=aData[6][_iIndex]+aData[4];
			}
			_hndTimer=setTimeout(vTween, _iFrameSecond);
		}else{
			clearTimeout(_hndTimer);
			_hndTimer=null;
			_evtDispatcher.dispatch(cyui.event.TweenEvent.TWEEN_COMPLETE);
		}
	};
	// Is play
	this.isPlay=function(){
		return !!_hndTimer;
	};
	// Start tween
	this.start=function(){
		if(_hndTimer==null){
			_iIndex=-1;
			_hndTimer=setTimeout(vTween, _iFrameSecond);
		}
	};
	// Stop tween
	this.stop= function(){
		if(_hndTimer!=null){
			clearTimeout(_hndTimer);
			_hndTimer=null;
		}
	};
	// Add event
	this.addListener= function(sEventType, fncCallBack, oTarget, aArgs){
		_evtDispatcher.addListener(sEventType, fncCallBack, oTarget, aArgs);
	};
	init();
};
cyui.Slider=function(_sTargetId, _sDirection, _sEaseType, _nAutoSlide, _bAutoReturn, _iMaxSlide){
	var _iPosition=-1;
	var _asSlideId=[];
	var _hndListener=[];
	var _oTweener=null;
	var _hndBtnListener=[];
	var _iAreaWidth=[];
	var _oTimer=null;
	var _sWidthType='offsetWidth';
	var _iTweenMark=1;
	var _sTweenProperty='up';
	var _evtDispatcher=null;
	var _bRequireData;
	var _asPrevBtnId=[];
	var _asNextBtnId=[];
	// Constructor
	var init=function(){
		// Check arguments
		if(_sDirection==null) _sDirection='up';
		if(_sEaseType==null) _sEaseType='easeInOutQuint';
		if(_nAutoSlide==null) _nAutoSlide=0;
		if(_bAutoReturn==null) _bAutoReturn=false;
		if(!_sTargetId||!_sDirection){
			alert('Any argument is not input.');
			return false;
		}else if((typeof _sTargetId!='string')||(typeof _sDirection!='string')||((_iMaxSlide!=null)&&(typeof _iMaxSlide!='number'))){
			alert('Any argument is not correct.');
			return false;
		}
		switch(_sDirection){
			default:
				alert('Direction must be "up", "down", "left", "right".');
				return false;
				break;
			case 'down':
				_iTweenMark=-1;
			case 'up':
				_sTweenProperty='top';
				_sWidthType='offsetHeight';
				break;
			case 'right':
				_iTweenMark=-1;
			case 'left':
				_sTweenProperty='left';
				_sWidthType='offsetWidth';
				break;
		}
		_evtDispatcher=new cyui.event.Dispatcher()
	};
	// Check can initalize
	var vCheckInit=function(){
		if(!cyui.$(_sTargetId)){
			alert('Argument for _sTargetId is not a id of document element.');
			return false;
		}
		if(_asSlideId.length<2){
			if(_asSlideId.length<_iMaxSlide){
				_evtDispatcher.addListener(cyui.event.SliderEvent.SLIDE_ADDED, hndInitSlideAdded);
				_evtDispatcher.dispatch(cyui.event.SliderEvent.REQURE_SLIDE);
			}else{
				return true;
			}
		}else{
			vInitalize();
			vInitButton();
		}
	};
	// Initalize
	var vInitalize=function(){
		if(_iMaxSlide && (_asSlideId.length<_iMaxSlide)) _evtDispatcher.addListener(cyui.event.SliderEvent.SLIDE_ADDED, hndSlideNextAdded);
		_iPosition=0;
		_iAreaWidth=_iTweenMark * cyui.$(_sTargetId)[_sWidthType];
		_oTweener=new cyui.transition.MultiTween(0.5, 48);
		_oTweener.add(cyui.$(_asSlideId[0]).style, _sTweenProperty, _iAreaWidth, _iAreaWidth, 'px', _sEaseType);
		_oTweener.add(cyui.$(_asSlideId[1]).style, _sTweenProperty, _iAreaWidth, _iAreaWidth, 'px', _sEaseType);
		if(cyui.browser.isIE) document.execCommand('BackgroundImageCache', false, true);
		if(_nAutoSlide && _oTimer==null) setTimeout(vAutoSlide, _nAutoSlide);
	};
	// Init slide added handler
	var hndInitSlideAdded=function(){
		if(_asSlideId.length>=_iMaxSlide){
			_evtDispatcher.removeListener(cyui.event.SliderEvent.SLIDE_ADDED, hndInitSlideAdded);
			vInitalize();
		}
	};
	// Slide next added handler
	var hndSlideNextAdded=function(){
		vSlideNext();
	};
	// Initalize button
	var vInitButton=function(){
		// Add button event listener
		var prevLen=_asPrevBtnId.length;
		var nextLen=_asNextBtnId.length;
		if(prevLen>0) for(var i=0;i<prevLen;i++) cyui.event.add(cyui.$(_asPrevBtnId[i]), 'click', vSlidePrev);
		if(nextLen>0) for(var i=0;i<nextLen;i++) cyui.event.add(cyui.$(_asNextBtnId[i]), 'click', vSlideNext);
	};
	// Slide to previous
	var vSlidePrev=function(){
		if(!_oTweener.isPlay()){
			var tmpPosition=_iPosition;
			if(_bAutoReturn){
				_iPosition=(_iPosition-1<0)?_asSlideId.length-1:_iPosition-1;
			}
			else{
				if(_iPosition-1>= 0){
					_iPosition=_iPosition-1;
					if(_iPosition==0) _evtDispatcher.dispatch(cyui.event.SliderEvent.BEGIN_OF_SLIDE);
					else _evtDispatcher.dispatch(cyui.event.SliderEvent.MIDDLE_OF_SLIDE);
				}else{
					return false;
				}
			}
			_oTweener.setTarget(0, cyui.$(_asSlideId[tmpPosition]).style);
			_oTweener.setBegin(0, 0);
			_oTweener.setFinish(0, _iAreaWidth);
			_oTweener.setTarget(1, cyui.$(_asSlideId[_iPosition]).style);
			_oTweener.setBegin(1, -_iAreaWidth);
			_oTweener.setFinish(1, 0);
			_oTweener.start();
		}
	};
	// Slide to next
	var vSlideNext=function(){
		if(!_oTweener.isPlay()){
			var tmpPosition=_iPosition;
			if(_bAutoReturn){
				_iPosition=(_iPosition+1<_asSlideId.length)?_iPosition+1:0;
			}else{
				if(_iPosition+1<_asSlideId.length){
					_iPosition=_iPosition+1;
					if(((_iPosition+1)==_asSlideId.length)&&(_iMaxSlide<=_asSlideId.length)) _evtDispatcher.dispatch(cyui.event.SliderEvent.END_OF_SLIDE);
					else _evtDispatcher.dispatch(cyui.event.SliderEvent.MIDDLE_OF_SLIDE);
				}else{
					if(_iMaxSlide>_asSlideId.length){
						_evtDispatcher.dispatch(cyui.event.SliderEvent.REQURE_SLIDE);
						return false;
					}else{
						return false;
					}
				}
			}
			_oTweener.setTarget(0, cyui.$(_asSlideId[tmpPosition]).style);
			_oTweener.setBegin(0, 0);
			_oTweener.setFinish(0, -_iAreaWidth);
			_oTweener.setTarget(1, cyui.$(_asSlideId[_iPosition]).style);
			_oTweener.setBegin(1, _iAreaWidth);
			_oTweener.setFinish(1, 0);
			_oTweener.start();
		}
	};
	// Auto slide
	var vAutoSlide=function(){
		vSlideNext();
		_oTimer=setTimeout(vAutoSlide, _nAutoSlide);
	};
	// Initalize slide
	this.init=function(){
		// Choose when initalize
		if(!!cyui.$(_sTargetId)){
			vCheckInit();
			return true;
		}else{
			cyui.event.add(window, 'load', vCheckInit);
		}
	};
	// Add slide id
	this.addSlideId=function(sSlideId){
		_asSlideId.push(sSlideId);
		_evtDispatcher.dispatch(cyui.event.SliderEvent.SLIDE_ADDED);
	};
	// Add button id
	this.addButtonId=function(sPrevBtnId, sNextBtnId){
		_asPrevBtnId.push(sPrevBtnId);
		_asNextBtnId.push(sNextBtnId);
	};
	// Add previous button id
	this.addPrevBtnId=function(sBtnId){
		_asPrevBtnId.push(sBtnId);
	};
	// Add next button id
	this.addNextBtnId=function(sBtnId){
		_asNextBtnId.push(sBtnId);
	};
	// Add event
	this.addListener= function(sEventType, fncCallBack, oTarget, aArgs){
		_evtDispatcher.addListener(sEventType, fncCallBack, oTarget, aArgs);
	};
	init();
};
cyui.transition.Tween=function(_oTarget, _sProperty, _iBegin, _iFinish, _sUnit, _iDuration, _iFrameRate, _sEaseType){
	var _iIndex=null;
	var _iFrameSecond=null;
	var _hndTimer=null;
	var _aValue=[];
	var _hndListener=[];
	var _hndEventQueue={};
	var _evtDispatcher=null;
	// Constructor
	var init=function(){
		// Check arguments
		if(_oTarget==null||_sProperty==null||_iBegin==null||_iFinish==null||_sUnit==null||!!!_iDuration||!!!_iFrameRate||!!!_sEaseType){
			alert('Any argument is not input.');
			return false;
		}else if((typeof _oTarget!='object')||(typeof _sProperty!='string')||(typeof _iBegin!='number')||(typeof _iFinish!='number')||(typeof _sUnit!='string')||(typeof _iDuration!='number')||(typeof _iFrameRate!='number')||(typeof _sEaseType!='string')){
			alert('Any argument is not correct.');
			return false;
		}
		_evtDispatcher=new cyui.event.Dispatcher();
		vInitalize();
	};
	// Initalize
	var vInitalize=function(){
		_iIndex=-1;
		_iFrameSecond=1000/_iFrameRate;
		_aValue=aGetValue(_sEaseType);
	};
	// Get values
	var aGetValue=function(sEaseType){
		var rtn=[];
		var dist=_iFinish-_iBegin;
		var l=_iFrameRate*_iDuration;
		for(var i=1; i <= l; i++) rtn.push(Math.round(cyui.transition.ease[sEaseType](i, _iBegin, dist, l)));
		return rtn;
	};
	// Get begin
	this.getProperty=function(){
		return _sProperty;
	};
	// Set begin
	this.setProperty=function(sProperty){
		if(typeof sProperty!='string') return false;
		if(_hndTimer==null&&_sProperty!=sProperty){
			_sProperty=sProperty;
			return true;
		}
	};
	// Get begin
	this.getBegin=function(){
		return _iBegin;
	};
	// Set begin
	this.setBegin=function(iBegin){
		if(typeof iBegin!='number') return false;
		if(_hndTimer==null&&_iBegin!=iBegin){
			_iBegin=iBegin;
			vInitalize();
			return true;
		}
	};
	// Get finish
	this.getFinish=function(){
		return _iFinish;
	};
	// Set finish
	this.setFinish=function(iFinish){
		if(typeof iFinish!='number') return false;
		if(_hndTimer==null&&_iFinish!=iFinish){
			_iFinish=iFinish;
			vInitalize();
			return true;
		}
	};
	// Get unit
	this.getUnit=function(){
		return _sUnit;
	};
	// Set unit
	this.setUnit=function(sUnit){
		if(typeof sUnit!='string') return false;
		_sUnit=sUnit;
		return true;
	};
	// Get position
	this.getPosition=function(){
		return _aValue[_iIndex];
	};
	// Set position
	this.setPosition=function(iIndex){
		if(typeof iIndex!='number') return false;
		if(_hndTimer==null&&_iIndex!=iIndex&&iIndex<_aValue.length) _iIndex=iIndex;
		return true;
	};
	// Tween
	var vTween=function(){
		if(_iIndex+1<_aValue.length){
			_iIndex++;
			_oTarget[_sProperty]=_aValue[_iIndex]+_sUnit;
			_hndTimer=setTimeout(vTween, _iFrameSecond);
		}else{
			clearTimeout(_hndTimer);
			_hndTimer=null;
			_evtDispatcher.dispatch(cyui.event.TweenEvent.TWEEN_COMPLETE);
		}
	};
	// Is play
	this.isPlay=function(){
		return !!_hndTimer;
	};
	// Start tween
	this.start=function(){
		if(_hndTimer==null){
			_iIndex=-1;
			_hndTimer=setTimeout(vTween, _iFrameSecond);
		}
	};
	// Stop tween
	this.stop= function(){
		if(_hndTimer!=null){
			clearTimeout(_hndTimer);
			_hndTimer=null;
		}
	};
	// Add event
	this.addListener= function(sEventType, fncCallBack, oTarget, aArgs){
		_evtDispatcher.addListener(sEventType, fncCallBack, oTarget, aArgs);
	};
	init();
};


/*  tween  */
/*
regularEaseIn = "Tween.regularEaseIn"
regularEaseOut = "Tween.regularEaseOut"
regularEaseInOut = "Tween.regularEaseInOut"
strongEaseIn = "Tween.strongEaseIn"
strongEaseOut = "Tween.strongEaseOut"
strongEaseInOut = "Tween.strongEaseInOut"
backEaseOut = "Tween.backEaseOut"
backEaseIn = "Tween.backEaseIn"
backEaseInOut = "Tween.backEaseInOut"
bounceEaseOut = "Tween.bounceEaseOut"
bounceEaseIn = "Tween.bounceEaseIn"
bounceEaseInOut = "Tween.bounceEaseInOut"
elasticEaseIn = "Tween.elasticEaseIn"
elasticEaseOut = "Tween.elasticEaseOut"
elasticEaseInOut = "Tween.elasticEaseInOut"
*/

function Delegate() {}
Delegate.create = function (o, f) {
	var a = new Array() ;
	var l = arguments.length ;
	for(var i = 2 ; i < l ; i++) a[i - 2] = arguments[i] ;
	return function() {
		var aP = [].concat(arguments, a) ;
		f.apply(o, aP);
	}
}

Tween = function(obj, prop, func, begin, finish, duration, suffixe){
	this.init(obj, prop, func, begin, finish, duration, suffixe)
}
var t = Tween.prototype;

t.obj = new Object();
t.prop='';
t.func = function (t, b, c, d) { return c*t/d + b; };
t.begin = 0;
t.change = 0;
t.prevTime = 0;
t.prevPos = 0;
t.looping = false;
t._duration = 0;
t._time = 0;
t._pos = 0;
t._position = 0;
t._startTime = 0;
t._finish = 0;
t.name = '';
t.suffixe = '';
t._listeners = new Array();	
t.setTime = function(t){
	this.prevTime = this._time;
	if (t > this.getDuration()) {
		if (this.looping) {
			this.rewind (t - this._duration);
			this.update();
			this.broadcastMessage('onMotionLooped',{target:this,type:'onMotionLooped'});
		} else {
			this._time = this._duration;
			this.update();
			this.stop();
			this.broadcastMessage('onMotionFinished',{target:this,type:'onMotionFinished'});
		}
	} else if (t < 0) {
		this.rewind();
		this.update();
	} else {
		this._time = t;
		this.update();
	}
}
t.getTime = function(){
	return this._time;
}
t.setDuration = function(d){
	this._duration = (d == null || d <= 0) ? 100000 : d;
}
t.getDuration = function(){
	return this._duration;
}
t.setPosition = function(p){
	this.prevPos = this._pos;
	var a = this.suffixe != '' ? this.suffixe : '';
	this.obj[this.prop] = Math.round(p) + a;
	this._pos = p;
	this.broadcastMessage('onMotionChanged',{target:this,type:'onMotionChanged'});
}
t.getPosition = function(t){
	if (t == undefined) t = this._time;
	return this.func(t, this.begin, this.change, this._duration);
};
t.setFinish = function(f){
	this.change = f - this.begin;
};
t.geFinish = function(){
	return this.begin + this.change;
};
t.init = function(obj, prop, func, begin, finish, duration, suffixe){
	if (!arguments.length) return;
	this._listeners = new Array();
	this.addListener(this);
	if(suffixe) this.suffixe = suffixe;
	this.obj = obj;
	this.prop = prop;
	this.begin = begin;
	this._pos = begin;
	this.setDuration(duration);
	if (func!=null && func!='') {
		this.func = func;
	}
	this.setFinish(finish);
}
t.start = function(){
	this.rewind();
	this.startEnterFrame();
	this.broadcastMessage('onMotionStarted',{target:this,type:'onMotionStarted'});
	//alert('in');
}
t.rewind = function(t){
	this.stop();
	this._time = (t == undefined) ? 0 : t;
	this.fixTime();
	this.update();
}
t.fforward = function(){
	this._time = this._duration;
	this.fixTime();
	this.update();
}
t.update = function(){
	this.setPosition(this.getPosition(this._time));
	}
t.startEnterFrame = function(){
	this.stopEnterFrame();
	this.isPlaying = true;
	this.onEnterFrame();
}
t.onEnterFrame = function(){
	if(this.isPlaying) {
		this.nextFrame();
		setTimeout(Delegate.create(this, this.onEnterFrame), 0);
	}
}
t.nextFrame = function(){
	this.setTime((this.getTimer() - this._startTime) / 1000);
	}
t.stop = function(){
	this.stopEnterFrame();
	this.broadcastMessage('onMotionStopped',{target:this,type:'onMotionStopped'});
}
t.stopEnterFrame = function(){
	this.isPlaying = false;
}

t.continueTo = function(finish, duration){
	this.begin = this._pos;
	this.setFinish(finish);
	if (this._duration != undefined)
		this.setDuration(duration);
	this.start();
}
t.resume = function(){
	this.fixTime();
	this.startEnterFrame();
	this.broadcastMessage('onMotionResumed',{target:this,type:'onMotionResumed'});
}
t.yoyo = function (){
	this.continueTo(this.begin,this._time);
}

t.addListener = function(o){
	this.removeListener (o);
	return this._listeners.push(o);
}
t.removeListener = function(o){
	var a = this._listeners;	
	var i = a.length;
	while (i--) {
		if (a[i] == o) {
			a.splice (i, 1);
			return true;
		}
	}
	return false;
}
t.broadcastMessage = function(){
	var arr = new Array();
	for(var i = 0; i < arguments.length; i++){
		arr.push(arguments[i])
	}
	var e = arr.shift();
	var a = this._listeners;
	var l = a.length;
	for (var i=0; i<l; i++){
		if(a[i][e])
		a[i][e].apply(a[i], arr);
	}
}
t.fixTime = function(){
	this._startTime = this.getTimer() - this._time * 1000;
}
t.getTimer = function(){
	return new Date().getTime() - this._time;
}
Tween.backEaseIn = function(t,b,c,d,a,p){
	if (s == undefined) var s = 1.70158;
	return c*(t/=d)*t*((s+1)*t - s) + b;
}
Tween.backEaseOut = function(t,b,c,d,a,p){
	if (s == undefined) var s = 1.70158;
	return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
}
Tween.backEaseInOut = function(t,b,c,d,a,p){
	if (s == undefined) var s = 1.70158; 
	if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
	return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
}
Tween.elasticEaseIn = function(t,b,c,d,a,p){
		if (t==0) return b;  
		if ((t/=d)==1) return b+c;  
		if (!p) p=d*.3;
		if (!a || a < Math.abs(c)) {
			a=c; var s=p/4;
		}
		else 
			var s = p/(2*Math.PI) * Math.asin (c/a);
		
		return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
	
}
Tween.elasticEaseOut = function (t,b,c,d,a,p){
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (!a || a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return (a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b);
	}
Tween.elasticEaseInOut = function (t,b,c,d,a,p){
	if (t==0) return b;  if ((t/=d/2)==2) return b+c;  if (!p) var p=d*(.3*1.5);
	if (!a || a < Math.abs(c)) {var a=c; var s=p/4; }
	else var s = p/(2*Math.PI) * Math.asin (c/a);
	if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
	return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;
}

Tween.bounceEaseOut = function(t,b,c,d){
	if ((t/=d) < (1/2.75)) {
		return c*(7.5625*t*t) + b;
	} else if (t < (2/2.75)) {
		return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
	} else if (t < (2.5/2.75)) {
		return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
	} else {
		return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
	}
}
Tween.bounceEaseIn = function(t,b,c,d){
	return c - Tween.bounceEaseOut (d-t, 0, c, d) + b;
	}
Tween.bounceEaseInOut = function(t,b,c,d){
	if (t < d/2) return Tween.bounceEaseIn (t*2, 0, c, d) * .5 + b;
	else return Tween.bounceEaseOut (t*2-d, 0, c, d) * .5 + c*.5 + b;
	}

Tween.strongEaseInOut = function(t,b,c,d){
	return c*(t/=d)*t*t*t*t + b;
	}

Tween.regularEaseIn = function(t,b,c,d){
	return c*(t/=d)*t + b;
	}
Tween.regularEaseOut = function(t,b,c,d){
	return -c *(t/=d)*(t-2) + b;
	}

Tween.regularEaseInOut = function(t,b,c,d){
	if ((t/=d/2) < 1) return c/2*t*t + b;
	return -c/2 * ((--t)*(t-2) - 1) + b;
	}
Tween.strongEaseIn = function(t,b,c,d){
	return c*(t/=d)*t*t*t*t + b;
	}
Tween.strongEaseOut = function(t,b,c,d){
	return c*((t=t/d-1)*t*t*t*t + 1) + b;
	}

Tween.strongEaseInOut = function(t,b,c,d){
	if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;
	return c/2*((t-=2)*t*t*t*t + 2) + b;
	}

/* @@@@@ marquee ticker @@@@@ */
var direction = new Array();
var temporary = new Array();
//This do the real job (moves the ticker)
function move_ticker( mess, speed, msg_start, msg_end, fname ) {
  var doc = eval(''+fname+'.scroll');
  var len = doc.size;
  var dir = direction[fname];
  if (dir > 0) {
    if (msg_end >= mess.length) {
      mess = mess.substring(msg_start, mess.length) + mess.substring(0, msg_start);
      msg_start = 0;
      msg_end = len;
    }
  } else {
    if (msg_start <= 0) {
      mess = mess.substring(msg_end, mess.length) + mess.substring(0, msg_end);
      msg_start = mess.length - msg_end;
      msg_end = mess.length;
    }
  }
  doc.value=mess.substring(msg_start, msg_end);
  msg_start+= dir;
  msg_end+= dir;
  window.setTimeout("move_ticker('"+mess+"', "+speed+", "+msg_start+", "+msg_end+", '"+fname+"')", speed);
}

//This inits the ticker and starts the movement. Executed only once at startup time
function init_ticker(fname, mess, speed, dir) {
  var len = eval(''+fname+'.scroll.size');
  direction[fname] = dir;
  while (mess.length < len) {
    mess = '' + mess + mess;
  }
  window.setTimeout("move_ticker('"+mess+"', "+speed+", 0, "+len+", '"+fname+"')", speed);
}

//This switches the tickerīs state (stop or start)
function switch_ticker(fname) {
  if (direction[fname] != 0) {
    temporary[fname] = direction[fname];
    direction[fname] = 0;
  } else {
    direction[fname] = temporary[fname];
  }
}

//This restarts the movement after a stop
function start_ticker(fname) {
   direction[fname] = temporary[fname];
}

//This stops the ticker
function stop_ticker(fname) {
  temporary[fname] = direction[fname];
  direction[fname] = 0;
}

//This reverts the tickerīs direction
function revert_ticker(fname) {
  temporary[fname] = -temporary[fname];
  direction[fname] = -direction[fname];
}