	/*
		----------------------------------------
		showInvalInput
		-----
		
		----------------------------------------
	*/
	function showInvalInput (invalItem)
	{
		$(invalItem).focus();
		$($(invalItem).parent()).addClass("missing");
	}


	/*
		----------------------------------------
		setupBioBlock
		-----
		
		----------------------------------------
	*/
	function setupBioBlock ( )
	{
		//hide the all of the element with class bio_text
		$(".bio_text").hide();

		//toggle the componenet with class bio_text
		$(".bio").click(function(){
			$(this).next(".bio_text").slideToggle(300);
		});

	}


	/*
		----------------------------------------
		validateHomeContactForm
		-----
		
		----------------------------------------
	*/
	function validateHomeContactForm ()
	{
		var fields = ["name", "company", "email", "city", "country", "sector"];

		$("li", "#contact").each(function() {
			$(this).removeClass("missing");
		});

		for (var i=0; i < fields.length; i++)
		{
			if ($("#"+fields[i]).attr("placeholder"))
			{
				// does it contain user value or placeholder ?
				if ($("#"+fields[i]).attr("placeholder") != $("#"+fields[i]).val())
				{
					// is it empty ?
					if (!$("#"+fields[i]).val() || $("#"+fields[i]).val()==0)
					{
						showInvalInput($("#"+fields[i]));
						return false;
					}

					// type checking
					// by default field types are considered as freeformat text

					//there are exceptions :
					if ($("#"+fields[i]).hasClass("email"))
					{
						var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
						if (!emailPattern.test($("#"+fields[i]).val()))
						{
							showInvalInput($("#"+fields[i]));
							return false;
						}
					}
				}
				else
				{
					showInvalInput($("#"+fields[i]));
					return false;
				}
			}
			else
			{
				if (!$("#"+fields[i]).val() || $("#"+fields[i]).val()==0)
				{
					showInvalInput($("#"+fields[i]));
					return false;
				}
			}

		}

		// ok we're very happy, just eremember to clear the notes from the defaulttext
		if ($("#msg").attr("placeholder") == $("#msg").val())
			$("#msg").val('');

		return true;
	}






	/*
		----------------------------------------
		document ready !
		-----
		
		----------------------------------------
	*/
$(document).ready(function()
{


	/*
		all input fields will hold a default value via jquery
		the searchbox in the navbar needs it anyway
	*/
	$("[placeholder]").each(function() {
		$(this).val($(this).attr("placeholder"));
	});

	$("[placeholder]").focus(function() {
		if ($(this).val() == $(this).attr("placeholder"))
			$(this).val('');
	});

	$("[placeholder]").blur(function() {
		if ($(this).val() == '')
			$(this).val($(this).attr("placeholder"));
	});





	//
	// depending the page we're on, we need to take different actions / inits
	switch ($("body").attr("id"))
	{
		case "home10":
			/*
				the contact form show/hide mechanism
			*/
			$("#form-holder").hide();
		
			$("#contact-flip").hover(function() {
				if ($("#form-holder").css("display") == "none")
					$("#form-hint").show(100);
			}, function () {
					$("#form-hint").hide(100);
			});
		
			$("#contact-flip").click(function() {
				$("#form-holder").toggle(300);
				if ($("#form-holder").css("display") == "block")
					$("#form-hint").hide();
				return false;
			});
		
		
			// need to intercept the contact form submission
			$("#sent-msg").hide();
			$("#contact").submit(function() {
				valResult = validateHomeContactForm();
				if (valResult)
				{
					var postData = $('#contact :input').serialize();
					$.post('team-ca/home-contact.php', postData, function(data) {
						$("#sent-msg").show();
//alert(data);
					});
				}
				return false;
			});
		
		
			$(".auto-height").equalHeights();

			break;

		case  "newsletter_issue":
			$(".auto-height").equalHeights();
			break;

		case  "news_article10":
			setupBioBlock();
			break;

		case 'sophia_maps':
			$("a#map-0").fancybox();
			$("a#map-1").fancybox();
			$("a#map-2").fancybox();
			$("a#map-3").fancybox();
			$("a#map-4").fancybox();
			$("a#map-5").fancybox();
			$("a#map-6").fancybox();
			$("a#map-7").fancybox();
			$("a#map-8").fancybox();


			break;

		default:
			break;
	}


});

