/*
frameworks.js
Copyright(c)2008-2011 UserBuddy Limited
All Rights Reserved
*/

var featureResolution = 660;
var featureOn = false;
var promoted = new Array();

// IF BROWSER SUPPORTS WebKit
var webkit = false;
if( navigator.userAgent.indexOf( "WebKit" ) > -1 )
{
	webkit = true;
}

// COOKIES
function setCookie( name, value, days )
{
	if( days )
	{
		var date = new Date();
		date.setTime( date.getTime() + ( days * 24 * 60 * 60 * 1000 ) );
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function getCookie( name )
{
	var nameEQ = name + "=";
	var ca = document.cookie.split( ';' );
	for( var i = 0; i < ca.length; i++ )
	{
		var c = ca[i];
		while( c.charAt( 0 ) == ' ' ) c = c.substring( 1, c.length );
		if( c.indexOf( nameEQ ) == 0 ) return c.substring( nameEQ.length, c.length );
	}
	return null;
}

function killCookie( name )
{
	setCookie( name, "", -1 );
}

// SEARCH TIP
var searchTipVisible = 0;
var duration = 500;  // effect time in milliseconds
function setOpacity( id, level )  // 0.00 through 1.00
{
	document.getElementById( id ).style.opacity = level;
	switch( level )
	{
		case 0:
		{
			document.getElementById( id ).style.display = 'none';
			document.getElementById( id ).style.visibility = 'hidden';
			break;
		}

		case 0.01:
		{
			document.getElementById( id ).style.display = 'block';
			document.getElementById( id ).style.visibility = 'visible';
			break;
		}
	}
}
function searchTipMarkVisible()
{
	searchTipVisible = 1;
}
function show( id, delay )  // element id, delay before action (milliseconds)
{
	var element = document.getElementById( id );
	if( element )
	{
		if( ( element.style.display == 'none' ) || ( element.style.display == '' ) )
		{
			if( id == 'searchTipContainer' )
			{
				if( searchTipVisible == 0 )
				{
					if( delay == undefined ) delay = 0;
					for( var i = 1; i <= 100; i++ )
					{
						var j = i / 100;
						setTimeout( function(){ setOpacity( id, j ) }, delay + ( j * duration ) );
					}
					setTimeout( function(){ searchTipMarkVisible() }, 500 );
				}
			}
			else
			{
				if( delay == undefined ) delay = 0;
				for( var i = 1; i <= 100; i++ )
				{
					var j = i / 100;
					setTimeout( function(){ setOpacity( id, j ) }, delay + ( j * duration ) );
				}
			}
		}
	}
}

function hide( id, delay )  // element id, delay before action (milliseconds)
{
	var element = document.getElementById( id );
	if( element )
	{
		if( element.style.display != 'none' )
		{
			if( document.getElementById( id ).style.opacity > 0 )
			{
				if( id == 'searchTipContainer' )
				{

					if( searchTipVisible == 1 )
					{
						if( delay == undefined ) delay = 0;
						for( var i = 1; i <= 100; i++ )
						{
							var j = i / 100;
							setTimeout( function(){ setOpacity( id, ( ( 100 - i ) / 100 ) ) }, delay + ( j * duration ) );
						}
						searchTipVisible = 0;
					}
				}
				else
				{
					if( delay == undefined ) delay = 0;
					for( var i = 1; i <= 100; i++ )
					{
						var j = i / 100;
						setTimeout( function(){ setOpacity( id, ( ( 100 - i ) / 100 ) ) }, delay + ( j * duration ) );
					}
				}
			}
		}
	}
}

// SCROLLBAR
function getScrollBarWidth()
{
	var inner = document.createElement('p');
	inner.style.width = "100%";
	inner.style.height = "200px";

	var outer = document.createElement('div');
	outer.style.position = "absolute";
	outer.style.top = "0px";
	outer.style.left = "0px";
	outer.style.visibility = "hidden";
	outer.style.width = "200px";
	outer.style.height = "150px";
	outer.style.overflow = "hidden";
	outer.appendChild (inner);

	document.body.appendChild (outer);
	var w1 = inner.offsetWidth;
	outer.style.overflow = 'scroll';
	var w2 = inner.offsetWidth;
	if (w1 == w2) w2 = outer.clientWidth;

	document.body.removeChild (outer);

	return (w1 - w2);
};

// PHOTO ZOOM
function zoom()
{
	function zoomStep()
	{
		var step = 10;
		var width = parseInt( img.getAttribute( 'width' ) );
		var height = parseInt( img.getAttribute( 'height' ) );
		if( img.state == 'small' )
		{
			width += step;
			height += Math.floor( step * img.ratio );
			img.setAttribute( 'width', width );
			img.setAttribute( 'height', height );
			if( width > img.largeWidth - step )
			{
				img.setAttribute( 'width', img.largeWidth );
				img.setAttribute( 'height', img.largeHeight );
				img.setAttribute( 'src', img.largeSrc );
				window.clearInterval( interval );
				img.state = 'large';
			}
		}
		else
		{
			width -= step;
			height -= Math.floor( step * img.ratio );
			img.setAttribute( 'width', width );
			img.setAttribute( 'height', height );
			if( width < img.smallWidth + step )
			{
				img.setAttribute( 'width', img.smallWidth );
				img.setAttribute( 'height', img.smallHeight );
				img.src = img.smallSrc;
				window.clearInterval( interval );
				img.state = 'small';
			}
		}
	}

	var img = this;
	img.src = img.smallSrc;
	if( !img.preloaded )
	{
		img.preloaded = new Image();
		img.preloaded.src = img.largeSrc;
	}

	var interval = window.setInterval( zoomStep, 3 );
	return false;
}
function initZoom()
{
	var img = document.getElementsByTagName( 'img' );
	for( var i = 0; i < img.length; i++ )
	{
		if( img[i].className == 'zoom' )
		{
			img[i].style.cursor = 'pointer';
			img[i].title        = 'Click to Zoom';
			img[i].state        = 'small';
			img[i].smallSrc     = img[i].getAttribute( 'src' );
			img[i].smallWidth   = parseInt( img[i].getAttribute( 'width' ) );
			img[i].smallHeight  = parseInt( img[i].getAttribute( 'height' ) );
			img[i].largeSrc     = img[i].getAttribute( 'largeSrc' );
			img[i].largeWidth   = parseInt( img[i].getAttribute( 'largeWidth' ) );
			img[i].largeHeight  = parseInt( img[i].getAttribute( 'largeHeight' ) );
			img[i].ratio        = ( img[i].smallHeight / img[i].smallWidth );
			img[i].onclick      = zoom;
		}
	}
}

// AJAX
function js( file )
{
	var id = 'run';
	script = document.createElement( 'script' );
	script.id = id;
	script.type = 'text/javascript';
	script.src = file;

	var element = document.getElementById( id );
	if( element != null )
	{
		element.parentNode.removeChild( element );
		delete element;
	}

	document.getElementsByTagName( "head" )[0].appendChild( script );
}
var scriptNumber = 0;
var searchAppend = '';
var scrollEnable = 0;
var searchType = 'property';
function ajax( url, id, append )
{
	if( ( !append ) && ( document.getElementById( 'ajaxMask' ) ) )
	{
		if( id == 'list' )
		{
			document.getElementById( 'ajaxMask' ).style.display    = 'block';
			document.getElementById( 'ajaxMask' ).style.visibility = 'visible';
		}
	}
	
	if( ( id == 'list' ) && ( !append ) )
	{
		if( url.indexOf( 'directory.php' ) > -1 )
		{
			document.getElementById( 'list' ).onscroll = function(){};
		}
		else
		{
			changeSearchType( 'property' );
			document.getElementById( 'list' ).onscroll = function()
			{
				liveScroll();
				return false;
			};	
		}
	}
	
	
	var ajax = false;
	if( navigator.appName == "Microsoft Internet Explorer" ) ajax = new ActiveXObject( "Microsoft.XMLHTTP" );
	else ajax = new XMLHttpRequest();
	if( ajax )
	{
		// CALLBACK FUNCTION
		ajax.onreadystatechange = function()
		{
			if( ajax.readyState == 4 && ajax.status == 200 )
			{
				// FIND MY SCRIPT ID
				var offset = ajax.responseText.indexOf( '<script id="dynamic" type="text/javascript">\n' );
				if(offset == -1)
				{
					if( id == 'list' )
					{
						if( appendable == 1 )
						{
							// JAVASCRIPT NOT FOUND
							if( append ) document.getElementById( id ).innerHTML += ajax.responseText;
							else document.getElementById( id ).innerHTML = ajax.responseText;
						}
					}
					else
					{
						// JAVASCRIPT NOT FOUND
						if( append ) document.getElementById( id ).innerHTML += ajax.responseText;
						else document.getElementById( id ).innerHTML = ajax.responseText;
					}
				}
				else
				{
					// JAVASCRIPT FOUND
					if( append ) document.getElementById( id ).innerHTML += ajax.responseText.substr( 0, offset );
					else document.getElementById( id ).innerHTML = ajax.responseText.substr( 0, offset );

					// POINTER TO SCRIPT ELEMENT
					var jsElement = ajax.responseText.substr( offset, ajax.responseText.length );

					// REMOVE TAGS
					jsElement = jsElement.replace( '<script id="dynamic" type="text/javascript">\n', '' );
					jsElement = jsElement.replace( '\n</script>\n', '' );

					// CREATE NEW SCRIPT ELEMENT IN <HEAD> AND COPY CONTENTS OF DOWNLOADED SCRIPT TO IT
					script = document.createElement( 'script' );
					script.id = 'dynamic' + scriptNumber;
					script.type = 'text/javascript';
					script.text = jsElement;
					document.getElementsByTagName( 'head' )[0].appendChild( script );

					// INCREMENT SCRIPT ID
					scriptNumber++;

					// PAGE ACCESS TO GOOGLE ANALYTICS
					if( typeof( window[ 'analytics' ] ) != "undefined" )
					{
						try {
							var pageTracker = _gat._getTracker( analytics );
							pageTracker._trackPageview();
						} catch( err ) {}
					}
				}

				if( append == null )
				{
					switch( id )
					{
					case 'window':
						document.getElementById( 'mask' ).style.display = '';
						document.getElementById( id ).style.visibility = 'visible';
						windowRePos();

						break;
					}
				}
				if( id == 'list' )
				{
					// START SCROLLING
					if( url.indexOf( 'directory.php' ) < 0 )
					{
						scrollEnable = 1;
					}
					
					if( url.indexOf( 'query=' ) > 0 )
					{ // CHECK FOR QUERY RESULT (TO ADD TO FILTERS)
						var query = url.substr( url.indexOf( 'query=' ) + 6 );
						query = query.substr( 0, query.indexOf( '&' ) );
						query = query.replace( /^\s+|\s+$/g, "" );
						
						if( query != '' )
						{
							if( ajax.responseText.indexOf( 'NO RESULTS' ) > 0 )
							{
								// DONT SAVE FILTER
							}
							else
							{
								// clear query
								// add filter
								
								if( searchType == 'directory' )
								{
									addSearchFilter( document.getElementById( 'query' ).value, 'filterQueryDirectory', document.getElementById( 'query' ).value );
								}
								else
								{
									addSearchFilter( document.getElementById( 'query' ).value, 'filterQuery', document.getElementById( 'query' ).value );
								}
								document.getElementById( 'query' ).value = '';
								
							}
						}
					}
				}
				initZoom();
				
				if( ( !append ) && ( document.getElementById( 'ajaxMask' ) ) )
				{
					if( id == 'list' )
					{
						document.getElementById( 'ajaxMask' ).style.display    = '';
						document.getElementById( 'ajaxMask' ).style.visibility = '';
					}
				}
			}
		}

		ajax.open( 'GET', url, true );
		ajax.setRequestHeader( 'Content-Type', 'application/x-www-form-urlencoded' );
		ajax.send( null );
	}
}

// WINDOW
var windowCounter = 0;  // TO KEEP TRACK OF HOW MANY WINDOWS ARE OPEN
var windowHandle = 0;   // TO IDENTIFY THE WINDOW
function openWindow( width, height, url )
{
	// AUTOSIZE
	if( width == undefined ) width = screenWidth - 40;
	if( height == undefined ) height = screenHeight;

	var ID = 'window' + windowHandle;
	var canvasID = 'window' + windowHandle + 'Canvas';
	var window = '\
		<div id="' + ID + '" class="window">\
			<table cellpadding="0" cellspacing="0">\
				<tbody>\
					<tr>\
						<td class="windowTopLeft">\
						</td>\
						<td class="windowTopCenter">\
						</td>\
						<td class="windowTopRight">\
							<div class="windowClose" title="Close" onClick="windowClose( \'' + ID + '\' )" />\
						</td>\
					</tr>\
					<tr>\
						<td class="windowMiddleLeft">\
						</td>\
						<td>\
							<div id="' + canvasID + '" class="windowCanvas">\
							</div>\
						</td>\
						<td class="windowMiddleRight">\
						</td>\
					</tr>\
					<tr>\
						<td class="windowBottomLeft">\
						</td>\
						<td class="windowBottomCenter">\
						</td>\
						<td class="windowBottomRight">\
						</td>\
					</tr>\
				</tbody>\
			</table>\
		</div>';

	document.getElementById( 'dynamic' ).innerHTML += window;

	// WINDOW SIZE
	document.getElementById( ID ).style.left = ( ( screenWidth / 2 ) - ( width / 2 ) ) + 'px';
	document.getElementById( ID ).style.top = ( ( screenHeight / 2 ) - ( ( height / 2 ) ) + 25 ) + 'px';
	document.getElementById( ID ).style.width = width + 'px';
	document.getElementById( ID ).style.height = height + 'px';

	document.getElementById( canvasID ).style.width = ( width - 50 ) + 'px';
	document.getElementById( canvasID ).style.height = ( height - 100 ) + 'px';

	if( url != undefined )
	{
		// ADD WINDOW ID AS NEW PARAMETER
		if( url.indexOf( '?' ) > -1 )
		{
			// ADD TO EXISTING PARAMS
			url += '&windowID=' + ID;
		}
		else
		{
			// NO CURRENT PARAMS
			url += '?windowID=' + ID;
		}

		// CALL FOR DATA
		ajax( url, canvasID );
	}
	// MASK ON
	if( windowCounter++ == 0 ) document.getElementById( 'mask' ).style.display = '';

	// SHOW THIS WINDOW
	document.getElementById( ID ).style.visibility = 'visible';

	// BUMP THE WINDOW HANDLE
	windowHandle++;

	// RETURN CANVAS ID (NEEDED IF EMPTY WINDOW REQUIRED)
	return canvasID;
}
/*
// ADAMS REPOSITIONER
//	windowWidth = width;
//	windowHeight = height;
var windowWidth = 0;
var windowHeight = 0;
function windowRePos()
{
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' )
	{
		// Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	}
	else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight))
	{
		// IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	}
	else if(document.body && (document.body.clientWidth || document.body.clientHeight))
	{
		// IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}

	var width = ( document.getElementById( 'windowCanvas' ).clientWidth + 90 );
	var height = ( document.getElementById( 'windowCanvas' ).clientHeight + 100 );


	var windowLeft = ( ( myWidth / 2 ) - ( width / 2 ) ) + 6;
	if( windowLeft < 0  )
	{
		windowLeft = 0;
	}
	document.getElementById( 'window' ).style.left = windowLeft + 'px';

	var windowTop = ( ( myHeight / 2 ) - ( height / 2 ) );
	if( windowTop < 0  )
	{
		windowTop = 0;
	}
	document.getElementById( 'window' ).style.top = windowTop + 'px';

	// if window width > browser width then resize width
	if( myWidth > windowWidth )
	{
		document.getElementById( 'window' ).style.width = windowWidth + 'px';
	}
	else if( myWidth < width )
	{
		document.getElementById( 'windowCanvas' ).style.width = myWidth - 90 + 'px';
		document.getElementById( 'window' ).style.width = myWidth + 'px';
	}

	// if window height > browser height then resize height
	if( myHeight > windowHeight )
	{
		document.getElementById( 'window' ).style.height = windowHeight + 'px';
	}
	else if( myHeight < height )
	{
		document.getElementById( 'window' ).style.height = myHeight - 10 + 'px';
	}
}
*/
function windowClose( ID )
{
	// REMOVING NODE
	var dynamic = document.getElementById( 'dynamic' );
	var element = document.getElementById( ID );
	if( element.hasChildNodes() )
	{
		while( element.childNodes.length >= 1 )
		{
			element.removeChild( element.firstChild );
		}
	}
	dynamic.removeChild( element );

	// MASK OFF
	if( --windowCounter == 0 ) document.getElementById( 'mask' ).style.display = 'none';
}
document.getElementById( 'mask'   ).style.display = 'none';

// CONTROL
var appendable = 1;
var googleMap = '';
function initializeMap()
{
	appendable = 0;
	document.getElementById( 'list' ).innerHTML = '';
	var myLatlng = new google.maps.LatLng( latitude, longitude );
	var myOptions = {
		zoom: mapZoom,
		center: myLatlng,
		mapTypeId: google.maps.MapTypeId.ROADMAP
	};
	googleMap = new google.maps.Map( document.getElementById( 'list' ), myOptions );
}

var mode = 'tile';
function changeToMap()
{
	mode = 'map';
	document.getElementById( 'listContainer' ).style.padding  = '0px';
	initializeMap();
	liveSearch();
}
function changeToTile()
{
	mode = 'tile';
	appendable = 1;
	document.getElementById( 'list' ).innerHTML = '';
	document.getElementById( 'list' ).style.overflow = '';
	document.getElementById( 'list' ).style.backgroundColor = '';
	document.getElementById( 'listContainer' ).style.padding  = '';
	liveSearch();
}

document.getElementById( 'controlTop' ).onclick = function()
{
	if( document.getElementById( 'controlTop' ).innerHTML == 'HIDE' )
	{
		document.getElementById( 'top' ).style.display    = 'none';
		document.getElementById( 'top' ).style.visibility = 'hidden';
		document.getElementById( 'listContainer' ).style.marginTop = '0px';
		document.getElementById( 'controlTop' ).style.top = '-15px';
		document.getElementById( 'controlTop' ).innerHTML = 'SHOW';
	}
	else
	{
		document.getElementById( 'top' ).style.display    = '';
		document.getElementById( 'top' ).style.visibility = 'visible';
		document.getElementById( 'listContainer' ).style.marginTop = '';
		document.getElementById( 'controlTop' ).style.top = '';
		document.getElementById( 'controlTop' ).innerHTML = 'HIDE';
	}
};
document.getElementById( 'controlCard' ).onclick = function()
{
	changeToTile();
}
document.getElementById( 'controlMap' ).onclick = function()
{
	changeToMap();
}

// SEARCH
var start = limit;
var limit = 50;
function liveSearch( theme )
{
	setCookie( 'cMode', mode, 30 );
	if( mode != '' )
	{
		theme = '&' + mode;
	}
	else
	{
		theme = '';
	}
	if(mode != 'map') document.getElementById( 'list' ).innerHTML = '';
	if( searchType == 'directory' )
	{
		ajax( 'directory.php?query=' + document.getElementById( 'query' ).value + '&filterQuery=' + document.getElementById( 'filterQueryDirectory' ).value, 'list' );
	}
	else
	{
		var targetElement = 'list';
		if(mode == 'map') targetElement = 'backgroundWorker';
		ajax(
			'search.php?query=' + document.getElementById( 'query' ).value + 
			'&filterQuery=' + document.getElementById( 'filterQuery' ).value + 
			'&zip=' + document.getElementById( 'zip' ).value + 
			'&radius=' + document.getElementById( 'radius' ).value + 
			'&transaction=' + document.getElementById( 'transaction' ).value + 
			'&start=0' + 
			'&limit=' + limit + 
			'&sort=' + document.getElementById( 'sort' ).value + 
			'&searchType=' + document.getElementById( 'searchType' ).value + 
			'&direction=' + document.getElementById( 'direction' ).value + 
			'&minPrice=' + document.getElementById( 'filterMinPrice' ).value + 
			'&maxPrice=' + document.getElementById( 'filterMaxPrice' ).value + 
			'&bedroom=' + document.getElementById( 'filterBedrooms' ).value + 
			'&city=' + document.getElementById( 'filterCity' ).value + 
			'&type=' + document.getElementById( 'filterType' ).value + 
			'&type2=' + document.getElementById( 'filterType2' ).value + 
			theme
			, 
			targetElement
		);
		start = limit;
	}

	// ADD RSS FEED LINK BASED ON SEARCH
	var id = 'rss';
	script = document.createElement( 'link' );
	script.id = id;
	script.type = 'application/rss+xml';
	script.href = 'rss/?q=' + document.getElementById( 'query' ).value;
	script.title = 'Search';
	var element = document.getElementById( id );
	if( element != null )
	{
		element.parentNode.removeChild( element );
		delete element;
	}
	document.getElementsByTagName( "head" )[0].appendChild( script );
}
function liveScroll()
{
	if( scrollEnable == 1 )
	{
		if( document.getElementById( 'list' ).scrollTop > ( document.getElementById( 'list' ).scrollHeight-( document.getElementById( 'list' ).clientHeight * 2 ) ) )
		{
			scrollEnable = 0;
			ajax(
				'search.php?query=' + document.getElementById( 'query' ).value + 
				'&filterQuery=' + document.getElementById( 'filterQuery' ).value + 
				'&zip=' + document.getElementById( 'zip' ).value + 
				'&radius=' + document.getElementById( 'radius' ).value + 
				'&transaction=' + document.getElementById( 'transaction' ).value + 
				'&start=' + start + 
				'&limit=20' + 
				'&sort=' + document.getElementById( 'sort' ).value + 
				'&direction=' + document.getElementById( 'direction' ).value + 
				'&type=' + document.getElementById( 'filterType' ).value + 
				'&bedroom=' + document.getElementById( 'filterBedrooms' ).value + 
				'&city=' + document.getElementById( 'filterCity' ).value + 
				'&minPrice=' + document.getElementById( 'filterMinPrice' ).value + 
				'&maxPrice=' + document.getElementById( 'filterMaxPrice' ).value,
				'list', 
				true
			);
			start += 20;
		}
	}
	return true;
}
var TIMEOUT
document.getElementById( 'query' ).onkeydown = function( e )
{
	if( !e ) var e = window.event;
	switch(e.keyCode)
	{
	case 13:
		liveSearch();
		break;
	default:
		if( ( e.keyCode ==  8 ) ||
		    ( e.keyCode == 46 ) ||
		  ( ( e.keyCode >= 48 ) && ( e.keyCode <=  57 ) ) ||  // 0-9
		  ( ( e.keyCode >= 65 ) && ( e.keyCode <=  90 ) ) ||  // A-Z
		  ( ( e.keyCode >= 97 ) && ( e.keyCode <= 122 ) ) )   // a-z
		{
			clearTimeout( TIMEOUT );
		}
	}
};
document.getElementById( 'query' ).onkeyup = function( e )
{
	// SEARCH TIP
	if( ( document.getElementById( 'query' ).value.length > 0 ) && (document.getElementById( 'query' ).value.length < 4 ) )
	{
		//show( 'searchTipContainer' );
	}
	if( ( document.getElementById( 'query' ).value.length == 0 ) || ( document.getElementById( 'query' ).value.length == 4 ) )
	{
		//hide( 'searchTipContainer' );
	}

	if( !e ) var e = window.event;
	clearTimeout( TIMEOUT );  // clear previous
	switch( e.keyCode )
	{
	case 13: break;
	default:
		if( ( e.keyCode ==  8 ) ||
		    ( e.keyCode == 46 ) ||
		  ( ( e.keyCode >= 48 ) && ( e.keyCode <=  57 ) ) ||   // 0-9
		  ( ( e.keyCode >= 65 ) && ( e.keyCode <=  90 ) ) ||   // A-Z
		  ( ( e.keyCode >= 97 ) && ( e.keyCode <= 122 ) ) )	   // a-z
		{
			if( ( document.getElementById( 'query' ).value.length > 2 ) || ( document.getElementById( 'query' ).value.length == 0 ) )
			{
				TIMEOUT = setTimeout( function(){ liveSearch() }, 2000 );
			}
		}
	}
};

document.getElementById( 'list' ).onscroll = function()
{
	liveScroll();
	return false;
};

// LINKS
if( document.getElementById( 'login' ) != null )
{
	document.getElementById( 'login' ).onclick = function()
	{
		location = 'Portal';
		return false;
	};
}

if( document.getElementById( 'linkTermsAndConditions' ) != null )
{
	document.getElementById( 'linkTermsAndConditions' ).onclick = function()
	{
		openWindow( 500, 600, 'termsAndConditions.php' );
		return false;
	};
}

if( document.getElementById( 'linkPrivacyPolicy' ) != null )
{
	document.getElementById( 'linkPrivacyPolicy' ).onclick = function()
	{
		openWindow( 500, 600, 'privacyPolicy.php' );
		return false;
	};
}
if( document.getElementById( 'linkContact' ) != null )
{
	document.getElementById( 'linkContact' ).onclick = function()
	{
		openWindow( 550, 410, 'contact.php' );
		return false;
	};
}

// MAP
function setMarker( latitude, longitude, title, type )
{
	switch( type )
	{
		case 'bungalow':
			var image = new google.maps.MarkerImage( '/images/pins/BungalowRed.png',
				// This marker is 20 pixels wide by 32 pixels tall.
				new google.maps.Size( 27, 30 ),
				// The origin for this image is 0,0.
				new google.maps.Point( 0, 0 ),
				// The anchor for this image is the base of the flagpole at 0,32.
				new google.maps.Point( 13, 30 ) );
			var shadow = new google.maps.MarkerImage( '/images/pins/BungalowShadow.png',
				// The shadow image is larger in the horizontal dimension
				// while the position and offset are the same as for the main image.
				new google.maps.Size( 45, 30 ),
				new google.maps.Point( 0, 0 ),
				new google.maps.Point( 13, 30 ) );
			break;

		case 'factory':
			var image = new google.maps.MarkerImage( '/images/pins/FactoryRed.png',
				// This marker is 20 pixels wide by 32 pixels tall.
				new google.maps.Size( 24, 35 ),
				// The origin for this image is 0,0.
				new google.maps.Point( 0, 0 ),
				// The anchor for this image is the base of the flagpole at 0,32.
				new google.maps.Point( 12, 35 ) );
			var shadow = new google.maps.MarkerImage( '/images/pins/FactoryShadow.png',
				// The shadow image is larger in the horizontal dimension
				// while the position and offset are the same as for the main image.
				new google.maps.Size( 45, 35 ),
				new google.maps.Point( 0, 0 ),
				new google.maps.Point( 12, 35 ) );
			break;

		case 'flat':
			var image = new google.maps.MarkerImage( '/images/pins/FlatRed.png',
				// This marker is 20 pixels wide by 32 pixels tall.
				new google.maps.Size( 23, 30 ),
				// The origin for this image is 0,0.
				new google.maps.Point( 0, 0 ),
				// The anchor for this image is the base of the flagpole at 0,32.
				new google.maps.Point( 11, 30 ) );
			var shadow = new google.maps.MarkerImage( '/images/pins/FlatShadow.png',
				// The shadow image is larger in the horizontal dimension
				// while the position and offset are the same as for the main image.
				new google.maps.Size( 45, 30 ),
				new google.maps.Point( 0, 0 ),
				new google.maps.Point( 11, 30 ) );
			break;

		case 'food':
			var image = new google.maps.MarkerImage( '/images/pins/FoodRed.png',
				// This marker is 20 pixels wide by 32 pixels tall.
				new google.maps.Size( 23, 30 ),
				// The origin for this image is 0,0.
				new google.maps.Point( 0, 0 ),
				// The anchor for this image is the base of the flagpole at 0,32.
				new google.maps.Point( 11, 30 ) );
			var shadow = new google.maps.MarkerImage( '/images/pins/FoodShadow.png',
				// The shadow image is larger in the horizontal dimension
				// while the position and offset are the same as for the main image.
				new google.maps.Size( 45, 30 ),
				new google.maps.Point( 0, 0 ),
				new google.maps.Point( 11, 30 ) );
			break;

		case 'house':
			var image = new google.maps.MarkerImage( '/images/pins/HouseRed.png',
				// This marker is 20 pixels wide by 32 pixels tall.
				new google.maps.Size( 27, 36 ),
				// The origin for this image is 0,0.
				new google.maps.Point( 0, 0 ),
				// The anchor for this image is the base of the flagpole at 0,32.
				new google.maps.Point( 13, 36 ) );
			var shadow = new google.maps.MarkerImage( '/images/pins/HouseShadow.png',
				// The shadow image is larger in the horizontal dimension
				// while the position and offset are the same as for the main image.
				new google.maps.Size( 37, 32 ),
				new google.maps.Point( 0, 0 ),
				new google.maps.Point( 13, 36 ) );
			break;

		case 'shop':
			var image = new google.maps.MarkerImage( '/images/pins/ShopRed.png',
				// This marker is 20 pixels wide by 32 pixels tall.
				new google.maps.Size( 23, 30 ),
				// The origin for this image is 0,0.
				new google.maps.Point( 0, 0 ),
				// The anchor for this image is the base of the flagpole at 0,32.
				new google.maps.Point( 11, 30 ) );
			var shadow = new google.maps.MarkerImage( '/images/pins/ShopShadow.png',
				// The shadow image is larger in the horizontal dimension
				// while the position and offset are the same as for the main image.
				new google.maps.Size( 45, 30 ),
				new google.maps.Point( 0, 0 ),
				new google.maps.Point( 11, 30 ) );
			break;
	}

	var myLatLng = new google.maps.LatLng( latitude, longitude );
	return new google.maps.Marker({
		position: myLatLng,
		map: googleMap,
		shadow: shadow,
		icon: image,
		title: title
//		zIndex: 0
	});
}
function clearOverlays()
{
	if( gmarkerProperty )
	{
		var i = 0;
		for( property in gmarkerProperty )
		{
			if(gmarkerProperty[i] != null)
			{
				gmarkerProperty[i].setMap( null );
			}
			i++;
		}
	}
}

window.onload = function()
{
	if( initialPage ) ajax( initialPage, 'content');
	if( document.getElementById( 'splashPropertyContainer' ) != null )
	{
		setTimeout( function(){ propertyScroll() }, 1000 );
	}
	
	if( document.getElementById( 'ticker' ) != null )
	{
		startTicker();
	}
	return false;
};

// WINDOW MAP
function brochureMap( latitude, longitude, buildingClass, type )
{
	var mapWindow = openWindow();

	var myLatlng = new google.maps.LatLng( latitude, longitude );
	var myOptions = {
		zoom: mapZoom,
		center: myLatlng,
		mapTypeId: google.maps.MapTypeId.ROADMAP
	};
	googleMap = new google.maps.Map( document.getElementById( mapWindow ), myOptions );

	var buildingType = '';

	switch( buildingClass )
	{
		case 'Commercial':
			switch( type )
			{
				case 80:  // RESTAURANT
				case 83:  // CAFE
				case 134:  // BAR
					buildingType = 'food';
					break;

				case 137:  // SHOP
					// SHOP
					buildingType = 'shop';
					break;

				default:
					// FACTORY
					buildingType = 'factory';
					break;
			}
			break;
		default:
			// FLAT/APARTMENT
			if( type >= 7 && type <= 11 )
			{
				// FLAT
				buildingType = 'flat';
			}
			else
			{
				// BUNGALOW
				if( ( type >= 12 && type <= 15 ) || ( type >= 28 && type <= 29 ) || type == 142 )
				{
					// BUNGALOW
					buildingType = 'bungalow';
				}
				// HOUSE
				else
				{
					// HOUSE
					buildingType = 'house';
				}
			}
			break;
	}
	setMarker(  latitude, longitude, '', buildingType );
}
function brochureSV( latitude, longitude, direction )
{
	var panoWindow = openWindow();
	var myLatLng = new google.maps.LatLng( latitude, longitude );
	var panoramaOptions = {
	  position: myLatLng,
	  pov: {
	    heading: 34,
	    pitch: 10,
	    zoom: 1
	  }
	};
	var panorama = new google.maps.StreetViewPanorama( document.getElementById( panoWindow ), panoramaOptions )
}

// SPLASH
function splashHide()
{
	if( document.getElementById( 'splash' ) != null )
	{
		// hide splash
		var element = document.getElementById( 'splash' );
		element.style.display = 'none';
		element.style.visibility = 'hidden';
		
		// Prevent ticker and property scroller when splash screen is not visible
		pause = true;
		pausePropertyScroll = true;
	}
	// focus the search box
	if(!TouchDevice) // Don't want it to automatically show onscreen keyboard
	{
		document.getElementById( 'query' ).focus();
	}
}

function splashShow()
{
	if( document.getElementById( 'splash' ) != null )
	{
		var element = document.getElementById( 'splash' );
		element.style.display = '';
		element.style.visibility = '';
		
		// Re-enable ticker and property scroller when splash screen is not visible
		pause = false;
		pausePropertyScroll = false;
	}
}

if( document.getElementById( 'ID' ).value != '' )
{
	openWindow( 850, null,'brochure.php?q=' + document.getElementById( 'ID' ).value );
}

function splashRemove()
{
	// REMOVE NODE
	var body = document.getElementsByTagName('body')[0];
	var element = document.getElementById( 'splash' );
	if( element.hasChildNodes() )
	{
		while( element.childNodes.length >= 1 )
		{
			element.removeChild( element.firstChild );
		}
	}
	body.removeChild( element );
}

if( document.getElementById( 'splashSearch' ) != null )
{
	document.getElementById( 'splashSearch' ).onclick = function()
	{
		splashHide();
		document.getElementById( 'start' ).value = 0;
		searchType = 'property';
		changeSearchType( 'property' );
		liveSearch();

		return false;
	};
}
else
{
		liveSearch();
}
if( document.getElementById( 'directory' ) )
{
	document.getElementById( 'directory' ).onclick = function()
	{
		splashHide();
		searchType = 'directory';
		changeSearchType( 'directory' );
		return false;
	};
}

function selectedItem( id )
{
	var menuCount = document.getElementById( 'menuCount' ).value;
	for( i = 0; i <= menuCount; i++ )
	{
		document.getElementById( 'menu' + i ).className = 'buttons';
	}

	if( document.getElementById( 'branchCount' ) != null )
	{
		var branchCount = document.getElementById( 'branchCount' ).value;
		for( i = 0; i <= branchCount; i++ )
		{
			document.getElementById( 'branch' + i ).className = 'branch';
		}
	}
	if( id.indexOf( 'menu' ) > -1 )
	{
		document.getElementById( id ).className         = 'selectedButton';
	}
	else if( id.indexOf( 'branch' ) > -1 )
	{
		document.getElementById( id ).className         = 'selectedBranch';
	}
}

// TICKER
var tickerWidth  = 701;
var tickerHeight = 40;
var tickerSpeed  = 2;
var tickerTime   = 10;
var pause        = false;
var ticker, tickerContentWidth;
function startTicker()
{
	if( document.getElementById( 'tickerContentContainer' ) != null )
	{
		ticker                                               = document.getElementById( 'tickerContentContainer' );
		ticker.style.left                                    = ( parseInt( tickerWidth ) + 0 ) + "px";
		tickerContentWidth                                   = document.getElementById( 'tickerContent' ).offsetWidth;
		document.getElementById( 'ticker' ).style.visibility = '';

		setInterval( function(){scrollTicker()}, tickerTime );
	}
}
function scrollTicker()
{
	if( !pause )
	{
		ticker.style.left = ( parseInt( ticker.style.left ) > ( 0 - tickerContentWidth ) ) ?parseInt( ticker.style.left ) - tickerSpeed + "px" : parseInt( tickerWidth ) + 0 + "px";
	}
}

///// TEST CODE
/*
var splashTop = 0;
var splashOpacity = 1.00;
var interval = '';
function hideSplash()
{
	interval = setInterval( "fadeSplashOut();", 1 );
}
function showSplash()
{
	interval = setInterval( "fadeSplashIn();", 1 );
}


function scrollSplash()
{
	if( splashTop < screenHeight )
	{
		document.getElementById( 'splash' ).style.top = splashTop + 'px';
		splashTop = splashTop + 10;
	}
	else
	{
		clearTimeout( interval );
	}
}

function fadeSplashOut()
{
	if( splashOpacity > 0 )
	{
		document.getElementById( 'splash' ).style.opacity = splashOpacity;
		splashOpacity = splashOpacity - 0.20;
	}
	else
	{
		clearTimeout( interval );
		document.getElementById( 'splash' ).style.visibility = 'hidden';
		document.getElementById( 'splash' ).style.display = 'none';
	}
}

function fadeSplashIn()
{
	document.getElementById( 'splash' ).style.visibility = '';
	document.getElementById( 'splash' ).style.display = '';
	if( splashOpacity < 1 )
	{
		document.getElementById( 'splash' ).style.opacity = splashOpacity;
		splashOpacity = splashOpacity + 0.20;
	}
	else
	{
		clearTimeout( interval );
		document.getElementById( 'splash' ).style.opacity = '';
	}
}
*/

if( document.getElementById( 'splashPropertyContainer' ) != null )
{
	var selectedImage = 0;
	var scrollProgress = 0;
	var pausePropertyScroll = 0;
	var imageWidth = '';
	var id= '';
	var idContainer = '';
	document.getElementById( 'splashPropertyContainer' ).style.left = 0 + 'px';
	function propertyScroll()
	{
		id = document.getElementById( 'propertyImage' + selectedImage );
		idContainer = document.getElementById( 'propertyImage' + selectedImage + 'Container' );
		if( id != null )
		{
			if( !pausePropertyScroll )
			{
				imageWidth = 0 - ( id.clientWidth + 20 );
				setTimeout( function(){ scrollImage() }, 100 );
			}
			else
			{
				setTimeout( function(){ propertyScroll() }, 3500 );
			}
		}
		else
		{
			if( !pausePropertyScroll )
			{
				selectedImage = 0;
			}
			propertyScroll();
		}
	}

	function scrollImage()
	{
		if( !pausePropertyScroll )
		{
			if( scrollProgress > imageWidth )
			{
				scrollProgress = scrollProgress - 20;
				document.getElementById( 'splashPropertyContainer' ).style.left = scrollProgress + 'px';
				setTimeout( function(){ scrollImage() }, 5 );
			}
			else
			{
				scrollProgress = 0;
				moveElement( idContainer );

				document.getElementById( 'splashPropertyContainer' ).style.left = 0 + 'px';
				selectedImage++
					
				setTimeout( function(){ propertyScroll() }, 3500 );
			}
		}
		else
		{
			setTimeout( function(){ scrollImage() }, 500 );
		}
	}
		
	function moveElement( id )
	{
	  var parent = document.getElementById('splashPropertyContainer');
	  var image  = id;

	  parent.removeChild( image );
	  parent.appendChild( image );
	}
}
/*
txt = "<p>Browser CodeName: " + navigator.appCodeName + "<br />";
txt+= "<p>Browser Name: " + navigator.appName + "<br />";
txt+= "<p>Browser Version: " + navigator.appVersion + "<br />";
txt+= "<p>Cookies Enabled: " + navigator.cookieEnabled + "<br />";
txt+= "<p>Platform: " + navigator.platform + "<br />";
txt+= "<p>User-agent header: " + navigator.userAgent + "<br />";

document.getElementById("splashLowerMiddle").innerHTML=txt;
*/


function panoramaChange()
{
	if( currentPanorama >= totalPanorama )
	{
		currentPanorama = 1;
	}
	else
	{
		currentPanorama++;
	}
	document.getElementById('splashTitlePanorama').style.backgroundImage = 'url(\'/images/Panoramic/' + currentPanorama + '.jpg\')';
}

function resetMaxPrice( optionID )
{
	optionID = optionID.substr( 3, 2 );
	if( optionID > 0 )
	{
		var maxPriceMin = parseFloat( optionID );
		
		for( i = 0; i < document.getElementById( 'filterMaxPriceSelector' ).options.length; i++ )
		{
			var maxID = 'max' + i;
			if( document.getElementById( maxID ) )
			{
				if( i <= maxPriceMin )
				{
					document.getElementById( maxID ).disabled = true;
				}
				else
				{
					document.getElementById( maxID ).disabled = false;
				}
			}
		}
	}
	else
	{
		for( i = 0; i < document.getElementById( 'filterMaxPriceSelector' ).options.length; i++ )
		{
			var maxID = 'max' + i;
			if( document.getElementById( maxID ) )
			{
				document.getElementById( maxID ).disabled = false;
			}
		}
	}
}

function resetMinPrice( optionID )
{
	optionID = optionID.substr( 3, 2 );

	if( optionID > 0 )
	{
		var minPriceMax = parseFloat( optionID );
		for( i = 0; i < document.getElementById( 'filterMinPriceSelector' ).options.length; i++ )
		{
			var minID = 'min' + i;
			if( document.getElementById( minID ) )
			{
				if( i >= minPriceMax )
				{
					document.getElementById( minID ).disabled = true;
				}
				else
				{
					document.getElementById( minID ).disabled = false;
				}
			}
		}
	}
	else
	{
		for( i = 0; i < document.getElementById( 'filterMinPriceSelector' ).options.length; i++ )
		{
			var minID = 'min' + i;
			if( document.getElementById( minID ) )
			{
				document.getElementById( minID ).disabled = false;
			}
		}
	}
}

function addSearchFilter( name, id, value, optionID )
{
	var inUse = false;
	if( name != '' )
	{
		name = name.toLowerCase();
		var currentFilters = document.getElementById( 'appliedFilterContainer' ).innerHTML;
		var currentFiltersSplit = currentFilters.split( '</span><span' );
		for( x in currentFiltersSplit )
		{
			// REMOVE SPAN EVERYTHING EXCEPT FOR INNER TEXT
			var originalCurrentFilter = currentFiltersSplit[x];
			currentFiltersSplit[x] = currentFiltersSplit[x].substr( ( currentFiltersSplit[x].indexOf( 'X</span>' ) + 8 ) );
			if( currentFiltersSplit[x].indexOf( '</span>' ) > -1 )
			{
				currentFiltersSplit[x] = currentFiltersSplit[x].substr( 0, currentFiltersSplit[x].indexOf( '</span>' ) );
			}

			if( id == 'filterMinPrice' )
			{
				if( currentFiltersSplit[x].indexOf( 'Min: ' ) > -1 )
				{
					currentFilterID = originalCurrentFilter.substr( ( originalCurrentFilter.indexOf( 'id="' ) + 4 ), 1 );
					removeSearchFilter( document.getElementById( currentFilterID ), 'filterMinPrice' );
				}
				resetMaxPrice( optionID );
			}
			else if( id == 'filterMaxPrice' )
			{
				if( currentFiltersSplit[x].indexOf( 'Max: ' ) > -1 )
				{
					currentFilterID = originalCurrentFilter.substr( ( originalCurrentFilter.indexOf( 'id="' ) + 4 ), 1 );
					removeSearchFilter( document.getElementById( currentFilterID ), 'filterMinPrice' );
				}
				resetMinPrice( optionID );
			}
			else
			{
				// FILTER ALREADY SET, FLAG IT
				if( currentFiltersSplit[x] == name )
				{
					inUse = true;
				}
			}
		}
		
		// IF FILTER IS NOT ALREADY SET
		if( !inUse )
		{
			appliedFilterID++;
			
			// THIS LINE IS FORMATTED THE WAY IT IS BECAUSE THE SCRIPT ABOVE SEARCHES FOR A CERTAIN PATTERN (DO NOT CHANGE)
			var newFilter = '<span id="' + appliedFilterID + '" onMouseOver="document.getElementById( \'' + appliedFilterID + 'Remove\').style.color = \'#FF0000\'" onMouseOut="document.getElementById( \'' + appliedFilterID + 'Remove\').style.color = \'\'" onClick="this.onmouseout = function(){}; removeSearchFilter( document.getElementById( \'' + appliedFilterID + '\' ), \'' + id + '\', \'' + value + '\' );" class="appliedFilter"><span class="appliedFilterRemove" id="' + appliedFilterID + 'Remove">X</span>' + name + '</span>';
			if( searchType == 'directory' )
			{
				document.getElementById( 'appliedFilterContainerDirectory' ).innerHTML += newFilter;
			}
			else
			{
				document.getElementById( 'appliedFilterContainer' ).innerHTML += newFilter;
			}

			var filterList = document.getElementById( id ).value;
			if( filterList == '' )
			{
				if( value == undefined )
				{
					document.getElementById( id ).value = '';
				}
				else
				{
					document.getElementById( id ).value = value;
				}
			}
			else
			{
				if( value == undefined )
				{
					document.getElementById( id ).value = '';
				}
				else
				{
					document.getElementById( id ).value += '|' + value;
				}
			}
			
			setCookie( 'pmmSearch_' + id, document.getElementById( id ).value, 30 );
			
			if( ( id != 'filterQuery' ) && ( id != 'filterQueryDirectory' ) )
			{
				liveSearch();
			}
		}
	}
	return true;
}

function removeSearchFilter( filter, id, value )
{
	if( ( id == 'filterMinPrice' ) || ( id == 'filterMaxPrice' ) )
	{
		document.getElementById( id ).value = '';
		
		if( id == 'filterMinPrice' )
		{
			resetMaxPrice( '0' );
		}
		else
		{
			resetMinPrice( '0' );
		}
	}
	else
	{
		var values = document.getElementById( id ).value.split( '|' );
		for( filterValue in values )
		{
			if( values[filterValue] == value )
			{	
				values.splice( filterValue, 1 );
				var newValue = values.join( '|' );
			}
		}
		document.getElementById( id ).value = newValue;
	}

	filter.parentNode.removeChild( filter );
	
	if( document.getElementById( id ).value == '' )
	{
		killCookie( 'pmmSearch_' + id );
	}
	else
	{
		setCookie( 'pmmSearch_' + id, document.getElementById( id ).value, 30 );
	}
	liveSearch();
}

function branchListSelector( id )
{
	if( id != '' )
	{
		var currentFilters = document.getElementById( 'branchListBranches' ).innerHTML;
		var currentFiltersSplit = currentFilters.split( '<div ' );
		for( x in currentFiltersSplit )
		{
			if( currentFiltersSplit[x].trim() != '' )
			{
				branchID = parseFloat( currentFiltersSplit[x].substr( ( currentFiltersSplit[x].indexOf( 'id="branchListBranch' ) + 20 ), 2 ) );
				var currentID = 'branchListBranch' + branchID;
				
				if( currentID == id )
				{
					document.getElementById( currentID ).style.backgroundColor = '#EE7600';
				}
				else
				{
					document.getElementById( currentID ).style.backgroundColor = '';	
				}
			}
		}	
	}
}

function changeSearchType( type )
{
	document.getElementById( 'searchType' ).value = type;
	if( type == 'directory' )
	{
		appendable = 1;
		document.getElementById( 'list' ).innerHTML = '';
		document.getElementById( 'list' ).style.overflow = '';
		document.getElementById( 'list' ).style.backgroundColor = '';
		liveSearch();
		
		
		if( document.getElementById( 'type' ) != null )
		{
			document.getElementById( 'type'                   ).style.visibility = 'hidden';
			document.getElementById( 'type'                   ).style.display    = 'none';
		}
		if( document.getElementById( 'directoryTitle' ) != null )
		{
			document.getElementById( 'directoryTitle'                   ).style.visibility = '';
			document.getElementById( 'directoryTitle'                   ).style.display    = '';
		}
		if( document.getElementById( 'directoryDisclaimer' ) != null )
		{
			document.getElementById( 'directoryDisclaimer'              ).style.visibility = '';
			document.getElementById( 'directoryDisclaimer'              ).style.display    = '';
		}
		
		document.getElementById( 'filters'                ).style.display    = 'none';
		document.getElementById( 'filters'                ).style.visibility = 'hidden';
		document.getElementById( 'appliedFilterContainer' ).style.display    = 'none';
		document.getElementById( 'appliedFilterContainer' ).style.visibility = 'hidden';
		
		document.getElementById( 'appliedFilterContainerDirectory' ).style.display    = '';
		document.getElementById( 'appliedFilterContainerDirectory' ).style.visibility = '';
		
		
		document.getElementById( 'controlCard'            ).style.display    = 'none';
		document.getElementById( 'controlCard'            ).style.visibility = 'hidden';
		document.getElementById( 'controlMap'             ).style.display    = 'none';
		document.getElementById( 'controlMap'             ).style.visibility = 'hidden';
	}
	else
	{
		if( document.getElementById( 'type' ) != null )
		{
			document.getElementById( 'type'                   ).style.visibility = '';
			document.getElementById( 'type'                   ).style.display    = '';
		}
		
		if( document.getElementById( 'directoryTitle' ) != null )
		{
			document.getElementById( 'directoryTitle'                   ).style.visibility = 'hidden';
			document.getElementById( 'directoryTitle'                   ).style.display    = 'none';
		}
		if( document.getElementById( 'directoryDisclaimer' ) != null )
		{
			document.getElementById( 'directoryDisclaimer'              ).style.visibility = 'hidden';
			document.getElementById( 'directoryDisclaimer'              ).style.display    = 'none';
		}
		document.getElementById( 'filters'                ).style.display    = '';
		document.getElementById( 'filters'                ).style.visibility = '';
		document.getElementById( 'appliedFilterContainer' ).style.display    = '';
		document.getElementById( 'appliedFilterContainer' ).style.visibility = '';
		
		document.getElementById( 'appliedFilterContainerDirectory' ).style.display    = 'none';
		document.getElementById( 'appliedFilterContainerDirectory' ).style.visibility = 'hidden';
		
		document.getElementById( 'controlCard'            ).style.display    = '';
		document.getElementById( 'controlCard'            ).style.visibility = '';
		document.getElementById( 'controlMap'             ).style.display    = '';
		document.getElementById( 'controlMap'             ).style.visibility = '';
	
		if(mode == 'map') initializeMap();
	}
	searchType = type;
}

// PRELOAD IMAGES
if( document.images )
{
    img1 = new Image();
    img1.src = '/images/starUnselected.png';
    img2 = new Image();
    img2.src = '/images/star.png';
}

