	//Spry data section:

	var dsRegions = new Spry.Data.XMLDataSet("/regions/Xml", "regions/region");
	var dsPhotographers = new Spry.Data.XMLDataSet("/photographers/regionXml/{dsRegions::id}", "photographers/photographer");
	var dsCountries = new Spry.Data.XMLDataSet("/countries/Xml/{dsRegions::id}", "countries/country");
	var dsCities = new Spry.Data.XMLDataSet("/cities/Xml", "cities/city");

	function cityFilter(ds, row, index)
	{ 
		var countryRows = dsCountries.getData(true);
		var countryNumRows = countryRows.length;

		//if a city is checked, show the Show All image.
		document.getElementById('showAllImage').style.visibility = 'visible';	

		//for each city, loop through the countries. 
		for (var x = 0; x < countryNumRows; x++)
		{
			
			//is this the country for this city?
			if(row['country_id'] == countryRows[x]['id'])
			{
				var countryEl = document.getElementById('countryCheck' + x);
				
				//is it checked?
				if(countryEl.checked == true)
					return row;
				else
					return null;
			}
		}
	}
	
	function photographerFilter(ds, row, index)
	{	 
		var booCountryChecked = false;
		var booCityChecked = false;
		var booReturnRow = false;
		
		var countryRows = dsCountries.getData(true);
		var cityRows = dsCities.getData(true);
		
		//if the city dataset is loaded, check:
		//1. if any cities are checked (booCityChecked) and
		//2. if the city for this photographer is checked (booReturnRow).
		if(cityRows != null)
		{
			var cityNumRows = cityRows.length;
			
			for (var x = 0; x < cityNumRows; x++)
			{
				var cityEl = document.getElementById('cityCheck' + x);
				
				if(cityEl != null)
				{
					if(cityEl.checked == true)
					{
						//is this the city for this photographer?
						if(row['city_id'] == cityRows[x]['id'])
							booReturnRow = true;
							
						booCityChecked = true;
					}
				}
			}			
		}
	
		//Only if no cities are checked, check
		//1. if any counries are checked (booCountryChecked) and
		//2. if the country for this photographer is checked.
		if(booCityChecked == false)
		{
			if(countryRows != null)
			{	
				var countryNumRows = countryRows.length;
				
				for (var x = 0; x < countryNumRows; x++)
				{
					var countryEl = document.getElementById('countryCheck' + x);
					
					if(countryEl.checked == true)
					{
						//is this the country for this photographer?
						if(row['country_id'] == countryRows[x]['id'])
							booReturnRow = true;
							
						booCountryChecked = true;
					}
				}
				
				//if no countries are checked, return the row because no filter has been applied.
				if(booCountryChecked == false)
					booReturnRow = true;
					
			}
			else
			{
				//if the dataset is null, return the row because the region is in transition.
				booReturnRow = true;
			}
		}

		if(booReturnRow == true)
			return row;
		else
			return null;
			
	}
			
	function filterAll(ds, row, index)
	{
		return null;
	}

	//an observer that will moniter dsCountries. When it first loads, apply city filter and show the div.
	var obsC = new Object; 
	
	obsC.onPostLoad = function(notifier, data)
	{
		dsCities.filter(filterAll, true);

		//Swap the country image:
		if(dsRegions.getCurrentRowNumber() == 0)
		{
			document.getElementById('countryLabel').style.display = 'none';
			document.getElementById('frenchRegionLabel').style.display = 'block';
		}
		else
		{
			document.getElementById('frenchRegionLabel').style.display = 'none';
			document.getElementById('countryLabel').style.display = 'block';
		}
	}
	
	dsCountries.addObserver(obsC);

	var obsP = new Object;

	obsP.onPostLoad = function(notifier, data)
	{

		var loading = document.getElementById('loading').style.display;

		document.getElementById('loading').style.display = 'none';

		if(loading == 'block')
			document.getElementById('searchcolumns').style.display = 'block';
	}

	dsPhotographers.addObserver(obsP);

	//also watch the panels and to see when they update.
	var countryPanelObserver = new Object; 

	countryPanelObserver.onPostUpdate = function(notifier, data) { getcontent_height(); } 
	countryPanelObserver.onPreUpdate = function(notifier, data) { moveToTop(); } 

	Spry.Data.Region.addObserver("spryCountries", countryPanelObserver);

	var cityPanelObserver = new Object; 

	cityPanelObserver.onPostUpdate = function(notifier, data) { getCitycontent_height(); } 
	cityPanelObserver.onPreUpdate = function(notifier, data) { moveCityToTop(); } 

	Spry.Data.Region.addObserver("spryCities", cityPanelObserver);

	var photogPanelObserver = new Object; 

	photogPanelObserver.onPostUpdate = function(notifier, data) { getPhotogcontent_height(); } 
	photogPanelObserver.onPreUpdate = function(notifier, data) { movePhotogToTop(); } 

	Spry.Data.Region.addObserver("spryPhotographers", photogPanelObserver);

	//end spry data section.

	//div control section:

	var loaded;

	function loadPhotographer(id)
	{
		showWait();

		var frm = document.getElementById('portfolioFrame');
		frm.src = "/photographers/portfolios/" + id;

		return false;

	}

	function showPhotographer()
	{	
		if(loaded == true)
		{
			document.getElementById('searchcolumns').style.display = 'none';	
			document.getElementById('loading').style.display = 'none';	
			document.getElementById('portfolio').style.display = 'block';	
		}
		else
		{
			loaded = true;
		}
	}
	
	function showWait()
	{
		document.getElementById('portfolio').style.display = 'none';	
		document.getElementById('searchcolumns').style.display = 'none';		
		document.getElementById('loading').style.display = 'block';
	}

	function showSearch()
	{
		document.getElementById('portfolio').style.display = 'none';	
		document.getElementById('loading').style.display = 'none';
		document.getElementById('searchcolumns').style.display = 'block';		
	}

	function changeRegion(pos)
	{
		if(pos == -1)
		{
			dsCountries.loadData(); //Refresh countries list to show all unchecked.
			document.getElementById('showAllImage').style.visibility = 'hidden';	

			var regRows = dsRegions.getData(true);
			
			for (var x = 0; x < regRows.length; x++)
			{
				var regEl = document.getElementById('regionCheck' + x);
				
				//is it checked?
				if(regEl.checked == true)
				{
					regEl.checked = false;
					break;
				}
			}
		}
		else
		{
			document.getElementById('showAllImage').style.visibility = 'visible';
		}

		dsCities.filter(filterAll, true); 
		dsPhotographers.filter(photographerFilter, true); 
		dsRegions.setCurrentRow(pos);

	}

	//end div control section.
	