(function($){$.fn.extend({carousel3d:function(options){opt=$.extend({},$.carouselSetup.defaults,options);$this=$(this);opt.speed=parseInt(6-opt.speed);btnSpeed=Math.round(10-opt.speed)*$.browser.msie?0.04:0.04;contSpeed=btnSpeed*$.browser.msie?0.5:0.15;opt.speed=opt.speed*$.browser.msie?2500:1500;$imgs=$('img',$this).hide();$texts=$('span',$('#carouselText')).hide();if(opt.textBox&&!$texts.size())alert('<div id="carouselText" /> + <span>\'s. . . do not exist.  either add them or set textBox option to 0');items=$imgs.size();numSlots=items*opt.padding;if(opt.padding==0)opt.padding=1;$imgs.each(function(i){new $.imageSetUp(this,i)});new $.carouselSetup()}});$.imageSetUp=function(im,_index){im.orig_w=$(im).width(),im.orig_h=$(im).height();var w_h=resize(im.orig_w,128,im.orig_h,108).split('|');im.h=w_h[1],im.w=w_h[0];im.slot=_index*opt.padding;im.angle=parseInt((_index*opt.padding)*((Math.PI*2)/numSlots)*1000)/1000;im.clicked={top:parseInt(opt.centerY-im.orig_h/3)+'px',left:parseInt(opt.centerX-im.orig_w/3)+'px',width:im.orig_w+'px',height:im.orig_h+'px'};im.animateOn=function(el){$imgs.fadeOut(700);el.animate(im.clicked,500)};new $.TextBoxSetUp(im,_index);$(im).attr('id','pix'+_index).css({position:'absolute'});$(im).hover(function(){rate=0},function(){rate=0.01});if($(im).hasClass('link'))$(im).click(function(){window.location=($(this).attr('longdesc'))});else $(im).one('click',clickOn);return false};$.TextBoxSetUp=function(im,_index){im.textClicked={left:opt.centerX-opt.radiusX-im.w+'px',top:opt.centerY+'px',width:im.w+'px',height:im.h+'px'};im.textBoxCss={top:opt.centerY*0.7+'px',left:opt.centerX-opt.radiusX*0.9+'px'};im.textAnimateOn=function(el){var msg='';if(!$texts.size())msg+='<div id="carouselText" /> + <span>\'s. . . do not exist';else if(!$('#text').size())msg+='<div id="text" /> does not exist';else{$imgs.fadeOut(700);el.animate(im.textClicked,500);$('#text').css(im.textBoxCss).html($texts.eq(_index).html()).fadeIn(700)}if(msg)alert('Cannot setup text box; '+msg)}};$.carouselSetup=function(){var im,_t,_s;if(opt.control=='buttons')controls();else if(opt.control=='continuous')rate=btnSpeed*.3;else $().mousemove(function(e){rate=(e.pageX-opt.centerX)/opt.speed});t1=new Tween(new Object(),'xyz',Tween.regularEaseInOut,0,10000,10000);t1.onMotionChanged=function(event){for(var j=0;j<items,im=$('#pix'+j)[0];j++){im.slot=(im.slot==numSlots-1)?0:im.slot++;_t=Math.sin(im.angle)*opt.radiusY+opt.centerY;_s=((_t-opt.perspective)/(opt.centerY+opt.radiusY-opt.perspective));$(im).css({top:_t,left:Math.cos(im.angle)*opt.radiusX+opt.centerX,width:im.w*_s,height:im.h*_s,zIndex:Math.round(_t)+100,opacity:(opt.fadeEffect==1)?Math.sin(im.angle):1});if(opt.fadeEffect==1){$(im)[Math.sin(im.angle)<=0?'hide':!$(im).is(':visible')?'show':'']}im.angle+=opt.control=='continuous'?contSpeed:rate}};t1.start();$imgs.fadeIn(1500)};var opt,numSlots,items,rate=contSpeed=btnSpeed=0.2;function clickOn(){var elem=this;t1.stop();$('#buttonwrapper:visible').fadeOut();$cloned=$(this).clone().prependTo($this).click(function(){$imgs.fadeIn();$(this).animate({left:$(elem).position().left+'px',top:$(elem).position().top+'px',width:$(elem).width()+'px',height:$(elem).height()+'px'},function(){$(this).remove();$(elem).one('click',clickOn);t1.start()});$('#text:visible').fadeOut();$('#buttonwrapper:hidden').fadeIn()});(opt.textBox)?elem.textAnimateOn($cloned):elem.animateOn($cloned)};function controls(){rate=0.01;var btns=$('<div id="buttonwrapper" />').css({left:opt.centerX+'px',top:opt.centerY*0.5+'px'}),left_btn=$('<div id="left" />').hover(function(){rate=btnSpeed},function(){rate=0}),right_btn=$('<div id="right" />').hover(function(){rate=-btnSpeed},function(){rate=0});$this.prepend(btns.append(left_btn,right_btn))};function resize(w,max_w,h,max_h){if(w>max_w||h>max_h){var x_ratio=max_w/w;var y_ratio=max_h/h;if((x_ratio*h)<max_h)return max_w+'|'+Math.ceil(x_ratio*h);else return Math.ceil(y_ratio*w)+'|'+max_h}else return w+'|'+h};function resetAnimations(){$imgs.each(function(i){this.clicked.left=parseInt(opt.centerX*1-this.orig_w/2)+'px';this.textClicked.left=parseInt(opt.centerX*1-opt.radiusX*1-this.w*1)+'px';this.textBoxCss.left=parseInt(opt.centerX*1-opt.radiusX*1)+'px'})};$(window).resize(function(){opt.centerX=$this.offset().left+$this.width()/2;resetAnimations()});$.carouselSetup.defaults={control:'mouse',speed:3,radiusX:270,radiusY:40,centerX:10,centerY:270,perspective:150,padding:6,fadeEffect:0,textBox:0}})(jQuery);