
/**
 * Scoping to NWS-Namespace and jQuery $
 */
(function (NWS, $, undefined) {

	/**
	 * +++++++++++++++++++++++++++++++++++++++++++
	 * ++ Some Component
	 * +++++++++++++++++++++++++++++++++++++++++++
	 */
	NWS.initSomeComponent = function () {
		// Start writing the code for your component
		// e.g. $(".flexslider").flexslider();
	};

	/**
	 * +++++++++++++++++++++++++++++++++++++++++++
	 * ++ SVG replace
	 * ++ Convert to inline svg
	 * +++++++++++++++++++++++++++++++++++++++++++
	 */
	NWS.initSvgReplace = function () {
		$("img[src$='.svg']").each(function () {
			var $img = $(this);
			var imgID = $img.attr('id');
			var imgClass = $img.attr('class');
			var imgURL = $img.attr('src');
			$.get(imgURL, function (data) {
				// Get the SVG tag, ignore the rest
				var $svg = $(data).find('svg');
				// Add replaced image's ID to the new SVG
				if (typeof imgID !== 'undefined') {
					$svg = $svg.attr('id', imgID);
				}
				// Add replaced image's classes to the new SVG
				if (typeof imgClass !== 'undefined') {
					$svg = $svg.attr('class', imgClass + ' replaced-svg');
				}
				// Remove any invalid XML tags as per http://validator.w3.org
				$svg = $svg.removeAttr('xmlns:a');
				// Replace image with new SVG
				$img.replaceWith($svg);
			}, 'xml');
		});
	};

	/**
	 * +++++++++++++++++++++++++++++++++++++++++++
	 * ++ To top smooth scroll
	 * +++++++++++++++++++++++++++++++++++++++++++
	 */
	NWS.initToTopSmoothScroll = function () {
		$("#totop-wrapper").click(function (event) {
			event.stopPropagation();
			$("html, body").animate({
				scrollTop: 0
			}, "slow");
		});
	};

	/**
	 * +++++++++++++++++++++++++++++++++++++++++++
	 * ++ Toggle Submenu
	 * +++++++++++++++++++++++++++++++++++++++++++
	 */

	NWS.initToogleSubmenu = function () {
		var t = $(this).parent();
		if (t.hasClass('expanded')) {
			return true;
		}
		else {
			$("li.hassub", t.parent()).removeClass("expanded");
			t.addClass('expanded');
			return false;
		}
	};

	// Headimage
	NWS.HeadImageReload = function () {
		var count = $('#headimage-inner > img').length;
		var random = Math.floor(Math.random() * (count)) + 1;
		var i = 1;
		$( "#headimage-inner > img").each(function() {
			$( this ).addClass( "hidden" );
			$("#headimage h2:nth-child(" + i + ")").addClass("hidden");
			if ( i == random) {
				$( this ).removeClass( "hidden" );
				$("#headimage h2:nth-child(" + i + ")").removeClass("hidden");
			};
			i++;
		});
	};

}(window.NWS = window.NWS || {}, jQuery));
(function (NWS, $, undefined) {

	$(function () {
		//NWS.initSomeComponent();
		//NWS.initSvgReplace();
		NWS.initToTopSmoothScroll();
		NWS.HeadImageReload();
	});

}(window.NWS = window.NWS || {}, jQuery));

var navbarLis = $('#nav-main li.hassub > a');

enquire.register("screen and (max-width: 992px)", {
	match: function () {
		navbarLis.on('click', NWS.initToogleSubmenu);
	},
	unmatch: function () {
		navbarLis.off('click', NWS.initToogleSubmenu).removeClass('expanded');
	}
}, true);
	$(function() {
		$("a.lightbox")
		.parents(".csc-textpic-imagewrap,.news-img-wrap")
		.each(function() {
			$(this).magnificPopup({
				delegate: 'a.lightbox',
				type: 'image',
				gallery: {
					enabled: true,
					navigateByImgClick: false
				}
			});
		});
	});