var gCoffeeIconLG = "images/pin_coffee.png";
var gFoodIconLG = "images/pin_food.png";
var gBarsIconLG = "images/pin_bar.png";
var gGymsIconLG = "images/pin_healthclub.png";
var gPropertyIconLG = "images/pin_property.png";
var gCompanyIconLG = "images/pin_localbusiness.png";

var gCoffeeTitle = "coffee";
var gFoodTitle = "food";
var gBarTitle = "bars";
var gGymTitle = "health clubs";
var gCompanyTitle = "local businesses";

function defineCustomIcons(pAryIcons){

	pAryIcons = new Array();

	var propertyIcon = new GIcon();
	propertyIcon.image = gPropertyIconLG;	
	propertyIcon.iconSize = new GSize(53, 85);	
	propertyIcon.iconAnchor = new GPoint(53, 85);
	propertyIcon.infoWindowAnchor = new GPoint(40,20);
	
	var coffeeIcon = new GIcon();
	coffeeIcon.image = gCoffeeIconLG;	
	coffeeIcon.iconSize = new GSize(35, 54);	
	coffeeIcon.iconAnchor = new GPoint(35, 54);
	coffeeIcon.infoWindowAnchor = new GPoint(20, 20);
	
	var foodIcon = new GIcon();
	foodIcon.image = gFoodIconLG;	
	foodIcon.iconSize = new GSize(35, 52);	
	foodIcon.iconAnchor = new GPoint(35, 52);
	foodIcon.infoWindowAnchor = new GPoint(20, 20);
	
	var barsIcon = new GIcon();
	barsIcon.image = gBarsIconLG;	
	barsIcon.iconSize = new GSize(34, 51);	
	barsIcon.iconAnchor = new GPoint(34, 51);
	barsIcon.infoWindowAnchor = new GPoint(20, 20);
	
	var gymIcon = new GIcon();
	gymIcon.image = gGymsIconLG;
	gymIcon.iconSize = new GSize(33, 51);
	gymIcon.iconAnchor = new GPoint(33, 51);
	gymIcon.infoWindowAnchor = new GPoint(20, 20);
	
	var CompanyIcon = new GIcon();
	CompanyIcon.image = gCompanyIconLG;
	CompanyIcon.iconSize = new GSize(31, 52);
	CompanyIcon.iconAnchor = new GPoint(31, 52);
	CompanyIcon.infoWindowAnchor = new GPoint(20, 20);
	
	pAryIcons.push(propertyIcon, coffeeIcon, foodIcon, barsIcon, gymIcon, CompanyIcon);

	return pAryIcons;
}


function makeInfoBox(pResult){
	var gads = document.getElementById("idgooglead");
	sInfo =  '<div style="width:400px;"><div style="width:200px; float:left;"><br />';
	sInfo += '<a href="' + pResult.url + '" target="_blank" class="formtext04">' + pResult.titleNoFormatting + "</a>";
	sInfo += "<br />" + pResult.streetAddress;
	sInfo += "<br />" + pResult.city + ' ' + pResult.region;
	sInfo += "<br />" + pResult.country;
	sInfo += "<br />";
	sInfo += "<br /><small>" + pResult.phoneNumbers[0].number + "</small>";
	
	if (pResult.ddUrl && pResult.ddUrl != null)
	{
		sInfo += '&nbsp;&nbsp;|&nbsp;&nbsp;<a href="'+pResult.ddUrl+'" target="_blank" class="loginlink3">Driving Directions</a>';
	}
	sInfo += '<br /><br /></div><div style="width:20; float:left;"></div><div style="width:180; float:left;">';
	sInfo += gads.innerHTML;
	//sInfo += '<iframe src="googlemapad.php" marginwidth="0" marginheight="0" vspace="0" hspace="0" allowtransparency="true" frameborder="0" height="150" scrolling="no" width="180">';
	//sInfo += '<scr' + 'ipt type="text/javascript"> src=" http://pagead2.googlesyndication.com/pagead/show_ads.js"></scr' + 'ipt>';
	//sInfo += '<iframe name="google_ads_frame" src=" http://pagead2.googlesyndication.com/pagead/ads?client=ca-pub-0310442538982633&amp;dt=1187361476015&amp;lmt=1187361471&amp;prev_fmts=200x200_as%2C200x200_as&amp;format=125x125_as&amp;output=html&amp;correlator=1187635814312&amp;url=http%3A%2F%2Fdev.findbyclick.com%2F&amp;color_bg=FFFFFF&amp;color_text=000000&amp;color_link=E21D27&amp;color_url=000000&amp;color_border=FFFFFF&amp;ad_type=text_image&amp;cc=100&amp;ga_vid=1084617195.1170780845&amp;ga_sid=1187634344&amp;ga_hid=1409657926&amp;ga_fc=true&amp;flash=9&amp;u_h=1050&amp;u_w=1680&amp;u_ah=1050&amp;u_aw=1680&amp;u_cd=32&amp;u_tz=-240&amp;u_his=30&amp;u_java=true&amp;u_nplug=15&amp;u_nmime=55 " marginwidth="0" marginheight="0" vspace="0" hspace="0" allowtransparency="true" frameborder="0" height="125" scrolling="no" width="125"></iframe>';
	sInfo += '</div></div>';
	return sInfo;
	
}


function makeCheckList(){

	var container = document.createElement("div");
	
	var tbl = document.createElement("table");
	tbl.style.background = "#FFF";
	tbl.style.border = "2px solid #ff0000";
	tbl.style.opacity = ".10"; 
	tbl.align = 'right';

	var tbody = document.createElement("tbody")
	
	var row = document.createElement("tr");		
	var cell = document.createElement("td");
		
	var control_0 = document.createElement("input");
	control_0.type = 'checkbox';
	control_0.defaultChecked = true;
	control_0.id = "check-0";		
	cell.appendChild(control_0);				
	row.appendChild(cell);			
	
	var cell = document.createElement("td");
	var cellText = document.createTextNode(gCoffeeTitle);
	cell.style.fontSize = "14px";
	cell.style.color = "#55462f";
	cell.style.fontWeight = "bold";	
	cell.appendChild(cellText);				
	row.appendChild(cell);
	
	var cell = document.createElement("td");
	var img = document.createElement("img");
	img.src = gCoffeeIconLG;
	cell.appendChild(img);				
	row.appendChild(cell);
	
	tbody.appendChild(row);
		
	var row = document.createElement("tr");		
	var cell = document.createElement("td");
		
	var control_1 = document.createElement("input");
	control_1.type = 'checkbox';
	control_1.defaultChecked = true;
	control_1.id = "check-1";		
	cell.appendChild(control_1);				
	row.appendChild(cell);		
	
	var cell = document.createElement("td");
	var cellText = document.createTextNode(gFoodTitle);
	cell.style.fontSize = "14px";
	cell.style.color = "#ce5c15";
	cell.style.fontWeight = "bold";
	cell.appendChild(cellText);				
	row.appendChild(cell);
	
	var cell = document.createElement("td");
	var img = document.createElement("img");
	img.src = gFoodIconLG;
	cell.appendChild(img);				
	row.appendChild(cell);
		
	tbody.appendChild(row);
	
	var row = document.createElement("tr");		
	var cell = document.createElement("td");
		
	var control_2 = document.createElement("input");
	control_2.type = 'checkbox';
	control_2.defaultChecked = true;
	control_2.id = "check-2";		
	cell.appendChild(control_2);				
	row.appendChild(cell);		
	
	var cell = document.createElement("td");
	var cellText = document.createTextNode(gBarTitle);
	cell.style.fontSize = "14px";
	cell.style.color = "#207001";
	cell.style.fontWeight = "bold";
	cell.appendChild(cellText);				
	row.appendChild(cell);
	
	var cell = document.createElement("td");
	var img = document.createElement("img");
	img.src = gBarsIconLG;
	cell.appendChild(img);				
	row.appendChild(cell);
		
	tbody.appendChild(row);
	
	var row = document.createElement("tr");		
	var cell = document.createElement("td");
		
	var control_3 = document.createElement("input");
	control_3.type = 'checkbox';
	control_3.defaultChecked = true;
	control_3.id = "check-3";		
	cell.appendChild(control_3);				
	row.appendChild(cell);		
	
	var cell = document.createElement("td");
	var cellText = document.createTextNode(gGymTitle);
	cell.style.fontSize = "14px";
	cell.style.color = "#4e5760";
	cell.style.fontWeight = "bold";
	cell.appendChild(cellText);				
	row.appendChild(cell);
	
	var cell = document.createElement("td");
	var img = document.createElement("img");
	img.src = gGymsIconLG;
	cell.appendChild(img);				
	row.appendChild(cell);
			
	tbody.appendChild(row);
	
	/* company row */
	var row = document.createElement("tr");		
	var cell = document.createElement("td");
		
	var control_4 = document.createElement("input");
	control_4.type = 'checkbox';
	control_4.defaultChecked = true;
	control_4.id = "check-4";		
	cell.appendChild(control_4);				
	row.appendChild(cell);		
	
	var cell = document.createElement("td");
	var cellText = document.createTextNode(gCompanyTitle);
	cell.style.fontSize = "14px";
	cell.style.color = "#2964e6";
	cell.style.fontWeight = "bold";
	cell.appendChild(cellText);				
	row.appendChild(cell);
	
	var cell = document.createElement("td");
	var img = document.createElement("img");
	img.src = gCompanyIconLG;
	cell.appendChild(img);				
	row.appendChild(cell);
		
	tbody.appendChild(row);
	
	/* end company row */
	
	tbl.appendChild(tbody);	
	container.appendChild(tbl);
	
	GEvent.addDomListener(control_0, "click", function(){ toggleDisplay(this,0) } );
	GEvent.addDomListener(control_1, "click", function(){ toggleDisplay(this,1) } );
	GEvent.addDomListener(control_2, "click", function(){ toggleDisplay(this,2) } );
	GEvent.addDomListener(control_3, "click", function(){ toggleDisplay(this,3) } );
	GEvent.addDomListener(control_4, "click", function(){ toggleDisplay(this,4) } );
	
	return container;
}

	function toggleDisplay(obj, value){	
		if(obj.checked){		
			for (var i = 0; i < gSearchParams[value][0].length; i++) {
				gMap.addOverlay(gSearchParams[value][0][i].marker());
			}			
		} else {
			for (var i = 0; i < gSearchParams[value][0].length; i++) {
				gMap.removeOverlay(gSearchParams[value][0][i].marker());
			}
		}
	}
	
	function showMarker(pSearch,pItem){
		
		//make sure the points are displayed on the map
		objCheck = document.getElementById("check-"+pSearch);
		if(objCheck.checked==false){
			objCheck.checked = true;
			for (var i = 0; i < gSearchParams[pSearch][0].length; i++) {
				gMap.addOverlay(gSearchParams[pSearch][0][i].marker());
			}
		}

		//pass the results array to formatting function				
		newMarker = gSearchParams[pSearch][0][pItem].marker();		
		var infoBoxDetails = makeInfoBox(gSearchResults[pSearch][0][pItem]);
		newMarker.openInfoWindowHtml(infoBoxDetails);
	}

