", {
css : {
"position" : "fixed",
"height" : "100%",
"width" : "100%",
"top" : "0",
"left" : "0",
"background" : options.backgroundColor,
"z-index" : "1",
"opacity" : options.backgroundOpacity
},
click : function(){
return yoxviewApi.clickBtn(yoxviewApi.close, true);
}
}).appendTo(popupWrap);
if (options.buttonsFadeTime != 0)
{
ctlButtons.hover(
function(){
if (yoxviewApi.isOpen)
$(this).stop().animate({ opacity : 0.6 }, options.buttonsFadeTime);
},
function(){
$(this).stop().animate({ opacity : 0 }, options.buttonsFadeTime);
}
);
}
}
$(cacheImg).load(function()
{
$.extend(images[currentCacheImg].media, {
width: this.width,
height: this.height,
loaded: true
});
advanceCache();
})
.error(function(){
advanceCache();
});
function advanceCache()
{
cachedImagesCount++;
if (cachedImagesCount == imagesCount)
cacheComplete = true;
if (!cacheComplete)
getCacheBuffer();
}
this.startCache = function()
{
loadViewImages(this.firstViewWithImages);
calculateCacheBuffer();
cacheImages(0);
}
function getCacheBuffer()
{
if (!options.cacheBuffer || currentCacheImg != cacheBufferLastIndex)
cacheImages(currentCacheImg + (cacheDirectionForward ? 1 : -1));
}
function calculateCacheBuffer()
{
if (options.cacheBuffer)
{
cacheBufferLastIndex = cacheDirectionForward ? currentItemIndex + options.cacheBuffer : currentItemIndex - options.cacheBuffer;
if (cacheBufferLastIndex < 0)
cacheBufferLastIndex += imagesCount;
else if (cacheBufferLastIndex >= imagesCount)
cacheBufferLastIndex -= imagesCount;
}
}
function cacheImages(imageIndexToCache)
{
if (cacheComplete)
return;
if (imageIndexToCache == imagesCount)
imageIndexToCache = 0;
else if (imageIndexToCache < 0)
imageIndexToCache += imagesCount;
var image = images[imageIndexToCache].media;
currentCacheImg = imageIndexToCache;
if (image && !image.loaded)
{
if (!image.type || image.type === "image")
cacheImg.src = image.src;
else
loadMedia(image, function(){
advanceCache();
});
}
else
getCacheBuffer();
}
function showLoaderIcon()
{
loading = true;
ajaxLoader.stop().stopTime()
.oneTime(options.buttonsFadeTime, function()
{
$(this).stop().css("opacity", "0.6").fadeIn(options.buttonsFadeTime);
});
}
function hideLoaderIcon()
{
loading = false;
ajaxLoader.stop().stopTime().fadeOut(options.buttonsFadeTime);
}
function setImage(itemIndex)
{
if (!isPlaying)
{
showLoaderIcon();
}
loadAndDisplayMedia(yoxviewApi.currentImage.media);
}
function resizePopup(_width, _height, _top, _left, callBack)
{
popup.stop().animate({
width: _width,
height: _height,
top: _top,
left: _left
}, options.popupResizeTime, callBack);
}
function startPlay()
{
if (imagesCount == 1)
return;
isPlaying = true;
if (currentItemIndex < imagesCount - 1)
{
popup.oneTime(options.playDelay, "play", function(){
yoxviewApi.next();
});
}
else
{
if (options.loopPlay)
popup.oneTime(options.playDelay, "play", function(){
yoxviewApi.select(0, null);
});
else
stopPlay();
}
}
function stopPlay()
{
popup.stopTime("play");
isPlaying = false;
}
function blink(_element)
{
_element.animate({ opacity : 0.8 }, 1000, function()
{
$(this).animate({opacity: 0.2}, 1000, blink($(this)));
});
}
var newPanel = panel1;
var oldPanel = panel2;
function getWindowDimensions()
{
var widthVal = $(parent.window).width();
var heightVal = $(parent.window).height();
var returnValue = {
height : heightVal,
width : widthVal,
usableHeight : heightVal - options.popupMargin * 2,
usableWidth : widthVal - options.popupMargin * 2
};
return returnValue;
}
windowDimensions = getWindowDimensions();
this.resize = function()
{
if (isPlaying)
{
resumePlay = true;
stopPlay();
}
var imageMaxSize = newPanel.data("maxSize");
if (!imageMaxSize || !imageMaxSize)
return;
var newImageDimensions = Yox.fitImageSize(
imageMaxSize,
{ width: windowDimensions.usableWidth, height: windowDimensions.usableHeight});
newPanel.css({"width" : "100%", "height" : "100%"});
var marginTop = Math.round((windowDimensions.height - newImageDimensions.height) / 2);
var marginLeft = Math.round((windowDimensions.width - newImageDimensions.width) / 2);
isResizing = true;
if (newPanel.isMedia)
ctlButtons.animate({top: newImageDimensions.height / 2 - mediaButtonsSize.height / 2}, options.popupResizeTime);
resizePopup(newImageDimensions.width,
newImageDimensions.height,
marginTop,
marginLeft,
function(){
var newImageWidth = popup.width();
var newImageHeight = popup.height();
newPanel.css({ "width" : newImageWidth + "px", "height" : newImageHeight + "px" });
isResizing = false;
if (infoPanel)
setInfoPanelHeight();
if (resumePlay)
{
startPlay();
resumePlay = false;
}
}
);
}
function setInfoPanelHeight(callback)
{
clearTimeout(hideInfoTimeout);
var titleHeight = infoText.outerHeight();
if (titleHeight < infoPanelMinHeight)
titleHeight = infoPanelMinHeight;
infoPanel.stop().animate({height : titleHeight}, 500, function(){
if (callback)
callback();
});
}
function hideInfoPanel(callback)
{
clearTimeout(hideInfoTimeout);
infoPanel.stop().animate({ height: 0 }, 500, function(){
if (callback)
callback();
});
}
function hideMenuPanel(callback)
{
clearTimeout(hideMenuTimeout);
menuPanel.stop().animate({ top: menuHidePosition }, 500, function(){
if (callback)
callback();
});
}
function showMenuPanel(callback)
{
clearTimeout(hideMenuTimeout);
menuPanel.stop().animate({ top: 0 }, 500, function(){
if (callback)
callback();
});
}
function changeMedia(media)
{
var currentImageElement;
var mediaIsImage = !media.type || media.type === "image";
if (mediaIsImage && disableInfo && infoPanel)
infoPanelWrap.css("display", "block");
clearTimeout(hideInfoTimeout);
if (panel1.css('z-index') == 1)
{
newPanel = panel1;
currentImageElement = image1;
oldPanel = panel2;
}
else
{
newPanel = panel2;
currentImageElement = image2;
oldPanel = panel1;
}
newPanel.data("maxSize", { width: media.width, height: media.height});
var newImageDimensions = Yox.fitImageSize(
media,
{ width: windowDimensions.usableWidth, height: windowDimensions.usableHeight });
if (infoPanel)
{
var infoTextValue = media.title || "";
if (media.description)
infoTextValue += infoTextValue != ""
? "
" + media.description + "
"
: media.description;
infoText.html(infoTextValue);
if (imagesCount > 1)
countDisplay.html(currentItemIndex + 1 + "/" + imagesCount);
if (infoPanelLink)
{
if (yoxviewApi.currentImage.link)
infoPanelLink.attr("href", yoxviewApi.currentImage.link).css("display", "inline");
else
infoPanelLink.css("display", "none");
}
}
var panelData = newPanel.data("yoxviewPanel");
if (mediaIsImage)
{
currentImageElement.attr({
src : media.src,
title : media.title,
alt: media.alt
});
ctlButtons.css({"height": "100%", "width": "50%", "top": "0"});
if(newPanel.isMedia)
{
panelData.media.remove();
panelData.media = undefined;
panelData.image.show();
newPanel.isMedia = false;
}
disableInfo = false;
}
else
{
if (!panelData.media)
{
panelData.media = $("
", {
className: "yoxview_mediaPanel"
});
panelData.image.hide();
newPanel.append(panelData.media);
}
else
panelData.media.show();
panelData.media.html(media.html);
ctlButtons.css({
"width": mediaButtonsSize.width,
"height": mediaButtonsSize.height,
"top": (newImageDimensions.height / 2) - (mediaButtonsSize.height / 2)
});
if (!newPanel.isMedia)
{
panelData.image.hide();
newPanel.isMedia = true;
}
if (infoPanel)
{
if (options.autoHideInfo !== false)
hideInfoPanel();
infoPanelWrap.css("display", "none");
disableInfo = true;
}
}
if (firstImage)
newPanel.animate({
width: newImageDimensions.width,
height: newImageDimensions.height
}, options.popupResizeTime);
else
newPanel.css({
"width" : newImageDimensions.width + "px",
"height" : newImageDimensions.height + "px"
});
var marginTop = Math.round((windowDimensions.height - newImageDimensions.height) / 2);
var marginLeft = Math.round((windowDimensions.width - newImageDimensions.width) / 2);
if (loading)
hideLoaderIcon();
isResizing = true;
resizePopup(newImageDimensions.width,
newImageDimensions.height,
marginTop,
marginLeft,
function()
{
if (firstImage)
{
yoxviewApi.isOpen = true;
if (options.controlsInitialDisplayTime > 0)
{
if (options.showButtonsOnOpen)
ctlButtons.animate({opacity: 0.5}, options.controlsInitialFadeTime, function(){
if(options.buttonsFadeTime != 0)
$(this).delay(options.controlsInitialDisplayTime).animate({opacity : 0}, options.controlsInitialFadeTime);
});
if (options.showBarsOnOpen)
{
showMenuPanel(function(){
if (options.autoHideMenu !== false)
hideMenuTimeout = setTimeout(function(){
hideMenuPanel();
},
options.controlsInitialDisplayTime
);
});
if (infoPanel)
setInfoPanelHeight(function(){
if (options.autoHideInfo !== false)
hideInfoTimeout = setTimeout(function(){ hideInfoPanel(); }, options.controlsInitialDisplayTime);
});
}
}
if (options.autoPlay)
yoxviewApi.play();
if (options.onOpen)
options.onOpen();
if (onOpenCallback)
{
onOpenCallback();
onOpenCallback = undefined;
}
firstImage = false;
}
isResizing = false;
}
);
newPanel.css({'z-index': '2', opacity: 1});
oldPanel.css('z-index', '1');
newPanel.fadeIn(options.popupResizeTime, function(){
oldPanel.css('display', 'none');
if (infoPanel)
setInfoPanelHeight(function(){
if (options.autoHideInfo !== false)
hideInfoTimeout = setTimeout(function(){ hideInfoPanel(); }, options.titleDisplayDuration);
});
if (imagesCount > 1)
{
if (currentItemIndex < imagesCount - 1 && options.cacheImagesInBackground)
cacheImages(currentItemIndex + 1);
if (isPlaying)
startPlay();
}
});
}
$(tempImg).load(function()
{
if (this.width == 0)
{
displayError("Image error");
return;
}
changeMedia($.extend({}, yoxviewApi.currentImage.media, {
width: this.width,
height: this.height
}));
})
.error(function(){
displayError("Image not found:
" + this.src + "");
});
function loadMediaFromProvider(provider, url, availableSize, onLoad, onError)
{
jQuery.jsonp({
url: (mediaProviderUrls[provider] || "http://oohembed.com/oohembed/"),
data: jQuery.extend({
"url" : url,
"format": "json"
}, availableSize),
dataType: 'jsonp',
callbackParameter: "callback",
success: function(data)
{
var media = {
title: data.title,
width: data.width,
height: data.height,
type: data.type
};
if (data.type === "video")
{
media.html = data.html
.replace(/