
$(document).ready(function() {

	$(".image-rollover").hover(
		function () {
			imageId = this.id;
			textId = imageId.replace("image", "text");
			$("#"+ textId).addClass("text-show");
		},
		function () {
			imageId = this.id;
			textId = imageId.replace("image", "text");
			$("#"+ textId).removeClass("text-show");
		}
	);

  
	$("area.imagemap-rollover").hover(
		function () {
			areaId = this.id;
			linkId = areaId.replace("area", "navigation");
			$("a#"+ linkId).addClass("navigation-show");
		},
		function () {
			areaId = this.id;
			linkId = areaId.replace("area", "navigation");
			$("a#"+ linkId).removeClass("navigation-show");
		}
	);
	
	$("a.navigation-hidden").hover(
		function () {
			linkId = this.id;
			$("a#"+ linkId).addClass("navigation-show");
		},
		function () {
			linkId = this.id;
			$("a#"+ linkId).removeClass("navigation-show");
		}
	);
	
	
	$("a#navigation-previous").click(function() {
		navigateToItem("previous", this);
	});
	
	$("a#navigation-next").click(function() {
		navigateToItem("next", this);
	});
	
});
	
function navigateToItem(direction, thisItem)  {
	
	isFirstItem = false;
	isLastItem = false;
	isProjectItem = false;
	
	currentIndex = GetCurrentIndex();
	currentIndex = parseInt(currentIndex);
	 
	objCurrentArray 	= objKunstWerkenSeriesArrays[currentIndex];
	currentProjectId 	= objCurrentArray[1];
	if (currentProjectId != "") {
		isProjectItem = true;
	}
		
	if (direction == "next") {
		if ((currentIndex+1) < objKunstWerkenSeriesArrays.length) {
			newIndex = currentIndex + 1;
		} else {
			isLastItem = true;
		}
	} else if (direction == "previous") {
		if (currentIndex > 0) {
			newIndex = currentIndex - 1;
		} else {
			isFirstItem = true;
		}
	}
	
	var objNewArray;
	
	if ((isLastItem) && (isProjectItem)) {
		currentProjectIndex = GetCurrentIndexForProject();
		newProjectIndex = currentProjectIndex + 1;
		objNewArray = objKunstWerkenProjectArrays[newProjectIndex];
	} else {
		objNewArray = objKunstWerkenSeriesArrays[newIndex];
		
	}
	
	newId 			= objNewArray[0];
	newProjectId 	= objNewArray[1];
	newShortname 	= objNewArray[3];
	newParentId 	= objNewArray[4];
	
	//build new link
	newHref = thisItem.href;
	if (isProjectItem) {
		newHref += "&project_id="+ newProjectId;
	}
	newHref += "&parent_id="+ newParentId;
	newHref += "&id="+ newId;
	newHref += "&kunstwerk="+ newShortname;
	
	thisItem.href = newHref;
	
	
}

function GetCurrentIndex()
{
	var currentIndex;
	
	for(i=0;i < objKunstWerkenSeriesArrays.length;i++)
	{
		objArray = objKunstWerkenSeriesArrays[i];
		isCurrent = objArray[5];
		if (isCurrent == "1") {
			currentIndex = i;
		}
	}
	
	return currentIndex;
}


function GetCurrentIndexForProject()
{
	var currentIndex;
	
	for(i=0;i < objKunstWerkenProjectArrays.length;i++)
	{
		objArray = objKunstWerkenProjectArrays[i];
		isCurrent = objArray[5];
		if (isCurrent == "1") {
			currentIndex = i;
		}
	}
	
	return currentIndex;
}





function isValidContactForm(objForm, language)
{
	strAlert = "";
	strAlertIntro = "The following fields are missing:";
	if (language == "nl") {
		strAlertIntro = "De volgende velden zijn niet (volledig) ingevuld:";
	}
	
	if (objForm.strFullName.value == "") {
		if (language == "nl") {
			strAlert += "> Uw naam \n";
		} else {
			strAlert += "> Your name \n";
		}
	}
	
	if ( (objForm.strEmailAddress.value == "") || (objForm.strEmailAddress.value.indexOf("@") == -1) ) {
		if (language == "nl") {
			strAlert += "> E-mailadres \n";
		} else {
			strAlert += "> Email address \n";
		}
	}
	
	if (objForm.strMessage.value == "") {
		if (language == "nl") {
			strAlert += "> Bericht \n";
		} else {
			strAlert += "> Message \n";
		}
	}
	
	if (strAlert != "") {
		alert(strAlertIntro +" \n"+ strAlert);
		return false;
	} else {
		return true;
	}
}


