// jshint ignore:start

// An async loader: http://gist.github.com/davesmiths/10277438
(function(c){var b=document.createElement("script"),a,d=[];b.type="text/javascript";b.async=true;a=function(i,j){var h,f,g=document.getElementsByTagName("script")[0],e;d[i]=d[i]||[];e=d[i].length;d[i][e]=j||function(){};if(e===0){h=b.cloneNode(true);h.onreadystatechange=h.onload=(function(k){return function(n){var m,l=d[k].length;if(!f&&(!this.readyState||this.readyState==="complete"||this.readyState==="loaded")){this.onreadystatechange=null;f=1;for(m=0;m<l;m++){d[k][m]()}d[k]=[]}}}(i));g.parentNode.insertBefore(h,g);h.src=i}};c["gist.github.com/davesmiths/10277438"]=a}(window));

// A version string helper: http://gist.github.com/davesmiths/c6e0eb456613b81985c2
(function(a){a["gist.github.com/davesmiths/c6e0eb456613b81985c2"]=function(b,e){var d,c;e=e||3;d=b.split(".");c="";for(i=0;i<e;i++){c+=""+((d[i]||0)*1+10000)}c=c*1;return c}}(this));

// Removes html.no-js and adds html.js
(function(C) {C.className = C.className.replace(/\bno-js\b/g,'') + ' js';}(document.documentElement));

// jshint ignore:end

(function(context) {

	'use strict';

	var get, version, number, i, ready, asset, assetsPathNet;

	// jshint ignore:start
	assetsPathNet = undefined;
	// jshint ignore:end

	if (!assetsPathNet) {
		// Obtain the assets path from the <script src of this script
		asset = document.getElementById('componenttcdprofilescriptasset');
		if (asset) {
			assetsPathNet = asset.src.split('/');
			assetsPathNet.pop();
			assetsPathNet = assetsPathNet.join('/') + '../../../..';
		}
		else {
			assetsPathNet = '//www.tcd.ie/assets';
		}
	}

    get = window['gist.github.com/davesmiths/10277438'];
	version = window['gist.github.com/davesmiths/c6e0eb456613b81985c2'];
	ready = function(jQuery) {
			var $;

			$ = jQuery;

//console.log('jQuery', jQuery.fn.jquery);
			$(function() {
				var $linkShowAllItems;

				$linkShowAllItems = $([]);

				$('.tcdprofile-tabs').tabs();

				$('.tcdprofile-publications,.tcdprofile-projects').each(function() {
					var $this,$a,$title,text,number,numberInitial;
					$this = $(this);
					number = $this.data('tcdprofile-items-number');
					numberInitial = $this.data('tcdprofile-items-number-initial');
					if (number > numberInitial) {
						$title = $this.find(':header:first');
						text = $title.length ? $title.text().toLowerCase() : '';
						$this.append('<a class="tcdprofile-items-show-all" href="">All '+number+' '+text+'</a>');
						$linkShowAllItems = $linkShowAllItems.add($this.find('a:last'));
					}
				});

				$linkShowAllItems.on('click', function(e) {
					var $this;

					e.preventDefault();

					$this = $(this);
					$this.parent().find('.tcdprofile-item-hide').show();
					$this.remove();

				});
			});

	};

	// If jQuery is not loaded on the page or the version is not high enough, get a jQuery
    if (context.jQuery === undefined || version(context.jQuery.fn.jquery) < version('1.10')) {
		get(assetsPathNet + '/components/tcdprofile/js/jquery-and-plugins/', function() {
			ready(context.jQuery.noConflict(true));
		});
    }
	else {
		get(assetsPathNet + '/components/tcdprofile/js/plugins/', function() {
			ready(context.jQuery);
		});
	}

}(this));
