$.fn.extend( { mtslideshow : function(options) { var settings = { nextTitle :'next', nextId :'nid', prevTitle :'prev', prevId :'pid', nextIconSrc : null, prevIconSrc : null, skipLinks : 'false', controlsAfter:true, indexId: '#', hideBack: 'false', hideId: '#', captionId: '#', transitionPostfix: 'default' }; if (options) $.extend(settings, options); this.each( function() { var self = $(this); var s = $("div", self).length; var current = 0; $("div", self).each( function() { $(this).hide(); //$(this).click(function() {animate("next", true);}); }); $("div:first", self).show(); var pid = self.attr('id')+settings.prevId; var nid = self.attr('id')+settings.nextId; if(settings.skipLinks == 'false' || settings.skipLinks == '') { var p = ''; var n = ''; if(settings.prevIconSrc && settings.nextIconSrc) { p = '\"\"'; n = '\"\"'; } var html = '
'; if(settings.hideBack == 'false') { html += ''; } else { html += ''; html += ''; html += settings.nextTitle + n + ''; html += '
'; html += '
' if(settings.controlsAfter) $(self).after(html); else $(self).before(html); } $("a#" + nid).attr("rel", "next"); $("a#" + pid).attr("rel", "prev"); $("a#" + nid).click( function() { animate("next", settings.indexId, settings.hideBack, settings.hideId , settings.captionId, pid, settings.transitionPostfix); }); $("a#" + pid).click( function() { animate("prev", settings.indexId, settings.hideBack, settings.hideId, settings.captionId, pid, settings.transitionPostfix); }); function animate(dir, indexId, hideBack, hideId, captionId, pid, transitionPostfix) { var last = current; switch (dir) { case "next": current = (current==s-1)?0:current+1; break; case "prev": current = (current==0)?s-1:current-1; break; default: break; }; if(indexId != '#') $(indexId).html(current+1); if(hideBack == 'true') { if(current+1 == 1) { if(hideId == '#'){ $("a#" + pid).hide(); }else{ $(hideId).hide(); } } else { if(hideId == '#'){ $("a#" + pid).show(); }else{ $(hideId).show(); } } } var uagent = navigator.userAgent.toLowerCase(); var cssanimation = "true"; if(window.orientation === undefined){ cssanimation = "false"; } if(uagent.search("android") > -1){ cssanimation = "false"; } if(uagent.search("webOS") > -1){ cssanimation = "true"; } //if it's mobile safari or android if (cssanimation == "false") { $('div:eq('+last+')',self).fadeOut("slow",function(){ $('div:eq('+current+')',self).fadeIn("slow"); }); }else{ if (current == 0){ $('div:eq('+current+')',self).css("position","absolute"); $('div:eq('+last+')',self).css("position",""); }else if(last > current){ $('div:eq('+current+')',self).css("position","absolute"); $('div:eq('+last+')',self).css("position",""); }else{ $('div:eq('+current+')',self).css("position",""); $('div:eq('+last+')',self).css("position","absolute"); } switch (dir) { case "next": $('div:eq('+last+')',self).addClass("dxf_slideshow_next_out_" + transitionPostfix);//,function(){ setTimeout(function(){ $('div:eq('+last+')',self).hide(); $('div:eq('+last+')',self).removeClass("dxf_slideshow_next_out_" + transitionPostfix); $('div:eq('+current+')',self).removeClass("dxf_slideshow_next_in_" + transitionPostfix); $('div:eq('+current+')',self).css("position",""); },2000); $('div:eq('+current+')',self).show().addClass("dxf_slideshow_next_in_" + transitionPostfix); break; case "prev": $('div:eq('+last+')',self).addClass("dxf_slideshow_prev_out_" + transitionPostfix);//,function(){ setTimeout(function(){ $('div:eq('+last+')',self).hide(); $('div:eq('+last+')',self).removeClass("dxf_slideshow_prev_out_" + transitionPostfix); $('div:eq('+current+')',self).removeClass("dxf_slideshow_prev_in_" + transitionPostfix); $('div:eq('+current+')',self).css("position",""); },2000); $('div:eq('+current+')',self).show().addClass("dxf_slideshow_prev_in_" + transitionPostfix); break; default: break; }; } if(captionId != '#') { var aNewCaption = $('div:eq('+current+') > p',self).html(); $(captionId).trigger("beforeCaptionChange", "").trigger("afterCaptionChange", ""); setTimeout(function() {$(captionId).html(aNewCaption);}, 1000); } }; }); } });