<?php
ob_start();
$optres['js'][] = $path . "amodules/wb_search_map/js/infobubble.js";
$wb_search_results_show = 1;
if(!isset($catdom_id) || intval($catdom_id) == 0) $catdom_id = $domain_id;
if(isset($_REQUEST['debug3'])) {
	echo "<br/><strong>CATDOM_ID=</strong>" . $catdom_id;
}

function show_adverts() {
	global $browser_type, $optres, $domain_id, $catdom_id, $general_path, $ultra_domainname, $ultra_addonname, $path, $domainname, $microdata_domains, $recomented_value_en;
	require_once(dirname(__FILE__) . "/../adverts/adverts.php");
}


$microdata_domain = str_replace("www.", "", $ultra_domainname);
$microdata_host = $_SERVER['HTTP_HOST'];
if(str_replace('www.', '', $microdata_host) != str_replace('www.', '', $ultra_domainname)) $microdata_host .= "/" . $ultra_addonname;
$have_microdata = (isset($microdata_domains) && in_array($microdata_domain, $microdata_domains));

$wb_domainname = str_replace("www.", "", $ultra_domainname);

$is_hotel = false;
if($wb_domainname == "cyprus-hotel.com") {
	$is_hotel = true;
}

if(isset($module_params)) {
	
	if(isset($_REQUEST['debugwb'])) {
		//echo '<br/>$fm_uid = ', $fm_uid;
		//echo '<br/>$fm_selected = ', $fm_selected;
		echo '<pre>', var_export($module_params, true), '</pre>';
	}
	//
	
	if(isset($_POST)) {
		//echo 'POST: <pre>', var_export($_POST, true), '</pre>';
	}
	
	
	if(isset($module_params['module_hotel_filter']) && intval($module_params['module_hotel_filter']) > 0) {
		$q = "select * from custom_hotels where catdom_id='$domain_id' and id='{$module_params['module_hotel_filter']}';";
		$r = @mysql_query($q);
		if($r && mysql_num_rows($r) == 1) {
			$row = mysql_fetch_assoc($r);
			$filter_module_params = unserialize(base64_decode($row['params']));
			
			//if(isset($_POST)) {
			//	echo 'FILTER: <pre>', var_export($filter_module_params, true), '</pre>';
			//}
			if(!isset($_POST['wb_search'])) {
				$_POST['wb_search'] = "wb_search";
				if(isset($filter_module_params['fm_uid'])) {
					$_POST['ch_fm_uid'] = $filter_module_params['fm_uid'];
				}
				$_POST = array_replace($_POST, $filter_module_params);
				
				$module_params = array_replace($module_params, $filter_module_params);
				
				//echo '<pre>', var_export($module_params, true), '</pre>';
			}
			else {
				$module_params = array_replace($module_params, $filter_module_params);
				
				$over_dcode = false;
				$over_dcode_value = '';
				$over_lcode = false;
				$over_lcode_value = '';
				
				if(isset($_POST['clear_search'])) {
					$over_dcode = true;
					$over_dcode_value = $_POST['dcode'];
					
					$over_lcode = true;
					$over_lcode_value = $_POST['lcode'];
					
					unset($_POST['clear_search']);
				}
				
				$_POST = array_replace($_POST, $filter_module_params);
				
				if($over_dcode) $_POST['dcode'] = $over_dcode_value;
				if($over_lcode) $_POST['lcode'] = $over_lcode_value;
			}
		}
	}

	$wb_hide_from_filter = isset($module_params['hide']) ? $module_params['hide'] : array();
	$wb_srch_dcode = isset($module_params['dcode']) ? trim($module_params['dcode']) : '';
	$wb_srch_lcode = isset($module_params['lcode']) ? trim($module_params['lcode']) : '';
	$wb_srch_fm_uid = isset($module_params['fm_uid']) ? trim($module_params['fm_uid']) : '';
	$wb_srch_selected_fm_uid = isset($module_params['module_selected_fm_uid']) ? trim($module_params['module_selected_fm_uid']) : '';
	$wb_srch_rpp = isset($module_params['module_num_results']) ? intval($module_params['module_num_results']) :20;
	$wb_srch_page_title = isset($module_params['module_page_title']) ? stripslashes(trim($module_params['module_page_title'])) : '';
	$wb_srch_page_title_tag = isset($module_params['module_title_tag']) ? stripslashes(trim($module_params['module_title_tag'])) : 'h1';
	$module_show_filter = isset($module_params['module_show_filter']) ? intval($module_params['module_show_filter']) : 0;
	
	$module_map_search = isset($module_params['module_map_search']) ? intval($module_params['module_map_search']) : 0;
	$module_map_search_image = isset($module_params['module_map_search_image']) ? trim($module_params['module_map_search_image']) : '';
	$module_show_adverts = isset($module_params['module_show_adverts']) ? trim($module_params['module_show_adverts']) : 'no';
	
	
	
	$block_districts = 0;
	if($wb_srch_dcode != "") $block_districts = 1;
	
	
	if(intval($module_show_filter) == 1) {
		$lc = array (
			  'module_id' => $req_modules['wb_search']['module_id'],
			  'module_params' => '',
			  'module_active' => 'yes',
			  'type' => 'module',
			  'location' => 'left',
			  'home_page' => '1',
			  'sec_page' => '1',
			);
			
		$left_pool [] = $lc;
	}
	
	
	if($wb_srch_fm_uid != "" && !isset($_REQUEST['fm_uid']) && !isset($_REQUEST['ch_fm_uid'])) {
		$fm_uid = $wb_srch_fm_uid;
	}
	
	if( (!isset($fm_uid) || $fm_uid == "" ) && $wb_srch_selected_fm_uid != '') {
		$fm_uid = $wb_srch_selected_fm_uid;
	}
	
	
	if(isset($_REQUEST['debugwb'])) {
		echo '<br/>$fm_uid = ', $fm_uid;
	}
}

if(isset($wb_srch_page_title) && $wb_srch_page_title != "") {
	if(trim($webpage_title_en) == "" ) $webpage_title_en = $wb_srch_page_title;
	echo '<' . $wb_srch_page_title_tag . ' class="page-header">'. $wb_srch_page_title . '</'.$wb_srch_page_title_tag.'>';
	
}
else {
	$webpage_title_en = $webpage_title_en;
	if(isset($webpage_header_en) && $webpage_header_en != "") {
		echo '<' . $wb_srch_page_title_tag . ' class="page-header">'. $webpage_header_en . '</' . $wb_srch_page_title_tag . '>';
	}
	else {
		echo '<' . $wb_srch_page_title_tag . ' class="page-header">'. $webpage_title_en . '</' . $wb_srch_page_title_tag . '>';
	}
}

if(isset($_REQUEST['debugwb'])) {
	echo '<br/>before adverts $fm_uid = ', $fm_uid;
}
if($module_show_adverts == 'top') {
	//require_once(dirname(__FILE__) . "/../adverts/adverts.php");
	show_adverts();
}
if(isset($_REQUEST['debugwb'])) {
	echo '<br/>after adverts $fm_uid = ', $fm_uid;
}

$current_page = 1;
$range = 10;
$start = ($current_page - 1) * $range;

if($wb_search_results_show == 1) {
	
	
	
	
	// Get domain catdoms
	$catdoms = array();
	$catdoms [] = $domain_id;
	$result_sub = mysql_query ("SELECT * FROM  domaincategories WHERE parent_id='$domain_id';");
	if (mysql_num_rows($result_sub) <> 0){			  
		while($line_sub = mysql_fetch_array($result_sub)){ 
			$catdoms [] = intval($line_sub["catdom_id"]);
		}
	}
	
	if(!isset($wb_uid)) {
	
		$q = "select wb.* from wb_categories_domains wb where wb.wb_domainname='$wb_domainname';";
		$r = mysql_query($q) or die("<strong>$q</strong>".mysql_error());
		if($r && mysql_num_rows($r) > 0) {
			$row = mysql_fetch_assoc($r);
			$wb_uid = $row['wb_uid'];
		}
			
	}
	
	if(isset($wb_uid) && strlen($wb_uid) == 16) {
		
		
		if(isset($_REQUEST['ch_fm_uid'])) {
			$fm_uid = mysql_real_escape_string(trim($_REQUEST['ch_fm_uid']));
		}
		
		if(!isset($fm_uid)) {
			$fm_uid = '';
		}
		
		
		require_once(dirname(__FILE__) . "/wb_actions.php");
		if($no_adverts_found) {
			require_once(dirname(__FILE__) . "/wb_no_adverts.php");
		}
		require_once(dirname(__FILE__) . "/wb_display.php");
		
		
	}
	?>
	<script type="text/javascript">
	//<![CDATA[
	// Top Map Search
	var wb_search_map = 'large';
	if(typeof have_wb_search_map_image != "undefined") {
		wb_search_map = have_wb_search_map_image == true ? 'small' : 'large';
	}
	var markerClusterer = null;
	var map = null;
	var icon_styles;
	var imageUrl = 'https://chart.apis.google.com/chart?cht=mm&amp;chs=24x32&' + 'chco=FFFFFF,008CFF,084272&amp;ext=.png';
	var cyprus_min_zoom = 8;
	var info_bubble;
	var js_prop_text = {
		"Hotels" 		: "<?php echo "Hotels";?>"
	};
	
	var styles = [[{
	    url: 'https://<?php echo $_SERVER['HTTP_HOST'];?>/modules/wb_search_map/res/markerclusterer/m1.png',
	    height: 52,
	    width: 53,
	    opt_anchor: [27, 10],
	    textColor: '#ffffff',
	    textSize: 11
	  }, {
	    url: 'https://<?php echo $_SERVER['HTTP_HOST'];?>/modules/wb_search_map/res/markerclusterer/m2.png',
	    height: 55,
	    width: 56,
	    opt_anchor: [28, 28],
	    textColor: '#ffffff',
	    textSize: 11
	  }
	  , {
	    url: 'https://<?php echo $_SERVER['HTTP_HOST'];?>/modules/wb_search_map/res/markerclusterer/m3.png',
	    height: 65,
	    width: 66,
	    opt_anchor: [33, 33],
	    textColor: '#ffffff',
	    textSize: 12
	  }
	  , {
	    url: 'https://<?php echo $_SERVER['HTTP_HOST'];?>/modules/wb_search_map/res/markerclusterer/m4.png',
	    height: 77,
	    width: 78,
	    opt_anchor: [39, 39],
	    textColor: '#ffffff',
	    textSize: 12
	  }
	  , {
	    url: 'https://<?php echo $_SERVER['HTTP_HOST'];?>/modules/wb_search_map/res/markerclusterer/m5.png',
	    height: 89,
	    width: 90,
	    opt_anchor: [45, 45],
	    textColor: '#ffffff',
	    textSize: 12
	  }
	  ]];
	
	
	  
	var infowindow = null;
	
	function init_wb_search_map() {
		
		//infowindow = new google.maps.InfoWindow();
		
		icon_styles = {
			'hotels': 'https://<?php echo $_SERVER['HTTP_HOST'];?>/modules/wb_search_map/res/markers/icon_hotels.png'
		};
		
		
		info_bubble = new InfoBubble({
			maxWidth: 400,
			minWidth: 380,
			content: '<div class="info-window">Loading..<\/div>',
			shadowStyle: 1,
			padding: 0,
			backgroundColor: '#ffffff',
			borderRadius: 0,
			arrowSize: 15,
			borderWidth: 1,
			borderColor: '#000000',
			disableAutoPan: false,
			hideCloseButton: true,
			arrowPosition: 50,
			backgroundClassName: 'iw-prop',
			arrowStyle: 0
			
		});
		
		
		var myOptions = {
			zoom: 7,
			center: new google.maps.LatLng(35.05181, 33.40537),
			mapTypeControl: true,
			mapTypeControlOptions: {
				style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
			},
			zoomControl: true,
			zoomControlOptions: {
				style: google.maps.ZoomControlStyle.SMALL
			},
			mapTypeId: google.maps.MapTypeId.ROADMAP
		}

		
		map = new google.maps.Map(document.getElementById('cyprus_map'), myOptions);
		
		google.maps.event.addListener(map, 'click', function() {
			//infowindow.close();
			if(wb_search_map == 'small') {
				wb_enlarge_map();
			}
			info_bubble.close();
		});
		
		google.maps.event.addListener(map, "zoom_changed", function() {
			//if(map.getZoom() < 8) map.setZoom(8);
			if(info_bubble.isOpen()) {
				info_bubble.close();
			}
		});
		
		 google.maps.event.addListener(map, 'bounds_changed', function() {
                  var bounds =  map.getBounds();
                  var ne = bounds.getNorthEast();
                  var sw = bounds.getSouthWest();
                  
                  //console.log('bounds: ' + bounds);
                  //console.log('ne: ' + ne);
                  //console.log('sw: ' + sw);
                  
                  //do whatever you want with those bounds
         });
	
		if(typeof have_wb_search_map_image != "undefined" && have_wb_search_map_image) { 
		
			var wb_enlarge = document.getElementById('map_enlarge');
			google.maps.event.addDomListener(wb_enlarge, 'click', wb_enlarge_map);
			
			var wb_smaller = document.getElementById('map_close');
			google.maps.event.addDomListener(wb_smaller, 'click', wb_smaller_map);
		}
		
		//var refresh = document.getElementById('refresh');
		//google.maps.event.addDomListener(refresh, 'click', refresh_wb_search_map);
		
		//var clear = document.getElementById('clear');
		//google.maps.event.addDomListener(clear, 'click', clearClusters);
		
		refresh_wb_search_clusterer_map();
		
		if(json_locations.length > 0) {
			if(typeof wb_startBounce != "undefined") {
				wb_startBounce($('#wb_search_map_img'));
			}
			$('#wb_search_map_container').show();
		}
		
	}
	
	function wb_enlarge_map (r) {
		
		r = typeof a !== 'undefined' ? r : 'map';
		
		wb_search_map = 'large';
		$('#wb_search_map_container').removeClass('wb_search_map_container_small').addClass('wb_search_map_container_large');
		$('#cyprus_map').removeClass('wb_search_map_gmap_small').addClass('wb_search_map_gmap_large');
		$('#wb_search_map').removeClass('wb_search_map_small').addClass('wb_search_map_large');
		$('#wb_search_map_image').hide();
		
		$('#map_menu_small').hide();
		$('#map_menu_large').show();
		
		if(r == 'map') {
			refresh_wb_search_map();
			markerClusterer.setZoomOnClick(true);
		}
		//refresh_wb_search_clusterer_map();
	}
	
	function wb_smaller_map () {
		wb_search_map = 'small';
		$('#wb_search_map_container').removeClass('wb_search_map_container_large').addClass('wb_search_map_container_small');
		$('#cyprus_map').removeClass('wb_search_map_gmap_large').addClass('wb_search_map_gmap_small');
		$('#wb_search_map').removeClass('wb_search_map_large').addClass('wb_search_map_small');
		$('#wb_search_map_image').show();
		
		$('#map_menu_large').hide();
		$('#map_menu_small').show();
		
		refresh_wb_search_map();
	}
		
	function refresh_wb_search_map() {
		google.maps.event.trigger(map, "resize");
		map.setCenter(new google.maps.LatLng(35.05181, 33.40537));
		map.setZoom(8);
		refresh_wb_search_clusterer_map();
	}
	
	function mycalc(mc, st) {
		return AA;
	}
	
	function refresh_wb_search_clusterer_map() {
		if (markerClusterer != null) {
			markerClusterer.clearMarkers();
		}
		
		var markers = [];
		
		var bounds = new google.maps.LatLngBounds();
		//var markerImage = new google.maps.MarkerImage(imageUrl, new google.maps.Size(24, 32));
		
		for (var i = 0; i < json_locations.length; i++) {
			var adv_code = json_locations[i]['adv_code'];
			var ilat = json_locations[i].lat;
			var ilng = json_locations[i].lng;
			var latLng = new google.maps.LatLng(ilat, ilng);
			
			bounds.extend(latLng);
			
			var fm_uid = json_locations[i].fm_uid;
			var fm_name = json_locations[i].fm_name;
			var num_venues = 1;
			var icon_url = "";
			icon_url = icon_styles['hotels'];
			
			var marker = new google.maps.Marker({
				'position': latLng,
				'draggable': false,
				'icon': icon_url,
				'adv_code': adv_code,
				'fm_uid': fm_uid,
				'fm_name': fm_name,
				'num_venues' : num_venues,
				'title': ' Click Me NOW! '
			});
			
			
			loadInfoWindow(marker);
			markers.push(marker);
			
			
			
		}
		
		
		//var zoom = parseInt(document.getElementById('zoom').value, 10);
		//var size = parseInt(document.getElementById('size').value, 10);
		//var style = parseInt(document.getElementById('style').value, 10);
		//zoom = zoom == -1 ? null : zoom;
		//size = size == -1 ? null : size;
		//style = style == -1 ? null: style;
		//alert('maxZoom=' + zoom + ' ; gridSize=' + size + ' ; styles=styles[' + style + ']');
		markerClusterer = new MarkerClusterer(map, markers, {
			maxZoom: 18,//zoom,
			gridSize: 30,//size,
			zoomOnClick: (wb_search_map == 'small') ? false : true,
			styles: [{
			    url: 'https://<?php echo $_SERVER['HTTP_HOST'];?>/modules/wb_search_map/res/markerclusterer/m1.png',
			    height: 52,
			    width: 53,
			    opt_anchor: [27, 10],
			    textColor: '#ffffff',
			    textSize: 11
			  }, {
			    url: 'https://<?php echo $_SERVER['HTTP_HOST'];?>/modules/wb_search_map/res/markerclusterer/m2.png',
			    height: 55,
			    width: 56,
			    opt_anchor: [28, 28],
			    textColor: '#ffffff',
			    textSize: 11
			  }
			  , {
			    url: 'https://<?php echo $_SERVER['HTTP_HOST'];?>/modules/wb_search_map/res/markerclusterer/m3.png',
			    height: 65,
			    width: 66,
			    opt_anchor: [33, 33],
			    textColor: '#ffffff',
			    textSize: 12
			  }
			  , {
			    url: 'https://<?php echo $_SERVER['HTTP_HOST'];?>/modules/wb_search_map/res/markerclusterer/m4.png',
			    height: 77,
			    width: 78,
			    opt_anchor: [39, 39],
			    textColor: '#ffffff',
			    textSize: 12
			  }
			  , {
			    url: 'https://<?php echo $_SERVER['HTTP_HOST'];?>/modules/wb_search_map/res/markerclusterer/m5.png',
			    height: 89,
			    width: 90,
			    opt_anchor: [45, 45],
			    textColor: '#ffffff',
			    textSize: 12
			  }
			  ],
			  calculator:function(mc, ind){
				var nf = {};
				nf.text = 0;
				nf.index = (ind - 2 > 0) ? (ind-2) : 0;
				
				for(var key in mc) {
					nf.text += mc[key].num_venues;
				}

				return nf;
			  }
		});
		
		/*
		google.maps.event.addListener(markerClusterer, 'click', function(cluster) {
			if(wb_search_map == 'small') {
				wb_enlarge_map();
			}
			//map.setCenter(cluster.getCenter());
		});
		*/
		
		google.maps.event.addListener(markerClusterer, "click", function (c) {
	        if(wb_search_map == 'small') {
				wb_enlarge_map('cluster');
				markerClusterer.setZoomOnClick(true);
				map.setCenter(c.getCenter());
				refresh_wb_search_clusterer_map();
			}
			         
        });

		if(wb_search_map == 'small') {
			map.fitBounds(bounds);
		}
		else {
	        map.setCenter(new google.maps.LatLng(35.05181, 33.40537));
			map.setZoom(8);
		}
		//map.fitBounds(bounds);
	}
	
	function loadInfoWindow(marker){
		
		google.maps.event.addListener(marker, 'click', function() {
			if(wb_search_map == 'small') {
				wb_enlarge_map();
			}
			if(info_bubble.isOpen()) {
				info_bubble.close();
			}
			$.ajax({
				url: 'https://<?php echo $_SERVER['HTTP_HOST']; ?>/modules/wb_search_map/ajax/getInfoWindow.php?adv_code=' + marker.adv_code+ '&domainname=<?php echo $ultra_domainname;?>',
				cache: false,
				success: function(data){
					// Run JS in infowindow content
					var $tmp_div = $('<div style="display: none;"><\/div>');
					$tmp_div.html(data);
					$('.click-link', $tmp_div).each(function(){
						var click_link_id = $(this).attr('rel');
						var extra_class = $(this).attr('extra_class');
						var sub_content = '<a href="' + tmp_click_links[click_link_id] + '" class="' + extra_class + '" target="_blank">' + $(this).html() + '<\/a>';
						$(this).replaceWith(sub_content);
					});
					var ibc = $tmp_div.html();
					$tmp_div.remove();
					info_bubble.setContent(ibc);
					info_bubble.open(map, marker);
					info_bubble.setMinWidth(300);
					info_bubble.setMinHeight(170);
					info_bubble.open(map, marker);
					info_bubble.panToView();
				}
			});
			
		});
	}
	
	/***********************************************************************************************************/
	// Individual Map
	var map_gmap = null;
	var myLatlng = null;
	var infoWindow = null;
	var markerArray = [];
	var infowindows = [];
	
	function openDirections(loc_id) {
		var $directions_dialog = $('<div id="directions_dialog"><\/div>');
		$directions_dialog.dialog({
			autoOpen: false,
			position: 'top',
			modal: true,
			dialogClass: "company_dialog",
			title: 'Get Map Directions',
			width: $(document).width() - 20,
			height: <?php echo ( isset($_REQUEST['page']) ? '$(window.parent).height()-20' : '$(window).height()-20'); ?>,
			open: function(event, ui) {
				//$('#stamp').val(new Date.getTime());
				var $frm = $('<iframe id="process_frm" name="process_frm"></iframe>');
				$frm.attr('src', '<?php echo $path;?>modules/adverts_map/map_directions.php?location_id=' + loc_id);
				$frm.attr('width', '100%');
				$frm.attr('height', '98%');
				$frm.css('border', '1px solid #000000');
				$frm.css('overflow-y', 'hidden');
				$('#directions_dialog').append($frm);
				
			},
			close: function(event, ui) {
				$('#process_frm').remove();
				$directions_dialog.dialog('destroy');
				$directions_dialog.remove();
			},
			buttons: {
				'Close': function(event, ui) {
					$(this).dialog('close');
				}
			}
		});
		$directions_dialog.dialog('open');
	}
	
	function openBigMap(loc_id) {
		var $directions_dialog = $('<div id="directions_dialog"><' + '/div>');
		$directions_dialog.dialog({
			autoOpen: false,
			position: 'top',
			modal: true,
			dialogClass: "company_dialog",
			title: 'Get Map Directions',
			width: $(document).width() - 20,
			height: <?php echo ( isset($_REQUEST['page']) ? '$(window.parent).height()-20' : '$(window).height()-20'); ?>,
			open: function(event, ui) {
				//$('#stamp').val(new Date.getTime());
				var $frm = $('<iframe id="process_frm" name="process_frm"></iframe>');
				$frm.attr('src', '<?php echo $path;?>modules/adverts_map/map_enlarge.php?location_id=' + loc_id);
				$frm.attr('width', '100%');
				$frm.attr('height', '98%');
				$frm.css('border', '1px solid #000000');
				$frm.css('overflow-y', 'hidden');
				$('#directions_dialog').append($frm);
				
			},
			close: function(event, ui) {
				$('#process_frm').remove();
				$directions_dialog.dialog('destroy');
				$directions_dialog.remove();
			},
			buttons: {
				'Close': function(event, ui) {
					$(this).dialog('close');
				}
			}
		});
		$directions_dialog.dialog('open');
	}
	
	
	function init_gmap(lat, lng, zoom) {

		myLatlng = new google.maps.LatLng(lat * 1, lng * 1);
	    var myOptions = {
	      zoom: zoom * 1 - 1,
	      center: myLatlng,
	      mapTypeId: google.maps.MapTypeId.ROADMAP
	    }
		map_gmap = new google.maps.Map(document.getElementById("gmap_canvas"), myOptions);
		
		
		// Creating a marker and positioning it on the map
		var marker = new google.maps.Marker({
			position: myLatlng,
			map: map_gmap
		});
		
		markerArray.push(marker);
		
		google.maps.event.trigger(map_gmap, 'resize');
		map_gmap.setZoom( map_gmap.getZoom() );
		//AutoCenter();
	}
	
	function AutoCenter() {
		//  Create a new viewpoint bound
		var bounds = new google.maps.LatLngBounds();
		//  Go through each...
		$.each(markerArray, function (index, marker) {
			bounds.extend(marker.position);
		});
		//  Fit these bounds to the map
		map_gmap.fitBounds(bounds);
	}

	
	
	function resizeMap(){
		google.maps.event.trigger(map_gmap, "resize");
		map_gmap.setCenter(myLatlng);
	}
	
	function init_gmap_null() {
		return true;
	}
	
	
	function appendBootstrap() {
		var script = document.createElement("script");
		script.type = "text/javascript";
		//script.src = "https://maps.google.com/maps/api/js?v=3.4&sensor=false&callback=init_gmap_null&language=en&region=CY";
		script.src = "https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&callback=init_gmap_null&language=en&region=CY";
		//document.body.appendChild(script);
		$('head').append(script);
	}
	
	function makeMarker(options, info_content){
		var pushPin = new google.maps.Marker({map:map_gmap});
		pushPin.setOptions(options);
		markerArray.push(pushPin);
		google.maps.event.addListener(pushPin, 'click', function(){
			var infowindow = new google.maps.InfoWindow({
			    content: info_content
			});
			
			infowindows.push(infowindow);
			infowindow.open(map_gmap, pushPin);
		});
		
		
		return pushPin;
	}
	
	function showMarker(i){
		google.maps.event.trigger(markerArray[i], 'click');
	};
	
	$(document).ready(function(){
		
		var click_links = <?php echo json_encode($click_count_paths);?>;
		$('.click-link').each(function(){
			var click_link_id = $(this).attr('rel');
			var extra_class = $(this).attr('extra_class');
			var sub_content = '<a href="' + click_links[click_link_id] + '" class="' + extra_class + '" target="_blank">' + $(this).html() + '</a>';
			$(this).replaceWith(sub_content);
		});
		
		$('.adv_linkage').each(function(){
			var $lnk = $(this);
			$lnk.click(function(ev){
				ev.preventDefault();
				window.open($lnk.attr('link'));
				return false;
			});
		});
		
		$('a.mailto').each(function(){
			var email = $(this).attr('rel');
			email = email.replace('[ at ]', '@');
			$(this).attr('href', 'mailto:' + email);
			$(this).text(email);
		});
		
		
		//appendBootstrap();
		<?php
		if($module_map_search == 1) {
			?>
			init_wb_search_map();
			<?php 
		}
		?>
		
		$('.wb-map-link').live('click', function(e){
			e.preventDefault();
			var loc_id = $(this).attr('rel');
			openBigMap(loc_id);
			return false;
		});
		
		
	});
//]]>
	</script>
	<?php

}

if($module_show_adverts == 'bottom') {
	//require_once(dirname(__FILE__) . "/../adverts/adverts.php");
	show_adverts();
}

$wb_content = ob_get_contents();
ob_end_clean();

if($wb_search_results_show == 1) {
	echo $wb_content;
}
else {
	?>

	<div class="more_wb_links">
		<?php	
		echo '<p><span style="float: left; margin-right: .3em;" class="ui-icon ui-icon-info"></span>Please click the following link to find more <a href="'.$protocol . $microdata_host.'/'.$wb_friendly_url.'/page-1.html" class="" title="'.$module_wb_title.'">'.$module_wb_title.'</a>.</p>';
		?>
	</div>
	<?php	
}
//else {
//	unset($wb_content);
//}