var toolbarAnimating = false;
var touchScroll = false; //Global variable to store whether or not a touch event is a touch scroll event or not. Used to distinguish between scrolls and clicks for touchend events.
var modalInit = false;
var facAccLoadInit = true; // Boolean to control if requests for more data can be made.
var mobile = false;
if(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|ipad|iris|kindle|Android|Silk|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(navigator.userAgent)
|| /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(navigator.userAgent.substr(0,4))) {
mobile = true;
}
function initMobileMenu(){
$('#mobile-menu-button').click(function(){
$(this).find('span').toggleClass('on').toggleClass(''+$(this).find('span').attr('data-icon')+' '+$(this).find('span').attr('data-icon-close')+'');
$('#logo').toggleClass('bumpUp');
$(document.body).toggleClass('open');
if($(document.body).hasClass('open')){
//Wrap everything
$(document.body).wrapInner('
');
} else {
//Unwrap everything
$('#alert').unwrap();
}
setTimeout(function(){
$('#content').toggleClass('bumpLeft');
}, 100);
});
$('#mobile-search-button').click(function(){
$(this).find('span').toggleClass('on').toggleClass(''+$(this).find('span').attr('data-icon')+' '+$(this).find('span').attr('data-icon-close')+'');;
$('#logo').toggleClass('bumpUp');
$(document.body).toggleClass('open');
if($(document.body).hasClass('open')){
//Wrap everything
$(document.body).wrapInner('');
var attr = $('#content').attr('data-old-height');
if (typeof attr !== typeof undefined && attr !== false) {
$('#content').height(attr);
}
} else {
//Unwrap everything
$('#alert').unwrap();
$('#content').height('auto'); //This is done to counteract searches that hard set #content's height so that results aren't clipped on mobile
}
setTimeout(function(){
$('#content, #toolbar').toggleClass('bumpRight');
if($('#content').hasClass('bumpRight')){
$('#urlinks, .flyout, #mobile-tools-button').hide(0);
$('.flyout.search, #top-search, #top-search-results').show(0);
} else{
$('#mobile-tools-button').show(0);
}
}, 100);
});
$('#mobile-tools-button').click(function(){
$(this).find('span').toggleClass('on').toggleClass(''+$(this).find('span').attr('data-icon')+' '+$(this).find('span').attr('data-icon-close')+'');;
if($('#logo').hasClass('bumpUp')){
//$('#logo').css('height', $('#logo').height());
//Tally the height of visible children and set it to the parent of height
}
$('#logo').toggleClass('bumpUp');
$(document.body).toggleClass('open');
if($(document.body).hasClass('open')){
//Wrap everything
$(document.body).wrapInner('');
} else {
//Unwrap everything
$('#alert').unwrap();
$('#content').height('auto'); //This is done to counteract searches that hard set #content's height so that results aren't clipped on mobile
}
setTimeout(function(){
$('#content, #toolbar').toggleClass('bumpRight');
if($('#content').hasClass('bumpRight')){
$('#top-search, #top-search-results, #mobile-search-button, .flyout').hide(0);
$('#urlinks').show(0);
} else{
$('#mobile-search-button').show(0);
}
}, 100);
});
}
function initToolbar(){
$('#toolbar .expandable').click(function(){
if(toolbarAnimating == false){
toolbarAnimating = true;
$('#urlinks .buttonWrap').removeClass('on');
$(this).parents('.buttonWrap').toggleClass('on');
$(this).toggleClass(''+$(this).attr('data-icon')+' '+$(this).attr('data-icon-close')+'');
if($('.flyout:visible').length==0){ //Open Flyout Sequence
if($(this).data('flyout') == 'directory'){
var attr = $('#content').attr('data-old-height');
if (typeof attr !== typeof undefined && attr !== false) {
$('#content').height(attr);
}
}
if($('#logo .shield').length > 0){
if($('#logo .shield').hasClass('on')){
$('#logo .shield').removeClass('on').addClass('off transition');
$('#logo .urwordmark').removeClass('off').addClass('on transition');
setTimeout(function(){
$('#logo a').removeClass('transition');
},250);
}
}
$('.flyout').hide();
$('.flyout.'+$(this).data('flyout')).show();
var height = $('#toolbar .viewer').height();
$('#toolbar .viewer').height(0).show().animate({
height: height
}, 300, function(){
$(this).css('height', 'auto');
toolbarAnimating = false;
});
} else if(! $('.flyout:visible').hasClass($(this).data('flyout'))){ //Open Different Flyout
if($(this).data('flyout') == 'directory'){
var attr = $('#content').attr('data-old-height');
if (typeof attr !== typeof undefined && attr !== false) {
$('#content').height(attr);
}
}
var oldheight = $('#toolbar .viewer').height();
$('.flyout').hide();
$('.flyout.'+$(this).data('flyout')).show();
var height = $('#toolbar .viewer').height();
$('#toolbar .viewer').height(oldheight).animate({
height: height
}, 300, function(){
$(this).css('height', 'auto');
$('#content').height('auto');
toolbarAnimating = false;
});
} else if($('.flyout:visible').hasClass($(this).data('flyout'))){ //Close Flyout Sequence
$(this).parents('.buttonWrap').removeClass('on');
if($('#stage').is(':hidden') || $('#stage').length==0){ //if the stage is hidden or the stage does not exist. #stage is an element of www only
if($('#logo .shield').length > 0){
$('#logo .shield').removeClass('off').addClass('on transition');
$('#logo .urwordmark').removeClass('on').addClass('off transition');
setTimeout(function(){
$('#logo a').removeClass('transition');
},250);
}
}
var height = $('#toolbar .viewer').height();
$('#toolbar .viewer').height(height).animate({
height: 0
}, 300, function(){
$(this).hide().css('height', 'auto');
$('.flyout').hide();
$('#content').height('auto');
toolbarAnimating = false;
});
}
return false; //Prevents anchor tag click
}
});
}
function heroAutoScroller(){
var scroller = $('#heroScroller');
var scrollControls;
var zIndex = scroller.children('.scrollWrap').length;
var activeIndex = 0;
var pauseScroller = false;
var panelSwapping = false;
//Pie chart timer variables
var loader;
var alpha = 0;
var pi = Math.PI;
var time = 23; //Time in milliseconds before draw is called again. 23*360 = 8280, or 8.280 seconds
//Testing
//var start;
function fadeIn(activeIndex){
panelSwapping = true;
var activePanel = scroller.find('.scrollWrap:eq(' + activeIndex + ')');
var img = $('#heroScroller .scrollWrap:eq(' + activeIndex + ') .responsiveImg');
resizeImg(img);
activePanel.css({
'z-index' : zIndex + 1
});
activePanel.fadeIn(500, function(){
$(this).css({
position: 'relative',
'z-index' : zIndex
});
scroller.find('.scrollWrap:not(:eq(' + activeIndex + '))').hide().css({
'z-index' : 'auto',
position: 'absolute'
});
panelSwapping = false;
});
scrollControls.find('.controlElement').removeClass('on');
scrollControls.find('.controlElement:eq(' + activeIndex + ')').addClass('on');
}
function advancePanel(){
activeIndex++;
if(activeIndex > scroller.find('.scrollWrap').length - 1){
activeIndex = 0;
}
fadeIn(activeIndex);
}
function draw(){
if(pauseScroller == false) {
alpha++;
alpha %= 360;
var r = ( alpha * pi / 180 )
, x = Math.sin(r) * 125
, y = Math.cos(r) * -125
, mid = ( alpha > 180 ) ? 1 : 0
, anim = 'M 0 0 v -125 A 125 125 1 '
+ mid + ' 1 '
+ x + ' '
+ y + ' z';
loader.attr('d', anim);
if (alpha == 0) {
advancePanel();
}
setTimeout(draw, time); // Redraw
}
}
scroller.after('
');
scrollControls = $('#scrollControls .controlsWrap');
scroller.find('.scrollWrap').each(function(){
if($(this).index() != 0){
//Hides all but the first slide on initialization. First slide provides the initial pressure to #heroScroller
$(this).hide();
resizeImg($(this).find('.responsiveImg'));
} else {
$(this).css({
'z-index' : zIndex
});
}
var title = $(this).find('.content h2').text();
var printableIndex = $(this).index() + 1;
var isOn = '';
if(title == '' || title == 'undefined'){
title = 'Panel ' + printableIndex;
}
if($(this).index() == 0){
isOn = ' on';
}
scrollControls.append('');
});
$(document).on('click', '#scrollControls .controlElement', function(){
if(panelSwapping == false) {
activeIndex = $(this).index();
alpha = 0;
//resets the pie chart timer
if( (typeof(isMobile) != 'undefined') && (isMobile == true) ){
pauseScroller = true;
}
scrollControls.find('.loader').attr('d', 'M 0 0 v -125 A 125 125 1 0 1 0 -125 z');
fadeIn(activeIndex);
}
});
//if(!isMobile == true){
if( (typeof(isMobile) != 'undefined') && (isMobile == false) ){
$("#heroWrap .content, #scrollControls .controlsWrap").hover(
function() {
pauseScroller = true;
}, function() {
pauseScroller = false;
draw();
}
);
}
loader = scrollControls.find('.loader');
//start = new Date().getTime();
draw();
}
function heroSlider() {
var slider = $('#heroSlider');
var numChildren = slider.children().length;
slider.children().hide();
slider.width(99999);
slider.children().each(function(){
$(this).width($(window).width());
$(this).show();
});
if(numChildren > 1){
slider.find('.parallaxWrap:first-child').addClass('on');
slider.parent().prepend('');
}
$('#hero-next').click(function(){
var hero = slider.find('.on');
if(hero.index() + 1 == numChildren - 1){
$('#hero-next').hide();
}
if(!$('#hero-prev').is(":visible")){
$('#hero-prev').show();
}
hero.next().addClass('on');
hero.removeClass('on');
var offset = (hero.index()+1) * 100 * -1;
slider.css({ marginLeft: offset+'%' });
});
$('#hero-prev').click(function(){
var hero = slider.find('.on');
if(hero.index() == 1){
$('#hero-prev').hide();
}
if(!$('#hero-next').is(":visible")){
$('#hero-next').show();
}
hero.prev().addClass('on');
hero.removeClass('on');
var offset = (hero.index()-1) * 100 * -1;
slider.css({ marginLeft: offset+'%' });
});
}
function heroParallax(img){
var windowWidth = $(window).width();
var responsiveImg = img.closest('.responsiveImg');
var parallaxWrap = responsiveImg.parent();
parallaxWrap.width(windowWidth);
var wrapHeight = Math.floor((windowWidth/2)*.7); //Always uses 2:1 images, so half the windowWidth should equal height
if(wrapHeight > 500){
wrapHeight = 500; //This is set in the css too as an initial value for parallaxWrap
}
parallaxWrap.height(wrapHeight);
var scrollTop = $(window).scrollTop();
if(scrollTop < 0){
scrollTop = 0;
}
var elementOffset = parallaxWrap.offset().top;
var distance = elementOffset + parallaxWrap.height();
var offset = ((windowWidth/2) - parallaxWrap.height()) * -1;
/*
if (scrollTop >= 0 && scrollTop <= distance) {
//Top of image to bottom
var percentageDown = scrollTop/distance;
var newTop = offset * percentageDown;
responsiveImg.css('margin-top',newTop+'px');
}
*/
if (scrollTop >= 0 && scrollTop <= distance) {
//Center of image to bottom
var percentageDown = scrollTop/distance;
var newTop = (offset/2) - (percentageDown * (offset/2));
responsiveImg.css('margin-top',newTop+'px');
} else {
responsiveImg.css('margin-top','0px');
}
}
function spotlightAutoScroller(){
var scroller = $('#spotlightScroller');
var padder = $('#spotlightScroller #spotlightPadder');
var scrollControls = $('#spotlights #scrollControls');
var activeIndex = 0;
var pauseScroller = false;
//Pie chart timer variables
var loader;
var alpha = 0;
var pi = Math.PI;
var time = 30; //Time in milliseconds before draw is called again. 30*360 = 10800, or 10.8 seconds
function advanceIndex(advanceBy){
padder.find('.scrollWrap').each(function(){
var newIndex;
newIndex = parseInt($(this).attr('data-index')) - advanceBy;
// On an sample length of -3
if(newIndex <= (padder.find('.scrollWrap').length -1) * -1){
// Less than
newIndex = newIndex + padder.find('.scrollWrap').length;
// 1 = -3 + 4
}
// On an sample length of 3
if(newIndex >= padder.find('.scrollWrap').length -1){
// Greater than
newIndex = newIndex - padder.find('.scrollWrap').length;
// -1 = 3 - 4;
}
if(newIndex == 0){
$(this).addClass('active');
} else {
$(this).removeClass('active');
}
$(this).attr('data-index',newIndex);
});
// Keep scroll controls locked in step with active element in the scroller
if(typeof scrollControls != 'undefined') {
if(padder.find('.active').index() != scrollControls.find('.on').index()) {
scrollControls.find('.on').removeClass('on');
scrollControls.find('.controlElement:eq(' + padder.find('.active').index() + ')').addClass('on');
}
}
if(advanceBy > 0) {
padder.addClass('slideLeft' + Math.abs(advanceBy));
setTimeout(function () {
padder.removeClass('slideLeft' + Math.abs(advanceBy));
if(modalInit == true){
modalInit = false;
}
}, 400);
}
if(advanceBy < 0) {
padder.addClass('slideRight' + Math.abs(advanceBy));
setTimeout(function () {
padder.removeClass('slideRight' + Math.abs(advanceBy));
if(modalInit == true){
modalInit = false;
}
}, 400);
}
}
function draw(){
if(pauseScroller == false) {
alpha++;
alpha %= 360;
var r = ( alpha * pi / 180 )
, x = Math.sin(r) * 125
, y = Math.cos(r) * -125
, mid = ( alpha > 180 ) ? 1 : 0
, anim = 'M 0 0 v -125 A 125 125 1 '
+ mid + ' 1 '
+ x + ' '
+ y + ' z';
loader.attr('d', anim);
if (alpha == 0) {
advanceIndex(1);
}
setTimeout(draw, time); // Redraw
}
}
function resetTimer(){
alpha = 0;
//resets the pie chart timer
if( (typeof(isMobile) != 'undefined') && (isMobile == true) ){
pauseScroller = true;
}
scrollControls.find('.loader').attr('d', 'M 0 0 v -125 A 125 125 1 0 1 0 -125 z');
}
$(document).on('click', '#spotlights #scrollControls .controlElement', function(){
activeIndex = $(this).index();
resetTimer();
if($(this).index() != padder.find('.active').index()){
var virtualIndex = parseInt(padder.find('.scrollWrap:eq(' + $(this).index() + ')').attr('data-index'));
advanceIndex(virtualIndex);
}
});
if(jQuery().hammer){ // if hammer.js is loaded
$('#spotlightScroller .scrollWrap a').on('click',function(event){
event.preventDefault(); // Prevents default anchor functionality
});
$('#spotlightScroller .scrollWrap').hammer().on('swiperight',function(event){
modalInit = true; // prevents modal events from firing on swipes
event.stopPropagation();
event.preventDefault();
resetTimer();
advanceIndex(-1);
}).on('swipeleft',function(event){
modalInit = true; // prevents modal events from firing on swipes
event.stopPropagation();
event.preventDefault();
resetTimer();
advanceIndex(1);
}).on('tap',function(event){
if($(this).find('a').length > 0) {
window.location.href = $(this).find('a').attr('href');
}
});
} else {
console.log('Hammer.js not loaded.');
}
if( (typeof(isMobile) != 'undefined') && (isMobile == false) ){
scroller.parent().hover(
function() {
pauseScroller = true;
}, function() {
pauseScroller = false;
draw();
}
);
}
loader = scrollControls.find('.loader');
draw();
}
function fullscreenSlideshow(){
var slideSwapping = false;
$('.fullscreenSlideshow').each(function(){
loadImg(1, $(this));
if($(this).find('.slider > div').length > 1){
bindSlideshowEvents($(this));
$(this).find('.next').show();
}
});
function loadImg(i, parent){
var imageSrc = parent.find('.linkset a:eq('+i+')').attr('href');
parent.find('.slider').append('
');
parent.find('.slider div:last-child img').load(function(){
if(i < parent.find('.linkset a').length - 1){
loadImg(i + 1, parent);
}
});
}
function fadeIn(parent, activeIndex){
slideSwapping = true;
var activePanel = parent.find('.slider > div:eq(' + activeIndex + ')');
var zIndex = 1;
parent.height(activePanel.height()); //Allows smooth animation between photos of different height
if (activeIndex == parent.find('.slider > div').length - 1) {
parent.find('.controls .next').hide();
} else {
parent.find('.controls .next').show();
}
if (activeIndex == 0) {
parent.find('.controls .previous').hide();
} else {
parent.find('.controls .previous').show();
}
activePanel.css({
'z-index' : zIndex + 1,
'opacity' : 0
});
activePanel.show().animate({
'z-index' : zIndex,
'opacity' : 1
}, 400, function(){
parent.find('.slider > div:not(:eq(' + activeIndex + '))').hide().css({
'z-index' : 'auto',
position: 'absolute',
'opacity' : 0
}).addClass('off').removeClass('on');
activePanel.css('position','relative').addClass('on').removeClass('off');
slideSwapping = false;
});
}
function bindSlideshowEvents(parent){
parent.find('.next').on('click', function(){
if(slideSwapping == false) {
var activeIndex = parent.find('.slider .on').next().index();
fadeIn(parent, activeIndex);
}
});
parent.find('.previous').on('click', function(){
if(slideSwapping == false) {
var activeIndex = parent.find('.slider .on').prev().index();
fadeIn(parent, activeIndex);
}
});
$(window).on('resize', parent, function(){
if(slideSwapping == false){
parent.height('auto'); //Allows parent to resize on with window
}
});
}
}
function calculateDimensions(element){
var elementWidth;
var elementHeight;
var availableWidth = $(window).width() * .65; //Controls take up 20% of width, additional 15% for padding
var availableHeight = $('.modalShade .slideshowWrap .player').height();
if(element.find('img').length > 0){
element = element.find('img').first();
}
if(element[0].nodeName == 'IMG'){
var wait = setInterval(function () {
if (element[0].naturalWidth === undefined) {
var i = new Image();
i.src = element[0].src;
elementWidth = i.width;
elementHeight = i.height;
} else {
elementWidth = element[0].naturalWidth;
elementHeight = element[0].naturalHeight;
}
if (elementWidth && elementHeight) {
clearInterval(wait);
resizeThisImage();
}
}, 30);
}
if(element[0].nodeName == 'SPAN'){
element.width(availableWidth).height('auto');
}
function resizeThisImage() {
element.height(availableHeight).width('auto');
//Update width after first resize
elementWidth = element.width();
if (elementWidth > availableWidth) {
element.width(availableWidth).height('auto');
}
//Update width after first resize
elementWidth = element.width();
if (element.prev().is('button')) {
var left = elementWidth / 2;
element.prev().css('left', left + 'px');
}
}
}
function bindSlideshowEvents(){
$('.modalShade .slideshowWrap .next').on('click', function(){
var active = $('.modalShade .slideshowWrap .slider .active').index();
var queued = active + 2;
var previous = active - 1;
var next = active + 1;
$('.modalShade .slideshowWrap .slider > *').addClass('animating');
setTimeout(function(){
$('.modalShade .slideshowWrap .slider > *').removeClass('animating');
}, 400); //Animating class enables css transitions for margin-left. Removed with setTimeout that matches the css transition length
if(($('.modalShade .slideshowWrap .captions .caption').length - 1) > active) {
$('.modalShade .slideshowWrap .captions .active').removeClass('active');
$('.modalShade .slideshowWrap .captions .caption:eq(' + next + ')').addClass('active').removeClass('off');
}
$('.modalShade .slideshowWrap .slider > *:eq('+queued+')').removeClass('off');
$('.modalShade .slideshowWrap .slider > *:eq('+previous+')').addClass('off');
$('.modalShade .slideshowWrap .slider > *:eq('+active+')').addClass('prevQueue').removeClass('active');
calculateDimensions($('.modalShade .slideshowWrap .slider > *:eq('+active+')'));
$('.modalShade .slideshowWrap .slider > *:eq('+next+')').addClass('active').removeClass('nextQueue off');
calculateDimensions($('.modalShade .slideshowWrap .slider > *:eq('+next+')'));
if($('.modalShade .slideshowWrap .slider .nextQueue').length == 0){
$('.modalShade .slideshowWrap .controls .next').hide();
if($(this).parents('.modalShade').hasClass('instagram')){
var id = $(this).parents('.modalShade').data('id');
if($('.instagramRow[data-id='+id+']').find('.panel').last().attr('data-maxid') != 'false'){
$('.instagramRow[data-id='+id+']').addClass('isLoading');
getInstagramData(id, function(){
$('.instagramRow[data-id='+id+']').find('.panel').last().removeClass('on');
});
}
}
} else {
$('.modalShade .slideshowWrap .controls .next').show();
}
if($('.modalShade .slideshowWrap .slider .prevQueue').length == 0){
$('.modalShade .slideshowWrap .controls .previous').hide();
} else {
$('.modalShade .slideshowWrap .controls .previous').show();
}
});
$('.modalShade .slideshowWrap .previous').on('click', function(){
var active = $('.modalShade .slideshowWrap .slider .active').index();
var queued = active - 2;
var previous = active - 1;
var next = active + 1;
$('.modalShade .slideshowWrap .slider > *').addClass('animating');
setTimeout(function(){
$('.modalShade .slideshowWrap .slider > *').removeClass('animating');
}, 400); //Animating class enables css transitions for margin-left. Removed with setTimeout that matches the css transition length
if(active > 0) {
$('.modalShade .slideshowWrap .captions .active').removeClass('active');
$('.modalShade .slideshowWrap .captions .caption:eq(' + previous + ')').addClass('active');
}
if(queued >= 0){
$('.modalShade .slideshowWrap .slider > *:eq('+queued+')').addClass('prevQueue').removeClass('off');
}
$('.modalShade .slideshowWrap .slider > *:eq('+previous+')').addClass('active').removeClass('prevQueue');
calculateDimensions($('.modalShade .slideshowWrap .slider > *:eq('+previous+')'));
$('.modalShade .slideshowWrap .slider > *:eq('+active+')').addClass('nextQueue').removeClass('active');
calculateDimensions($('.modalShade .slideshowWrap .slider > *:eq('+active+')'));
$('.modalShade .slideshowWrap .slider img:eq('+next+')').addClass('off');
if($('.modalShade .slideshowWrap .slider .nextQueue').length == 0){
$('.modalShade .slideshowWrap .controls .next').hide();
} else {
$('.modalShade .slideshowWrap .controls .next').show();
}
if($('.modalShade .slideshowWrap .slider .prevQueue').length == 0){
$('.modalShade .slideshowWrap .controls .previous').hide();
} else {
$('.modalShade .slideshowWrap .controls .previous').show();
}
});
}
function modalSlideshow(type, id, title, showcaptions, index){
if(typeof index == 'undefined'){
index = 0;
}
var slideshow = {
title: title,
id: id,
type: type,
showcaptions: showcaptions,
index: index
};
function loadImg(i){
var imageSrc = $('.modalShade .slideshowWrap .linkset a').eq(i).attr('href');
var caption = $('.modalShade .slideshowWrap .linkset a').eq(i).attr('data-caption');
var needleIndex;
var resizeDelay = 100;
if(typeof $('.modalShade .slideshowWrap').attr('data-needle') === 'undefined'){
$('.modalShade .slideshowWrap').attr('data-needle',i);
needleIndex = i;
} else {
needleIndex = parseInt($('.modalShade .slideshowWrap').attr('data-needle'));
}
if($('.modalShade .slideshowWrap .slider img').length == 0){ //If this is the first image to be loaded in the modal set
$('.modalShade .slideshowWrap .slider').append('');
$('.modalShade .slideshowWrap .captions').append('