
(function($){$.fn.carousel=function(settings){settings=$.extend({width:0,height:0,interval:2000,autoPlay:false,easing:null,animSpeed:1000,startIndex:0,addNavigation:false,vertical:false,rotate:true,flashStatus:null},settings);return this.each(function(){carouselMethods.init(settings,$(this));});};var carouselMethods=(function(){var initSettings={};var container=null;var carousel=null;var size=0;var width=0;var height=0;var interval=0;var easing=null;var autoPlay=false;var animSpeed=0;var startIndex=0;var addNavigation=false;var vertical=false;var rotate=true;var timer=null;var itemIndex=0;var fullscreen=false;function moveSlide(dir,isEnd){if(vertical){if(typeof dir==='number'){if(animSpeed===0){carousel.css({top:'-'+dir*height+'px'});}
else{carousel.animate({top:'-'+dir*height+'px'},animSpeed,easing);}}
else if(dir==='next'){if(isEnd===false){if(animSpeed===0){carousel.css({top:'-'+height*itemIndex+'px'});}
else{carousel.animate({top:'-='+height+'px'},animSpeed,easing);}}
else{if(animSpeed===0){carousel.css({top:'0'});}
else{carousel.animate({top:'-='+height+'px'},animSpeed,easing,function(){carousel.css({top:'0px'})});}}}
else if(dir==='prev'){if(isEnd===false){if(animSpeed===0){carousel.css({top:'-'+height*itemIndex+'px'});}
else{carousel.animate({top:'+='+height+'px'},animSpeed,easing);}}
else{if(animSpeed===0){carousel.css({top:'-='+((size*height)-height)+'px'});}
else{carousel.css({top:'-'+((size*height)-height)+'px'});carousel.animate({top:'+='+height+'px'},animSpeed,easing);}}}}
else{if(typeof dir==='number'){if(animSpeed===0){carousel.css({left:'-'+dir*width+'px'});}
else{carousel.animate({left:'-'+dir*width+'px'},animSpeed,easing);}}
else if(dir==='next'){if(isEnd===false){if(animSpeed===0){carousel.css({left:'-'+width*itemIndex+'px'});}
else{carousel.animate({left:'-='+width+'px'},animSpeed,easing);}}
else{if(animSpeed===0){carousel.css({left:'0'});}
else{carousel.animate({left:'-='+width+'px'},animSpeed,easing,function(){carousel.css({left:'0px'});});}}}
else if(dir==='prev'){if(isEnd===false){if(animSpeed===0){carousel.css({left:'-'+width*itemIndex+'px'});}
else{carousel.animate({left:'+='+width+'px'},animSpeed,easing);}}
else{if(animSpeed===0){carousel.css({left:'-'+width*(size-1)+'px'});}
else{carousel.css({left:'-'+width*(size-1)+'px'});carousel.animate({left:'+='+width+'px'},animSpeed,easing);}}}}};function isEnd(index){if(itemIndex===index){return true;}
else return false;};function next(){var end=isEnd(size-2);if(end===true&&rotate===false)return;setActiveNav(itemIndex,itemIndex+1);itemIndex++;if(end){moveSlide('next',true);itemIndex=0;setActiveNav(itemIndex,0);}
else{moveSlide('next',false);}};function prev(){var end=isEnd(0);if(end===true&&rotate===false)return;setActiveNav(itemIndex,itemIndex-1);itemIndex--;if(end){moveSlide('prev',true);itemIndex=size-2;setActiveNav(itemIndex,size-2);}
else{moveSlide('prev',false);}};function play(){timer=setInterval(function(){next();},interval);};function paus(){clearInterval(timer);};function getStartSlide(){if(startIndex!==0){setItemIndex(startIndex);return width*startIndex-1;}
else return 0;};function setItemIndex(index){itemIndex=index;};function toggleFullscreen(){if(fullscreen){fullscreen=false;width=initSettings.width;height=initSettings.height;}
else{fullscreen=true;width=$(window).width();height=$(window).height();}
setActiveNav(itemIndex,0);setItemIndex(0);setStyles();};function setStyles(){if(fullscreen){container.css({position:'absolute',left:'0',top:'0',overflow:'hidden',width:width+'px',height:height+'px'});}
else{container.css({position:'relative',overflow:'hidden',width:width+'px',height:height+'px'});}
if(vertical){carousel.css({position:'absolute',top:'0',left:'0',whiteSpace:'nowrap',height:(size*height)+'px',width:width+'px'});carousel.find('li').css({width:width+'px',height:height+'px',overflow:'hidden'});}
else{carousel.css({position:'absolute',top:'0',left:'-'+getStartSlide()+'px',whiteSpace:'nowrap',height:height+'px',width:(size*width)+'px'});carousel.find('li').css({width:width+'px',height:height+'px',float:'left',overflow:'hidden'});}};function gotoSlide(index){index=parseInt(index);moveSlide(index,false);setActiveNav(itemIndex,index);setItemIndex(index);};function setActiveNav(oldIndex,newIndex){container.find('ul.nav a[href='+oldIndex+']').parent('li:eq(0)').removeClass('current');container.find('ul.nav a[href='+newIndex+']').parent('li:eq(0)').addClass('current');};function setNavigation(){var ul=document.createElement('ul');var readableNames=false;if(carousel.find('li:eq(0)[title]').length>0){readableNames=true;}
for(var i=0;i<size-1;i++){var li=document.createElement('li');var a=document.createElement('a');if(readableNames){$(a).attr('href',i).text(carousel.find('li').eq(i).attr('title'));}
else{$(a).attr('href',i).text(i+1);}
li.appendChild(a);ul.appendChild(li);}
$(ul).addClass('nav').appendTo(container).find('a').each(function(){$(this).click(function(e){e.preventDefault();gotoSlide($(this).attr('href'));});if(parseInt($(this).attr('href'))===itemIndex){$(this).parent('li:eq(0)').addClass('current');}});};function init(settings,$this){initSettings=settings;container=$this;carousel=$this.find('ul:eq(0)');$this.find('li:eq(0)').clone().appendTo(carousel);size=$this.find('li').size();width=settings.width;height=settings.height;interval=settings.interval;easing=settings.easing;autoPlay=settings.autoPlay;animSpeed=settings.animSpeed;startIndex=settings.startIndex;addNavigation=settings.addNavigation;vertical=settings.vertical;rotate=settings.rotate;setStyles();setNavigation();if(!addNavigation){container.find('.nav').hide();}
if(autoPlay){play();}};return{init:init,prev:prev,next:next,play:play,paus:paus,toggleFullscreen:toggleFullscreen};})();$.carouselNext=function(opt){opt=$.extend({callback:undefined},opt);carouselMethods.next();if(typeof opt.callback!=='undefined'){opt.callback();}};$.carouselPrev=function(opt){opt=$.extend({callback:undefined},opt);carouselMethods.prev();if(typeof opt.callback!=='undefined'){opt.callback();}};$.carouselPlay=function(opt){opt=$.extend({callback:undefined},opt);carouselMethods.play();if(typeof opt.callback!=='undefined'){opt.callback();}};$.carouselPaus=function(opt){opt=$.extend({callback:undefined},opt);carouselMethods.paus();if(typeof opt.callback!=='undefined'){opt.callback();}};$.carouselFullscreen=function(opt){opt=$.extend({callback:undefined},opt);carouselMethods.toggleFullscreen();if(typeof opt.callback!=='undefined'){opt.callback();}};})(jQuery);