$(document).ready(function() {

var $domain = OUC.globalProps['domain']
	var $currentPage = $domain + OUC.globalProps['path'] /* window.location */
	var $extension = OUC.globalProps['extension'] /* .html, .aspx, .php, etc */
	var $indexFile = OUC.globalProps['index-file'] /* default, index etc */

	// if the http root is not the same as domain
	var $trueHTTP = $domain


				
				$("div.widget.widget-menu > ul > li > ul").each(function(){
				$(this).parent().addClass("plus");
				$(this).parent().prepend('<span class="nn"></span>' );
				});
				
				$("div.widget.widget-menu > ul > li > ul > li > ul").each(function(){
				$(this).parent().addClass("plus");
				$(this).parent().prepend('<span class="nn"></span>' );
				});
				
				
				$('div.widget.widget-menu ul li a').each(function(index, anchorTag){
				
				$link =  $(this).attr('href')
				
				if ( $currentPage.indexOf($extension) == -1)
				{
				$currentPage = $currentPage + $indexFile + index
				
				}
				// check if link matches current page
				if ($currentPage == $link || $trueHTTP+$link == $currentPage)
				{
				//$(this).parent().addClass('current');
				$(this).parents("li").addClass('current');
				
				// break out of the loop
				return false
				
				}
				
				});

	/*var switchfunction = function(element) {
	 	$(element).toggleClass("active-right");
		$(element).next().toggleClass("active");
		$(element).prev().toggleClass("active");
	};
	$(".switcher .switch").click(function(e) {
		var href = $(this).attr("href");
		$.when(switchfunction(this)).done(function(){
			window.location = href;
		})	
	});*/
	if($(".switcher .switch").length>0)
	{	
		/*var currentLocation = window.location.href;

		var omaklink = $(".switcher .switch").next().attr("href");// get next link

		var url = omaklink.substring(0, omaklink.lastIndexOf("/"));

		if(currentLocation.indexOf(url) != -1)
		{
			$(".switcher .switch").addClass("notransition");
			$(".switcher .switch").toggleClass("active-right");
			$(".switcher .switch").next().find("p").toggleClass("active");
			$(".switcher .switch").prev().find("p").toggleClass("active");
			$(".switcher .switch").removeClass("notransition");
		}*/


		var switchfunction = function(element) {
			/*if(currentLocation.indexOf(url) != -1)
			{*/
				$(element).toggleClass("active-right");
				$(element).next().find("p").toggleClass("active");
				$(element).prev().find("p").toggleClass("active");
			//}
		};
		$(".switcher p").click(function(e) {
			e.preventDefault();
		})
		$(".switcher .switch").click(function(e) {
			var href;// Define href to calculate the current position of button on header
			if(!$(this).prev().find("p").hasClass("active")){
				href = $(this).prev().attr("href");// get the link
			}
			else{
				href = $(this).next().attr("href");// get the link
			}
			e.preventDefault();
			$.when(switchfunction(this)).done(function(){
				window.setTimeout(function(){
					window.location = href;
				},400);
			})	
		});
	}
	var default0 = false;

	var next = true;

	var speedval = ($('.bxslider-home').attr("speed")) ? parseInt($('.bxslider-home').attr("speed"),10) : 1000;
	var autoplay = ($('.bxslider-home').attr("auto")) ? $('.bxslider-home').attr("auto") === "true" : false;
	$('.bxslider-home').bxSlider({
		mode: "fade",
		speed: speedval,
		auto: autoplay,
		touchEnabled: false,
		pause: 9000,
		onSlideBefore: function (currentSlideNumber, totalSlideQty, currentSlideHtmlObject) {
			$('.active-slide').removeClass('active-slide');
			window.setTimeout(function() {
				doThis(currentSlideNumber, totalSlideQty, currentSlideHtmlObject);
			}, 100);
		},
		onSlideAfter: function (currentSlideNumber, totalSlideQty, currentSlideHtmlObject) {
			$('.active-slide').removeClass('active-slide');
			window.setTimeout(function() {
				$('.bxslider-home li:not(.bx-clone)').eq(currentSlideHtmlObject).addClass('active-slide')
			}, 0);
		},
		onSliderLoad: function () {
			$('.bxslider-home li:not(.bx-clone)').eq(0).addClass('active-slide')
		},
	});
	var speedval = ($('.bxslider-home3').attr("speed")) ? parseInt($('.bxslider-home3').attr("speed"),10) : 1000;
	var autoplay = ($('.bxslider-home3').attr("auto")) ? $('.bxslider-home3').attr("auto") === "true" : false;
		$(".bxslider-home3").bxSlider({
		mode: "fade",
		speed: speedval,
		auto: autoplay,
		touchEnabled: false,
		pause: 9000,	
		onSlideAfter: function (currentSlideNumber, totalSlideQty, currentSlideHtmlObject) {
			$('.active-slide').removeClass('active-slide');
			window.setTimeout(function() {
				$('.bxslider-home3 li:not(.bx-clone)').eq(currentSlideHtmlObject).addClass('active-slide')
			}, 0);
		},
		onSliderLoad: function () {
			$('.bxslider-home3 li:not(.bx-clone)').eq(0).addClass('active-slide')
		},
	});
	var speedval = ($('.bxslider-con').attr("speed")) ? parseInt($('.bxslider-con').attr("speed"),10) : 1000;
	var autoplay = ($('.bxslider-con').attr("auto")) ? $('.bxslider-con').attr("auto") === "true" : false;
	$(".bxslider-con").bxSlider({	speed: speedval, touchEnabled: false,
		auto: autoplay});
	var speedval = ($('.bxslider-home2').attr("speed")) ? parseInt($('.bxslider-home2').attr("speed"),10) : 1000;
	var autoplay = ($('.bxslider-home2').attr("auto")) ? $('.bxslider-home2').attr("auto") === "true" : false;
	$(".bxslider-home2").bxSlider({	speed: speedval, touchEnabled: false,
		auto: autoplay});
	var speedval = ($('.bxslider-score').attr("speed")) ? parseInt($('.bxslider-score').attr("speed"),10) : 1000;
	var autoplay = ($('.bxslider-score').attr("auto")) ? $('.bxslide-score').attr("auto") === "true" : false;
	$(".bxslider-score").bxSlider({	speed: speedval, touchEnabled: false,
		auto: autoplay});


	var slider = $(".bxslider-home4:not(.aa)").bxSlider({
		onSlideBefore: doThis2,
		speed: speedval,
		touchEnabled: false,
		auto: true,
		
		
	});

	var slider1 = $(".bxslider-home4.aa").bxSlider({
		mode: "fade",
		speed: speedval,
		touchEnabled: false,
		auto: true,
		pager: false,
		controls: false,
		
	});

	function doThis(ele, oldIndex, newIndex){
		if (next) {
			$('.custom-animation li').removeClass('pt-page-rotateRoomLeftOut pt-page-rotateRoomLeftIn pt-page-current pt-page-ontop');
			$('.custom-animation li').removeClass('pt-page-rotateRoomLeftOut').eq(oldIndex).addClass('pt-page-current pt-page-rotateRoomLeftOut pt-page-ontop');
			$('.custom-animation li').removeClass('pt-page-rotateRoomLeftIn').eq(newIndex).addClass('pt-page-current pt-page-rotateRoomLeftIn');
			window.setTimeout(function() {
				$('.custom-animation li').removeClass('pt-page-rotateRoomLeftOut pt-page-rotateRoomLeftIn').eq(oldIndex).removeClass('pt-page-current');
			}, 1000);
		} else {
			$('.custom-animation li').removeClass('pt-page-rotateRoomRightOut pt-page-rotateRoomRightIn pt-page-current pt-page-ontop');
			$('.custom-animation li').removeClass('pt-page-rotateRoomRightOut').eq(oldIndex).addClass('pt-page-current pt-page-rotateRoomRightOut pt-page-ontop');
			$('.custom-animation li').removeClass('pt-page-rotateRoomRightIn').eq(newIndex).addClass('pt-page-current pt-page-rotateRoomRightIn');
			window.setTimeout(function() {
				$('.custom-animation li').removeClass('pt-page-rotateRoomRightOut pt-page-rotateRoomRightIn').eq(oldIndex).removeClass('pt-page-current');
			}, 1000);
		}
	}
	function doThis2(ele, oldIndex, newIndex){
		slider1.goToSlide(newIndex);
	}
	$(".home-slider .bx-pager-item a").click(function() {
		default0 = true;
	});

	var speedval = ($('.bxslider').attr("speed")) ? parseInt($('.bxslider').attr("speed"),10) : 1000;
	var autoplay = ($('.bxslider').attr("auto")) ? $('.bxslider').attr("auto") === "true" : false;
	$(".bxslider").bxSlider({speed: speedval,
		auto: autoplay,
		touchEnabled: false,
		pause: 7000					
	});
	
	$("#header .top-line .search .close-trig, #header .header-bar .search .close-trig").click(function() {
		$("#header .top-line .search input, #header .header-bar .search input[name='q']").val("").blur();
		return false;
	});
	
	/*Adding logic to have multiple departments */
	$("#dep").change(function() {
		var val = $(this).val();
		$(".con-module .persons article, .con-module .inline-persons article").removeClass("vis0").removeClass("even").removeClass("odd")
		if (val == "all") {
			$(".con-module .persons article, .con-module .inline-persons article").addClass("vis0")
		} else {
			$(".con-module .persons article").each(function() {
				var container = this;
				$(this).find(".role").each(function() { 
				if($(this).text() == val)
					$(container).addClass("vis0") 
					
				});
			});
			$(".con-module .inline-persons article").each(function() {
				var container = this;
				$(this).find(".role").each(function() { 
				if($(this).text() == val)
					$(container).addClass("vis0") 
					
				});
			});	
		};
		$(".con-module .persons article.vis.vis0:odd, .con-module .inline-persons article.vis.vis0:odd").addClass("odd");
		$(".con-module .persons article.vis.vis0:even, .con-module .inline-persons article.vis.vis0:even").addClass("even");
		equalHeight($(".height-1"));
		equalHeight($(".height2"));
		equalHeight($(".height3"));
		equalHeight2($(".con-box3 .news, .con-box3 .score"));
	}).change();



});


