/** * jquery bxslider v3.0 * http://bxslider.com * * copyright 2010, steven wanderski * http://stevenwanderski.com * * free to use and abuse under the mit license. * http://www.opensource.org/licenses/mit-license.php * */ (function($){$.fn.bxslider=function(options){var defaults={mode:'horizontal',infiniteloop:true,hidecontrolonend:false,controls:true,speed:500,easing:'swing',pager:false,pagerselector:null,pagertype:'full',pagerlocation:'bottom',pagershortseparator:'/',pageractiveclass:'pager-active',nexttext:'next',nextimage:'',nextselector:null,prevtext:'prev',previmage:'',prevselector:null,captions:false,captionsselector:null,auto:false,autodirection:'next',autocontrols:false,autocontrolsselector:null,autostart:true,autohover:false,autodelay:0,pause:3000,starttext:'start',startimage:'',stoptext:'stop',stopimage:'',ticker:false,tickerspeed:5000,tickerdirection:'next',tickerhover:false,wrapperclass:'bx-wrapper',startingslide:0,displayslideqty:1,moveslideqty:1,randomstart:false,onbeforeslide:function(){},onafterslide:function(){},onlastslide:function(){},onfirstslide:function(){},onnextslide:function(){},onprevslide:function(){},buildpager:null} var options=$.extend(defaults,options);var base=this;var $parent='';var $origelement='';var $children='';var $outerwrapper='';var $firstchild='';var childrenwidth='';var childrenouterwidth='';var wrapperwidth='';var wrapperheight='';var $pager='';var interval='';var $autocontrols='';var $stophtml='';var $startcontent='';var $stopcontent='';var autoplaying=true;var loaded=false;var childrenmaxwidth=0;var childrenmaxheight=0;var currentslide=0;var origleft=0;var origtop=0;var origshowwidth=0;var origshowheight=0;var tickerleft=0;var tickertop=0;var isworking=false;var firstslide=0;var lastslide=$children.length-1;this.gotoslide=function(number,stopauto){if(!isworking){isworking=true;currentslide=number;options.onbeforeslide(currentslide,$children.length,$children.eq(currentslide));if(typeof(stopauto)=='undefined'){var stopauto=true;} if(stopauto){if(options.auto){base.stopshow(true);}} slide=number;if(slide==firstslide){options.onfirstslide(currentslide,$children.length,$children.eq(currentslide));} if(slide==lastslide){options.onlastslide(currentslide,$children.length,$children.eq(currentslide));} if(options.mode=='horizontal'){$parent.animate({'left':'-'+getslideposition(slide,'left')+'px'},options.speed,options.easing,function(){isworking=false;options.onafterslide(currentslide,$children.length,$children.eq(currentslide));});}else if(options.mode=='vertical'){$parent.animate({'top':'-'+getslideposition(slide,'top')+'px'},options.speed,options.easing,function(){isworking=false;options.onafterslide(currentslide,$children.length,$children.eq(currentslide));});}else if(options.mode=='fade'){setchildrenfade();} checkendcontrols();if(options.moveslideqty>1){number=math.floor(number/options.moveslideqty);} makeslideactive(number);showcaptions();}} this.gotonextslide=function(stopauto){if(typeof(stopauto)=='undefined'){var stopauto=true;} if(stopauto){if(options.auto){base.stopshow(true);}} if(!options.infiniteloop){if(!isworking){var slideloop=false;currentslide=(currentslide+(options.moveslideqty));if(currentslide<=lastslide){checkendcontrols();options.onnextslide(currentslide,$children.length,$children.eq(currentslide));base.gotoslide(currentslide);}else{currentslide-=options.moveslideqty;}}}else{if(!isworking){isworking=true;var slideloop=false;currentslide=(currentslide+options.moveslideqty);if(currentslide>lastslide){currentslide=currentslide%$children.length;slideloop=true;} options.onnextslide(currentslide,$children.length,$children.eq(currentslide));options.onbeforeslide(currentslide,$children.length,$children.eq(currentslide));if(options.mode=='horizontal'){var parentleft=(options.moveslideqty*childrenouterwidth);$parent.animate({'left':'-='+parentleft+'px'},options.speed,options.easing,function(){isworking=false;if(slideloop){$parent.css('left','-'+getslideposition(currentslide,'left')+'px');} options.onafterslide(currentslide,$children.length,$children.eq(currentslide));});}else if(options.mode=='vertical'){var parenttop=(options.moveslideqty*childrenmaxheight);$parent.animate({'top':'-='+parenttop+'px'},options.speed,options.easing,function(){isworking=false;if(slideloop){$parent.css('top','-'+getslideposition(currentslide,'top')+'px');} options.onafterslide(currentslide,$children.length,$children.eq(currentslide));});}else if(options.mode=='fade'){setchildrenfade();} if(options.moveslideqty>1){makeslideactive(math.ceil(currentslide/options.moveslideqty));}else{makeslideactive(currentslide);} showcaptions();}}} this.gotopreviousslide=function(stopauto){if(typeof(stopauto)=='undefined'){var stopauto=true;} if(stopauto){if(options.auto){base.stopshow(true);}} if(!options.infiniteloop){if(!isworking){var slideloop=false;currentslide=currentslide-options.moveslideqty;if(currentslide<0){currentslide=0;if(options.hidecontrolonend){$('.bx-prev',$outerwrapper).hide();}} checkendcontrols();options.onprevslide(currentslide,$children.length,$children.eq(currentslide));base.gotoslide(currentslide);}}else{if(!isworking){isworking=true;var slideloop=false;currentslide=(currentslide-(options.moveslideqty));if(currentslide<0){negativeoffset=(currentslide%$children.length);if(negativeoffset==0){currentslide=0;}else{currentslide=($children.length)+negativeoffset;} slideloop=true;} options.onprevslide(currentslide,$children.length,$children.eq(currentslide));options.onbeforeslide(currentslide,$children.length,$children.eq(currentslide));if(options.mode=='horizontal'){var parentleft=(options.moveslideqty*childrenouterwidth);$parent.animate({'left':'+='+parentleft+'px'},options.speed,options.easing,function(){isworking=false;if(slideloop){$parent.css('left','-'+getslideposition(currentslide,'left')+'px');} options.onafterslide(currentslide,$children.length,$children.eq(currentslide));});}else if(options.mode=='vertical'){var parenttop=(options.moveslideqty*childrenmaxheight);$parent.animate({'top':'+='+parenttop+'px'},options.speed,options.easing,function(){isworking=false;if(slideloop){$parent.css('top','-'+getslideposition(currentslide,'top')+'px');} options.onafterslide(currentslide,$children.length,$children.eq(currentslide));});}else if(options.mode=='fade'){setchildrenfade();} if(options.moveslideqty>1){makeslideactive(math.ceil(currentslide/options.moveslideqty));}else{makeslideactive(currentslide);} showcaptions();}}} this.gotofirstslide=function(stopauto){if(typeof(stopauto)=='undefined'){var stopauto=true;} base.gotoslide(firstslide,stopauto);} this.gotolastslide=function(){if(typeof(stopauto)=='undefined'){var stopauto=true;} base.gotoslide(lastslide,stopauto);} this.getcurrentslide=function(){return currentslide;} this.getslidecount=function(){return $children.length;} this.stopshow=function(changetext){clearinterval(interval);if(typeof(changetext)=='undefined'){var changetext=true;} if(changetext&&options.autocontrols){$autocontrols.html($startcontent).removeclass('stop').addclass('start');autoplaying=false;}} this.startshow=function(changetext){if(typeof(changetext)=='undefined'){var changetext=true;} setautointerval();if(changetext&&options.autocontrols){$autocontrols.html($stopcontent).removeclass('start').addclass('stop');autoplaying=true;}} this.stopticker=function(changetext){$parent.stop();if(typeof(changetext)=='undefined'){var changetext=true;} if(changetext&&options.ticker){$autocontrols.html($startcontent).removeclass('stop').addclass('start');autoplaying=false;}} this.startticker=function(changetext){if(options.mode=='horizontal'){if(options.tickerdirection=='next'){var stoppedleft=parseint($parent.css('left'));var remainingdistance=(origshowwidth+stoppedleft)+$children.eq(0).width();}else if(options.tickerdirection=='prev'){var stoppedleft=-parseint($parent.css('left'));var remainingdistance=(stoppedleft)-$children.eq(0).width();} var finishingspeed=(remainingdistance*options.tickerspeed)/origshowwidth;movetheshow(tickerleft,remainingdistance,finishingspeed);}else if(options.mode=='vertical'){if(options.tickerdirection=='next'){var stoppedtop=parseint($parent.css('top'));var remainingdistance=(origshowheight+stoppedtop)+$children.eq(0).height();}else if(options.tickerdirection=='prev'){var stoppedtop=-parseint($parent.css('top'));var remainingdistance=(stoppedtop)-$children.eq(0).height();} var finishingspeed=(remainingdistance*options.tickerspeed)/origshowheight;movetheshow(tickertop,remainingdistance,finishingspeed);if(typeof(changetext)=='undefined'){var changetext=true;} if(changetext&&options.ticker){$autocontrols.html($stopcontent).removeclass('start').addclass('stop');autoplaying=true;}}} this.initshow=function(){$parent=$(this);$origelement=$parent.clone();$children=$parent.children();$outerwrapper='';$firstchild=$parent.children(':first');childrenwidth=$firstchild.width();childrenmaxwidth=0;childrenouterwidth=$firstchild.outerwidth();childrenmaxheight=0;wrapperwidth=getwrapperwidth();wrapperheight=getwrapperheight();isworking=false;$pager='';currentslide=0;origleft=0;origtop=0;interval='';$autocontrols='';$stophtml='';$startcontent='';$stopcontent='';autoplaying=true;loaded=false;origshowwidth=0;origshowheight=0;tickerleft=0;tickertop=0;firstslide=0;lastslide=$children.length-1;$children.each(function(index){if($(this).outerheight()>childrenmaxheight){childrenmaxheight=$(this).outerheight();} if($(this).outerwidth()>childrenmaxwidth){childrenmaxwidth=$(this).outerwidth();}});if(options.randomstart){var randomnumber=math.floor(math.random()*$children.length);currentslide=randomnumber;origleft=childrenouterwidth*(options.moveslideqty+randomnumber);origtop=childrenmaxheight*(options.moveslideqty+randomnumber);}else{currentslide=options.startingslide;origleft=childrenouterwidth*(options.moveslideqty+options.startingslide);origtop=childrenmaxheight*(options.moveslideqty+options.startingslide);} initcss();if(options.pager&&!options.ticker){if(options.pagertype=='full'){showpager('full');}else if(options.pagertype=='short'){showpager('short');}} if(options.controls&&!options.ticker){setcontrolsvars();} if(options.auto||options.ticker){if(options.autocontrols){setautocontrolsvars();} if(options.autostart){settimeout(function(){base.startshow(true);},options.autodelay);}else{base.stopshow(true);} if(options.autohover&&!options.ticker){setautohover();}} if(options.moveslideqty>1){makeslideactive(math.ceil(currentslide/options.moveslideqty));}else{makeslideactive(currentslide);} checkendcontrols();if(options.captions){showcaptions();} options.onafterslide(currentslide,$children.length,$children.eq(currentslide));} this.destroyshow=function(){clearinterval(interval);$('.bx-next, .bx-prev, .bx-pager, .bx-auto',$outerwrapper).remove();$parent.unwrap().unwrap().removeattr('style');$parent.children().removeattr('style').not('.pager').remove();$children.removeclass('pager');} this.reloadshow=function(){base.destroyshow();base.initshow();} function initcss(){setchildrenlayout(options.startingslide);if(options.mode=='horizontal'){$parent.wrap('
').wrap('
').css({width:'99999px',position:'relative',left:'-'+(origleft)+'px'});$parent.children().css({width:childrenwidth,'float':'left',liststyle:'none'});$outerwrapper=$parent.parent().parent();$children.addclass('pager');}else if(options.mode=='vertical'){$parent.wrap('
').wrap('
').css({height:'99999px',position:'relative',top:'-'+(origtop)+'px'});$parent.children().css({liststyle:'none',height:childrenmaxheight});$outerwrapper=$parent.parent().parent();$children.addclass('pager');}else if(options.mode=='fade'){$parent.wrap('
').wrap('
');$parent.children().css({liststyle:'none',position:'absolute',top:0,left:0,zindex:98});$outerwrapper=$parent.parent().parent();$children.not(':eq('+currentslide+')').fadeto(0,0);$children.eq(currentslide).css('zindex',99);} if(options.captions&&options.captionsselector==null){$outerwrapper.append('
');}} function setchildrenlayout(){if(options.mode=='horizontal'||options.mode=='vertical'){var $prependedchildren=getarraysample($children,0,options.moveslideqty,'backward');$.each($prependedchildren,function(index){$parent.prepend($(this));});var totalnumberafterwindow=($children.length+options.moveslideqty)-1;var pagerexcess=$children.length-options.displayslideqty;var numbertoappend=totalnumberafterwindow-pagerexcess;var $appendedchildren=getarraysample($children,0,numbertoappend,'forward');if(options.infiniteloop){$.each($appendedchildren,function(index){$parent.append($(this));});}}} function setcontrolsvars(){if(options.nextimage!=''){nextcontent=options.nextimage;nexttype='image';}else{nextcontent=options.nexttext;nexttype='text';} if(options.previmage!=''){prevcontent=options.previmage;prevtype='image';}else{prevcontent=options.prevtext;prevtype='text';} showcontrols(nexttype,nextcontent,prevtype,prevcontent);} function setautointerval(){if(options.auto){if(!options.infiniteloop){if(options.autodirection=='next'){interval=setinterval(function(){currentslide+=options.moveslideqty;if(currentslide>lastslide){currentslide=currentslide%$children.length;} base.gotoslide(currentslide,false);},options.pause);}else if(options.autodirection=='prev'){interval=setinterval(function(){currentslide-=options.moveslideqty;if(currentslide<0){negativeoffset=(currentslide%$children.length);if(negativeoffset==0){currentslide=0;}else{currentslide=($children.length)+negativeoffset;}} base.gotoslide(currentslide,false);},options.pause);}}else{if(options.autodirection=='next'){interval=setinterval(function(){base.gotonextslide(false);},options.pause);}else if(options.autodirection=='prev'){interval=setinterval(function(){base.gotopreviousslide(false);},options.pause);}}}else if(options.ticker){options.tickerspeed*=10;$('.pager',$outerwrapper).each(function(index){origshowwidth+=$(this).width();origshowheight+=$(this).height();});if(options.tickerdirection=='prev'&&options.mode=='horizontal'){$parent.css('left','-'+(origshowwidth+origleft)+'px');}else if(options.tickerdirection=='prev'&&options.mode=='vertical'){$parent.css('top','-'+(origshowheight+origtop)+'px');} if(options.mode=='horizontal'){tickerleft=parseint($parent.css('left'));movetheshow(tickerleft,origshowwidth,options.tickerspeed);}else if(options.mode=='vertical'){tickertop=parseint($parent.css('top'));movetheshow(tickertop,origshowheight,options.tickerspeed);} if(options.tickerhover){settickerhover();}}} function movetheshow(leftcss,distance,speed){if(options.mode=='horizontal'){if(options.tickerdirection=='next'){$parent.animate({'left':'-='+distance+'px'},speed,'linear',function(){$parent.css('left',leftcss);movetheshow(leftcss,origshowwidth,options.tickerspeed);});}else if(options.tickerdirection=='prev'){$parent.animate({'left':'+='+distance+'px'},speed,'linear',function(){$parent.css('left',leftcss);movetheshow(leftcss,origshowwidth,options.tickerspeed);});}}else if(options.mode=='vertical'){if(options.tickerdirection=='next'){$parent.animate({'top':'-='+distance+'px'},speed,'linear',function(){$parent.css('top',leftcss);movetheshow(leftcss,origshowheight,options.tickerspeed);});}else if(options.tickerdirection=='prev'){$parent.animate({'top':'+='+distance+'px'},speed,'linear',function(){$parent.css('top',leftcss);movetheshow(leftcss,origshowheight,options.tickerspeed);});}}} function setautocontrolsvars(){if(options.startimage!=''){startcontent=options.startimage;starttype='image';}else{startcontent=options.starttext;starttype='text';} if(options.stopimage!=''){stopcontent=options.stopimage;stoptype='image';}else{stopcontent=options.stoptext;stoptype='text';} showautocontrols(starttype,startcontent,stoptype,stopcontent);} function setautohover(){$outerwrapper.find('.bx-window').hover(function(){if(autoplaying){base.stopshow(false);}},function(){if(autoplaying){base.startshow(false);}});} function settickerhover(){$parent.hover(function(){if(autoplaying){base.stopticker(false);}},function(){if(autoplaying){base.startticker(false);}});} function setchildrenfade(){$children.not(':eq('+currentslide+')').fadeto(options.speed,0).css('zindex',98);$children.eq(currentslide).css('zindex',99).fadeto(options.speed,1,function(){isworking=false;options.onafterslide(currentslide,$children.length,$children.eq(currentslide));});};function makeslideactive(number){if(options.pagertype=='full'&&options.pager){$('a',$pager).removeclass(options.pageractiveclass);$('a',$pager).eq(number).addclass(options.pageractiveclass);}else if(options.pagertype=='short'&&options.pager){$('.bx-pager-current',$pager).html(currentslide+1);}} function showcontrols(nexttype,nextcontent,prevtype,prevcontent){var $nexthtml=$('');var $prevhtml=$('');if(nexttype=='text'){$nexthtml.html(nextcontent);}else{$nexthtml.html('');} if(prevtype=='text'){$prevhtml.html(prevcontent);}else{$prevhtml.html('');} if(options.prevselector){$(options.prevselector).append($prevhtml);}else{$outerwrapper.append($prevhtml);} if(options.nextselector){$(options.nextselector).append($nexthtml);}else{$outerwrapper.append($nexthtml);} $nexthtml.click(function(){base.gotonextslide();return false;});$prevhtml.click(function(){base.gotopreviousslide();return false;});} function showpager(type){var pagerqty=$children.length;if(options.moveslideqty>1){if($children.length%options.moveslideqty!=0){pagerqty=math.ceil($children.length/options.moveslideqty);}else{pagerqty=$children.length/options.moveslideqty;}} var pagerstring='';if(options.buildpager){for(var i=0;i'+i+'';}}else if(type=='short'){pagerstring=''+(options.startingslide+1)+' '+options.pagershortseparator+' '+$children.length+'';} if(options.pagerselector){$(options.pagerselector).append(pagerstring);$pager=$(options.pagerselector);}else{var $pagercontainer=$('
');$pagercontainer.append(pagerstring);if(options.pagerlocation=='top'){$outerwrapper.prepend($pagercontainer);}else if(options.pagerlocation=='bottom'){$outerwrapper.append($pagercontainer);} $pager=$('.bx-pager',$outerwrapper);} $pager.children().click(function(){if(options.pagertype=='full'){var slideindex=$pager.children().index(this);if(options.moveslideqty>1){slideindex*=options.moveslideqty;} base.gotoslide(slideindex);} return false;});} function showcaptions(){var caption=$('img',$children.eq(currentslide)).attr('title');if(caption!=''){if(options.captionsselector){$(options.captionsselector).html(caption);}else{$('.bx-captions',$outerwrapper).html(caption);}}else{if(options.captionsselector){$(options.captionsselector).html(' ');}else{$('.bx-captions',$outerwrapper).html(' ');}}} function showautocontrols(starttype,startcontent,stoptype,stopcontent){$autocontrols=$('');if(starttype=='text'){$startcontent=startcontent;}else{$startcontent='';} if(stoptype=='text'){$stopcontent=stopcontent;}else{$stopcontent='';} if(options.autocontrolsselector){$(options.autocontrolsselector).append($autocontrols);}else{$outerwrapper.append('
');$('.bx-auto',$outerwrapper).html($autocontrols);} $autocontrols.click(function(){if(options.ticker){if($(this).hasclass('stop')){base.stopticker();}else if($(this).hasclass('start')){base.startticker();}}else{if($(this).hasclass('stop')){base.stopshow(true);}else if($(this).hasclass('start')){base.startshow(true);}} return false;});} function checkendcontrols(){if(!options.infiniteloop&&options.hidecontrolonend){if(currentslide==firstslide){$('.bx-prev',$outerwrapper).hide();}else{$('.bx-prev',$outerwrapper).show();} if(currentslide==lastslide){$('.bx-next',$outerwrapper).hide();}else{$('.bx-next',$outerwrapper).show();}}} function getslideposition(number,side){if(side=='left'){var position=$('.pager',$outerwrapper).eq(number).position().left;}else if(side=='top'){var position=$('.pager',$outerwrapper).eq(number).position().top;} return position;} function getwrapperwidth(){var wrapperwidth=$firstchild.outerwidth()*options.displayslideqty;return wrapperwidth;} function getwrapperheight(){var wrapperheight=$firstchild.outerheight()*options.displayslideqty;return wrapperheight;} function getarraysample(array,start,length,direction){var sample=[];var looplength=length;var startpopulatingarray=false;if(direction=='backward'){array=$.makearray(array);array.reverse();} while(looplength>0){$.each(array,function(index,val){if(looplength>0){if(!startpopulatingarray){if(index==start){startpopulatingarray=true;sample.push($(this).clone());looplength--;}}else{sample.push($(this).clone());looplength--;}}else{return false;}});} return sample;} this.each(function(){base.initshow();});return this;}})(jquery);