
/* Merged Plone Javascript file
 * This file is dynamically assembled from separate parts.
 * Some of these parts have 3rd party licenses or copyright information attached
 * Such information is valid for that section,
 * not for the entire composite file
 * originating files are separated by - filename.js -
 */

/* - ++resource++plonetruegallery-portlet.js - */
// http://www.jba.org.jm/portal_javascripts/++resource++plonetruegallery-portlet.js?original=1
(function($){$.fn.imagesLoaded=function(callback){var elems=this.filter('img'),len=elems.length;elems.bind('load',function(){if(--len<=0){callback.call(elems,this)}}).each(function(){if(this.complete||this.complete===undefined){var src=this.src;this.src='#';this.src=src}})};
function set_controls_position(container){var width=container.find('img').width();var left=(width/2)-43;container.find('div.gallery-portlet-controls').css("left",left)}
function get_image(link){var linkele=link[0];if(linkele.active!=undefined&&linkele.active){return}
linkele.active=true;var container=link.parents('dl.applied-portlet-gallery');var controls=link.parents('div.gallery-portlet-controls');var portlet_item=link.parents('dd.portletItem');var next=controls.find('span.next a');var prev=controls.find('span.prev a');var img=container.find('img');$.ajax({url:'@@get-image-for-gallery-portlet',data:link.attr('href').split('?')[1],type:'GET',success: function(data,results){eval("var json="+data);var newimg=document.createElement('img');newimg.src=json.src;newimg.width=img.width();newimg=$(newimg);newimg.css('display','none');portlet_item.css('height',img.height());img.fadeOut(1000, function(){img.replaceWith(newimg);newimg.imagesLoaded(function(){portlet_item.animate({height:$(this).height()},500,'linear');$(this).fadeIn(1000, function(){linkele.active=false})},newimg)
var linked=newimg.parent()
linked.attr('href',json['image-link']);linked.attr('title',json['title']);linked.attr('alt',json['description']);next.attr('href',next.attr('href').split('?')[0]+'?'+json['next-url']);prev.attr('href',prev.attr('href').split('?')[0]+'?'+json['prev-url']);set_controls_position(container)})}})}
function get_timeout_ele(portlet){if(portlet.hasClass('portletItem')){portlet=portlet.parent()}
return portlet.find("input.timeout_id")}
function get_timeout_id(portlet){var timeout_id=get_timeout_ele(portlet);if(timeout_id.size()==0){return 0}else{return parseInt(timeout_id.attr('value'))}}
function set_timeout_id(portlet,val){var timeout_id=get_timeout_ele(portlet);if(timeout_id.size()==0){portlet.append('<input type="hidden" name="timeout_id" class="timeout_id" value="'+val+'" />')}else{timeout_id.attr('value',val)}}
function perform_play(portlet){portlet.find('span.next a').trigger('click');set_timeout_id(portlet,setTimeout(function(){perform_play(portlet)},5000))}
function play(portlet){portlet.find('span.play-pause').addClass('timed');set_timeout_id(portlet,setTimeout(function(){perform_play(portlet)},5000))}
function pause(portlet){clearTimeout(get_timeout_id(portlet));portlet.find('span.play-pause').removeClass('timed')}
$(document).ready(function(){$('dl.portletGallery span.next a,dl.portletGallery span.prev a').click(function(){get_image($(this));return false});$('dl.portletGallery span.play-pause').css({'display':'inline'});var portlets=$('dl.portletGallery');portlets.addClass('applied-portlet-gallery');portlets.each(function(){var portlet=$(this);set_controls_position(portlet);if(portlet.hasClass('timed')){play(portlet)}else{pause(portlet)}});$('dl.portletGallery span.play-pause a').click(function(){var portlet=$(this).parent().parent().parent();if(portlet.find('span.play-pause').hasClass('timed')){pause(portlet)}else{play(portlet)}
return false});$('dl.portletGallery').hover(
function(){var controls=$(this).find('div.gallery-portlet-controls:not(.hide)');controls.fadeIn()},
function(){var controls=$(this).find('div.gallery-portlet-controls:not(.hide)');controls.fadeOut()})})})(jQuery);

/* - visualbox.js - */
// http://www.jba.org.jm/portal_javascripts/visualbox.js?original=1
(function($){$(document).ready(function(){$(".visualBoxEntry").mouseenter(
function(){$(this).find("img").fadeOut(560, function(){})});$(".visualBoxEntry").mouseleave(
function(){$(this).find("img").fadeIn(480, function(){})})})})(jQuery);

/* - ++resource++bling-slider.js - */
function slideShow(target, interval, repeat, links) {
    var running = true;
    var timer;
    
    // Speeds can be "fast", "slow", or a numerical value (in milliseconds).
    // Set to 0 to disable the effect.
    var imageShowSpeed = "slow";
    var imageHideSpeed = "slow";
    var captionShowSpeed = "slow";
    var captionHideSpeed = "fast";

    (function($) {
        //append a LI item to the UL list for displaying caption
        caption = $('<li class="caption slideshow-caption"><div class="slideshow-caption-container"><h3></h3><p></p></div></li>');
        if(links)
            $('div', caption).append('<a class="read-more" href="">Read More</a>');
        $('ul.slideshow', target).append(caption);

        //Hide all slideshow images
        $('.slideshow-image', target).hide();
        
        //Get the first image and display it (set it to full opacity)
        first = $('.slideshow-image:first', target)
        first.addClass('show').show();
        
        //Get the caption of the first image from REL attribute and display it
        $('.slideshow-caption', target)
            .find('h3').html($('img', first).attr('title'))
            .find('p').html($('img', first).attr('alt'));
        if(links)    
            $('.slideshow-caption a', target).attr('href', $('a'. first).attr('href'));
        
        var gallery = function() {
            var current = $('.slideshow-image.show', target);
            //Get next image, if it reached the end of the slideshow, rotate it back to the first image
            var next = current.next('.slideshow-image');
            if (next.length == 0){
                if(repeat) {
                    next = $('.slideshow-image:first', target);
                } else {
                    running = false;
                    return;
                }
            }
            
            //Get next image caption
            var title = $('img', next).attr('title');
            var desc = $('img', next).attr('alt');
            var href = links ? $('a', next).attr('href') : '';
            
            //Set the fade in effect for the next image, show class has higher z-index
            next.fadeIn(imageShowSpeed).addClass('show');
            
            //Hide the caption first, and then set and display the caption
            $('.slideshow-caption', target).slideUp(captionHideSpeed, function () {
                $('h3', this).html(title);
                $('p', this).html(desc);
                if(links)
                    $('a', this).attr('href', href);
                $(this).slideDown(captionShowSpeed);
            });
            
            //Hide the current image
            current.fadeOut(imageHideSpeed).removeClass('show');
            timer = setTimeout(gallery, interval);
        };
        
        //Call the gallery function to run the slideshow
        timer = setTimeout(gallery, interval);
        
        //pause the slideshow on mouse over
        $('ul.slideshow', target).hover(
            function () {
                if(running)
                    clearTimeout(timer);
            },
            function () {
                if(running)
                    timer = setTimeout(gallery, interval);
            }
        );
    })(jQuery);

}


