(function($) { jQuery.fn.buttonrotator = function(options) { var opt = $.extend({ speed: 600, minOpacity: 0.4, autorotate: true, mouseOverSize: 0.08, titleMinOpacity: 0.4, childSelector: "", items: 5, autointerval: 5000 }, options); return this.each(function() { var container = this; var containerID = $(container).attr("id"); var buttonContainers = $(container).children(opt.childSelector); var tempLeftHidden; var tempRightHidden; var leftBackButtonID, leftMiddleButtonID, frontButtonID, rightMiddleButtonID, rightBackButtonID, tempLeftHiddenID, tempRightHiddenID; var buttonData = (typeof arguments[0] != "object") ? {} : arguments[0]; buttonData = { position: null, height: null, width: null }; rightBackButtonID = $(".rightBackButton", container).eq(0).attr("id"); tempLeftHidden = $("#" + rightBackButtonID).clone(true); tempLeftHidden = $(tempLeftHidden).get(0); $("#" + rightBackButtonID).attr("id", "removeButton"); $(tempLeftHidden).removeClass("rightBackButton").addClass("leftBackHidden").prependTo(container); frontButtonID = $(".frontButton", container).eq(0).attr("id"); $(".springmanLogo", "#" + frontButtonID).css({ "z-index": "9" }); var autotimer; var hoverspeed; var currentItem; var isBusy = false; var container_width = $(container).width(); var items = buttonContainers.length; function resetBusyFlag() { isBusy = false; } function refreshButtonCache() { rightBackButtonID = $("#removeButton", container).eq(0).attr("id"); rightMiddleButtonID = $("#hideButton", container).eq(0).attr("id"); frontButtonID = $(".frontButton", container).eq(0).attr("id"); leftMiddleButtonID = $(".leftMiddleButton", container).eq(0).attr("id"); leftBackButtonID = $(".leftBackButton", container).eq(0).attr("id"); tempLeftHiddenID = $(".leftBackHidden", container).eq(0).attr("id"); tempRightHiddenID = $(".rightBackHidden", container).eq(0).attr("id"); } function rotate() { alert("Rotate method triggered!"); } function rotateLeft() { isBusy = true; if (opt.autorotate) { stopInterval(); } } function rotateRight() { var elementID = ""; var tempID; var cloneTemp = null; var isCloneSetupComplete = false; if (opt.autorotate) { } rightMiddleButtonID = $(".rightMiddleButton", container).eq(0).attr("id"); tempRightHidden = $("#" + rightMiddleButtonID).clone(true); tempRightHidden = $(tempRightHidden).get(0); $("#" + rightMiddleButtonID).attr("id", "hideButton"); $(tempRightHidden).removeClass("rightMiddleButton").addClass("rightBackHidden").prependTo(container); refreshButtonCache(); $("#removeButton").css({ "z-index": "-10" }); $("#" + tempLeftHiddenID).switchClass("leftBackHidden", "leftBackButton", { duration: 50, queue: false }, function(e) { $("#" + leftBackButtonID).delay(100).switchClass("leftBackButton", "leftMiddleButton", { duration: 400, queue: false }); $("#" + leftMiddleButtonID).delay(100).switchClass("leftMiddleButton", "frontButton", { duration: 400, queue: false }, function(e) { $(".springmanLogo", "#" + leftMiddleButtonID).css({ "z-index": "9" }); }); $(".springmanLogo", "#" + frontButtonID).css({ "z-index": "-1" }); $("#" + frontButtonID).delay(100).switchClass("frontButton", "rightMiddleButton", { duration: 400, queue: false }); $("#hideButton").delay(100).switchClass("rightMiddleButton", "rightBackButton", { duration: 400, queue: false }, function(e) { $("#removeButton").animate({ opacity: 0 }, { duration: 600, queue: false }).detach(); $("#hideButton").attr("id", "removeButton"); }); $("#" + tempRightHiddenID).delay(900).switchClass("rightBackHidden", "leftBackHidden", { duration: 0, queue: false }); resetBusyFlag(); }); } function stopInterval() { if (autotimer) { clearInterval(autotimer); autotimer = false; } } function startInterval() { if (autotimer) { stopInterval(); } autotimer = setInterval(function() { if (!isBusy) { rotateRight(); } }, opt.autointerval); } $("#" + containerID).live({ mouseenter: function(e) { stopInterval(); }, mouseleave: function(e) { startInterval(); } }); if (opt.autorotate) { startInterval(); } }); }; })(jQuery);
