


var gmaps_class;
if(!gmaps_class) gmaps_class = {};

gmaps_class.maps = {};

gmaps_class.maps.set = function(j_element,options)
{
	var map_name = jQuery(j_element).attr("id");
	var this_map = new GMap2(j_element);
	gmaps_class.maps[map_name] = this_map;
	gmaps_class.maps[map_name].options = options;
	return gmaps_class.maps[map_name];
}

gmaps_class.maps.get = function(j_element)
{
	return gmaps_class.maps[jQuery(j_element).attr("id")];
}
gmaps_class.maps.append = function ( j_element, description, appending ) 
{
	var map_name = jQuery(j_element).attr('id');
	gmaps_class.maps[map_name][description] = appending;
};

gmaps_class.get_map_type = function(map_type)
{
	switch(map_type) 
	{
		case 'map':
			map_type = G_NORMAL_MAP;
			break;
		case 'sat':
			map_type = G_SATELLITE_MAP;
			break;
		case 'hybrid':
			map_type = G_HYBRID_MAP;
			break;
	};
	return map_type;
}



gmaps_class.init = function(j_element, options, callback )
{
	
	function defaults()
	{
		return {
			"language" : "en",
			"map_type" : "map",
			"map_center" : [0,0],
			"map_zoom" : 12,
			"map_control" : "large",
			"map_enable_type" : false,
			"map_enable_overview" : false,
			"map_enable_dragging" : true,
			"map_enable_info_windows": true,
			"map_enable_2click_zoom" : true,
			"map_enable_scroll_zoom" : false,
			"map_enable_smooth_zoom" : false,
			"map_enable_scall_control" : false
		};
	};
	
	options = jQuery.extend(defaults(),options);
	
	if (GBrowserIsCompatible()) 
	{
		
		var this_map = gmaps_class.maps.set(j_element,options);
		var map_type = gmaps_class.get_map_type(options.map_type);
		this_map.setCenter(new GLatLng(options.map_center[0], options.map_center[1]), options.map_zoom*1,map_type);
		
		switch (options.map_control) 
		{
			case "small":
				this_map.addControl(new GSmallMapControl());
				break;
			case "large":
				this_map.addControl(new GLargeMapControl());
				break;
		};
		
		if (options.map_enable_type) this_map.addControl(new GMapTypeControl()); // Off by default
		
		if (options.map_enable_overview) this_map.addControl(new GOverviewMapControl());// Off by default
	
		if (!options.map_enable_dragging) this_map.disableDragging();
		if (!options.map_enable_info_windows) this_map.disableInfoWindow();
		if (options.map_enable_2click_zoom) this_map.enableDoubleClickZoom();
		if (options.map_enable_scroll_zoom) this_map.enableScrollWheelZoom();
		if (options.map_enable_smooth_zoom) this_map.enableContinuousZoom();
		if (options.map_enable_scale_control) this_map.addControl(new GScaleControl());
		
		if (typeof callback == 'function') 
			return callback(this_map, j_element, options);
	}
	else
	{
		jQuery(j_element).text('Your browser does not support Google Maps.');
		return false;
	}
	return;
}

gmaps_class.remove_marker = function ( j_element, marker, callback ) 
{
	var this_map = gmaps_class.maps.get(j_element);
	this_map.removeOverlay(marker);
	if (typeof callback === 'function') return callback(marker);
	return;
}
gmaps_class.clear_overlays = function (j_element,callback)
{
	var this_map = gmaps_class.maps.get(j_element);
	this_map.clearOverlays();
	if (typeof callback === 'function') return callback(marker);
	return;
}

gmaps_class.add_marker = function(j_element,options,callback)
{
	function defaults() {
		return {
			'point_lat_lng': undefined,
			'point_html': undefined,
			'point_open_html_event': 'click',
			'point_is_draggable': false,
			'point_is_removable': false,
			'point_remove_event': 'dblclick',
			'point_min_zoom': 4,
			'point_max_zoom': 17,
			'point_icon': undefined,
			'center_map': false,
			'center_move_method':'normal',
			'auto_pan' : false
		};
	};
	var this_map = gmaps_class.maps.get(j_element);
	
	options = jQuery.extend({},defaults(),options);
	
	var marker_options = {};
	
	if (typeof options.point_icon == 'object') 
	{
		jQuery.extend(marker_options, {'icon': options.point_icon});
	}
	
	if (options.point_is_draggable) jQuery.extend(marker_options, {'draggable': options.point_is_draggable});
	if (options.auto_pan) jQuery.extend(marker_options, {'autoPan': options.auto_pan});
			
	if (options.center_map) {
		switch (options.center_move_method) 
		{
			case 'normal':
				this_map.setCenter(new GLatLng(options.point_lat_lng[0],options.point_lat_lng[1]));
				break;
			case 'pan':
				this_map.panTo(new GLatLng(options.point_lat_lng[0],options.point_lat_lng[1]));
				break;
		}
	}
		
	var marker = new GMarker(new GLatLng(options.point_lat_lng[0],options.point_lat_lng[1]), marker_options);
	//gmaps_class.debug(marker);
	if(options.point_html)
	{
		GEvent.addListener(marker, options.point_open_html_event, 
		function()
		{
			marker.openInfoWindowHtml(options.point_html, {maxContent: options.point_max_content, maxTitle: options.point_max_title});
		});
	}
	
	if(options.point_is_removable)
	{
		GEvent.addListener(marker, options.point_remove_event, 
		function()
		{
			this_map.removeOverlay(marker);
		});
	}
	
	this_map.addOverlay(marker);
	if (typeof callback == 'function') return callback(marker, options);
	return;
}

gmaps_class.create_icon = function(options)
{
	function defaults()
	{
		return {
			'icon_img' : undefined,
			'icon_shadow' : undefined,
			'icon_size' : undefined,
			'icon_shadow_size' : undefined,
			'icon_anchor' : undefined,
			'icon_info_window_anchor' : undefined
		};
	}
	options = jQuery.extend(defaults(),options);
	
	var icon = new GIcon(G_DEFAULT_ICON);
	
	if(options.icon_img) icon.image = options.icon_img;
	if(options.icon_shadow) icon.shadow = options.icon_shadow;
	if(options.icon_size) icon.iconSize = options.icon_size;
	if(options.icon_shadow_size) icon.shadowSize = options.icon_shadow_size;
	if(options.icon_anchor) icon.iconAnchor = options.icon_anchor;
	if(options.icon_info_window_anchor) icon.infoWindowAnchor = options.icon_info_window_anchor;
	return icon;
}

gmaps_class.search = function(j_element, options, callback) {
	function defaults() {
		return {
			'query': null,
			'return_type': 'getLatLng',
			'cache' : undefined
		};
	};
	var this_map = gmaps_class.maps.get(j_element);
	options = jQuery.extend(defaults(), options);
	
	if (typeof this_map.Geocoder === 'undefined') 
	{	
		if (typeof options.cache === 'undefined') {
		 	var geoCoder = new GClientGeocoder();
		} 
		else 
		{
			var geoCoder = new GClientGeocoder(cache);
		}
		gmaps_class.maps.append(j_element, 'Geocoder', geoCoder);
		this_map = gmaps_class.maps.get(j_element);
	}
	this_map.Geocoder[options.return_type](options.query, function(result){
		if (typeof callback === 'function') {
			return callback(result, options); 
		}
	});
	return;
};

gmaps_class.search_code = function ( code ) {
	switch (code) {
		case G_GEO_SUCCESS:
			return {'code':G_GEO_SUCCESS,'success':true,'message':'Success'};
		case G_GEO_UNKNOWN_ADDRESS:
			return {'code' : G_GEO_UNKNOWN_ADDRESS, 'success' : false, 'message' : 'No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect'};
			break;
		case G_GEO_SERVER_ERROR:
			return {'code' : G_GEO_UNKNOWN_ADDRESS, 'success' : false, 'message' : 'A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.'};
			break;
		case G_GEO_MISSING_QUERY:
			return {'code' : G_GEO_UNKNOWN_ADDRESS, 'success' : false, 'message' : 'The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.'};
			break;
		case G_GEO_BAD_KEY:
			return {'code' : G_GEO_UNKNOWN_ADDRESS, 'success' : false, 'message' : 'The given key is either invalid or does not match the domain for which it was given.'};
			break;
		case G_GEO_BAD_REQUEST:
			return {'code' : G_GEO_UNKNOWN_ADDRESS, 'success' : false, 'message' : 'A directions request could not be successfully parsed.'};
			break;
		default:
			return {
				'code': null,
				'success': false,
				'message': 'An unknown error occurred.'
			};
		break;
	};
}

gmaps_class.move_to = function ( j_element, options, callback ) {
	function defaults() {
		return {
			'center_method': 'normal',
			'map_type': 'map',
			'map_center': [],
			'map_zoom': null
		};
	};
	
	var this_map = gmaps_class.maps.get(j_element);
	options = jQuery.extend(defaults(),options);	
	
	if (options.map_type)
		var map_type = gmaps_class.get_map_type(options.map_type);
	var point = new GLatLng(options.map_center[0], options.map_center[1]);
	switch (options.center_method) {
		case 'normal':
			this_map.setCenter(point, options.map_zoom, map_type);
			break;
		case 'pan':
			this_map.panTo(point);
			break;
	}
	if (typeof callback == 'function') return callback(point, options);
};


gmaps_class.debug = function(object)
{
	var out="";
	if(typeof object == 'object')
	{
		for(i in object) 
		{
			out+="\n"+i;
		}
		document.write(out);
	}
}

var gmaps_class;
if(!gmaps_class) gmaps_class = {};
(function($)
{
	$.fn.vrs4_gmap = function(method, options, callback) {
		
		return this.each(
			function(){
				if (method == 'init' && typeof options == 'undefined') 
				{
					new gmaps_class.init(this, {}, null);
				} 
				else if (method == 'init' && typeof options == 'object') 
				{
					new gmaps_class.init(this, options, callback);
				} 
				else if (method == 'init' && typeof options == 'function') 
				{
					new gmaps_class.init(this, {}, options);
				} 
				else if (typeof method == 'object' || method == null) 
				{
					new gmaps_class.init(this, method, options);
				} 
				else 
				{
					try {
						new gmaps_class[method](this, options, callback);
					} 
					catch(err) 
					{
						//console.log(err);
						throw Error('gmaps function does not exist / method: '+method);
					}
				}
		});
	}
})(jQuery);



var href = window.location.href;
//alert(href.search('advanced_search'));
if(href.search('advanced_search')==-1)
{
	var ico = new GIcon(G_DEFAULT_ICON);
	ico.image = site_domain+"public/images/gmap_marker.png";
	ico.shadow = site_domain+"public/images/gmap_marker_shadow.png";
}

function refine_search()
{
	$(":input",$("#refine-search-form")).each(
		function()
		{
			$(this).click(
				function()
				{
					var default_string = "";
					var query_out = [];
					var query_obj = {
						"property_type" : [],
						"indoor_facilities":[],
						"outdoor_facilities":[]
					};
					$("input[@type='checkbox'][@name='property_type']").each(
						function()
						{
							if ($(this).is(":checked"))
							{ 
								query_obj.property_type.push($(this).val());
							}
						}
					);
					$("input[@type='checkbox'][@name='indoor_facilities']").each(
						function()
						{
							if ($(this).is(":checked"))
							{ 
								query_obj.indoor_facilities.push($(this).val());
							}
						}
					);
					$("input[@type='checkbox'][@name='outdoor_facilities']").each(
						function()
						{
							if ($(this).is(":checked"))
							{ 
								query_obj.outdoor_facilities.push($(this).val());
							}
						}
					);
					for(var i in query_obj) 
					{
						var temp = eval("query_obj."+i);
						if(temp.length!=0) query_out.push(i+"~"+temp.join(","));
					}
					if($("#refine_availability").val()!="") default_string+= $("#refine_availability").val()+":";
					if($("#refine_location").val()) default_string+= $("#refine_location").val()+":";
					if($("#refine_regional").val()) default_string+= $("#refine_regional").val()+":";
					if($("#refine_number_bedrooms").val()) default_string+= $("#refine_number_bedrooms").val()+":";
					if($("#refine_number_bathrooms").val()) default_string+= $("#refine_number_bathrooms").val()+":";
					//alert($("#availability").val());
					window.location.href = $("#search-form").attr("action")+"/"+default_string+query_out.join(":");
					return;
				}
			);
		}
	);
}

function add_search_marker(point_info,property_id)
{
	var point = [point_info[0],point_info[1]];
	$("#details_map").vrs4_gmap(
		'add_marker',
		{
			'point_lat_lng': point,
			'center_map':true,
			'point_icon' : ico
		},function(marker,options){
			GEvent.addListener(marker,'click', 
			function()
			{
				$.scrollTo($("#property_"+property_id),800);
				$("img.thumb").each(function(){$(this).removeClass("selected")});
				$("img.thumb",$("#property_"+property_id)).addClass("selected");
			});
		}
	);
}

$(document).ready(
function(){
	//get_ajax_regional();
	refine_search();
	$("#details_map").vrs4_gmap('init',
	{
		"map_center":[55.41,12.34],
		"map_zoom":($("#location").val()!="")?4:1
	}
	);
});


/**
 * jQuery.ScrollTo
 * Copyright (c) 2007-2008 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
 * Dual licensed under MIT and GPL.
 * Date: 9/11/2008
 *
 * @projectDescription Easy element scrolling using jQuery.
 * http://flesler.blogspot.com/2007/10/jqueryscrollto.html
 * Tested with jQuery 1.2.6. On FF 2/3, IE 6/7, Opera 9.2/5 and Safari 3. on Windows.
 *
 * @author Ariel Flesler
 * @version 1.4
 *
 * @id jQuery.scrollTo
 * @id jQuery.fn.scrollTo
 * @param {String, Number, DOMElement, jQuery, Object} target Where to scroll the matched elements.
 *	  The different options for target are:
 *		- A number position (will be applied to all axes).
 *		- A string position ('44', '100px', '+=90', etc ) will be applied to all axes
 *		- A jQuery/DOM element ( logically, child of the element to scroll )
 *		- A string selector, that will be relative to the element to scroll ( 'li:eq(2)', etc )
 *		- A hash { top:x, left:y }, x and y can be any kind of number/string like above.
 * @param {Number} duration The OVERALL length of the animation, this argument can be the settings object instead.
 * @param {Object,Function} settings Optional set of settings or the onAfter callback.
 *	 @option {String} axis Which axis must be scrolled, use 'x', 'y', 'xy' or 'yx'.
 *	 @option {Number} duration The OVERALL length of the animation.
 *	 @option {String} easing The easing method for the animation.
 *	 @option {Boolean} margin If true, the margin of the target element will be deducted from the final position.
 *	 @option {Object, Number} offset Add/deduct from the end position. One number for both axes or { top:x, left:y }.
 *	 @option {Object, Number} over Add/deduct the height/width multiplied by 'over', can be { top:x, left:y } when using both axes.
 *	 @option {Boolean} queue If true, and both axis are given, the 2nd axis will only be animated after the first one ends.
 *	 @option {Function} onAfter Function to be called after the scrolling ends. 
 *	 @option {Function} onAfterFirst If queuing is activated, this function will be called after the first scrolling ends.
 * @return {jQuery} Returns the same jQuery object, for chaining.
 *
 * @desc Scroll to a fixed position
 * @example $('div').scrollTo( 340 );
 *
 * @desc Scroll relatively to the actual position
 * @example $('div').scrollTo( '+=340px', { axis:'y' } );
 *
 * @dec Scroll using a selector (relative to the scrolled element)
 * @example $('div').scrollTo( 'p.paragraph:eq(2)', 500, { easing:'swing', queue:true, axis:'xy' } );
 *
 * @ Scroll to a DOM element (same for jQuery object)
 * @example var second_child = document.getElementById('container').firstChild.nextSibling;
 *			$('#container').scrollTo( second_child, { duration:500, axis:'x', onAfter:function(){
 *				alert('scrolled!!');																   
 *			}});
 *
 * @desc Scroll on both axes, to different values
 * @example $('div').scrollTo( { top: 300, left:'+=200' }, { axis:'xy', offset:-20 } );
 */
;(function( $ ){
	
	var $scrollTo = $.scrollTo = function( target, duration, settings ){
		$(window).scrollTo( target, duration, settings );
	};

	$scrollTo.defaults = {
		axis:'y',
		duration:1
	};

	// Returns the element that needs to be animated to scroll the window.
	// Kept for backwards compatibility (specially for localScroll & serialScroll)
	$scrollTo.window = function( scope ){
		return $(window).scrollable();
	};

	// Hack, hack, hack... stay away!
	// Returns the real elements to scroll (supports window/iframes, documents and regular nodes)
	$.fn.scrollable = function(){
		return this.map(function(){
			// Just store it, we might need it
			var win = this.parentWindow || this.defaultView,
				// If it's a document, get its iframe or the window if it's THE document
				elem = this.nodeName == '#document' ? win.frameElement || win : this,
				// Get the corresponding document
				doc = elem.contentDocument || (elem.contentWindow || elem).document,
				isWin = elem.setInterval;

			return elem.nodeName == 'IFRAME' || isWin && $.browser.safari ? doc.body
				: isWin ? doc.documentElement
				: this;
		});
	};

	$.fn.scrollTo = function( target, duration, settings ){
		if( typeof duration == 'object' ){
			settings = duration;
			duration = 0;
		}
		if( typeof settings == 'function' )
			settings = { onAfter:settings };
			
		settings = $.extend( {}, $scrollTo.defaults, settings );
		// Speed is still recognized for backwards compatibility
		duration = duration || settings.speed || settings.duration;
		// Make sure the settings are given right
		settings.queue = settings.queue && settings.axis.length > 1;
		
		if( settings.queue )
			// Let's keep the overall duration
			duration /= 2;
		settings.offset = both( settings.offset );
		settings.over = both( settings.over );

		return this.scrollable().each(function(){
			var elem = this,
				$elem = $(elem),
				targ = target, toff, attr = {},
				win = $elem.is('html,body');

			switch( typeof targ ){
				// A number will pass the regex
				case 'number':
				case 'string':
					if( /^([+-]=)?\d+(px)?$/.test(targ) ){
						targ = both( targ );
						// We are done
						break;
					}
					// Relative selector, no break!
					targ = $(targ,this);
				case 'object':
					// DOMElement / jQuery
					if( targ.is || targ.style )
						// Get the real position of the target 
						toff = (targ = $(targ)).offset();
			}
			$.each( settings.axis.split(''), function( i, axis ){
				var Pos	= axis == 'x' ? 'Left' : 'Top',
					pos = Pos.toLowerCase(),
					key = 'scroll' + Pos,
					old = elem[key],
					Dim = axis == 'x' ? 'Width' : 'Height',
					dim = Dim.toLowerCase();

				if( toff ){// jQuery / DOMElement
					attr[key] = toff[pos] + ( win ? 0 : old - $elem.offset()[pos] );

					// If it's a dom element, reduce the margin
					if( settings.margin ){
						attr[key] -= parseInt(targ.css('margin'+Pos)) || 0;
						attr[key] -= parseInt(targ.css('border'+Pos+'Width')) || 0;
					}
					
					attr[key] += settings.offset[pos] || 0;
					
					if( settings.over[pos] )
						// Scroll to a fraction of its width/height
						attr[key] += targ[dim]() * settings.over[pos];
				}else
					attr[key] = targ[pos];

				// Number or 'number'
				if( /^\d+$/.test(attr[key]) )
					// Check the limits
					attr[key] = attr[key] <= 0 ? 0 : Math.min( attr[key], max(Dim) );

				// Queueing axes
				if( !i && settings.queue ){
					// Don't waste time animating, if there's no need.
					if( old != attr[key] )
						// Intermediate animation
						animate( settings.onAfterFirst );
					// Don't animate this axis again in the next iteration.
					delete attr[key];
				}
			});			
			animate( settings.onAfter );			

			function animate( callback ){
				$elem.animate( attr, duration, settings.easing, callback && function(){
					callback.call(this, target, settings);
				});
			};
			function max( Dim ){
				var attr ='scroll'+Dim,
					doc = elem.ownerDocument;
				
				return win
						? Math.max( doc.documentElement[attr], doc.body[attr]  )
						: elem[attr];
			};
		}).end();
	};

	function both( val ){
		return typeof val == 'object' ? val : { top:val, left:val };
	};

})( jQuery );