$(function(){ var stop_auto = false; $.extend($.support, { touch: "ontouchend" in document }); $.fn.asus_padfone_slider = function(options) { var defaults = {}; var options = $.extend(defaults,options); var cache = []; var loads = 0; var pushzero = function (num,n){ return (Array(n).join(0) + num).slice(-n);}; var start = function(obj,i,mod) { if (options.auto_start == true){ setTimeout(function(){ if (stop_auto == false) { $('.padfone_sliders').hide(); $('.padfone_slider_'+i).show(); // $(obj).css("background-image","url("+options.image_name + pushzero(i,3) + "."+ options.type+")" ); } i++; if (i >= options.image_Total){i = 0; } if (stop_auto == false) {start(obj,i,mod);} else { } },(1000/options.auto_speed)); } }; var first_one = function(){ if ((!options.first)&&(typeof(options.first_click) == "function")){ for(var i=0 ; i<=options.image_Total ;i++ ) { $("#demo").append(''); } options.first_click(); } options.first = true; } var user_down = function(obj,event){ first_one(); var x = event.screenX; var in_id = options.mouse_start; $(document).bind("selectstart",function(){return false;}); $(document).bind("mousemove",function(event){ user_move(obj,event,x,in_id);}); $(document).one("mouseup",function(){ $(document).unbind("selectstart"); $(document).unbind("mousemove"); run(obj,options.mouse_start); }); } var user_move = function(obj,event,x,in_id){ var new_x = event.screenX ; var tstart_id; var x_move = x - new_x; if (x_move < 0){ tstart_id = in_id - parseInt(x_move/options.mouse_speed) > options.image_Total ? options.image_Total : in_id - parseInt(x_move/options.mouse_speed); } else { tstart_id = in_id - parseInt(x_move/options.mouse_speed) < 0 ? 0 : in_id - parseInt(x_move/options.mouse_speed); } if (((tstart_id == 0)||(tstart_id == options.image_Total))&&(Math.abs(x_move) > options.mouse_speed)){ in_id = tstart_id; x = new_x;} if (tstart_id != options.mouse_start){ //$(obj).css("background-image","url("+options.image_name + pushzero(tstart_id,options.bit) + "." + options.type+")"); $('.padfone_sliders').hide(); $('.padfone_slider_'+tstart_id).show(); } options.mouse_start = tstart_id; }; var mouse_start = function(obj) { $('.padfone_sliders').hide(); $('.padfone_slider_'+options.mouse_start).show(); // $(obj).css("background-image","url("+options.image_name + pushzero(options.mouse_start,options.bit) + "." + options.type+")"); if (!$.support.touch){$(obj).bind("mousedown",function(event){ user_down($(this),event); });} else { $(obj)[0].addEventListener("touchstart", function (e) { first_one(); var x = e.touches[0].screenX; options.touchstart_x = x; options.touchstart_id = options.mouse_start; }); $(obj)[0].addEventListener("touchmove", function (e) { if (e.touches.length < 2){ e.preventDefault(); user_move(obj,e.touches[0],options.touchstart_x,options.touchstart_id); } }); $(obj)[0].addEventListener("touchend", function () { run(obj,options.mouse_start); }); } }; var run = function(obj,in_id){ var stop; for (var set in options.arrays){ if (eval(in_id +" "+options.arrays[set][0])){ stop = options.arrays[set][1];break;} } if (in_id != options.mouse_start){ setTimeout(function(){ if (in_id > stop) { in_id = in_id-1;run(obj,in_id);} else if (in_id < stop) { in_id = in_id+1;run(obj,in_id);} options.mouse_start = in_id; $('.padfone_sliders').hide(); $('.padfone_slider_'+in_id).show(); // $(obj).css("background-image","url("+options.image_name + pushzero(in_id,options.bit) + "." + options.type+")"); },10); } } this.each(function(){ var obj = this; if (options.push_div){ // $(this).html('