<%
function get_youtube_id(url) {
    var regExp = /^.*(youtu\.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/;
    var match = url.match(regExp);
    if (match && match[2].length == 11) {
        return match[2];
    } else {
        return false;
    }
}

function get_vimeo_id(url) {
    var regExp = /https?:\/\/(www\.)?vimeo.com\/(\d+)($|\/)/;
    
    var match = url.match(regExp);
    
    if (match){
        return match[2];
    } else {
        return false;
    }
}

function get_dailymotion_id(url) {
    var regExp = /^(?:(?:http|https):\/\/)?(?:www.)?(dailymotion\.com|dai\.ly)\/((video\/([^_]+))|(hub\/([^_]+)|([^\/_]+)))$/;

    var match = url.match(regExp);

    if (match) {
        if(match[4] !== undefined) {
            return match[4];
        }
        return match[2];
    }
    return false;
}

function get_facebook_id(url) {
    var regExp = /^https?:\/\/www\.facebook\.com\/(?:video\.php\?v=\d+|.*?\/videos\/\d+)\/?$/;
    
    var match = url.match(regExp);

    if (match) {
        return encodeURIComponent(url);
    }
    return false;
}

%>
<h2>
    <span class="Rk-CloseX">&times;</span>
    <% if (options.show_node_tooltip_color) { %>
        <span class="Rk-UserColor" style="background: <%-node.color%>;"></span>
    <% } %>
    <span class="Rk-Display-Title">
        <% if (node.uri) { %>
            <a href="<%-node.uri%>" target="_blank">
        <% } %>
        <%=node.title%>
        <% if (node.uri) { %></a><% } %>
    </span>
</h2>
<% if (node.uri && options.show_node_tooltip_uri) {
    var video_id = false;
    if(video_id = get_youtube_id(node.uri)) { %>
        <iframe width="255" height="143" src="https://www.youtube.com/embed/<%=video_id%>" frameborder="0"></iframe>
        <p><a href="<%-node.uri%>" target="_blank"><%-renkan.translate("Link")%></a></p>
    <%  }
    else if(video_id = get_vimeo_id(node.uri)) { %>
        <iframe src="https://player.vimeo.com/video/<%=video_id%>" width="255" height="143" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
        <p><a href="<%-node.uri%>" target="_blank"><%-renkan.translate("Link")%></a></p>
    <%  }
    else if(video_id = get_dailymotion_id(node.uri)) { %>
        <iframe frameborder="0" width="255" height="143" src="https://www.dailymotion.com/embed/video/<%=video_id%>?autoPlay=0" allowfullscreen=""></iframe>
        <p><a href="<%-node.uri%>" target="_blank"><%-renkan.translate("Link")%></a></p>
    <%  }
    else if(video_id = get_facebook_id(node.uri)) { %>
        <iframe src="https://www.facebook.com/plugins/video.php?href=<%=video_id%>&width=255&show_text=false&height=143&appId" width="255" height="143" style="border:none;overflow:hidden" scrolling="no" frameborder="0" allowTransparency="true" allowFullScreen="true"></iframe>
        <p><a href="<%-node.uri%>" target="_blank"><%-renkan.translate("Video link")%></a></p>
    <%  }
    else { %> 
        <video width="320" height="240" controls>
            <source src="<%-node.uri%>" type="video/mp4">
        </video>
    <%  }
    }
%>
    <a href="#?idnode=<%-node._id%>"><%-renkan.translate("Link to the node")%></a>
