function formatText(index, panel) {
  return linksList[index-1];
}

function equalHeight(group) {
	tallest = 0;
	group.each(function() {
		thisHeight = $(this).height();
		if(thisHeight > tallest) {
			tallest = thisHeight;
		}
	});
	group.height(tallest);
}
function validateForm(form) {
	var incomplete = false;
	var invalidEmail = false;

	for (var i = 0, l = form.elements.length; i < l; i++) {
		switch (form.elements[i].nodeName.toUpperCase()) {
			case "INPUT":
				if ((form.elements[i].type.toUpperCase() == "TEXT") && !incomplete && (/^\s*$/).test(form.elements[i].value)) {
					incomplete = true;
				}

				if ((form.elements[i].name.indexOf("email") > -1) && (form.elements[i].value.indexOf("@") == -1)) {
					invalidEmail = !(/^\s*$/).test(form.elements[i].value);
				}
				break;

			case "TEXTAREA":
				if (!incomplete && (/^\s*$/).test(form.elements[i].value)) {
					incomplete = true;
				}

				break;
		}
	}

	if (incomplete || invalidEmail) {
		var message = [];

		if (incomplete) {
			message.push("It seems you left some fields empty,\nplease fill each one.");
		}

		if (invalidEmail) {
			if (incomplete) {
				message.push("\n\nBesides, your ");
			} else {
				message.push("Your ");
			}
			message.push("email address seems to be incorrect,\nplease check it.");
		}

		alert(message.join(""));
		return false;
	}

	return true;
}

$(function () {
	/*
	$("#loginBox form").submit(function () {
		var host = location.host;
		if (!(/^\d+\./).test(host) && !(/^www\./i).test(host)) {
			host = "www." + host;
			this[0].form.action = "https://" + host + "/Passport/Account/LogOn";
			return true;
		}
		else {
			this[0].form.action = "http://" + host + "/Passport/Account/LogOn";
			return true;
		}
	});
	
	$("#loginBox input").keydown(function (e) {
		if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
			$("#loginBox form").submit();
			return true;
		}
	});
	*/
	
	$('.slideShow').anythingSlider({
		easing: "easeInOutExpo",         // Anything other than "linear" or "swing" requires the easing plugin
		autoPlay: true,                  // This turns off the entire FUNCTIONALY, not just if it starts running or not.
		delay: 10000,                     // How long between slide transitions in AutoPlay mode
		startStopped: false,             // If autoPlay is on, this can force it to start stopped
		animationTime: 1000,             // How long the slide transition takes
		hashTags: true,                  // Should links change the hashtag in the URL?
		buildNavigation: false,          // If true, builds and list of anchor links to link to each slide
		pauseOnHover: true,              // If true, and autoPlay is enabled, the show will pause on hover
		startText: "Go",             	 // Start text
		stopText: "Stop",                // Stop text
		navigationFormatter: formatText  // Details at the top of the file on this use (advanced use)
	});
	
	$('#planning').click(function(){ $('.slideShow').anythingSlider(1); });
	$('#serving').click(function(){ $('.slideShow').anythingSlider(2); });
	$('#search').click(function(){ $('.slideShow').anythingSlider(3); });
	$('#tracking').click(function(){ $('.slideShow').anythingSlider(4); });
	$('#reporting').click(function(){ $('.slideShow').anythingSlider(5); });
	
	var tabContainers = $('div.tabs > div');
	tabContainers.hide().filter(':first').show();
	
	$('div.tabs ul.tabsNav a').click(function () {
		tabContainers.hide();
		tabContainers.filter(this.hash).show();
		$('div.tabs ul.tabsNav a').removeClass('selected');
		$(this).addClass('selected');
		return false;
	}).filter(':first').click();
	
	/*
	$("#login > a").click(function(e) { 
		$(this).parent().toggleClass('on');
		$('#loginBox').toggle(); 
		$('#username').focus();
		e.preventDefault();
	});
	*/ 
	
	$('.topic .name').click(function(e) {
		$(this).parent().toggleClass('hidden');
	});
	
	equalHeight($(".equal"));
	
	/*
	var subscribeField = $("#news input[type=text]")[0];
	var presetValue = subscribeField.value;
	subscribeField.onfocus = function () {
		if (this.value.toLowerCase() == presetValue.toLowerCase())
			this.value = "";
	};
	subscribeField.onblur = function () {
		if (/^\s*$/.test(this.value))
			this.value = presetValue;
	};
	*/
});