/* copyright (c) 2008 kean loong tan http://www.gimiti.com/kltan * licensed under the mit (http://www.opensource.org/licenses/mit-license.php) * jflow * version: 1.2 (july 7, 2008) * requires: jquery 1.2+ */ (function($) { $.fn.jflow = function(options) { var opts = $.extend({}, $.fn.jflow.defaults, options); var randnum = math.floor(math.random()*11); var jfc = opts.controller; var jfs = opts.slidewrapper; var jsel = opts.selectedwrapper; var cur = 0; var timer; var maxi = $(jfc).length; // sliding function var slide = function (dur, i) { $(opts.slides).children().css({ overflow:"hidden" }); $(opts.slides + " iframe").hide().addclass("temp_hide"); $(opts.slides).animate({ marginleft: "-" + (i * $(opts.slides).find(":first-child").width() + "px") }, opts.duration*(dur), opts.easing, function(){ $(opts.slides).children().css({ overflow:"hidden" }); $(".temp_hide").show(); } ); } $(this).find(jfc).each(function(i){ $(this).click(function(){ dotimer(); if ($(opts.slides).is(":not(:animated)")) { $(jfc).removeclass(jsel); $(this).addclass(jsel); var dur = math.abs(cur-i); slide(dur,i); cur = i; } }); }); $(opts.slides).before('
').appendto(jfs); $(opts.slides).find("div").each(function(){ $(this).before('').appendto($(this).prev()); }); //initialize the controller $(jfc).eq(cur).addclass(jsel); var resize = function (x){ $(jfs).css({ position:"relative", width: opts.width, height: opts.height, overflow: "hidden" }); //opts.slides or #myslides container $(opts.slides).css({ position:"relative", width: $(jfs).width()*$(jfc).length+"px", height: $(jfs).height()+"px", overflow: "hidden" }); // jflowslidecontainer $(opts.slides).children().css({ position:"relative", width: $(jfs).width()+"px", height: $(jfs).height()+"px", "float":"left", overflow:"hidden" }); $(opts.slides).css({ marginleft: "-" + (cur * $(opts.slides).find(":eq(0)").width() + "px") }); } // sets initial size resize(); // resets size $(window).resize(function(){ resize(); }); $(opts.prev).click(function(){ dotimer(); doprev(); }); $(opts.next).click(function(){ dotimer(); donext(); }); var doprev = function (x){ if ($(opts.slides).is(":not(:animated)")) { var dur = 1; if (cur > 0) cur--; else { cur = maxi -1; dur = cur; } $(jfc).removeclass(jsel); slide(dur,cur); $(jfc).eq(cur).addclass(jsel); } } var donext = function (x){ if ($(opts.slides).is(":not(:animated)")) { var dur = 1; if (cur < maxi - 1) cur++; else { cur = 0; dur = maxi -1; } $(jfc).removeclass(jsel); //$(jfs).fadeout("fast"); slide(dur, cur); //$(jfs).fadein("fast"); $(jfc).eq(cur).addclass(jsel); } } var dotimer = function (x){ if((opts.auto) == true) { if(timer != null) clearinterval(timer); timer = setinterval(function() { $(opts.next).click(); }, 3000); } } dotimer(); }; $.fn.jflow.defaults = { controller: ".jflowcontrol", // must be class, use . sign slidewrapper : "#jflowslide", // must be id, use # sign selectedwrapper: "jflowselected", // just pure text, no sign auto: false, easing: "swing", duration: 400, width: "100%", prev: ".jflowprev", // must be class, use . sign next: ".jflownext" // must be class, use . sign }; })(jquery);