(function(c){function b(i,m,g){var h,k,f=i.width,j=i.width,n,o;o=c(i.parentNode);this.element=h=o.append("<canvas class='reflection' style='position:absolute'/>").find(":last")[0];if(!h.getContext&&c.browser.msie){this.element=h=o.append("<img class='reflection' style='position:absolute'/>").find(":last")[0];h.src=i.src;h.style.filter="flipv progid:DXImageTransform.Microsoft.Alpha(opacity="+(g*100)+", style=1, finishOpacity=0, startx=0, starty=0, finishx=0, finishy="+(m/j*100)+")"}else{k=h.getContext("2d");try{c(h).attr({width:f,height:m});k.save();k.translate(0,j-1);k.scale(1,-1);k.drawImage(i,0,0,f,j);k.restore();k.globalCompositeOperation="destination-out";n=k.createLinearGradient(0,0,0,m);n.addColorStop(0,"rgba(255, 255, 255, "+(1-g)+")");n.addColorStop(1,"rgba(255, 255, 255, 1.0)");k.fillStyle=n;k.fillRect(0,0,f,m)}catch(l){return}}c(h).attr({alt:c(i).attr("alt"),title:c(i).attr("title")})}var a=function(g,h){this.orgWidth=g.width;this.orgHeight=g.height;this.image=g;this.reflection=null;this.alt=g.alt;this.title=g.title;this.imageOK=false;this.options=h;var e=g.getAttribute("rel");this.related=e?document.getElementById(e):null;if(this.related){var f=this.related.getAttribute("rel").split(",");this.related_width=this.related.width;this.related_height=this.related.height;this.related_pos={x:f[0],y:f[1]};this.related.style.position="absolute"}this.imageOK=true;if(this.options.reflHeight>0){this.reflection=new b(this.image,this.options.reflHeight,this.options.reflOpacity)}c(this.image).css("position","absolute")};var d=function(i,k,h){var g=[],f=Math.sin,j=Math.cos,e=this;this.controlTimer=0;this.stopped=false;this.container=i;this.xRadius=h.xRadius;this.yRadius=h.yRadius;this.showFrontTextTimer=0;this.autoRotateTimer=0;if(h.xRadius===0){this.xRadius=(c(i).width()/2.3)}if(h.yRadius===0){this.yRadius=(c(i).height()/6)}this.xCentre=h.xPos;this.yCentre=h.yPos;this.frontIndex=0;this.rotation=this.destRotation=Math.PI/2;this.timeDelay=1000/h.FPS;if(h.altBox!==null){c(h.altBox).css("display","block");c(h.titleBox).css("display","block")}c(i).css({position:"relative",overflow:"hidden"});c(h.buttonLeft).css("display","inline");c(h.buttonRight).css("display","inline");c(h.buttonLeft).bind("mouseup",this,function(l){l.data.rotate(-1);return false});c(h.buttonRight).bind("mouseup",this,function(l){l.data.rotate(1);return false});if(h.mouseWheel){c(i).bind("mousewheel",this,function(l,m){l.data.rotate(m);return false})}c(i).bind("mouseover click",this,function(n){clearInterval(n.data.autoRotateTimer);var p=c(n.target).attr("alt");if(p!==undefined&&p!==null){clearTimeout(n.data.showFrontTextTimer);c(h.altBox).html((c(n.target).attr("alt")));c(h.titleBox).html((c(n.target).attr("title")));if(h.bringToFront&&n.type=="click"){var l=c(n.target).data("itemIndex");var m=n.data.frontIndex;var o=(l-m)%k.length;if(Math.abs(o)>k.length/2){o+=(o>0?-k.length:k.length)}n.data.rotate(-o)}}});c(i).bind("mouseout",this,function(m){var l=m.data;clearTimeout(l.showFrontTextTimer);l.showFrontTextTimer=setTimeout(function(){l.showFrontText()},1000);l.autoRotate()});c(i).bind("mousedown",this,function(l){l.data.container.focus();return false});i.onselectstart=function(){return false};this.innerWrapper=c(i).wrapInner('<div style="position:absolute;width:100%;height:100%;"/>').children()[0];this.showFrontText=function(){if(g[this.frontIndex]===undefined){return}c(h.titleBox).html(c(g[this.frontIndex].image).attr("title"));c(h.altBox).html(c(g[this.frontIndex].image).attr("alt"))};this.go=function(){if(this.controlTimer!==0){return}var l=this;this.controlTimer=setTimeout(function(){l.updateAll()},this.timeDelay)};this.stop=function(){clearTimeout(this.controlTimer);this.controlTimer=0};this.rotate=function(l){this.frontIndex-=l;this.frontIndex%=g.length;this.destRotation+=(Math.PI/g.length)*(2*l);this.showFrontText();this.go()};this.autoRotate=function(){if(h.autoRotate!=="no"){var l=(h.autoRotate==="right")?1:-1;this.autoRotateTimer=setInterval(function(){e.rotate(l)},h.autoRotateDelay)}};this.updateAll=function(){var u=h.minScale;var r=(1-u)*0.5;var q,D,p,o,G,E,F;var l=(this.destRotation-this.rotation);var s=Math.abs(l);this.rotation+=l*h.speed;if(s<0.001){this.rotation=this.destRotation}var B=g.length;var n=(Math.PI/B)*2;var H=this.rotation;var I=c.browser.msie;this.innerWrapper.style.display="none";var C;var t="px",z;var m=this;for(var A=0;A<B;A++){E=g[A];F=f(H);G=((F+1)*r)+u;p=this.xCentre+(((j(H)*this.xRadius)-(E.orgWidth*0.5))*G);o=this.yCentre+(((F*this.yRadius))*G);var v=Math.abs(((H*180/Math.PI)+90)%360);if(v>=90&&v<=270){E.image.style.opacity=0.7+0.3*f(H)}else{E.image.style.opacity=0.7}if(E.imageOK){var J=E.image;q=J.width=E.orgWidth*G;D=J.height=E.orgHeight*G;J.style.left=p+t;J.style.top=o+t;J.style.zIndex=""+(G*100)>>0;if(E.related!==null){E.related.style.width=E.related_width*G+t;E.related.style.left=(p+E.related_pos.x*G)+t;E.related.style.top=(o+E.related_pos.y*G)+t;E.related.style.opacity=E.image.style.opacity}if(E.reflection!==null){z=h.reflHeight*G;C=E.reflection.element.style;C.left=p+t;C.top=(o+D+h.reflGap*G-2)+t;C.width=q+t;if(I){C.filter.finishy=(z/D*100)}else{C.height=z+t}}}H+=n}this.innerWrapper.style.display="block";if(s>=0.001){this.controlTimer=setTimeout(function(){m.updateAll()},this.timeDelay)}else{this.stop()}};this.checkImagesLoaded=function(){var l;for(l=0;l<k.length;l++){if((k[l].width===undefined)||((k[l].complete!==undefined)&&(!k[l].complete))){return}}for(l=0;l<k.length;l++){g.push(new a(k[l],h));c(k[l]).data("itemIndex",l)}clearInterval(this.tt);this.showFrontText();this.autoRotate();this.updateAll();if(h.onload){h.onload()}};this.tt=setInterval(function(){e.checkImagesLoaded()},50)};c.fn.CloudCarousel=function(e){this.each(function(){e=c.extend({},{reflHeight:0,reflOpacity:0.5,reflGap:0,minScale:0.5,xPos:0,yPos:0,xRadius:0,yRadius:0,altBox:null,titleBox:null,FPS:30,autoRotate:"no",autoRotateDelay:3000,speed:0.2,mouseWheel:false,bringToFront:false},e);c(this).data("cloudcarousel",new d(this,c(".cloudcarousel",c(this)),e))});return this}})(jQuery);
