﻿/*-----------------------------------------------------------------------
Copyright (c) 2011 Tremayne Christ, http://tremaynechrist.co.uk/

MIT LICENSE

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-----------------------------------------------------------------------*/

(function ($) { $.fn.photofy = function (options) { var $photofy = this; var photofy_images = []; var photofy_imageList = []; var photofy_imagePositions = []; var photofy_imageSelectionOrder = []; var photofy_Options_imagecount = Infinity; var photofy_Options_images = null; var photofy_Options_delay = 5000; if (options) { photofy_Options_imagecount = options.imagecount || Infinity; photofy_Options_images = options.images; photofy_Options_delay = options.delay || 5000 } if (photofy_Options_images != null) { $photofy.html(""); for (var i = 0; i < photofy_Options_images.length; i++) { var htmlImageForPhotofy = new Image(); htmlImageForPhotofy.src = photofy_Options_images[i]; $photofy.append(htmlImageForPhotofy) } } $photofy.children("img").each(function () { var photofy_image = new Image(); photofy_image.src = $(this).attr("src"); photofy_imageList.push(photofy_image); if (photofy_images.length < photofy_Options_imagecount) { photofy_images.push($(this)) } }); $photofy.html(""); for (var i = 0; i < photofy_images.length; i++) { $photofy.append(photofy_images[i]) } function Photofy() { var photofy_count = photofy_images.length; photofy_imagePositions = []; photofy_imageSelectionOrder = []; for (var i = 0; i < photofy_count; i++) { photofy_imagePositions.push(i) } for (var i = 0; i < photofy_imageList.length; i++) { photofy_imageSelectionOrder.push(i) } photofy_imagePositions.sort(function () { return 0.5 - Math.random() }); photofy_imageSelectionOrder.sort(function () { return 0.5 - Math.random() }); for (var i = 0; i < photofy_count; i++) { Photofy_Load(i) } } function Photofy_Load(i) { setTimeout(function Photofy_Swap() { var photofy_imagePosition = photofy_imagePositions[i]; var photofy_imageSelection = photofy_imageSelectionOrder[i]; var photofy_currentImage = photofy_images[photofy_imagePosition]; var photofy_selectedImage = photofy_imageList[photofy_imageSelection]; photofy_currentImage.fadeTo(100, 0.2, function () { photofy_currentImage.attr("src", photofy_selectedImage.src).fadeTo(500, 1) }) }, 50 * i) } setTimeout(Photofy, 2000); setInterval(Photofy, ((photofy_images.length * 50) + 550) + photofy_Options_delay) } })(jQuery);
