!function(){if(!window.hasCookieConsent){window.hasCookieConsent=!0;var e="cookieconsent_options",t="update_cookieconsent_options",n="cookieconsent_dismissed",i="//cdnjs.cloudflare.com/ajax/libs/cookieconsent2/1.0.9/";if(!(document.cookie.indexOf(n)>-1)){"function"!=typeof String.prototype.trim&&(String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")});var o,s={isArray:function(e){var t=Object.prototype.toString.call(e);return"[object Array]"==t},isObject:function(e){return"[object Object]"==Object.prototype.toString.call(e)},each:function(e,t,n,i){if(s.isObject(e)&&!i)for(var o in e)e.hasOwnProperty(o)&&t.call(n,e[o],o,e);else for(var r=0,c=e.length;c>r;r++)t.call(n,e[r],r,e)},merge:function(e,t){e&&s.each(t,function(t,n){s.isObject(t)&&s.isObject(e[n])?s.merge(e[n],t):e[n]=t})},bind:function(e,t){return function(){return e.apply(t,arguments)}},queryObject:function(e,t){var n,i=0,o=e;for(t=t.split(".");(n=t[i++])&&o.hasOwnProperty(n)&&(o=o[n]);)if(i===t.length)return o;return null},setCookie:function(e,t,n,i,o){n=n||365;var s=new Date;s.setDate(s.getDate()+n);var r=[e+"="+t,"expires="+s.toUTCString(),"path="+o||"/"];i&&r.push("domain="+i),document.cookie=r.join(";")},addEventListener:function(e,t,n){e.addEventListener?e.addEventListener(t,n):e.attachEvent("on"+t,n)}},r=function(){var e="data-cc-event",t="data-cc-if",n=function(e,t,i){return s.isArray(t)?s.each(t,function(t){n(e,t,i)}):void(e.addEventListener?e.addEventListener(t,i):e.attachEvent("on"+t,i))},i=function(e,t){return e.replace(/\{\{(.*?)\}\}/g,function(e,n){for(var i,o,r=n.split("||");o=r.shift();){if(o=o.trim(),'"'===o[0])return o.slice(1,o.length-1);if(i=s.queryObject(t,o))return i}return""})},o=function(e){var t=document.createElement("div");return t.innerHTML=e,t.children[0]},r=function(e,t,n){var i=e.parentNode.querySelectorAll("["+t+"]");s.each(i,function(e){var i=e.getAttribute(t);n(e,i)},window,!0)},c=function(t,i){r(t,e,function(e,t){var o=t.split(":"),r=s.queryObject(i,o[1]);n(e,o[0],s.bind(r,i))})},a=function(e,n){r(e,t,function(e,t){var i=s.queryObject(n,t);i||e.parentNode.removeChild(e)})};return{build:function(e,t){s.isArray(e)&&(e=e.join("")),e=i(e,t);var n=o(e);return c(n,t),a(n,t),n}}}(),c={options:{message:"This website uses cookies to ensure you get the best experience on our website. ",dismiss:"Got it!",learnMore:"More info",link:null,target:"_self",container:null,theme:"light-floating",domain:null,path:"/",expiryDays:365,markup:['<div class="cc_banner-wrapper {{containerClasses}}">','<div class="cc_banner cc_container cc_container--open">','<a href="#null" data-cc-event="click:dismiss" target="_blank" class="cc_btn cc_btn_accept_all">{{options.dismiss}}</a>','<p class="cc_message">{{options.message}} <a data-cc-if="options.link" target="{{ options.target }}" class="cc_more_info" href="{{options.link || "#null"}}">{{options.learnMore}}</a></p>','<a class="cc_logo" target="_blank" href="http://silktide.com/cookieconsent">Cookie Consent plugin for the EU cookie law</a>',"</div>","</div>"]},init:function(){var t=window[e];t&&this.setOptions(t),this.setContainer(),this.options.theme?this.loadTheme(this.render):this.render()},setOptionsOnTheFly:function(e){this.setOptions(e),this.render()},setOptions:function(e){s.merge(this.options,e)},setContainer:function(){this.options.container?this.container=document.querySelector(this.options.container):this.container=document.body,this.containerClasses="",navigator.appVersion.indexOf("MSIE 8")>-1&&(this.containerClasses+=" cc_ie8")},loadTheme:function(e){var t=this.options.theme;-1===t.indexOf(".css")&&(t=i+t+".css");var n=document.createElement("link");n.rel="stylesheet",n.type="text/css",n.href=t;var o=!1;n.onload=s.bind(function(){!o&&e&&(e.call(this),o=!0)},this),document.getElementsByTagName("head")[0].appendChild(n)},render:function(){this.element&&this.element.parentNode&&(this.element.parentNode.removeChild(this.element),delete this.element),this.element=r.build(this.options.markup,this),this.container.firstChild?this.container.insertBefore(this.element,this.container.firstChild):this.container.appendChild(this.element)},dismiss:function(e){e.preventDefault&&e.preventDefault(),e.returnValue=!1,this.setDismissedCookie(),this.container.removeChild(this.element)},setDismissedCookie:function(){s.setCookie(n,"yes",this.options.expiryDays,this.options.domain,this.options.path)}},a=!1;(o=function(){a||"complete"!=document.readyState||(c.init(),a=!0,window[t]=s.bind(c.setOptionsOnTheFly,c))})(),s.addEventListener(document,"readystatechange",o)}}}();;
function init_cforge()
{
    projects = $("div.projects li");
    for (i=0; i < projects.length; i++)
    {
		child = projects[i];

		if (child.childNodes.length < 3 || child.childNodes[2].length < 2)
		{
			continue;
		}

		url = child.childNodes[2].childNodes[1];
		url_parts = String(url).split("/");
		url_parts.splice(url_parts.length - 3, 0, "rest");
		rest_url = url_parts.join("/");
		json = $.getJSON(rest_url, (function() {
			var mychild = child;
			var repos = [];
			return function(result){
				url = result["url"];
				$.each(result["tools"], function(key, tool){
					if (tool["name"] == "svn")
					{
						parts = (url + tool["mount_point"]).split("/");
						base_url = "https://" + parts[2] + "/svn/";
						repo = parts[parts.length-3] + "," + parts[parts.length-2] + "," + parts[parts.length-1]
						repos.push(base_url + repo);
					}
					
				});

				/*
				 * Add links for the cforge tool to the project:
				 * - checkout
				 * - build
				 * - commit
				 */
				html = "";
				for (j=0; j < repos.length; j++)
				{
					repo_parts = repos[j].split(",");
					name = repo_parts[repo_parts.length - 1];
					repo_url_parts = repos[j].split("/");
					repo_name = repo_url_parts[repo_url_parts.length - 1];
					url = repos[j];
					html +='<span style="clear:both; float:left;"><b>' + name + ":</b> ";
					html += '<a href="' + url + '">browse</a>';
					html += ' | ';
					html += '<a href="cforge:checkout:' + url + '">checkout</a>';
					html += ' | ';
					html += '<a href="cforge:update:' + repo_name + '">update</a>';
					html += ' | ';
					html += '<a href="cforge:commit:' + repo_name + '">commit</a>';
					html += ' | ';
					html += '<a href="cforge:build:' + repo_name + '">build</a>';
					html += '</span>';
				}
				mychild.innerHTML += html;
				
			};
		})());

    }

    /* add spaces to group the digit pairs of the view count */
    views = $("span.views");
    for (i=0; i < views.length; i++)
    {
		viewText = views[i].innerHTML;
        views[i].innerHTML = viewText.replace(/\B(?=(\d{3})+(?!\d))/g, " ");
    }



    /* show thumbnails for icons and images */
    iconlinks = $("a.icon");
    for (i=0; i < iconlinks.length; i++)
    {
		href = iconlinks[i].href;
		link = iconlinks[i];
		if (href.endsWith(".png") || href.endsWith(".jpg"))
		{
			link.innerHTML += '<img src="' + href + '?format=raw" width="16" style="margin-left: 16px" />';
		}
    }



	$('.reaction-button').each(function() {
		var btnId = $(this).attr('id');
		$(this).click(function(e) {
			e.preventDefault();
			reactComment($(this), ':+1:');
		});
		var x = document.getElementsByClassName("fa-smile-o");
		var i, j;
		j = x.length;
		for (i = 0; i < j; i++) {
		    // Note: The list changes while we are updating the classes
		    // So we always change the first element
		    x[0].className = "fa fa-thumbs-up";
		} 

	});

    // add some events to manipulate tickets
    var form_holder = $('div.form_holder');
    var view_holder = $('div.view_holder');
    var discussion_holder = $('#discussion_holder');
    var ticket_content = $('#ticket_content');
    var title_holder = $('h2.dark');
    var original_title = title_holder.html();
    var title_actions = title_holder.find('small');
    var vote = $('#vote');

    function edit_ticket() {
        form_holder.show();
        view_holder.hide();
        discussion_holder.hide();
        ticket_content.hide();
        title_actions.hide();
        title_actions.appendTo(document.body);
        title_holder.text('\u00A0');
        vote.hide();
        $('div.new-ticket-title label').hide();
        $('a.edit_ticket').addClass('btn_activate');
    }
    function edit_ticket_text(event) {
		if (event.target.nodeName != "A")
		{
			edit_ticket();
			
            var cm = get_cm(form_holder);
            cm.refresh();
            cm.focus();
            $('textarea[name="ticket_form.description"]').trigger('editticket.forgetracker');
            $(this).trigger('editTicket');
            return false;
		}
        return true;
    }
    function edit_ticket_owner() {
		edit_ticket();
		input = $('#w-1\\.assigned_to').next().children();
		input[0].focus();
        return false;
    }
    function edit_ticket_label() {
		edit_ticket();
		input = $('#w-1\\.labels').next().children().children();
		input[0].focus();
        return false;
    }

    if(form_holder.length > 0)
    {
		divs = $('#ticket_content');
		for (i=0; i < divs.length; i++)
		{
			divs[i].title = "Keyboard Shortcut to edit: 'e'";
		}

		// - click on owner
		$('div.ticket-assigned-to').click(edit_ticket_owner);
		divs = $('div.ticket-assigned-to');
		for (i=0; i < divs.length; i++)
		{
			divs[i].title = "Click to edit\nKeyboard Shortcut: 'a'";
		}
		
		// click on label
		$('div.ticket-assigned-to').next().click(edit_ticket_label);
		divs = $('div.ticket-assigned-to').next();
		for (i=0; i < divs.length; i++)
		{
			divs[i].title = "Click to edit\nKeyboard Shortcut: 'l'";
		}

		// - press key 'e'
		$(document).keypress(function(event){
			if (event.target.nodeName == "BODY")
			{
				switch(String.fromCharCode(event.which))
				{
					case 'e':
					if (!form_holder.is(":visible"))
					{
						edit_ticket_text(event);
					}
					break;
					case 'a':
					if (!form_holder.is(":visible"))
					{
						edit_ticket_owner();
					}
					break;
					case 'l':
					if (!form_holder.is(":visible"))
					{
						edit_ticket_label();
					}
					break;
				}
			}
		});
    }

    // fix inline images in discussions
    posts = $('.discussion-post')
    for (i = 0; i < posts.length; i++)
    {
	imgs = $(posts[i]).find('img');
	for (j = 0; j < imgs.length; j++)
	{
	    if (imgs[j].src.includes("/thread/") && imgs[j].src.includes("/attachment/") && !imgs[j].src.match("/[a-f0-9]{4}/attachment/"))
	    {
		postid = posts[i].id
		imgs[j].src = imgs[j].src.replace("/attachment/", "/" + postid + "/attachment/")
	    }
	}
    }
    
    // render slide shows
    show_slides();    
}

var slideIndex = 0;
function show_slides() {
	var i;
	var slides = document.getElementsByClassName("slideshow");
	if (slides.length > 0)
	{
		for (i = 0; i < slides.length; i++) {
			slides[i].style.display = "none";
		}
		slideIndex++;
		if (slideIndex > slides.length) {slideIndex = 1}    
		slides[slideIndex-1].style.display = "block";  
		
		regexp = /.*slideshow-time-([0-9]*)\b.*/
		time = slides[slideIndex-1].className.replace(regexp, "$1")
		time = parseInt(time)*1000
		setTimeout(show_slides, time); // Change image every 2 seconds
	}
}

function show_hidden_posts()
{
    posts = $(".hide");
    for (i=0; i < posts.length; i++)
    {
	posts[i].classList.remove('hide')
    }
    show_hidden_link = $(".show_hidden");
    for (i=0; i < show_hidden_link.length; i++)
    {
	show_hidden_link[i].classList.add('show_hidden_hide')
    }
}

$('document').ready(init_cforge);



