// background changer

window.onload = addButtons;

var backImage = new Array(); 

backImage[0] = "main";
backImage[1] = "space";
backImage[2] = "turbine";

function changeBGImage(whichImage){
	if (document.body){
		document.getElementsByTagName('body')[0].className = backImage[whichImage];
		setCookie('bgimage',whichImage,365);
	}
}


function addButtons(){

	
bgimage=getCookie('bgimage');
if (bgimage!=null && bgimage!="")
  {
  document.getElementsByTagName('body')[0].className = backImage[bgimage];	  	
  }
  else 
  {
  document.getElementsByTagName('body')[0].className = backImage[1];
  if (bgimage!=null && bgimage!="")
    {
    setCookie('bgimage',bgimage,365);
    }
  }
	
eDIV = document.getElementById("topboxes");

eUL = document.createElement("ul");
eDIV.appendChild(eUL);

eLI1 = document.createElement("li");
eUL.appendChild(eLI1);

	eAnchor1 = document.createElement("a");
	eAnchor1.setAttribute("href","javascript:changeBGImage(0)");
	eAnchor1.setAttribute("title","change background to field");
	eLI1.appendChild(eAnchor1);

	eImg1 = document.createElement("img");
	eImg1.setAttribute("src","http://www.footprintfriends.com/siteimages/background-box-main.jpg");
	eImg1.setAttribute("alt","main");
	eAnchor1.appendChild(eImg1);
	
eLI2 = document.createElement("li");
eUL.appendChild(eLI2);

	eAnchor2 = document.createElement("a");
	eAnchor2.setAttribute("href","javascript:changeBGImage(1)");
	eAnchor2.setAttribute("title","change background to space");
	eUL.appendChild(eAnchor2);

	eImg2 = document.createElement("img");
	eImg2.setAttribute("src","http://www.footprintfriends.com/siteimages/background-box-space.jpg");
	eImg2.setAttribute("alt","space");
	eAnchor2.appendChild(eImg2);

eLI3 = document.createElement("li");
eUL.appendChild(eLI3);

	eAnchor3 = document.createElement("a");
	eAnchor3.setAttribute("href","javascript:changeBGImage(2)");
	eAnchor3.setAttribute("title","change background to wind turbine");
	eUL.appendChild(eAnchor3);

	eImg3 = document.createElement("img");
	eImg3.setAttribute("src","http://www.footprintfriends.com/siteimages/background-box-wind.jpg");
	eImg3.setAttribute("alt","turbine");
	eAnchor3.appendChild(eImg3);


document.getElementById("topboxes").appendChild(eDIV);

}

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1; 
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    } 
  }
return "";
}

function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}


