function amILocal($needle){
	$haystack=window.location.href;
	if($haystack.search($needle)>=0){
		return true;
	} else {
		return false;
	}
}

if(amILocal("localhost")){
	$host="localhost";
	ROOT="http://"+$host+"/foodlinks/";
	AJAXURLstop="happyprint";
} else {
	$host="www.herefordshirefoodlinks.org.uk";
	ROOT="http://"+$host+"/";
	AJAXURLstop="herefordshirefoodlinks.org.uk";
}

function setOpacity($item, $opacity){
	if(document.all){
		$item.setStyle("filter","alpha(opacity="+$opacity+")");
	} else {
		$item.style.opacity=$opacity/100 ;
	}
}

function createCookie(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 readCookie(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;
}

URLparts=window.location.href.split("/");
addParts=true;
AJAXlink="";
for(i=URLparts.length-2; i>0; i--){
	if(URLparts[i]==AJAXURLstop){
		addParts=false;
	}
	if(addParts){
		AJAXlink+="../";
	}
}
AJAXlink+="ajax/ajax.php";






////////////////////// GOOGLE MAPS API /////////////////////////////

var map;
var geocoder;
var postcodes=Array();
function load() {
  if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById("map"));
		geocoder = new GClientGeocoder();
		map.setCenter(new GLatLng(52.059599, -2.727741), 8);
		map.addControl(new GSmallZoomControl());
    for(i=0; i<postcodes.length; i++){
    	showAddress(postcodes[i].postcode, postcodes[i].content);
    }
	}
}

function showAddress(address, content) {  
	geocoder.getLatLng(
		address,
		function(point) {
			if (!point) {
			} else {
				//map.panTo(point);
				var marker = new GMarker(point);
				map.addOverlay(marker);
				GEvent.addListener(marker, "click", function(){
					map.panTo(point);
					showDetails(content);
				});
			}
		}
	);
}

window.addEvent("domready", function(){
	$("searchdropdown").onchange=function(){
		window.location.href=ROOT+"page_view/member_"+this.value+"/index.html";
	}
  $("maplink").onmouseover=function(){
    this.getChildren()[1].style.display="block";
  }
  $("maplink").onmouseout=function(){
    this.getChildren()[1].style.display="none";
  }
});

function showDetails(content){
	$("details").innerHTML=content;
	$("details").style.display="block";
}

