(function($){$.fn.slidepanel=function(options){var defaults={pause:5,start:0,autoPlay:true,loop:true,height:null,playBtn:null,pauseBtn:null,nextBtn:null,prevBtn:null,slideButtons:null,slideButtonsClass:"button",slideButtonsSelectedClass:"selected",endOfLoopClass:"endOfLoop",grouped:true,trans:'fade',transSpeed:500};var options=$.extend(defaults,options);return this.each(function(){var parent=this;var obj=$(this).children('li');var current=options.start;var prev=null;var playStatus=true;$(this).append("<div class='ejb_timer'></div>");var timer=$(this).children('.ejb_timer');if(options.trans.toLowerCase()=='fade'){$(obj).css({'display':'none','position':'absolute'});}if(options.trans.toLowerCase()=='slide'){$(obj).css({'float':'left'});var element=document.createElement("div");$(this).css({'overflow':'hidden'});$(element).css('width',500000);$(obj).wrapAll($(element));var panelWidth=$(this).width();var widthIndex=0;var distanceTillNextSlide=0;$(obj).each(function(){$(this).data('position',{left:widthIndex});var oldWidth=widthIndex;widthIndex=parseInt($(this).outerWidth(true))+widthIndex;if(options.grouped){if(widthIndex>distanceTillNextSlide){$(this).addClass('slidePanelMarker');distanceTillNextSlide=oldWidth+panelWidth;}}});if(options.grouped){$(obj[0]).addClass('slidePanelMarker');obj=$(parent).find('.slidePanelMarker');}}if(options.playBtn){$(options.playBtn).click(function(){slidePlay(true);});}if(options.pauseBtn){$(options.pauseBtn).click(function(){slidePlay(false);});}if(options.nextBtn){$(options.nextBtn).click(function(){slideNext();});}if(options.prevBtn){$(options.prevBtn).click(function(){slidePrev();});}if(options.slideButtons){for(i=0;i!=obj.length;i++){var element=document.createElement("div");$(element).addClass(options.slideButtonsClass);$(element).data('slideIndex',i);$(options.slideButtons).append($(element));}var slideButtons=$('.'+options.slideButtonsClass);$(slideButtons).click(function(){if($(this).attr('name')!=current){current=$(this).data('slideIndex');$(timer).stop(true);loadSlide(current);}});}function loopStatus(cur){if(cur<=0){$(options.prevBtn).addClass(options.endOfLoopClass);}else{$(options.prevBtn).removeClass(options.endOfLoopClass);}if(cur>=obj.length-1){$(options.nextBtn).addClass(options.endOfLoopClass);}else{$(options.nextBtn).removeClass(options.endOfLoopClass);}}function animateOut(who){switch(options.trans.toLowerCase()){case'fade':$(who).fadeOut(options.transSpeed);break;case'slide':break;}}function animateIn(who){switch(options.trans.toLowerCase()){case'fade':$(who).fadeIn(options.transSpeed);break;case'slide':$(who).parent().animate({marginLeft:-$(who).data('position').left},options.transSpeed);break;}}function slidePlay(status){if(status){$(timer).stop();options.autoPlay=true;$(timer).fadeTo(options.transSpeed,100,function(){current++;if(current>=obj.length){current=(options.loop)?0:obj.length-1;loadSlide(current);}else{loadSlide(current);}});}else{options.autoPlay=false;$(timer).stop();}}function slidePrev(){current--;$(timer).stop(true);if(current<0){current=(options.loop)?obj.length-1:0;if(options.loop)loadSlide(current);}else{loadSlide(current);}}function slideNext(){current++;$(timer).stop(true);if(current>obj.length-1){current=(options.loop)?0:obj.length-1;if(options.loop)loadSlide(current);}else{loadSlide(current);}}function loadSlide(which){animateOut(obj);animateIn(obj[which]);if(!options.loop)loopStatus(which);if(options.slideButtons){$(slideButtons).removeClass(options.slideButtonsSelectedClass);$(slideButtons[which]).addClass(options.slideButtonsSelectedClass);}if(options.autoPlay){$(timer).fadeTo(options.pause*1000,100,function(){current++;if(current>=obj.length){current=(options.loop)?0:obj.length-1;loadSlide(current);}else{loadSlide(current);}});}}loadSlide(current);$(this).bind('loadSlide',function(event,slideNumber){if(current!=slideNumber&&typeof(slideNumber)=='number'){current=slideNumber;loadSlide(slideNumber);}else{}});$(this).bind('slideNext',function(event){slideNext();});$(this).bind('slidePrev',function(event){slidePrev();});$(this).bind('slidePlay',function(event,status){slidePlay(status);});});}})(jQuery);
