(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.05:0.05;if($.browser.safari){btnSpeed=Math.round(10-opt.speed)*0.003}var is_chrome=navigator.userAgent.toLowerCase().indexOf('chrome')>-1;if(is_chrome){btnSpeed=Math.round(10-opt.speed)*0.012};contSpeed=btnSpeed*$.browser.msie?0.3: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,150,im.orig_h,165).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'});if($(im).hasClass('link'))$(im).click(function(){parent.location=$(this).attr('longdesc')});else $(im).one('click',clickOn)};$.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++){angleSine=Math.sin(im.angle);if(angleSine<0){leftpos=0;width1=0;height1=0}else{angleCos=Math.cos(im.angle);im.slot=(im.slot==numSlots-1)?0:im.slot++;_t=angleSine*(opt.radiusY/2)+opt.centerY;_s=((opt.centerY+(opt.radiusY/2)-opt.perspective)/(_t-opt.perspective));width1=(angleSine*(im.w*_s));height1=im.h*_s;leftpos=angleCos*opt.radiusX+opt.centerX;if(leftpos>opt.centerX){width1=width1/(leftpos/opt.centerX)}}$(im).css({top:_t,left:leftpos,width:width1,height:height1,zIndex:Math.round(_t)+100,opacity:(opt.fadeEffect==1)?angleSine:1});if(opt.fadeEffect==1){$(im)[angleSine<=0?'hide':!$(im).is(':visible')?'show':'']}im.angle+=opt.control=='continuous'?contSpeed:rate}};t1.start();$imgs.fadeIn(500)};var opt,numSlots,items,rate=contSpeed=btnSpeed=0;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;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/2},function(){rate=0}),right_btn=$('<div id="right" />').hover(function(){rate=-btnSpeed/2},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)-10;resetAnimations()});$.carouselSetup.defaults={control:'mouse',speed:1,radiusX:250,radiusY:250,centerX:250,centerY:45,perspective:120,padding:12,fadeEffect:0,textBox:0}})(jQuery);

