
/* 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 -
 */

/* - fancyzoom-integration.js - */
// http://www.amnesty.ch/portal_javascripts/fancyzoom-integration.js?original=1
jQuery.fn.fancyzoom=function(){this.each(function(){var jqobj=jq(this);var img_class=jqobj.find('img.zoomable').attr('class');jqobj.find('img.zoomable').wrap('<div class="zoomable"></div>').removeAttr('class');jqobj.find('div.zoomable').attr('class',img_class);jqobj.find('.zoomable img').after('<div class="zoomIn"></div>');jqobj.find('.zoomable img').each(function(){var url_parts=jq(this).attr('src').split('/');var img_id,img_src=null;if(url_parts[url_parts.length-2]=='@@images'){img_id=url_parts[url_parts.length-1].replace(/[.]/g,'_');img_src=url_parts.slice(0,url_parts.length-2).join('/')}
else if(url_parts[url_parts.length-3]=='@@images'){img_id=url_parts[url_parts.length-4].replace(/[.]/g,'_');img_src=url_parts.slice(0,url_parts.length-3).join('/')}
else{img_id=url_parts[url_parts.length-2].replace(/[.]/g,'_');img_src=url_parts.slice(0,url_parts.length-1).join('/')}
jq(this).attr('rel','#zoomed_'+img_id).parents('.zoomable').after('<div class="overlayImage" id="zoomed_'+img_id+'"><img src="'+img_src+'" /></div>')});jqobj.find("img[rel]").overlay({expose:{color:'#ccc',opacity:0.5}})})};jq(document).ready(function(){jq(this).fancyzoom()});

/* - collective.flowplayer.js - */
(function($) {
        $(function() {
            $('.autoFlowPlayer').each(function() {
                var config = {
    "clip": {
        "scaling": "fit", 
        "autoBuffering": false, 
        "autoPlay": false
    }, 
    "plugins": {
        "audio": {
            "url": "http%3A//www.amnesty.ch//%2B%2Bresource%2B%2Bcollective.flowplayer/flowplayer.audio.swf"
        }, 
        "controls": {
            "url": "http%3A//www.amnesty.ch//%2B%2Bresource%2B%2Bcollective.flowplayer/flowplayer.controls.swf", 
            "volume": true
        }
    }
};
                var $self = $(this);
                if ($self.is('.minimal')) {
                    config.plugins.controls = null;
                };
                var audio = $self.is('.audio');
                if (audio && !$self.is('.minimal')) {
                    config.plugins.controls.all = false;
                    config.plugins.controls.play = true;
                    config.plugins.controls.scrubber = true;
                    config.plugins.controls.mute = true;
                    config.plugins.controls.volume = true;
                    config.plugins.controls.time = true;
                    config.plugins.controls.autoHide = false;
                }
                if ($self.is('div')) {
                    // comming from Kupu, there are relative urls
                    config.clip.baseUrl = $('base').attr('href');
                    config.clip.url = $self.find('a').attr('href');
                    if (audio) {
                      // force .mp3 extension
                      config.clip.url = config.clip.url + '?e=.mp3';
                    };
                    // Ignore global autoplay settings
                    if ($self.find('img').length == 0) {
                        // no image. Don't autoplay, remove all elements inside the div to show player directly.
                        config.clip.autoPlay = false;
                        $self.empty();
                    } else {
                        // Clip is probably linked as image, so autoplay the clip after image is clicked
                        config.clip.autoPlay = true;
                    }
                }
                flowplayer(this, {"src": "http://www.amnesty.ch//++resource++collective.flowplayer/flowplayer.swf"}, config).onLoad( function() { this.setVolume(50); });
                $('.flowPlayerMessage').remove();
            });
            $('.playListFlowPlayer').each(function() {
                var config = {
    "clip": {
        "scaling": "fit", 
        "autoBuffering": false, 
        "autoPlay": false
    }, 
    "plugins": {
        "audio": {
            "url": "http%3A//www.amnesty.ch//%2B%2Bresource%2B%2Bcollective.flowplayer/flowplayer.audio.swf"
        }, 
        "controls": {
            "url": "http%3A//www.amnesty.ch//%2B%2Bresource%2B%2Bcollective.flowplayer/flowplayer.controls.swf", 
            "volume": true
        }
    }
};
                var $self = $(this);
                var audio = $self.is('.audio');
                if (audio) { config.plugins.controls.fullscreen = false; }
                if ($self.is('.minimal')) { config.plugins.controls = null; }
                if ($self.find('img').length > 0) {
                    // has splash
                    config.clip.autoPlay = true;
                }
                portlet_parents = $self.parents('.portlet');
                var playlist_selector = 'div#flowPlaylist';
                if (portlet_parents.length > 0) {
                    var portlet = true;
                    // playlist has to be bound to unique item
                    playlist_selector_id = portlet_parents.parent().attr('id')+'-playlist';
                    $self.parent().find('.flowPlaylist-portlet-marker').attr('id', playlist_selector_id);
                    playlist_selector = '#'+playlist_selector_id;
                    if (audio && !$self.is('.minimal')) {
                        config.plugins.controls.all = false;
                        config.plugins.controls.play = true;
                        config.plugins.controls.scrubber = true;
                        config.plugins.controls.mute = true;
                        config.plugins.controls.volume = false;
                    }
                } else {
                    var portlet = false;
                }
                if (!portlet) {
                    $("#pl").scrollable({items:playlist_selector, size:4, clickable:false});
                }
                // manual = playlist is setup using HTML tags, not using playlist array in config
                flowplayer(this, {"src": "http://www.amnesty.ch//++resource++collective.flowplayer/flowplayer.swf"}, config).playlist(playlist_selector, {loop: true, manual: true}).onLoad( function() { this.setVolume(50); });
                $self.show();
                $('.flowPlayerMessage').remove();

            });
        });
})(jQuery);


/* - jquery.tmpl.1.1.1.js - */
// http://www.amnesty.ch/portal_javascripts/jquery.tmpl.1.1.1.js?original=1
(function($){var regx=/#\{([^{}]*)}/g;$.extend({tmpl: function(tmpl){tmpl=tmpl||'';var vals=(2===arguments.length&&'object'===typeof arguments[1]?arguments[1]:Array.prototype.slice.call(arguments,1));var repr=function(str,match){return typeof vals[match]==='string'||typeof vals[match]==='number'?vals[match]:str};return tmpl.replace(regx,repr)}})})(jQuery);

/* - ui.multiselect.js - */
// http://www.amnesty.ch/portal_javascripts/ui.multiselect.js?original=1
(function($){$.widget("ui.multiselect",{options:{sortable:true,searchable:true,animated:'fast',show:'slideDown',hide:'slideUp',dividerLocation:0.6,nodeComparator: function(node1,node2){var text1=node1.text(),text2=node2.text();return text1==text2?0:(text1<text2?-1:1)}},_create: function(){this.element.hide();this.id=this.element.attr("id");this.container=$('<div class="ui-multiselect ui-helper-clearfix ui-widget"></div>').insertAfter(this.element);this.count=0;this.selectedContainer=$('<div class="selected"></div>').appendTo(this.container);this.availableContainer=$('<div class="available"></div>').appendTo(this.container);this.selectedActions=$('<div class="actions ui-widget-header ui-helper-clearfix"><span class="count">0 '+$.ui.multiselect.locale.itemsCount+'</span><a href="#" class="remove-all">'+$.ui.multiselect.locale.removeAll+'</a></div>').appendTo(this.selectedContainer);this.availableActions=$('<div class="actions ui-widget-header ui-helper-clearfix"><input type="text" class="search empty ui-widget-content ui-corner-all"/><a href="#" class="add-all">'+$.ui.multiselect.locale.addAll+'</a></div>').appendTo(this.availableContainer);this.selectedList=$('<ul class="selected connected-list"><li class="ui-helper-hidden-accessible"></li></ul>').bind('selectstart', function(){return false}).appendTo(this.selectedContainer);this.availableList=$('<ul class="available connected-list"><li class="ui-helper-hidden-accessible"></li></ul>').bind('selectstart', function(){return false}).appendTo(this.availableContainer);var that=this;this.container.width(this.element.width()+1);this.selectedContainer.width(Math.floor(this.element.width()*this.options.dividerLocation));this.availableContainer.width(Math.floor(this.element.width()*(1-this.options.dividerLocation)));this.selectedList.height(Math.max(this.element.height()-this.selectedActions.height(),1));this.availableList.height(Math.max(this.element.height()-this.availableActions.height(),1));if(!this.options.animated){this.options.show='show';this.options.hide='hide'}
this._populateLists(this.element.find('option'));if(this.options.sortable){this.selectedList.sortable({placeholder:'ui-state-highlight',axis:'y',update: function(event,ui){that.selectedList.find('li').each(function(){if($(this).data('optionLink'))
$(this).data('optionLink').remove().appendTo(that.element)})},receive: function(event,ui){ui.item.data('optionLink').attr('selected',true);that.count+=1;that._updateCount();that.selectedList.children('.ui-draggable').each(function(){$(this).removeClass('ui-draggable');$(this).data('optionLink',ui.item.data('optionLink'));$(this).data('idx',ui.item.data('idx'));that._applyItemState($(this),true)});setTimeout(function(){ui.item.remove()},1)}})}
if(this.options.searchable){this._registerSearchEvents(this.availableContainer.find('input.search'))} else{$('.search').hide()}
this.container.find(".remove-all").click(function(){that._populateLists(that.element.find('option').removeAttr('selected'));return false});this.container.find(".add-all").click(function(){that._populateLists(that.element.find('option').attr('selected','selected'));return false})},destroy: function(){this.element.show();this.container.remove();$.Widget.prototype.destroy.apply(this,arguments)},_populateLists: function(options){this.selectedList.children('.ui-element').remove();this.availableList.children('.ui-element').remove();this.count=0;var that=this;var items=$(options.map(function(i){var item=that._getOptionNode(this).appendTo(this.selected?that.selectedList:that.availableList).show();if(this.selected) that.count+=1;that._applyItemState(item,this.selected);item.data('idx',i);return item[0]}));this._updateCount()},_updateCount: function(){this.selectedContainer.find('span.count').text(this.count+" "+$.ui.multiselect.locale.itemsCount)},_getOptionNode: function(option){option=$(option);var node=$('<li class="ui-state-default ui-element" title="'+option.text()+'"><span class="ui-icon"/>'+option.text()+'<a href="#" class="action"><span class="ui-corner-all ui-icon"/></a></li>').hide();node.data('optionLink',option);return node},_cloneWithData: function(clonee){var clone=clonee.clone();clone.data('optionLink',clonee.data('optionLink'));clone.data('idx',clonee.data('idx'));return clone},_setSelected: function(item,selected){item.data('optionLink').attr('selected',selected);if(selected){var selectedItem=this._cloneWithData(item);item[this.options.hide](this.options.animated, function(){$(this).remove()});selectedItem.appendTo(this.selectedList).hide()[this.options.show](this.options.animated);this._applyItemState(selectedItem,true);return selectedItem} else{var items=this.availableList.find('li'),comparator=this.options.nodeComparator;var succ=null,i=item.data('idx'),direction=comparator(item,$(items[i]));if(direction){while(i>=0&&i<items.length){direction>0?i++:i--;if(direction!=comparator(item,$(items[i]))){succ=items[direction>0?i:i+1];break}}} else{succ=items[i]}
var availableItem=this._cloneWithData(item);succ?availableItem.insertBefore($(succ)):availableItem.appendTo(this.availableList);item[this.options.hide](this.options.animated, function(){$(this).remove()});availableItem.hide()[this.options.show](this.options.animated);this._applyItemState(availableItem,false);return availableItem}},_applyItemState: function(item,selected){if(selected){if(this.options.sortable)
item.children('span').addClass('ui-icon-arrowthick-2-n-s').removeClass('ui-helper-hidden').addClass('ui-icon');else
item.children('span').removeClass('ui-icon-arrowthick-2-n-s').addClass('ui-helper-hidden').removeClass('ui-icon');item.find('a.action span').addClass('ui-icon-minus').removeClass('ui-icon-plus');this._registerRemoveEvents(item.find('a.action'))} else{item.children('span').removeClass('ui-icon-arrowthick-2-n-s').addClass('ui-helper-hidden').removeClass('ui-icon');item.find('a.action span').addClass('ui-icon-plus').removeClass('ui-icon-minus');this._registerAddEvents(item.find('a.action'))}
this._registerHoverEvents(item)},_filter: function(list){var input=$(this);var rows=list.children('li'),cache=rows.map(function(){return $(this).text().toLowerCase()});var term=$.trim(input.val().toLowerCase()),scores=[];if(!term){rows.show()} else{rows.hide();cache.each(function(i){if(this.indexOf(term)>-1){scores.push(i)}});$.each(scores, function(){$(rows[this]).show()})}},_registerHoverEvents: function(elements){elements.removeClass('ui-state-hover');elements.mouseover(function(){$(this).addClass('ui-state-hover')});elements.mouseout(function(){$(this).removeClass('ui-state-hover')})},_registerAddEvents: function(elements){var that=this;elements.click(function(){var item=that._setSelected($(this).parent(),true);that.count+=1;that._updateCount();return false});if(this.options.sortable){elements.each(function(){$(this).parent().draggable({connectToSortable:that.selectedList,helper: function(){var selectedItem=that._cloneWithData($(this)).width($(this).width()-50);selectedItem.width($(this).width());return selectedItem},appendTo:that.container,containment:that.container,revert:'invalid'})})}},_registerRemoveEvents: function(elements){var that=this;elements.click(function(){that._setSelected($(this).parent(),false);that.count-=1;that._updateCount();return false})},_registerSearchEvents: function(input){var that=this;input.focus(function(){$(this).addClass('ui-state-active')}).blur(function(){$(this).removeClass('ui-state-active')}).keypress(function(e){if(e.keyCode==13)
return false}).keyup(function(){that._filter.apply(this,[that.availableList])})}});$.extend($.ui.multiselect,{locale:{addAll:'Add all',removeAll:'Remove all',itemsCount:'items selected'}})})(jQuery);

/* - amnesty_overlay.js - */
// http://www.amnesty.ch/portal_javascripts/amnesty_overlay.js?original=1
jq(function(){jq('a.overlayForm').each(function(){var link=jq(this);link.prepOverlay({subtype:'ajax',formselector:'.pfg-form form',filter:'#content > *',config:{mask:{}}});link.attr('href','#')});jq('a.overlayVideo').each(function(){var link=jq(this);link.prepOverlay({subtype:'ajax',filter:'#content > #parent-fieldname-text > *',cssclass:'center',config:{mask:{}}});link.attr('href','#')})});

