﻿/*!
* jQuery Picture Story Rotator Widget
* Copyright 2011, Edict Incorporated
* http://www.edict.com/
* Date: 05.10.2011
* Packed with: http://jscompress.com/
*/
(function (a) { a.widget("ui.pictureStoryRotator", { options: { imagesAJAXPage: false, images: false, pictureStoryInterval: false, intervalInitialMilliseconds: 12e3, intervalMilliseconds: 7e3, isPaused: false }, _create: function () { var b = this; var c = this.options; if (!c.images && c.imagesAJAXPage) { a.ajax({ url: c.imagesAJAXPage, async: false, dataType: "json", success: function (a) { c.images = a } }) } b._initRotator() }, _initRotator: function () { var b = this; var c = this.element; var d = this.options; if (!d.images || d.images.length == 0) { c.hide() } else { c.html("").addClass("picture-stories"); var e = a('<div id="rotator"></div>'); c.append(e); var f = a("<ul></ul>"); e.append(f); c.append('<div class="clearpad"></div>'); c.append('<div id="thumbnails-scroll-left"><img src="/images/icons/scroll_left.png" alt="scroll left" title="scroll left" width="14" height="20" /></div>'); var g = a('<div id="rotator-thumbnails"></div>'); c.append(g); var h = a("<ul></ul>"); g.append(h); c.append('<div id="thumbnails-scroll-right"><img src="/images/icons/scroll_right.png" alt="scroll right" title="scroll right" width="14" height="20" /></div>'); c.append('<div class="clear"></div>'); for (var i = 0; i < d.images.length; i++) { var j = a('<li id="li' + i + '"></li>'); f.append(j); var k = a('<li id="liThumb' + i + '" class="picture-story-thumbnail"></li>'); h.append(k); if (i == 0) { j.addClass("show"); k.css({ opacity: 1 }).addClass("on") } else { j.hide(); k.css({ opacity: .5 }) } if (d.images[i]["picture_story_url"]) { if (d.images[i]["picture_story_type"] == "1") { var l = d.images[i]["picture_story_url"].replace("http://www.youtube.com/watch?v=", ""); j.attr("videoID", l); var m = 0; if (d.images[i]["video_autoplay"] == "True") { m = 1 } j.attr("ap", m); if (i == 0) { j.append('<div class="video"><iframe width="483" height="244" src="http://www.youtube.com/embed/' + l + "?autoplay=" + m + '" frameborder="0"></iframe></div>'); d.isPaused = true } else { j.append('<div class="video"></div>') } } else { var n = "_self"; if (d.images[i]["url_target_new"]) { n = "_blank" } j.append('<a href="' + d.images[i]["picture_story_url"] + '" target="' + n + '" title="' + d.images[i]["picture_story_title"] + '"><img src="' + d.images[i]["picture_story_image_url"] + '" alt="' + d.images[i]["picture_story_title"] + '" width="483" height="244" /></a>') } j.append('<h2><a href="' + d.images[i]["picture_story_url"] + '" target="' + n + '" title="' + d.images[i]["picture_story_title"] + '">' + d.images[i]["picture_story_title"] + "</a></h2>") } else { j.append('<img src="' + d.images[i]["picture_story_image_url"] + '" alt="' + d.images[i]["picture_story_title"] + '" width="483" height="244" />'); j.append("<h2>" + d.images[i]["picture_story_title"] + "</h2>") } j.append(d.images[i]["picture_story_description"]); k.append('<a href="javascript:void(0);" title="click to view"><img src="' + d.images[i]["picture_story_image_url_thumb"] + '" alt="' + d.images[i]["picture_story_title"] + '" width="87" height="45" /></a>') } f.find("li:first").load(); f.find("li").mouseover(function () { d.isPaused = true }).mouseout(function () { if (!a(this).attr("videoID")) { d.isPaused = false } }); h.find("li").click(function () { var c = a("div#rotator ul li.show") ? a("div#rotator ul li.show") : a("div#rotator ul li:first"); var d = a("#" + a(this).attr("id").replace("liThumb", "li")); b._showImage(c, d, true) }).mouseover(function () { if (!a(this).hasClass("on")) { a(this).css("opacity", "0.8") } }).mouseout(function () { if (!a(this).hasClass("on")) { a(this).css("opacity", "0.5") } }); a("#thumbnails-scroll-left,#thumbnails-scroll-right").click(function () { var b = a("#rotator-thumbnails").width() - 45; if (a(this).is("#thumbnails-scroll-left")) { var c = a("#rotator-thumbnails").scrollLeft() - b } else { var c = a("#rotator-thumbnails").scrollLeft() + b } a("#rotator-thumbnails").animate({ scrollLeft: c + "px" }); return false }); d.pictureStoryInterval = b._setRotatorInterval(d.intervalInitialMilliseconds, true); b._preLoadImages(h.find("img")); b._preLoadImages(f.find("img")) } }, _setRotatorInterval: function (a, b) { var c = this; var d = this.options; return setInterval(function () { if (!d.isPaused) { c._rotate(b) } }, a) }, _rotate: function (b) { var c = a("div#rotator ul li.show") ? a("div#rotator ul li.show") : a("div#rotator ul li:first"); var d = c.next().length ? c.next().hasClass("show") ? a("div#rotator ul li:first") : c.next() : a("div#rotator ul li:first"); this._showImage(c, d, b) }, _showImage: function (b, c, d) { var e = this; var f = this.options; if (b.attr("id") != c.attr("id")) { var g = a("div#rotator-thumbnails ul li.on") ? a("div#rotator-thumbnails ul li.on") : a("div#rotator-thumbnails ul li:first"); var h = a("#" + c.attr("id").replace("li", "liThumb")); c.stop().addClass("show").fadeIn(1e3); b.stop().removeClass("show").fadeOut(1e3); h.stop().addClass("on").animate({ opacity: 1 }, 1e3); g.stop().animate({ opacity: .5 }, 1e3).removeClass("on"); var i = h.offset().left - a("#rotator-thumbnails").offset().left; if (i > a("#rotator-thumbnails").width() / 2 || i < 0) { a("#rotator-thumbnails").animate({ scrollLeft: i + "px" }) } if (c.attr("videoID")) { f.isPaused = true; var j = c.attr("videoID"); var k = c.attr("ap"); c.find("div.video").html('<iframe width="483" height="244" src="http://www.youtube.com/embed/' + j + "?autoplay=" + k + '" frameborder="0"></iframe>') } else { f.isPaused = false; if (b.attr("videoID")) { b.find("div.video").html("") } if (d) { if (f.pictureStoryInterval) { clearInterval(f.pictureStoryInterval) } if (a("div#rotator ul li").length > 1) { f.pictureStoryInterval = e._setRotatorInterval(f.intervalMilliseconds, false) } } } } }, _preLoadImages: function (b) { for (var c = 0; c < b.length; c++) { var d = b[c]; if (!d.preloaded) { var e = a(new Image); e.attr("src", d.src); if (this._isImageLoaded(e[0])) { d.preloaded = true; d.size = { width: e[0].width, height: e[0].height} } else { e.load(function () { d.preloaded = true; d.size = { width: this.width, height: this.height} }).error(function () { d.error = true; d.preloaded = false; d.size = false }) } } } }, _isImageLoaded: function (a) { if (typeof a.complete != "undefined" && !a.complete) { return false } if (typeof a.naturalWidth != "undefined" && a.naturalWidth == 0) { return false } return true }, destroy: function () { a.Widget.prototype.destroy.apply(this, arguments) } }) })(jQuery)
