//(c) 2005-2011 by AD
if (typeof(CE)=='undefined') CE={};

//top focus
CE.FRT = (function(){
	var vdatas, curri, iwidth, anim, zidx, opct;
	var drt=1000;
	return {
		init:function(v,ci,w){
			vdatas=v; curri=ci; iwidth=w; anim=false;
			$('#image-rotator .container .arrow-left').click(this.rotate(true));
			$('#image-rotator .container .arrow-right').click(this.rotate(false));
			var lbl=$('#image-rotator .bottom .focus');
			zidx=parseInt(lbl.css('z-index'), 10); if (isNaN(zidx)) zidx=100;
			opct=parseFloat(lbl.css('opacity')); if (isNaN(opct)) opct=1.0;
		},
		rotate:function(prev){
			return function(){
				if (anim) return;
				var first, last;
				last=(first=$('#image-rotator .image-box .image').first()).end().last();
				anim=true;
				if (prev) {
					curri--;if(curri<0)curri=vdatas.length-1;
				} else {
					curri++;if(curri>vdatas.length-1)curri=0;
				}
				var lbl1=$('#image-rotator .bottom .focus'), lbl2=lbl1.clone().css({'z-index':0,opacity:0.0}).appendTo('#image-rotator .bottom');
				var v=vdatas[curri];
				lbl2.find('.tit').html(v.t); lbl2.find('.dir').html(v.d); lbl2.find('a').attr('href',v.l);
				if(prev){
					last.css('left', parseInt(first.css('left'), 10) - iwidth).prependTo('#image-rotator .image-box');
					$('#image-rotator .image-box .image').animate({'left':'+='+iwidth},{duration:drt,easing:'easeOutExpo',complete:function(){anim=false;}});
				}else{
					first.css('left', parseInt(last.css('left'), 10) + iwidth).appendTo('#image-rotator .image-box');
					$('#image-rotator .image-box .image').animate({'left':'-='+iwidth},{duration:drt,easing:'easeOutExpo',complete: function(){anim=false;}});
				}
				lbl1.animate({/*'z-index':0,*/'opacity':0.0},{duration:drt,easing:'easeOutExpo',complete:function(){lbl1.remove()}});
				lbl2.animate({/*'z-index':zidx,*/'opacity':opct},{duration:drt,easing:'easeOutExpo',complete:function(){}});				
			};
		}
	};
})();

