function updateBackground(newBackgroundImage, newBackgroundColor) {
	elBackground = findObject('backgroundContainer');
	elBackground.style.backgroundImage = "url('"+wwwroot+"/images/nav/"+newBackgroundImage+"')";
	elBackground.style.backgroundColor = "#"+newBackgroundColor;
}

function changeMedialist(album, listToShow, mediaType) {
	var i=1;
	while (findObject(mediaType+'List_'+album+'_'+i)!=null) {
		findObject(mediaType+'List_'+album+'_'+i).style.display = (i==listToShow ? '' : 'none');
		findObject(mediaType+'Link_'+album+'_'+i).className = (i==listToShow ? 'inactiveMoreLink' : 'activeMoreLink');
		i++;
	}
}

/** Add or remove a destination from the list of saved destinations */
function toggleSave(id, title, doDelete, deleteFrom, url) {
	var cookieDate = new Date();
	cookieDate.setFullYear(2015);
	var savedDestinations = getCookie('savedDestinations');
	savedDestinations=(savedDestinations?savedDestinations.split(','):[]);
	if (doDelete) {
		var savedDestinations2=[];
		for(var i=0; i<savedDestinations.length; i++) {
			if (savedDestinations[i]!=id) savedDestinations2.push(savedDestinations[i]);
		}
		savedDestinations = savedDestinations2;
		if (deleteFrom!='submit') {
			var el1=findObject('savedDestination'+id);
			if (el1) el1.parentNode.removeChild(el1);
		}
		if (deleteFrom!='saved') {
			var el2=findObject('submitDestination'+id);
			if (el2) el2.parentNode.removeChild(el2);
			var el2b=findObject('submitDestinationB'+id);
			if (el2b) el2b.parentNode.removeChild(el2b);
			if (savedDestinations.length<=3) {
				var el3=findObject('submitDestinationWarning');
				if (el3) el3.parentNode.removeChild(el3);
				var el3b=findObject('submitDestinationWarningB');
				if (el3b) el3b.parentNode.removeChild(el3b);
			}
		}
	} else {
		var found=false;
		for(var i=0; i<savedDestinations.length && !found; i++) {
			if (savedDestinations[i]==id) found=true;
		}
		if (!found) savedDestinations.push(id);
	}
	var totalSavedDestinationsEl = findObject('totalSavedDestinationsEl');
	if (totalSavedDestinationsEl) totalSavedDestinationsEl.innerHTML = savedDestinations.length;
	setCookie("savedDestinations",savedDestinations.join(','), cookieDate, (atDevelopmentServer ? wwwroot+'/' : wwwroot.replace(/%20/, "")+'/'));
	if (url) {
		window.location=wwwroot+'/'+url;
	} else if (!doDelete) {
		window.location.reload();
	}
}

/** Check whether the currently displayed list of saved destinations is accurate (may differ due to back-button action s*/
function refreshSavedIfNeeded(displayedSavedDestinations) {
	var savedDestinations = getCookie('savedDestinations');
	savedDestinations=(savedDestinations?savedDestinations.split(','):[]);
	if (!haveSameElements(savedDestinations, displayedSavedDestinations)) {
		window.location.reload();
	}
}

/** Check whether two arrays have the same elements */
function haveSameElements(arr1, arr2) {
	arr1.sort();
	arr2.sort();
	var i=0, j=0;
	while(i<arr1.length && j<arr2.length) {
		if (arr1[i]!=arr2[j]) return false;
		var val=arr1[i];
		while(i<arr1.length && arr1[i]==val) i++;
		while(j<arr2.length && arr2[j]==val) j++;
	}
	return (i>=arr1.length && j>=arr2.length);
}

var currentMap = 'uitleg';
function showList(map) {
	findObject('map_'+currentMap).style.display = 'none';
	findObject('map_'+map).style.display = '';
	currentMap = map;
}

// The following functions are used in the destination filter
// from the destination_search.ihtml template

var search = { 'continent':'', 'budget':'', 'type':'' };
function togglePulldown(showPulldown, show) {
	// Get the right pulldown.
	pd = findObject(showPulldown);
	// If show == undefined just toggle the display.
	if (show == undefined) {
		// Toggle
		show = (pd.style.display == 'none' ? true : false);
	}
	// Set the display of the pulldown.
	pd.style.display = (show ? '' : 'none');
}

function passSearch() {
//	findObject('searchContinent').value = search['continent'];
//	findObject('searchBudget').value = search['budget'];
//	findObject('searchType').value = search['type'];
	return true;
}

function toggleSearch(el, type, value, doSetCookie) {
	search[type]=(search[type]?','+search[type]:'');
	if (el.src.match(/_f2/)!=null) {
		// Turn checkbox off
		el.src = el.src.replace(/_f2/, '');
		// Remove search from string
		search[type] = search[type].replace(','+value, '');
	} else {
		// Turn checkbox on
		el.src = el.src.replace(/.gif/, '_f2.gif');
		// Add search to string
		search[type] += ','+value;
	}
	search[type]=search[type].replace(/^,+/, '');
	// Save value in cookie, for transmitting to server
	if (doSetCookie) {
		setCookie('search'+type.substr(0,1).toUpperCase()+type.substr(1),
				 search[type],0,wwwroot+'/');
	}
}


// The following functions are used elsewhere

function delayShowCorrectButton() {
	if (mouseInId[1] || mouseInId[2] || mouseInId[3]) {
		ct_button.style.display = 'none';
		ct_button_f2.style.display = '';
	} else {
		ct_button.style.display = '';
		ct_button_f2.style.display = 'none';
	}
}

function showCorrectButton() {
	setTimeout("delayShowCorrectButton()", '50');
}

/** tweets_list scroll-effect */
function doScrollEffect(id, vspeed) {
   var scrollId = id;
   var scrollVspeed = vspeed;
   if (scrollId) {
      var div = document.getElementById(scrollId);
      div.scrollTop=Math.max(0, Math.min(div.scrollHeight-div.clientHeight, div.scrollTop+scrollVspeed));
   }
   return false;
}

