');
switchView.html('View Images');
switchView.attr('data-media', 'image');
}else{
dCarousel.find('.carousel-inner').append('
');
switchView.html('View Videos');
switchView.attr('data-media', 'video');
}
jContainer.append('
');
});
$('.mediaGallery_imageContainer_controls .count').html(eMedia.length);
reBuild();
},
complete: function(data) {
if(media == 'video') {
$('#vidframe').on('load', function(){
$("#loading").hide();
});
}else{
$("#loading").hide();
}
}
});
}
function showMedia(mediaType){
dCarousel.find('.carousel-inner').html('');
jContainer.html('');
$("#loading").show();
getMedia(mediaType);
$('#mediaGallery, #mediaGallery .' + mediaType).show();
$("html, body").scrollTop(0).css({overflow:'hidden'});
}
switchView.click(function(){
var mediaType = $(this).attr('data-media');
showMedia(mediaType);
});
/** when we tap the gallery trigger, work out which gallery to show, show it and add overflow hidden to body **/
$('.mediaGalleryTrigger.trig-trig').click(function () {
var mediaType = $(this).attr('data-media');
showMedia(mediaType);
});
/** when we tap the close button inside the gallery, hide the gallery and remove overflow hidden from body **/
$('#mediaGallery .close').click(function(){
$('#mediaGallery, #mediaGallery .video, #mediaGallery .image').hide();
$("html, body").attr('style', '');
});
window.addEventListener('deferEnd', function(){
$('#detailsCarousel').carousel('pause');
});
reBuild();
window.addEventListener('resize', function(){
reBuild();
});
function reBuild(){
var dImage = $('#detailsCarousel .item img');
/** get offset dependant on whether thumbnails should be showing **/
var offset = ($(window).width() 1400){
$('.image-thumb').css({width: $(window).width() / 12 + 'px'});
}else if($(window).width() > 1100){
$('.image-thumb').css({width: $(window).width() / 9 + 'px'});
}else if($(window).width() > 900){
$('.image-thumb').css({width: $(window).width() / 7 + 'px'});
}else{
$('.image-thumb').css({width: $(window).width() / 6 + 'px'});
}
}
/** handle the tapping of the start slideshow button **/
$('.slideshow-control').on('click', function(){
if($(this).hasClass('start-slideshow')){
$('#detailsCarousel').carousel('cycle');
$(this).html('
Pause Slideshow
');
}else{
$('#detailsCarousel').carousel('pause');
$(this).html('
Play Slideshow
');
}
$(this).toggleClass('start-slideshow');
});
var container = document.querySelector('.thumb-container');
// Set up plugin to leverage Collection Service and pass in the container
var collection = new CollectionService(container);
var handleThumb = new vehicleThumb(collection, container, 'activeimage', true);
var total = $('#detailsCarousel .carousel-inner .item').length;
var index = $('#detailsCarousel .carousel-inner .item.active').index() + 1;
/**
* We have already cached current large image position
* When the bootstrap carousel (large images) has finished sliding, remove the active thumb, change the image count to be the item index +1
* work out if we moved left or right and set the corresponding thumb to active
* Call translateThumbs from the vehicle thumb plugin to handle the animation of the thumbnails moving.
* recache new position of active large image for use next time this event is triggered.
*
*/
dCarousel.bind('slid.bs.carousel', function(e) {
$('.image-thumb').removeClass('activeimage');
var item = $('#detailsCarousel .carousel-inner .item.active');
$('.mediaGallery_imageContainer_controls .current').html(item.index() + 1);
if(item.index() + 1 == total && index == 1){
direction = 'Right';
}else if(item.index() + 1 == 1 && total == index ){
direction = 'Left';
}else{
direction = (index 0){
newLeft = 0
}
jContainer.css('left', newLeft + 'px');
}
});
/** handle swipe **/
var detailsCarousel = document.getElementById('detailsCarousel');
function swipeLeft(){
$('#detailsCarousel').carousel('next');
}
function swipeRight(){
$('#detailsCarousel').carousel('prev');
}
/**
* pass in an elem(node), and two callback functions to handle what to do when you swipe left and right on the elem.
*/
AW_lib.touchSwipe(detailsCarousel, swipeLeft, swipeRight);
/** end handle swipe **/
}());