//Site Search behaviour
$(document).ready(function () {

	$("body").addClass("js");

	var interval;

	$('.carousel').roundabout({
		btnNext: '#next',
		btnPrev: '#previous'
	})
	.hover(
		function () {
			// oh no, it's the cops!
			clearInterval(interval);
		},
		function () {
			// false alarm: PARTY!
			interval = startAutoPlay();
		}
	);

	// let's get this party started
	interval = startAutoPlay();

	function startAutoPlay() {
		return setInterval(function () {
			$('.carousel').roundabout_animateToNextChild();
		}, 7000);
	}

	// No :hover selector in CSS for buttons
	$('input.imgButton').hover(
		function () {
			$(this).attr("src", "/images/moreArrowOn.png");
		},
		function () {
			$(this).attr("src", "/images/moreArrow.png");
		}
	);

	//	$('.search .text').focus(function () { searchFocus(this, "Enter search"); });
	//	$('.search .text').blur(function () { searchBlur(this, "Enter search"); });

	//	$('.caseStudySearch .text').focus(function () { searchFocus(this, "Enter text"); });
	//	$('.caseStudySearch .text').blur(function () { searchBlur(this, "Enter text"); });

	$('input').click(function () {
		if ($(this).val() == 'Enter text' || $(this).val() == 'Enter search')
			$(this).val('');
	});

	$('input, textarea').keyup(function () {
		var value = $(this).val();
		while (value.indexOf('>') != -1 || value.indexOf('<') != -1) {
			value = value.replace('>', '').replace('<', '')
			$(this).val(value);
		}
	});

	function searchFocus(input, defaultText) {
		if (input.value == defaultText) { input.value = ""; }
	}
	function searchBlur(input, defaultText) {
		if (input.value == "") { input.value = defaultText; }
	}

	var footerStatus = "closed";
	var footerButton = $(".footerExpand");
	footerButton.click(function () {
		if (footerStatus == "closed") {
			$(".footerFull").slideDown(300);
			footerStatus = "open";
			footerButton.addClass("open");
		}
		else {
			$(".footerFull").slideUp(300);
			footerStatus = "closed";
			footerButton.removeClass("open");
		}
	});


	var count = 1;
	$(".menu ul").children().each(function () {
		addClickEvent($(this), count);
		count++;
	});
	function addClickEvent(listitem, counter) {
		$(listitem.children()).click(function () { toggleFeature(counter); return false; });
	}
	function toggleFeature(id) {
		$(".featureImages").children().each(function () {
			var child = $(this);
			child.removeClass("selected");
		});
		$(".menuitem").removeClass("selected");
		var imageClass = ".image" + id;
		var spanClass = ".caption" + id;
		var menuClass = ".menu" + id;
		$(imageClass).addClass("selected");
		$(spanClass).addClass("selected");
		$(menuClass).addClass("selected");
	}


	//accordion script
	var accStatus1 = "closed";
	var accStatus2 = "closed";
	var accStatus3 = "closed";

	$(".section1 .toggle").click(function () { accordionToggle(1); return false; });
	$(".section2 .toggle").click(function () { accordionToggle(2); return false; });
	$(".section3 .toggle").click(function () { accordionToggle(3); return false; });
	function accordionToggle(id) {
		var tempStatus = "";
		if (id == 1) {
			tempStatus = accStatus1;
		}
		if (id == 2) {
			tempStatus = accStatus2;
		}
		if (id == 3) {
			tempStatus = accStatus3;
		}
		if (tempStatus == "open") {

			$(".section" + id + " .accContent").slideUp(300);
			$(".section" + id).removeClass("selected");

			if (id == 1) {
				accStatus1 = "closed";
			}
			if (id == 2) {
				accStatus2 = "closed";
			}
			if (id == 3) {
				accStatus3 = "closed";
			}
		}
		if (tempStatus == "closed") {

			$(".section" + id + " .accContent").slideDown(300);
			$(".section" + id).addClass("selected");

			if (id == 1) {
				accStatus1 = "open";
			}
			if (id == 2) {
				accStatus2 = "open";
			}
			if (id == 3) {
				accStatus3 = "open";
			}
		}
	}

	accordionToggle(1);


	$('.scroll-pane-split').jScrollPane(
			{
				showArrows: true,
				verticalArrowPositions: 'split',
				horizontalArrowPositions: 'split'
			}
		);



	$('#nav li').hover(
			function () {
				//show its submenu
				$('ul', this).slideDown(100);
			},
			function () {
				//hide its submenu
				$('ul', this).slideUp(100);
			}
		);


	$(".lightbox").colorbox({ iframe: true, innerWidth: 425, innerHeight: 344 });



});
