var winHeight = $(window).height();
var twoThirdsHeight = $(window).height()/3*2;
$(document).ready(function () {
	$('.home .banner-img').css('height', winHeight);


	if ($(window).width() <= 767) {
		if (!$('.wrapper').is('.home')) {
			$('.banner-img').css('height', twoThirdsHeight);
		}
	}

    $('#search-box i').click(function(){
         $('#search-box form').submit();
    });

    $('#nav-search em').click(function(){
         $('#nav-search form').submit();
    });


	var oTogglees = $(".main-head .burger, #toggle-mobile-search");
	oTogglees.on('click', function () {
        // oTogglees.hide();
		$(".top-header .right-nav").slideToggle(function(){
			$("html").addClass("menu-opened");
		});

        var currentScroll = $(window).scrollTop();
        $(".main-head").attr('data-top-scroll',currentScroll);

		if (this.id == "toggle-mobile-search") {
			$("#nav-search").show();
			$(".main-nav").hide();
		}
		else {
			$("#nav-search").attr("style", "display: none !important"); // Fixes visible-xs problem on desktop
			$("html").addClass("menu-open");
			$(".main-nav").show();
		}
	});

	// Submenu wont close parents when clicking :)
	$(".main-nav").on("click", ".dropdown-menu", function (e) {
		$(this).parent().is(".open") && e.stopPropagation();
	});

	$(".main-head .fa.fa-times").on("click", function () {
		var oSelf = $(this);
		$("html").removeClass("menu-open menu-opened");
		$(".top-header .right-nav").slideToggle(function () {
			oSelf.hide();
			// $(".main-head .burger").show();

			$(window).trigger("scroll");
		});
        window.scroll(0,$(".main-head").attr('data-top-scroll'));
	});

	$("#down-click a").on('click', function (event) {
		if (this.hash !== "") {

			event.preventDefault();


			var hash = this.hash;


			$('html, body').animate({
				scrollTop: $(hash).offset().top - 60
			}, 1000);
		}
	});


	$(".accordion-toggle").click(function () {
		var oSelf = $(this);

			oSelf.parents(".accordion-group").toggleClass("open", oSelf.hasClass("collapsed"));

	});

	var $accordion3 = $('#accordion3');

	$accordion3.on('show.bs.collapse', function (e) {
		$(e.target).parent().addClass("open");
	});

	$accordion3.on('hide.bs.collapse', function (e) {
		$(e.target).parent().removeClass("open");
	});

    $(document).on('click', '.accordion-heading > .content-box', function(e) {
        e.stopImmediatePropagation();
        e.preventDefault();
        $(this).parent().find("a.accordion-toggle").trigger("click");
    });

    // http://stackoverflow.com/a/28214968
    function ieRepaint(element) {
        element.html(element.html().replace('>', '>'));
    }

    $accordion3.on('shown.bs.collapse hidden.bs.collapse', function () {
        ieRepaint($('#accordion3'));
    });


	/****************************Chart1******************************/

	/*!
	 * jquery.drawPieChart.js
	 * Version: 0.3(Beta)
	 * Inspired by Chart.js(http://www.chartjs.org/)
	 *
	 * Copyright 2013 hiro
	 * https://github.com/githiro/drawPieChart
	 * Released under the MIT license.
	 */
	;
	(function ($, undefined) {
		$.fn.drawPieChart = function (data, options) {
			var $this = this,
				W = $this.width(),
				H = $this.height(),
				centerX = W / 2,
				centerY = H / 2,
				cos = Math.cos,
				sin = Math.sin,
				PI = Math.PI,
				settings = $.extend({
					segmentShowStroke: true,
					segmentStrokeColor: "#fff",
					segmentStrokeWidth: 1,
					baseColor: "#fff",
					baseOffset: 15,
					edgeOffset: 30,//offset from edge of $this
					pieSegmentGroupClass: "pieSegmentGroup",
					pieSegmentClass: "pieSegment",
					lightPiesOffset: 12,//lighten pie's width
					lightPiesOpacity: .3,//lighten pie's default opacity
					lightPieClass: "lightPie",
					animation: true,
					animationSteps: 90,
					animationEasing: "easeInOutExpo",
					tipOffsetX: -15,
					tipOffsetY: -45,
					tipClass: "pieTip",
					beforeDraw: function () {
					},
					afterDrawed: function () {
					},
					onPieMouseenter: function (e, data) {
					},
					onPieMouseleave: function (e, data) {
					},
					onPieClick: function (e, data) {
					}
				}, options),
				animationOptions = {
					linear: function (t) {
						return t;
					},
					easeInOutExpo: function (t) {
						var v = t < .5 ? 8 * t * t * t * t : 1 - 8 * (--t) * t * t * t;
						return (v > 1) ? 1 : v;
					}
				},
				requestAnimFrame = function () {
					return window.requestAnimationFrame ||
						window.webkitRequestAnimationFrame ||
						window.mozRequestAnimationFrame ||
						window.oRequestAnimationFrame ||
						window.msRequestAnimationFrame ||
						function (callback) {
							window.setTimeout(callback, 1000 / 60);
						};
				}();

			var $wrapper = $('<svg width="' + W + '" height="' + H + '" viewBox="0 0 ' + W + ' ' + H + '" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"></svg>').appendTo($this);
			var $groups = [],
				$pies = [],
				$lightPies = [],
				easingFunction = animationOptions[settings.animationEasing],
				pieRadius = Min([H / 2, W / 2]) - settings.edgeOffset,
				segmentTotal = 0;

			//Draw base circle
			var drawBasePie = function () {
				var base = document.createElementNS('http://www.w3.org/2000/svg', 'circle');
				var $base = $(base).appendTo($wrapper);
				base.setAttribute("cx", centerX);
				base.setAttribute("cy", centerY);
				base.setAttribute("r", pieRadius + settings.baseOffset);
				base.setAttribute("fill", settings.baseColor);
			}();

			//Set up pie segments wrapper
			var pathGroup = document.createElementNS('http://www.w3.org/2000/svg', 'g');
			var $pathGroup = $(pathGroup).appendTo($wrapper);
			$pathGroup[0].setAttribute("opacity", 0);

			//Set up tooltip
			var $tip = $('<div class="' + settings.tipClass + '" />').appendTo('body').hide(),
				tipW = $tip.width(),
				tipH = $tip.height();

			for (var i = 0, len = data.length; i < len; i++) {
				segmentTotal += data[i].value;
				var g = document.createElementNS('http://www.w3.org/2000/svg', 'g');
				g.setAttribute("data-order", i);
				g.setAttribute("class", settings.pieSegmentGroupClass);
				$groups[i] = $(g).appendTo($pathGroup);
				$groups[i]
					.on("mouseenter", pathMouseEnter)
					.on("mouseleave", pathMouseLeave)
					.on("mousemove", pathMouseMove)
					.on("click", pathClick);

				var p = document.createElementNS('http://www.w3.org/2000/svg', 'path');
				p.setAttribute("stroke-width", settings.segmentStrokeWidth);
				p.setAttribute("stroke", settings.segmentStrokeColor);
				p.setAttribute("stroke-miterlimit", 2);
				p.setAttribute("fill", data[i].color);
				p.setAttribute("class", settings.pieSegmentClass);
				$pies[i] = $(p).appendTo($groups[i]);

				var lp = document.createElementNS('http://www.w3.org/2000/svg', 'path');
				lp.setAttribute("stroke-width", settings.segmentStrokeWidth);
				lp.setAttribute("stroke", settings.segmentStrokeColor);
				lp.setAttribute("stroke-miterlimit", 2);
				lp.setAttribute("fill", data[i].color);
				lp.setAttribute("opacity", settings.lightPiesOpacity);
				lp.setAttribute("class", settings.lightPieClass);
				$lightPies[i] = $(lp).appendTo($groups[i]);
			}

			settings.beforeDraw.call($this);
			//Animation start
			triggerAnimation();

			function pathMouseEnter(e) {
				var index = $(this).data().order;
				$tip.text(data[index].title + ": " + data[index].value).stop().fadeIn(200);
				if ($groups[index][0].getAttribute("data-active") !== "active") {
					$lightPies[index].animate({opacity: .8}, 180);
				}
				settings.onPieMouseenter.apply($(this), [e, data]);
			}

			function pathMouseLeave(e) {
				var index = $(this).data().order;
				$tip.stop().hide();
				if ($groups[index][0].getAttribute("data-active") !== "active") {
					$lightPies[index].stop().animate({opacity: settings.lightPiesOpacity}, 100);
				}
				settings.onPieMouseleave.apply($(this), [e, data]);
			}

			function pathMouseMove(e) {
				$tip.css({
					top: e.pageY + settings.tipOffsetY,
					left: e.pageX - $tip.width() / 2 + settings.tipOffsetX
				});
			}

			function pathClick(e) {
				var index = $(this).data().order;
				var targetGroup = $groups[index][0];
				for (var i = 0, len = data.length; i < len; i++) {
					if (i === index) continue;
					$groups[i][0].setAttribute("data-active", "");
					$lightPies[i].css({opacity: settings.lightPiesOpacity});
				}
				if (targetGroup.getAttribute("data-active") === "active") {
					targetGroup.setAttribute("data-active", "");
					$lightPies[index].css({opacity: .8});
				} else {
					targetGroup.setAttribute("data-active", "active");
					$lightPies[index].css({opacity: 1});
				}
				settings.onPieClick.apply($(this), [e, data]);
			}

			function drawPieSegments(animationDecimal) {
				var startRadius = -PI / 2,//-90 degree
					rotateAnimation = 1;
				if (settings.animation) {
					rotateAnimation = animationDecimal;//count up between0~1
				}

				$pathGroup[0].setAttribute("opacity", animationDecimal);

				//draw each path
				for (var i = 0, len = data.length; i < len; i++) {
					var segmentAngle = rotateAnimation * ((data[i].value / segmentTotal) * (PI * 2)),//start radian
						endRadius = startRadius + segmentAngle,
						largeArc = ((endRadius - startRadius) % (PI * 2)) > PI ? 1 : 0,
						startX = centerX + cos(startRadius) * pieRadius,
						startY = centerY + sin(startRadius) * pieRadius,
						endX = centerX + cos(endRadius) * pieRadius,
						endY = centerY + sin(endRadius) * pieRadius,
						startX2 = centerX + cos(startRadius) * (pieRadius + settings.lightPiesOffset),
						startY2 = centerY + sin(startRadius) * (pieRadius + settings.lightPiesOffset),
						endX2 = centerX + cos(endRadius) * (pieRadius + settings.lightPiesOffset),
						endY2 = centerY + sin(endRadius) * (pieRadius + settings.lightPiesOffset);
					var cmd = [
						'M', startX, startY,//Move pointer
						'A', pieRadius, pieRadius, 0, largeArc, 1, endX, endY,//Draw outer arc path
						'L', centerX, centerY,//Draw line to the center.
						'Z'//Cloth path
					];
					var cmd2 = [
						'M', startX2, startY2,
						'A', pieRadius + settings.lightPiesOffset, pieRadius + settings.lightPiesOffset, 0, largeArc, 1, endX2, endY2,//Draw outer arc path
						'L', centerX, centerY,
						'Z'
					];
					$pies[i][0].setAttribute("d", cmd.join(' '));
					$lightPies[i][0].setAttribute("d", cmd2.join(' '));
					startRadius += segmentAngle;
				}
			}

			var animFrameAmount = (settings.animation) ? 1 / settings.animationSteps : 1,//if settings.animationSteps is 10, animFrameAmount is 0.1
				animCount = (settings.animation) ? 0 : 1;

			function triggerAnimation() {
				if (settings.animation) {
					requestAnimFrame(animationLoop);
				} else {
					drawPieSegments(1);
				}
			}

			function animationLoop() {
				animCount += animFrameAmount;//animCount start from 0, after "settings.animationSteps"-times executed, animCount reaches 1.
				drawPieSegments(easingFunction(animCount));
				if (animCount < 1) {
					requestAnimFrame(arguments.callee);
				} else {
					settings.afterDrawed.call($this);
				}
			}

			function Max(arr) {
				return Math.max.apply(null, arr);
			}

			function Min(arr) {
				return Math.min.apply(null, arr);
			}

			return $this;
		};
	})(jQuery);
	/***************************************Chart2*******************************************************/

	/*!
	 * jquery.drawPieChart.js
	 * Version: 0.3(Beta)
	 * Inspired by Chart.js(http://www.chartjs.org/)
	 *
	 * Copyright 2013 hiro
	 * https://github.com/githiro/drawPieChart
	 * Released under the MIT license.
	 */

	(function ($, undefined) {
		$.fn.drawPieChart2 = function (data, options) {
			var $this = this,
				W = $this.width(),
				H = $this.height(),
				centerX = W / 2,
				centerY = H / 2,
				cos = Math.cos,
				sin = Math.sin,
				PI = Math.PI,
				settings = $.extend({
					segmentShowStroke: true,
					segmentStrokeColor: "#fff",
					segmentStrokeWidth: 1,
					baseColor: "#fff",
					baseOffset: 15,
					edgeOffset: 30,//offset from edge of $this
					pieSegmentGroupClass: "pieSegmentGroup",
					pieSegmentClass: "pieSegment",
					lightPiesOffset: 12,//lighten pie's width
					lightPiesOpacity: .3,//lighten pie's default opacity
					lightPieClass: "lightPie",
					animation: true,
					animationSteps: 90,
					animationEasing: "easeInOutExpo",
					tipOffsetX: -15,
					tipOffsetY: -45,
					tipClass: "pieTip",
					beforeDraw: function () {
					},
					afterDrawed: function () {
					},
					onPieMouseenter: function (e, data) {
					},
					onPieMouseleave: function (e, data) {
					},
					onPieClick: function (e, data) {
					}
				}, options),
				animationOptions = {
					linear: function (t) {
						return t;
					},
					easeInOutExpo: function (t) {
						var v = t < .5 ? 8 * t * t * t * t : 1 - 8 * (--t) * t * t * t;
						return (v > 1) ? 1 : v;
					}
				},
				requestAnimFrame = function () {
					return window.requestAnimationFrame ||
						window.webkitRequestAnimationFrame ||
						window.mozRequestAnimationFrame ||
						window.oRequestAnimationFrame ||
						window.msRequestAnimationFrame ||
						function (callback) {
							window.setTimeout(callback, 1000 / 60);
						};
				}();

			var $wrapper = $('<svg width="' + W + '" height="' + H + '" viewBox="0 0 ' + W + ' ' + H + '" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"></svg>').appendTo($this);
			var $groups = [],
				$pies = [],
				$lightPies = [],
				easingFunction = animationOptions[settings.animationEasing],
				pieRadius = Min([H / 2, W / 2]) - settings.edgeOffset,
				segmentTotal = 0;

			//Draw base circle
			var drawBasePie = function () {
				var base = document.createElementNS('http://www.w3.org/2000/svg', 'circle');
				var $base = $(base).appendTo($wrapper);
				base.setAttribute("cx", centerX);
				base.setAttribute("cy", centerY);
				base.setAttribute("r", pieRadius + settings.baseOffset);
				base.setAttribute("fill", settings.baseColor);
			}();

			//Set up pie segments wrapper
			var pathGroup = document.createElementNS('http://www.w3.org/2000/svg', 'g');
			var $pathGroup = $(pathGroup).appendTo($wrapper);
			$pathGroup[0].setAttribute("opacity", 0);

			//Set up tooltip
			var $tip = $('<div class="' + settings.tipClass + '" />').appendTo('body').hide(),
				tipW = $tip.width(),
				tipH = $tip.height();

			for (var i = 0, len = data.length; i < len; i++) {
				segmentTotal += data[i].value;
				var g = document.createElementNS('http://www.w3.org/2000/svg', 'g');
				g.setAttribute("data-order", i);
				g.setAttribute("class", settings.pieSegmentGroupClass);
				$groups[i] = $(g).appendTo($pathGroup);
				$groups[i]
					.on("mouseenter", pathMouseEnter)
					.on("mouseleave", pathMouseLeave)
					.on("mousemove", pathMouseMove)
					.on("click", pathClick);

				var p = document.createElementNS('http://www.w3.org/2000/svg', 'path');
				p.setAttribute("stroke-width", settings.segmentStrokeWidth);
				p.setAttribute("stroke", settings.segmentStrokeColor);
				p.setAttribute("stroke-miterlimit", 2);
				p.setAttribute("fill", data[i].color);
				p.setAttribute("class", settings.pieSegmentClass);
				$pies[i] = $(p).appendTo($groups[i]);

				var lp = document.createElementNS('http://www.w3.org/2000/svg', 'path');
				lp.setAttribute("stroke-width", settings.segmentStrokeWidth);
				lp.setAttribute("stroke", settings.segmentStrokeColor);
				lp.setAttribute("stroke-miterlimit", 2);
				lp.setAttribute("fill", data[i].color);
				lp.setAttribute("opacity", settings.lightPiesOpacity);
				lp.setAttribute("class", settings.lightPieClass);
				$lightPies[i] = $(lp).appendTo($groups[i]);
			}

			settings.beforeDraw.call($this);
			//Animation start
			triggerAnimation();

			function pathMouseEnter(e) {
				var index = $(this).data().order;
				$tip.text(data[index].title + ": " + data[index].value).stop().fadeIn(200);
				if ($groups[index][0].getAttribute("data-active") !== "active") {
					$lightPies[index].stop().animate({opacity: .8}, 180);
				}
				settings.onPieMouseenter.apply($(this), [e, data]);
			}

			function pathMouseLeave(e) {
				var index = $(this).data().order;
				$tip.stop().hide();
				if ($groups[index][0].getAttribute("data-active") !== "active") {
					$lightPies[index].stop().animate({opacity: settings.lightPiesOpacity}, 100);
				}
				settings.onPieMouseleave.apply($(this), [e, data]);
			}

			function pathMouseMove(e) {
				$tip.css({
					top: e.pageY + settings.tipOffsetY,
					left: e.pageX - $tip.width() / 2 + settings.tipOffsetX
				});
			}

			function pathClick(e) {
				var index = $(this).data().order;
				var targetGroup = $groups[index][0];
				for (var i = 0, len = data.length; i < len; i++) {
					if (i === index) continue;
					$groups[i][0].setAttribute("data-active", "");
					$lightPies[i].css({opacity: settings.lightPiesOpacity});
				}
				if (targetGroup.getAttribute("data-active") === "active") {
					targetGroup.setAttribute("data-active", "");
					$lightPies[index].css({opacity: .8});
				} else {
					targetGroup.setAttribute("data-active", "active");
					$lightPies[index].css({opacity: 1});
				}
				settings.onPieClick.apply($(this), [e, data]);
			}

			function drawPieSegments(animationDecimal) {
				var startRadius = -PI / 2,//-90 degree
					rotateAnimation = 1;
				if (settings.animation) {
					rotateAnimation = animationDecimal;//count up between0~1
				}

				$pathGroup[0].setAttribute("opacity", animationDecimal);

				//draw each path
				for (var i = 0, len = data.length; i < len; i++) {
					var segmentAngle = rotateAnimation * ((data[i].value / segmentTotal) * (PI * 2)),//start radian
						endRadius = startRadius + segmentAngle,
						largeArc = ((endRadius - startRadius) % (PI * 2)) > PI ? 1 : 0,
						startX = centerX + cos(startRadius) * pieRadius,
						startY = centerY + sin(startRadius) * pieRadius,
						endX = centerX + cos(endRadius) * pieRadius,
						endY = centerY + sin(endRadius) * pieRadius,
						startX2 = centerX + cos(startRadius) * (pieRadius + settings.lightPiesOffset),
						startY2 = centerY + sin(startRadius) * (pieRadius + settings.lightPiesOffset),
						endX2 = centerX + cos(endRadius) * (pieRadius + settings.lightPiesOffset),
						endY2 = centerY + sin(endRadius) * (pieRadius + settings.lightPiesOffset);
					var cmd = [
						'M', startX, startY,//Move pointer
						'A', pieRadius, pieRadius, 0, largeArc, 1, endX, endY,//Draw outer arc path
						'L', centerX, centerY,//Draw line to the center.
						'Z'//Cloth path
					];
					var cmd2 = [
						'M', startX2, startY2,
						'A', pieRadius + settings.lightPiesOffset, pieRadius + settings.lightPiesOffset, 0, largeArc, 1, endX2, endY2,//Draw outer arc path
						'L', centerX, centerY,
						'Z'
					];
					$pies[i][0].setAttribute("d", cmd.join(' '));
					$lightPies[i][0].setAttribute("d", cmd2.join(' '));
					startRadius += segmentAngle;
				}
			}

			var animFrameAmount = (settings.animation) ? 1 / settings.animationSteps : 1,//if settings.animationSteps is 10, animFrameAmount is 0.1
				animCount = (settings.animation) ? 0 : 1;

			function triggerAnimation() {
				if (settings.animation) {
					requestAnimFrame(animationLoop);
				} else {
					drawPieSegments(1);
				}
			}

			function animationLoop() {
				animCount += animFrameAmount;//animCount start from 0, after "settings.animationSteps"-times executed, animCount reaches 1.
				drawPieSegments(easingFunction(animCount));
				if (animCount < 1) {
					requestAnimFrame(arguments.callee);
				} else {
					settings.afterDrawed.call($this);
				}
			}

			function Max(arr) {
				return Math.max.apply(null, arr);
			}

			function Min(arr) {
				return Math.min.apply(null, arr);
			}

			return $this;
		};

	})(jQuery);


	// var headerHeight = ($('.main-head').height()) + 50;
	// $('.header-text').css('marginTop', headerHeight);


});


$(document).ready(function ($) {

	$(".ul-container").on("mouseenter", "li", function () {
		$(this).addClass("green");
		$(this).parent().parent().find(".active").removeClass("green");
	}).on("mouseleave", "li", function () {
		$(this).removeClass("green");
	}).on("mouseleave", function () {
		$(this).find(".active").addClass("green");
	});

	if ($('.counter').length) {
		$('.counter').counterUp({
			delay: 100,
			time: 2500
		});
	}

	equalheight('.adaptation-section h6 ');
	if ($('.percent-count').length) {
		$('.percent-count').counterUp({
			delay: 100,
			time: 2500
		});
	}
});


$(window).on('load resize', function () {

	$('.home .banner-img img').css('height', winHeight);

});

var loadPieChart = function () {

	$("#pieChart").drawPieChart([
		{title: "Energy", value: 55, color: "#adce5c"},
		{title: "Agriculture, forestry and land-use", value: 22, color: "#5dbe8d"},
		{title: "Waste", value: 13, color: "#a5cde9"},
		{title: "Industrial processes and product use", value: 10, color: "#95bad3"}
	]);

	$("#pieChart2").drawPieChart2([
		{title: "Agriculture", value: 37, color: "#adce5c"},
		{title: "Water", value: 34, color: "#5dbe8d"},
		{title: "Infrastructure /settlement", value: 14, color: "#a5cde9"},
		{title: "Climate observation", value: 6, color: "#95bad3"},
		{title: "Human health", value: 4, color: "#a69ec9"},
		{title: "Tourism", value: 1, color: "#948cb2"},
		{title: "Energy", value: 1, color: "#767190"},
		{title: "Other", value: 3, color: "#bf7ccc"}
	]);

};

var bLoadedPiechart = false;
$(window).on("load scroll ", function (e) {

	if ($(".right-nav").css("display") != "block" || $(window).width() >= 768) {
		if ($(this).scrollTop() > 50 && !$('html').hasClass('menu-opened')) {
			$(".main-head").addClass('fixed-header');
		} else if (!$('html').hasClass('menu-opened')) {
			$(".main-head").removeClass("fixed-header");
		}
	}

	if ($("#pieChart").length) {
		if ($("#pieChart").offset().top - 800 < $(this).scrollTop()) {
			if (!bLoadedPiechart) {
				loadPieChart();
				bLoadedPiechart = true;
			}
		}
	}


});


/* 	$(window).on( "load scroll ", function() {
			var winwidth = $(window).width();
				if ($(this).scrollTop() > 500 && winwidth >= 768){
						  $('.counter').counterUp({
							delay: 10,
							time: 1000
						});

					}

		}); */


equalheight = function (container) {
	var currentTallest = 0,
		currentRowStart = 0,
		rowDivs = new Array(),
		$el;
	$(container).each(function () {

		$el = $(this);
		$($el).height('auto');
		topPostion = $el.position().top;

		if (currentRowStart != topPostion) {
			for (currentDiv = 0; currentDiv < rowDivs.length; currentDiv++) {
				rowDivs[currentDiv].height(currentTallest);
			}
			rowDivs.length = 0; // empty the array
			currentRowStart = topPostion;
			currentTallest = $el.height();
			rowDivs.push($el);
		} else {
			rowDivs.push($el);
			currentTallest = (currentTallest < $el.height()) ? ($el.height()) : (currentTallest);
		}
		for (currentDiv = 0; currentDiv < rowDivs.length; currentDiv++) {
			rowDivs[currentDiv].height(currentTallest);
		}
	});
};

$(window).load(function () {
	equalheight('.adaptation-section h6 ');
	equalheight("#icons-height .eq");

	if($(window).width() <= 991) {
		$('html').addClass('touch');
	}

	fnRecalcElementHeights = function() {
		if ($(window).width() >= 767 && $(window).width() <= 1023 || $(window).width() >= 1025) {
			setTimeout(function () {
				$(".twitter").find("iframe").height($(".news-count").height() - $(".twitter-header").innerHeight() - $(".twitter-footer").innerHeight() - 16);
			}, 1000);
		}
		else if ($(window).width() == 1024) {
			setTimeout(function () {
				$(".twitter").find("iframe").height($(".news-count").height() - $(".twitter-header").innerHeight() - $(".twitter-footer").innerHeight() - 15);
			}, 1000);
		}


		if ($(window).width() >= 992) {
			setTimeout(function () {
				var leftHeight = $(".twitter-data").height() + $(".blue-div").height()+32;
                var rightCol = $(".purple-div");
                var listItems = $('.purple-div ul li');
                var listHeight = 0;

                listItems.show(); // Show items again on resize

                rightCol.height(leftHeight);
                for(var i = 0; i < listItems.length; i++) {
                    listHeight += listItems[i].offsetHeight;
                    if(rightCol.height() - 75 < listHeight) { // bottom padding (30) + link height (30) + extra 15
                        $(listItems[i]).hide();
                    }
                }

                var paddingTopMoreEvents = (rightCol.height()-rightCol.find('ul').height()-70)/2;

                rightCol.find('.more-events').css('padding-top',paddingTopMoreEvents);

			}, 1400);
		}

	};

	fnRecalcElementHeights();
	$(window).resize(fnRecalcElementHeights);



});

$(window).resize(function () {
	equalheight('.adaptation-section h6 ');

});

$(window).load(function () {
	if (detectIE()) {
		$('html').addClass('ie');
	}

	function detectIE() {
		var ua = window.navigator.userAgent;

		var msie = ua.indexOf('MSIE ');
		if (msie > 0) {
			// IE 10 or older => return version number
			return parseInt(ua.substring(msie + 5, ua.indexOf('.', msie)), 10);
		}

		var trident = ua.indexOf('Trident/');
		if (trident > 0) {
			// IE 11 => return version number
			var rv = ua.indexOf('rv:');
			return parseInt(ua.substring(rv + 3, ua.indexOf('.', rv)), 10);
		}

		var edge = ua.indexOf('Edge/');
		if (edge > 0) {
			// Edge (IE 12+) => return version number
			return parseInt(ua.substring(edge + 5, ua.indexOf('.', edge)), 10);
		}

		// other browser
		return false;
	}
});