﻿/*!
* Time limit JavaScript Library v1.0.0
* http://mrzzcn.diandian.com/
*
* Copyright 2011, Mrzzcn
* Copyright 2011, The Dojo Foundation
* Released under the MIT, BSD, and GPL Licenses.
*
* Date: Fri Oct 14 16:18:33 2011 -9711
*/

(function($) { $.fn.PictureRotation = function(options) { $.OtherFunction.debug(this); var settings = new Array(); $.extend(settings, $.fn.PictureRotation.defaults, options); var showWindow = $(this); showWindow.width(settings.width + "px").height(settings.height + "px").css("position", "relative").css("overflow", "hidden"); settings.ShowWindow = showWindow; if (showWindow.attr("id") == undefined || showWindow.attr("id") == "") { var id = $.OtherFunction.getRandomID(); showWindow.attr("id", id); } settings.moving = false; var switchItmes = showWindow.children().eq(0).children(); switchItmes.width(settings.width).height(settings.height).css("position", "absolute"); var itemscount = switchItmes.length; for (var i = 0; i < itemscount; i++) { if (settings.direction == "left") { switchItmes.eq(i).css("left", i * settings.width + "px"); } else if (settings.direction == "top") { switchItmes.eq(i).css("top", i * settings.height + "px"); } } settings.SwitchItems = switchItmes; var picContainer = showWindow.children().eq(0); if (settings.direction == "left") { picContainer.height(settings.height + "px").width(itemscount * settings.width + "px"); } else if (settings.direction == "top") { picContainer.width(settings.width + "px").height(itemscount * settings.height + "px"); } picContainer.css("position", "absolute"); settings.PicContainer = picContainer; settings.currentDirection = 1; var pageid = $.OtherFunction.getRandomID(); var $pages; switch (settings.menutype) { case "other": $pages = $(settings.menuExpression); break; case "lastNext": var pageHtml = "<div tag='lastptzz' class=\"" + settings.lastNext.lastClass + "\" >"; pageHtml += settings.lastNext.lastHtml; pageHtml += "</div>"; pageHtml += "<div tag='nextptzz' class=\"" + settings.lastNext.nextClass + "\" >"; pageHtml += settings.lastNext.nextHtml; pageHtml += "</div>"; showWindow.append(pageHtml); settings.menuExpression = "div[tag*='ptzz']"; $pages = $(settings.menuExpression); break; case "num": var pageHtml = "<div id=\"" + pageid + "\" class=\"" + settings.numMenu.pageClass + "\" style=\"" + settings.numMenu.pageStyle + "\" >"; for (var i = 1; i <= itemscount; i++) { var page = "<a href=\"#\" class=\"" + settings.numMenu.itemClass + "\">" + i + "</a>"; pageHtml += page; } pageHtml += "</div>"; showWindow.append(pageHtml); settings.menuExpression = "div[id*='" + pageid + "']>a"; $pages = $(settings.menuExpression); break; default: var pageHtml = "<div id=\"" + pageid + "\" class=\"" + settings.numMenu.pageClass + "\" style=\"" + settings.numMenu.pageStyle + "\" >"; for (var i = 1; i <= itemscount; i++) { var page = "<a href=\"#\" class=\"" + settings.numMenu.itemClass + "\">" + i + "</a>"; pageHtml += page; } pageHtml += "</div>"; showWindow.append(pageHtml); settings.menuExpression = "div[id*='" + pageid + "']>a"; $pages = $(settings.menuExpression); break; } $pages.eq(0).addClass(settings.menuActive); settings.currentID = 0; $pages.each(function(index) { $(this).hover(function() { settings.mousein = true; var _self = this; clearTimeout($.fn.PictureRotation.mousemoveEvents[index]); $.fn.PictureRotation.mousemoveEvents[index] = setTimeout(function() { settings.timeToNext = 0; var currentID = $.OtherFunction.getCurrentID(settings); var nextToShow = $(_self).index(); if ($(_self).attr("tag") == "lastptzz") { settings.currentDirection = -1; nextToShow = currentID + settings.currentDirection; if (nextToShow < 0) { settings.currentDirection = 1; nextToShow = 1; } } else if ($(_self).attr("tag") == "nextptzz") { settings.currentDirection = 1; nextToShow = currentID + settings.currentDirection; if (nextToShow > settings.SwitchItems.length - 1) { settings.currentDirection = -1; nextToShow = settings.SwitchItems.length - 2; } } $.OtherFunction.active(settings, nextToShow); }, 200); }, function() { settings.mousein = false; }); }); if (settings.mouseinstop) { showWindow.hover(function() { settings.mousein = true; }, function() { settings.mousein = false; }); } $(settings.menuExpression).click(function() { var currentID = $.OtherFunction.getCurrentID(settings); var nextToShow = 1; if ($(this).attr("tag") == "lastptzz") { settings.timeToNext = 0; settings.currentDirection = -1; nextToShow = currentID + settings.currentDirection; if (nextToShow < 0) { settings.currentDirection = 1; nextToShow = 1; } $.OtherFunction.active(settings, nextToShow); } else if ($(this).attr("tag") == "nextptzz") { settings.timeToNext = 0; settings.currentDirection = 1; nextToShow = currentID + settings.currentDirection; if (nextToShow > settings.SwitchItems.length - 1) { settings.currentDirection = -1; nextToShow = settings.SwitchItems.length - 2; } $.OtherFunction.active(settings, nextToShow); } else { return !settings.clearClick; } }); if (settings.autoPlay) { setInterval(function() { if ((settings.mouseinstop && (!settings.mousein)) || (!settings.mouseinstop)) { settings.timeToNext = settings.timeToNext + 100; if (settings.timeToNext == (settings.speed + settings.delay)) { settings.timeToNext = 0; var currentIndex = $.OtherFunction.getCurrentID(settings); var next = currentIndex + settings.currentDirection; if (next < 0) { next = 1; settings.currentDirection = 1; } if (next > settings.SwitchItems.length - 1) { next = 0; if (settings.cycleback) { next = settings.SwitchItems.length - 2; settings.currentDirection = -1; } } $.OtherFunction.active(settings, next); } } }, 100); } return $(this); }; $.OtherFunction = { debug: function($obj) { if (window.console && window.console.log) window.console.log('hilight selection count: ' + $obj.size()); }, getRandomID: function() { var date = new Date(); var id = date.getHours() + "" + date.getMinutes() + "" + date.getSeconds() + date.getMilliseconds(); var r = Math.random(); return id + "" + r; }, clearMoving: function() { }, play: function($obj, animate, time) { $obj.animate(animate, time / 2).animate({}, time / 2); }, autoPaly: function($items, options) { }, setItemsDefault: function(options) { }, getCurrentID: function(options) { return options.currentID; }, moveMovie: function(options, value) { if (options.direction == "left") { options.PicContainer.animate({ left: value + "px" }, options.speed).delay(options.delay).animate({}, options.delay); } else if (options.direction == "top") { options.PicContainer.animate({ top: value + "px" }, options.speed).delay(options.delay).animate({}, options.delay); } }, active: function(options, index) { var $pages = $(options.menuExpression); var $container = options.PicContainer; var currentIndex = $.OtherFunction.getCurrentID(options); var count = $container.children("div").length; if (currentIndex == undefined) { currentIndex = count - 2; } currentIndex = parseInt(currentIndex); var next = index; if (currentIndex == next) { return false; } if (currentIndex <= 0) { options.currentDirection = 1; } if (next > count - 1) { next = count - 2; options.currentDirection = -1; } var width = options.width; var height = options.height; var left = -(index) * width; var top = -(index) * height; var tdire = "left"; var tvalue = left; if (options.direction == "top") { tdire = "top"; tvalue = top; } if (options.movieType == "move") { $.OtherFunction.moveMovie(options, tvalue); } else if (options.movieType == "switch") { $container.css(tdire, tvalue + "px"); options.SwitchItems.hide().eq(index).fadeIn(options.speed).delay(options.delay).animate({}, options.delay); } $pages.removeClass(options.menuActive); $pages.eq(next).addClass(options.menuActive); options.currentID = next; } }; $.fn.PictureRotation.timeToNext = 100; $.fn.PictureRotation.moving = false; $.fn.PictureRotation.mousemoveEvents = []; $.fn.PictureRotation.defaults = { width: 100, height: 100, hascaption: true, menutype: "num", menuActive: "active", menuExpression: "", speed: 1000, delay: 1000, timeToNext: 100, numMenu: { pageClass: "paging", pageStyle: "", itemClass: "" }, lastNext: { lastClass: "last", lastHtml: "<<<", nextClass: "next", nextHtml: ">>>", currentDirection: 1, currentClass: "" }, movieType: "move", direction: "top", mouseinstop: false, mousein: false, cycleback: true, autoPlay: true, clearClick: true }; })(jQuery);
