// source --> https://www.aims-2-trials.eu/wp-content/plugins/imagemapper/imagemapper_script.js?ver=1ec81bb16e19110d06cd036e9644a219 
/* ImageMapper Wordpress frontend script
*/
var Image;
var Canvas, Ctx;

jQuery(function($) {
	
	$('img[usemap]').each(function() {
		var areas = [];
		$('map[name="' + $(this).attr('usemap').substr(1) + '"]').find('area').each(function() {
			areas.push({
				'key': $(this).attr('data-mapkey'),
				'toolTip': $(this).attr('data-tooltip'),
				'isSelectable': false,
				'render_highlight': {
					'fillColor': $(this).attr('data-fill-color'),
					'fillOpacity': $(this).attr('data-fill-opacity'),
					'strokeColor': $(this).attr('data-stroke-color'),
					'strokeOpacity': $(this).attr('data-stroke-opacity'),
					'stroke': $(this).attr('data-stroke-width') > 0,
					'strokeWidth': $(this).attr('data-stroke-width'),
					'fade': true,
					'fadeDuration': 300
				}
			});
		});
		
		var map = this;
		$(this).mapster({
			clickNavigate: true,
			showToolTip: true,
			toolTipContainer: $('<div class="imagemapper-tooltip"></div>'),
			toolTipClose: ['area-click'],
			mapKey: 'data-mapkey',
			onClick: AreaClicked,
			onMouseover: function(m) {
				if(!m.options.toolTip.length)
					$(map).mapster('tooltip', false);
					
				clearTimeout($(map).data('mapster-highlight-timeout'));
				$(map).mapster('highlight', false);
				$(map).mapster('highlight', m.key);
			},
			singleSelect: true,
			render_select: {
				fillOpacity: 0
			},
			areas: areas
		});

		// If pulse option is set, initialize it.
		if(imgmap.pulseOption && imgmap.pulseOption != 'never') {
			$(this).mouseenter(function(e) {
				
				//Prevent pulse from happening when mouse moves on the image map from tooltip or area. (Prevent mouseenter from "inner" elements)
				if($(e.fromElement).hasClass('imagemapper-tooltip') || $(e.fromElement).is('area')) 
					return;
				
				//If this is set true, the pulse has been done already and Wordpress doesn't want to do it again.
				if(!$(this).attr('data-first-mouseenter')) {
					
					//Mark image map as "pulsed" if the first_time pulse option is set.
					if(imgmap.pulseOption == 'first_time')
						$(this).attr('data-first-mouseenter', true);
					
					//Prevent duplicate highlights
					$(this).mapster('highlight', false);
					//Highlight all areas
					for(var area in areas) {
						$(this).mapster('highlight', areas[area].key);
					}
					
					var map = this;
					
					// Stop highlighting after a short delay
					// Also fade highlighted areas out rather than hide them instantly
					clearTimeout($(this).data('mapster-highlight-timeout'));
					$(this).data('mapster-highlight-timeout', setTimeout(function() { 
						$(map).closest('.imgmap-frontend-image').find('canvas').each(function() { 
							$(this).stop().animate({ opacity: 0 }, 300, function() { $(map).mapster('highlight', false); });
						});						
					}, 500));
				}
			});
		}
		//Close tooltips when clicking outside the tooltip.
		$('body').click(function(e) {
			if(!$(e.target).is('.imagemapper-tooltip') && !$(e.target).closest('.imagemapper-tooltip').length && $(e.target).attr('data-type') != 'tooltip')
				$(map).mapster('tooltip', false);
				
			if(!$(e.target).is('.imgmap-dialog-alt') && !$(e.target).closest('.imgmap-dialog-alt').length)
				$('.imgmap-dialog-alt').hide(200);
		}); 
	});
	if(!imgmap.alt_dialog) {
		if($().dialog) {
			$('.imgmap-dialog-wrapper').dialog({ 
				autoOpen: false, 
				zIndex: 10000,
				maxWidth: 700,
				width: 'auto',
				show: 300,
				dialogClass: 'imgmap-dialog',
				position: {
					of: $(parent)
					}
				});
			$('body').click(function(e) {
				if(!$(e.target).is('.ui-dialog, a') && !$(e.target).closest('.ui-dialog').length)
					$('.imgmap-dialog-wrapper').each(function(e) { $(this).dialog('close'); });
			});
		}
		else {
			if($('area[data-type="popup"]').length) {
				
				if(imgmap.admin_logged) {
					var close = $('<a>');
					close.text('Close').css( { cursor: 'pointer', float: 'right', fontSize: '0.9em' });
					close.click(function() { $('.imgmap-dialog-wrapper').text(''); });
					
					$('.imgmap-dialog-wrapper').
					html("There was a problem loading jQuery UI Dialog widget. A plugin or a theme you're using might be including its own copy of jQuery library which causes conflict with the copy included in Wordpress. Because of this ImageMapper isn't able to use jQuery UI Dialog widget causing the popup window function incorrectly or not at all.<br />This message is shown only to an admin. This message is shown because some of the image map areas on this page are using the popup functionality and thus not working properly.").
					css({ color: 'red', padding: '5px', fontSize: '0.8em' }).append(close);
				}
			}
		}
	}
	
	
	
	$('.alternative-links-imagemap').
	click(AlternativeLinkClicked).
	mouseenter(function () {
		var mapster = $($(this).attr('data-parent').replace('imgmap', '#imagemap')).get(0);
		jQuery(mapster).mapster('highlight', false);
		jQuery(mapster).mapster('highlight', $(this).attr('data-key'));
	}).
	mouseleave(function () {
		var mapster = $($(this).attr('data-parent').replace('imgmap', '#imagemap')).get(0);
		jQuery(mapster).mapster('highlight', false);
	});
	
	$('.altlinks-toggle').click(function() {
		$('#altlinks-container-' + $(this).attr('data-parent')).toggle(200);
	});
	
});



function AlternativeLinkClicked() {
	var key = jQuery(this).attr('data-key');
	var type = jQuery(this).attr('data-type');
	var parent = jQuery(this).attr('data-parent');
	AlternativeLinkAction(key, type, parent);
}

function AlternativeLinkAction(areaKey, areaType, imagemap) {
	switch(areaType) {
		case 'popup': 
			OpenImgmapDialog(areaKey, jQuery('map[name="' + imagemap + '"]').get(0));
		break;
		
		case 'tooltip':
			imagemap = jQuery('img[usemap="#' + imagemap + '"]').get(0);
			jQuery(imagemap).mapster('tooltip', areaKey);
		break;
	}
}

function AreaClicked(data) {
	var type = jQuery('area[data-mapKey='+data.key+']').attr('data-type'); 
	if(type == 'popup' || type == '' ) {
		OpenImgmapDialog(data.key, jQuery(this).parent()[0]);
	}
}

function OpenImgmapDialog(key, parent) {
	var image = jQuery('#' + parent.name.replace('imgmap', 'imagemap'));
	var dialog = parent.name.replace('imgmap', '#imgmap-dialog');
	
	jQuery.post(imgmap.ajaxurl, { 
		action: 'imgmap_load_dialog_post',
		id: key.replace('area-', '')
		}, function(response) {
			if(response.length <= 0) return; 
			if(!imgmap.alt_dialog) {
					jQuery(dialog).dialog('option', 'title', jQuery('area[data-mapkey='+key+']').attr('title'));
					jQuery(dialog).html(response).dialog('open');
			} else {
				
				// Some ugly quick bug-fixing code
				// Sometimes it's needed since everything does not always make sense. Or at least seem to do.
				
				// Resets the element
				// Without this centering the element doesn't work well
				jQuery(dialog).replaceWith('<div class="imgmap-dialog-wrapper" id="' + dialog.replace('#','') + '" style="visibility:hidden"></div>').hide(0);
				
				jQuery(dialog).addClass('imgmap-dialog-alt').html(response);
				setTimeout(function() {
					jQuery(dialog).position({ 
						my: 'center',
						at: 'center',
						of: image
					}).
					hide().
					css({visibility:'visible'}).
					show(200);
				}, 0);
				
				
			}
	});
};
// source --> https://www.aims-2-trials.eu/wp-content/plugins/email-encoder-bundle/assets/js/custom.js?ver=2c542c9989f589cd5318f5cef6a9ecd7 
/* Email Encoder */
/*global jQuery, window*/
jQuery(function ($) {

    'use strict';

    // encoding method
    function rot13(s) {
        // source: http://jsfromhell.com/string/rot13
        return s.replace(/[a-zA-Z]/g, function (c) {
            return String.fromCharCode((c <= 'Z' ? 90 : 122) >= (c = c.charCodeAt(0) + 13) ? c : c - 26);
        });
    }

    /**
     * EMAIL RELATED LOGIC
     */

    // fetch email from data attribute
    function fetchEmail(el) {
        var email = el.getAttribute('data-enc-email');

        if (!email) {
            return null;
        }

        // replace [at] sign
        email = email.replace(/\[at\]/g, '@');

        // encode
        email = rot13(email);

        return email;
    }

    // replace email in title attribute
    function parseTitle(el) {
        var title = el.getAttribute('title');
        var email = fetchEmail(el);

        if (title && email) {
            title = title.replace('{{email}}', email);
            el.setAttribute('title', title);
        }
    }

    // set input value attribute
    function setInputValue(el) {
        var email = fetchEmail(el);

        if (email) {
            el.setAttribute('value', email);
        }
    }

    // open mailto link
    function mailto(el) {
        var email = fetchEmail(el);

        if (email) {
            window.location.href = 'mailto:' + email;
        }
    }
    
    // revert
    function revert(el, rtl) {
        var email = fetchEmail(el);

        if (email) {
           rtl.text(email);
           rtl.removeClass('eeb-rtl');
        }
    }

    // prepare for copying email
    document.addEventListener('copy', function(e){
        $('a[data-enc-email]').each(function () {
            var rtl = $(this).find('.eeb-rtl');

            if (rtl.text()) {
                revert(this, rtl);
            }
        });
        console.log('copy');
    });

    // set mailto click
    $('body').on('click', 'a[data-enc-email]', function () {
        mailto(this);
    });

    // parse title attirbute
    $('a[data-enc-email]').each(function () {
        parseTitle(this);
    });

    // parse input fields
    $('input[data-enc-email]').each(function () {
        setInputValue(this);
    });

});
// source --> https://www.aims-2-trials.eu/wp-content/plugins/divi-visual-footer/js/dvf-js.js?ver=1ec81bb16e19110d06cd036e9644a219 
jQuery(function($){

/*
** Check if CDATA exists to know if footer reveal is active
*/
//if( $('script').text().indexOf('footer_reveal_vars') >= 0) {
//    var $footer_active_or_not = footer_reveal_vars.is_footer_reveal_active
//    }


/*
** Add an ID to the Visual Footer placed on the source page
*/
    $( ".page-id-" + pageSelection + " .entry-content > .et_pb_section:last-child" ).attr('id', 'divi-visual-footer');


/*
** Display the Visual Footer before the Divi footer
*/
    $( "#divi-visual-footer" ).insertBefore( "footer" );

/*
** Display the scroll-to-top button after the footer (to avoid calculation bug when "footer reveal" option selected)
*/
    $( ".et_pb_scroll_top" ).insertAfter( "footer" );

/*
** Remove the Visual Footer on blank pages
*/
    if ($( "body" ).hasClass( "page-template-page-template-blank" )) {
        $( "#divi-visual-footer" ).remove();
    }


/*
** DIVI FOOTER + VISUAL FOOTER => wrap the twice, check if footer reveal script is loaded to use footerReveal function
*/
    else {

        if ($("#main-footer").is(":visible")) {
            $('#divi-visual-footer,#main-footer').wrapAll('<div id="default-plus-visual-footer"></div>');

//            if ($footer_active_or_not === 'yes') {
            if ($('script[src*="js/dvf-footer-reveal.js"]').length >= 1) {
                $('#default-plus-visual-footer').footerReveal();
            }
        }


/*
** VISUAL FOOTER ONLY => Check if footer reveal script is loaded to use footerReveal function
*/

            if ($("#main-footer").is(":hidden")) {
//                if ($footer_active_or_not === 'yes') {
                if ($('script[src*="js/dvf-footer-reveal.js"]').length >= 1) {
                    $('#divi-visual-footer').footerReveal();
                }
          }



    } // end else



});