(function(c){function ea(w,q){function l(){r=j.length;x=s*2/r;for(var b=0;b<r;b++)fa(b);n(g);c.browser.msie||J(0);c(document).bind("mousemove",function(d){k=d.pageX;o=d.pageY});w.onselectstart=function(){return false};a.settings.autoScroll&&K();a.settings.mouseScroll&&L();a.settings.mouseDrag&&U();a.settings.mouseWheel&&V();a.settings.scrollbar&&ga();a.settings.tooltip&&c('<div class="tooltip"><p></p></div>').css("opacity",0).appendTo(i)}function fa(b){var d=c('<img class="carousel-item"/>').appendTo(i);
W.push(d);d.css({width:a.settings.itemWidth,h:a.settings.itemHeight}).data({w:a.settings.itemWidth,h:a.settings.itemHeight,index:b}).addClass("out").bind({mouseover:function(){c(this).hasClass("out")&&c(this).removeClass("out").addClass("over");a.settings.tooltip&&ha(b);var e={type:"itemMouseOver",index:b,data:j[b]};c.isFunction(a.settings.itemMouseOver)&&a.settings.itemMouseOver.call(this,e)},mouseout:function(){c(this).hasClass("over")&&c(this).removeClass("over").addClass("out");a.settings.tooltip&&
ia();var e={type:"itemMouseOut",index:b,data:j[b]};c.isFunction(a.settings.itemMouseOut)&&a.settings.itemMouseOut.call(this,e)},click:function(){i.find(".click").removeClass("click").addClass("out");c(this).removeClass("over").addClass("click");a.settings.scrollOnClick&&y(b);j[b].link&&window.open(j[b].link);var e={type:"itemClick",index:b,data:j[b]};c.isFunction(a.settings.itemClick)&&a.settings.itemClick.call(this,e)}});j[b].link&&d.css("cursor","pointer");c.browser.msie&&J(b)}function J(b){var d=
j[b].path,e=W[b];c("<img/>").load(function(){var h=parseInt(c(this).attr("width")),f=parseInt(c(this).attr("height"));if(a.settings.crop)e.css("background-image","url("+d+")");else{e.attr("src",d);e.css("background-image","none")}if(a.settings.resize)if(a.settings.maintainAspectRatio){scaleX=a.settings.itemWidth/h;scaleY=a.settings.itemHeight/f;if(scaleX<scaleY){h*=scaleX;f*=scaleX}else{h*=scaleY;f*=scaleY}}else{h=a.settings.itemWidth;f=a.settings.itemHeigh}e.css({width:h,height:f});e.data({w:h,h:f});
n(g);c.browser.msie||b<r-1&&J(++b)}).attr("src",d)}function n(b){i.find(".carousel-item").each(function(d){var e=c(this),h=e.data("w"),f=e.data("h"),z=Math.sin(-(x*d)+s*0.5+b*X)*a.settings.verticalRadius+M-f*0.5,p=(z-(Y-f*0.5))/(Z-Y)*(1-a.settings.scaleRatio)+a.settings.scaleRatio;e.css({width:h*p,height:f*p,left:Math.cos(-(x*d)+s*0.5+b*X)*a.settings.horizontalRadius+N-h*0.5+h*(1-p)/2,top:z+f*(1-p)/2,"z-index":Math.floor(p*10*r)})});a.settings.scrollbar&&!t&&ja(O())}function y(b){u=b;var d=x*(180/
s)*b%360;g%=360;if(Math.abs(d-g)>180)d+=d>g?-360:360;if(d-g>180&&d>g)d-=360;A();P=setInterval(function(){if(Math.abs(d-g)>0.5){g+=(d-g)*(a.settings.scrollSpeed/100);n(g)}else B()},30);b={type:"itemSelect",index:b,data:j[b]};c.isFunction(a.settings.itemSelect)&&a.settings.itemSelect.call(this,b)}function $(){y(u==j.length-1?0:u+1)}function aa(){y(u==0?j.length-1:u-1)}function K(){a.settings.autoScroll=true;C=setTimeout(function(){if(a.settings.autoScrollDirection=="next")$();else a.settings.autoScrollDirection==
"previous"&&aa()},a.settings.autoScrollDelay)}function L(){a.settings.mouseScroll=true;var b=0,d=a.settings.mouseScrollReverse?-1:1;D=setInterval(function(){if(k>i.offset().left&&k<i.offset().left+a.settings.width&&o>i.offset().top&&o<i.offset().top+a.settings.height){b=d*(k-(i.offset().left+N))*(a.settings.mouseScrollSpeed/1E3);g+=b;n(g)}else if(Math.abs(b)>0.1){b*=a.settings.mouseScrollEase/100;g+=b;n(g)}else b=0},30)}function U(){function b(f){Q=f.pageX;if(!E){A();d()}}function d(){E=true;F=setInterval(function(){var f=
(360*(h*(Q-ba)/(100*a.settings.mouseDragSpeed))+e-g)*(a.settings.mouseDragEase/100);if((f>=0?f:-f)>0.1){g+=f;n(g)}else B()},30)}a.settings.mouseDrag=true;var e=0,h=a.settings.mouseDragReverse?1:-1;c(document).bind("mousedown",function(f){if(k>i.offset().left&&k<i.offset().left+a.settings.width&&o>i.offset().top&&o<i.offset().top+a.settings.height){Q=ba=f.pageX;e=g;c(document).bind("mousemove",b)}});c(document).bind("mouseup",function(){c(document).unbind("mousemove",b)})}function V(){a.settings.mouseWheel=
true;var b=0,d=a.settings.mouseWheelReverse?-1:1;i.bind("mousewheel",function(e,h){e.preventDefault();if(!G){A();G=true;b=g;H=setInterval(function(){if(Math.abs(b-g)>0.5){g+=(b-g)*(a.settings.mouseWheelSpeed/100);n(g)}else B()},30)}b+=d*h*10})}function ga(){function b(){m=k-h.offset().left-ca;d()}function d(){if(m<0)m=0;else if(m>parseInt(h.css("width"))-parseInt(f.css("width")))m=parseInt(h.css("width"))-parseInt(f.css("width"));t&&f.css("left",m);R=m/(parseInt(h.css("width"))-parseInt(f.css("width")));
if(!I){A();I=true;g%=360;S=setInterval(function(){if(Math.abs(O()-R)>0.0010){var T=(R-O())*(a.settings.scrollbarEase/100);g+=T*360;n(g)}else I&&B()},30)}}var e=c('<div class="scrollbar"></div>').appendTo(i),h=c('<div class="track"></div>').appendTo(e),f=c('<div class="thumb"></div>').appendTo(h),z=c('<div class="left"></div>').appendTo(e),p=c('<div class="right"></div>').appendTo(e),m=0,ca;e.css({top:Z,left:N-parseInt(e.css("width"))/2});f.bind("mousedown",function(T){T.preventDefault();ca=k-f.offset().left;
t=true;c(document).bind("mousemove",b)});c(document).bind("mouseup",function(){if(t){t=false;c(document).unbind("mousemove",b)}});z.bind("click",function(){m=parseInt(f.css("left"))-a.settings.arrowScrollAmount;d()});p.bind("click",function(){m=parseInt(f.css("left"))+a.settings.arrowScrollAmount;d()})}function ja(b){var d=i.find(".scrollbar").find(".track"),e=d.find(".thumb");e.css("left",b*(parseInt(d.css("width"))-parseInt(e.css("width"))))}function O(){var b=g%360/360;if(b<0)b+=1;return b}function A(){da();
if(!v){v=true;c.isFunction(a.settings.scrollStart)&&a.settings.scrollStart.call(this)}}function B(){da();if(v){v=false;c.isFunction(a.settings.scrollComplete)&&a.settings.scrollComplete.call(this)}a.settings.mouseScroll&&L();a.settings.autoScroll&&K()}function da(){D&&clearInterval(D);if(F){E=false;clearInterval(F)}if(H){G=false;clearInterval(H)}if(S){I=false;clearInterval(S)}P&&clearInterval(P);C&&clearTimeout(C)}function ha(b){if(b=j[b].tooltip){var d=i.find(".tooltip");d.find("p").html(b);d.stop().animate({opacity:1},
300);var e=-d.outerWidth()/2,h=0-d.outerHeight()-parseInt(d.css("marginBottom"));d.css({left:k-i.offset().left+e,top:o-i.offset().top+h});c(document).bind("mousemove.tooltip",function(){d.css({left:k-i.offset().left+e,top:o-i.offset().top+h})})}}function ia(){var b=i.find(".tooltip");b&&b.stop().animate({opacity:0},200,function(){c(document).unbind("mousemove.tooltip");b.css("left",-9999)})}this.settings=c.extend({},c.fn.carousel.defaults,q);var i=c(w),a=this,u=0,j=[],W=[],s=Math.PI,X=s/180,P,C,D,
F,H,S,k,o,Q=0,ba=0,E=false,G=false,t=false,I=false,R=0,g=0,N=a.settings.width/2,M=a.settings.height/2,Y=M-a.settings.verticalRadius,Z=M+a.settings.verticalRadius,x,r,v=false;(function(){i.addClass("carousel").css({width:a.settings.width,height:a.settings.height});if(a.settings.xmlSource){i.empty();c.ajax({type:"GET",url:a.settings.xmlSource,dataType:c.browser.msie?"text":"xml",success:function(b){var d;if(c.browser.msie){d=new ActiveXObject("Microsoft.XMLDOM");d.async=false;d.loadXML(b)}else d=b;
c(d).find("item").each(function(){for(var e={},h=0;h<c(this).children().length;h++){var f=c(this).children()[h];e[f.nodeName]=c(this).find(f.nodeName).text()}j.push(e)});l()}})}else{i.children().each(function(){for(var b={},d=0;d<c(this).children().length;d++){var e=c(this).children()[d];if(c(e).is("a")){b.path=c(e).find("img").attr("src");b.link=c(e).attr("href")}else if(c(e).is("img"))b.path=c(e).attr("src");else b[c(e).attr("class")]=c(e).html()}j.push(b)});i.empty();l()}})();this.startAutoScroll=
K;this.stopAutoScroll=function(){a.settings.autoScroll=false;clearTimeout(C)};this.startMouseScroll=L;this.stopMouseScroll=function(){a.settings.mouseScroll=false;clearInterval(D)};this.startMouseDrag=U;this.stopMouseDrag=function(){E=a.settings.mouseDrag=false;clearInterval(F)};this.startMouseWheel=V;this.stopMouseWheel=function(){G=a.settings.mouseWheel=false;clearInterval(H)};this.scrollToItem=y;this.scrollToNext=$;this.scrollToPrevious=aa;this.isScrolling=function(){return v}}c.fn.carousel=function(w){for(var q=
[],l=0;l<this.length;l++)if(!this[l].carousel){this[l].carousel=new ea(this[l],w);q.push(this[l].carousel)}return q.length>1?q:q[0]};c.fn.carousel.defaults={xmlSource:null,width:500,height:300,itemWidth:100,itemHeight:100,horizontalRadius:250,verticalRadius:100,resize:true,maintainAspectRatio:true,crop:false,scaleRatio:0.5,mouseScroll:false,scrollOnClick:true,mouseDrag:false,scrollbar:false,arrowScrollAmount:50,tooltip:true,mouseScrollEase:90,mouseDragEase:10,scrollbarEase:10,scrollSpeed:10,mouseDragSpeed:20,
mouseScrollSpeed:10,mouseWheel:false,mouseWheelSpeed:10,mouseScrollReverse:false,mouseDragReverse:false,mouseWheelReverse:false,autoScroll:false,autoScrollDirection:"next",autoScrollDelay:3E3,itemSelect:null,itemClick:null,itemMouseOver:null,itemMouseOut:null,scrollStart:null,scrollComplete:null}})(jQuery);

