(function() { var flowIDs; var nextPicFunctions = {}; var nextPicManualFunctions = {}; var isWebkit = 'WebkitAppearance' in document.documentElement.style; jQuery(document).ready(function() { flowIDs = getFlowIDs(); flowIDs.every(function(DOM) { return makeFlow(DOM); }); }); function getFlowIDs() { var flowDivs = jQuery('[id^=flow-]'); return jQuery.map(flowDivs, function(div) { return jQuery("#" + div.id); }); } function makeFlow(DOM) { var id = DOM.data("id"); var curr = 0; var prev = 0; var timer = false; var auto_change = false; var blocked = 0; var count = DOM.data("pictures"); var counter = 0; var flowtime = DOM.data("flowtime"); var flowtype = DOM.data("flowtype"); var intersectiontime = DOM.data("intersectiontime"); var restart_number = DOM.data("restartnumber"); var changetime = DOM.data("changetime"); var preview = DOM.data("preview"); var switchmode = DOM.data("switchmode"); var scale_to = DOM.data("scaleto"); var height = DOM.data("height"); var width = DOM.data("width"); var random = DOM.data("random"); var nextpicManual = function(direction, target) { window.clearTimeout(timer); if(auto_change) auto_change = false; nextpic(direction,target); } var resetWebkitFix = function() { if(isWebkit) { jQuery("#flowdata-"+id+"-"+prev).css("-webkit-transform", "initial"); jQuery("#flowdata-"+id+"-"+curr).css("-webkit-transform", "initial"); } } var nextpic = function(direction, target) { if(!blocked) { blocked = true; window.setTimeout(function() {blocked = false;}, flowtime); if(arguments[0] == '-1'){ if(curr == 0) next = count - 1; else next = curr - 1; } else { next = (curr+1) % count; if(next == count-1) counter += 1; } if(random) { next = curr; if(count > 1) { while(next == curr) { next = Math.floor(Math.random() * count); } } } if(arguments[1] !== undefined) { next = arguments[1]; } // Webkit workaround for puff / zoom effect if(isWebkit && (flowtype == "puff" || flowtype == "slide" || flowtype == "drop" || flowtype == "clip")) { var translation; if(scale_to == "width") { translation = (height - jQuery("#flowdata-"+id+"-"+curr).height()) / 2; jQuery("#flowdata-"+id+"-"+curr).css("top", 0).css("bottom", 0).css("-webkit-transform", "translateY("+translation+"px)"); translation = (height - jQuery("#flowdata-"+id+"-"+next).height()) / 2; jQuery("#flowdata-"+id+"-"+next).css("top", 0).css("bottom", 0).css("-webkit-transform", "translateY("+translation+"px)"); } else { translation = (width - jQuery("#flowdata-"+id+"-"+curr).width()) / 2; jQuery("#flowdata-"+id+"-"+curr).css("left", 0).css("right", 0).css("-webkit-transform", "translateX("+translation+"px)"); translation = (width - jQuery("#flowdata-"+id+"-"+next).height()) / 2; jQuery("#flowdata-"+id+"-"+next).css("left", 0).css("right", 0).css("-webkit-transform", "translateX("+translation+"px)"); } } if(flowtype != "fade") { if(arguments[0] != '-1'){ jQuery("#flowdata-"+id+"-"+curr).hide(flowtype, {direction:'left'},flowtime, resetWebkitFix); } else { jQuery("#flowdata-"+id+"-"+curr).hide(flowtype, {direction:'right'},flowtime, resetWebkitFix); } } else { jQuery("#flowdata-"+id+"-"+curr).fadeOut(flowtime); } if(preview) { jQuery("#flowdata-"+id+"-thumb-"+curr).css("border", "2px solid transparent"); jQuery("#flowdata-"+id+"-thumb-"+next).css("border", "2px solid black"); } if(flowtype != "fade") { if(arguments[0] != '-1'){ jQuery("#flowdata-"+id+"-"+next).show(flowtype, {direction:'right'},flowtime, resetWebkitFix); } else { jQuery("#flowdata-"+id+"-"+next).show(flowtype, {direction:'left'},flowtime, resetWebkitFix); } } else { jQuery("#flowdata-"+id+"-"+next).delay(flowtime-intersectiontime).fadeIn(flowtime); } prev = curr; curr = next; if(auto_change && arguments[1] === undefined && (restart_number == 0 || counter < restart_number)){ timer = window.setTimeout(nextpic, (changetime+2*flowtime-intersectiontime)); } } }; if(switchmode == "auto" || switchmode == "both") { auto_change = true; counter = 0; window.setTimeout(nextpic, changetime); } nextPicFunctions[id] = nextpic; nextPicManualFunctions[id] = nextpicManual; jQuery("#flowbutton-" + id + "-left").click(function() { nextpicManual(-1); }); jQuery("#flowbutton-" + id + "-right").click(function() { nextpicManual(1); }); var flowpreview = jQuery('[id^=flowdata-' + id + '-thumb-]'); flowpreview.each(function(index, preview) { p = jQuery(preview); p.click(function() { nextpicManual(0, jQuery(this).data("index")); }); }); return true; } function nextPic(flow, manual, direction, target) { if(!manual) { nextPicFunctions[flow](direction, target); } else { nextPicManualFunctions[flow](direction, target); } } })();