google.load('search', '1');

	var imageSearch;
	var searchTerm;
	var searchSite;
     
	function searchComplete() {

        // Check that we got results
        if (imageSearch.results && imageSearch.results.length > 0) {
			var results = imageSearch.results;	
			var imageToPull = results.length;			
			imageToPull = Math.random() * imageToPull;
			imageToPull = Math.floor(imageToPull);
			var urlString = "url(" + results[imageToPull].url + ")";
			document.getElementById("search-term").innerHTML = searchTerm;
			document.getElementById("image-url").innerHTML = "<a href=\"" + results[imageToPull].url + "\">" + results[imageToPull].visibleUrl + "</a>";
			document.getElementById("content").style.backgroundImage = urlString;
        }
		else
		{
			document.getElementById("search-term").innerHTML = "no results for: " + searchTerm;
			//OnLoad();	
		}
      }

      function OnLoad() {
      
	  	searchTerm = getSearchTerm();
		searchSite = getPhotoSite();
		//alert(searchTerm);
		
        // Create an Image Search instance.
        imageSearch = new google.search.ImageSearch();
		imageSearch.setRestriction(
			google.search.ImageSearch.RESTRICT_IMAGESIZE,
  			google.search.ImageSearch.IMAGESIZE_MEDIUM
			);
		imageSearch.setRestriction(
  			google.search.Search.RESTRICT_SAFESEARCH,
 			google.search.Search.SAFESEARCH_STRICT
			);
	
        // Set searchComplete as the callback function when a search is 
        // complete.  The imageSearch object will have results in it.
        imageSearch.setSearchCompleteCallback(this, searchComplete, null);
		imageSearch.setResultSetSize(8);
		imageSearch.setSiteRestriction(searchSite);

        // search
        imageSearch.execute(searchTerm);
        
        // Include the required Google branding
        google.search.Search.getBranding('branding');
      }
      google.setOnLoadCallback(OnLoad);
	  
	  function getSearchTerm(){
		  	var searchTerms = ["a","b","c","quark","tongue","goat","space","bontanical","cyst","eye","mondrian","jackson+pollack","kevin+appel","rash","salt","mile","l","argon","pluto","excess","insomnia","sand","5","burger","german","islamic+pattern","drawing","night+sky","skeleton","red", "gold", "kremlin", "kgb", "ddr", "olvetti", "commodore+pet", "drunk+sailor", "duchamp", "dubrovnik", "los+angeles", "good+luck+charm", "as+seen+on+tv", "gustav+klimt", "egon", "vein", "aorta", "ameoba", "electron+microscope", "catherine+opie", "sinister", "euro", "cookie", "medical", "lame", "havoc", "apple", "wind", "springs", "radon", "neon", "carbon", "missing+link", "vector+art", "agro", "amorphous", "meloncholy", "rabid", "twang", "robbery", "law", "lesion", "cloud", "earth", "martian", "gravity", "burg", "cardomon", "lemon+zest", "jelly", "sponge", "virus", "egg", "divine", "totality", "terminus", "simple", "easy", "crazy+cat", "mean+granny", "angry+mob", "wet", "eerie", "leg+up", "corporate+ladder", "i+mean+business", "mullet", "comb+over", "nerd", "1976", "1988", "1888", "fashion", "estrogen", "thorn", "london", "holly", "sherbert", "electron+puppy", "1777", "washing", "book", "leaf", "brick", "oleo", "ohio", "ascot", "london", "asphalt", "biscuit", "1993", "2001", "chip", "crisp", "rage", "rerun", "bad+television", "drupal", "code", "louisville", "ottawa", "ice", "polar", "straw", "cliff", "tin", "periodic", "lathe", "lacan", "barthes", "windows", "jason", "luc+tuymans", "edward+hopper", "sol+lewitt", "jasper+johns", "ed+rusha", "francis+bacon+painter", "painter", "expression", "john+cage", "peter+agostini", "alexander+calder", "josef+albers", "malevich", "buzzcocks", "stuart+davis", "dekooning", "joseph+beuys", "louise+bourgeois", "bauhaus", "rothko", "motherwell", "cern", "neutrino", "optic", "spectrum", "bean", "lazy", "trickle", "1999", "1821", "18th+century", "rococo", "fabric", "stitch", "electric", "helvetica", "1973", "celebration", "coup+d'état", "namibia", "french+west+africa", "simulacra", "semiotic", "signifier", "east+germany", "marx", "kant", "sage", "yellow", "honor", "orange", "volcano", "evil+twin", "speech+act", "chihuahua", "cute+puppy", "skunk", "sloth", "labor", "union", "solidarity", "warsaw", "gdansk", "krakow", "titian", "north+carolina", "oaxaca", "lazar+segall", "matta", "wifredo+lam", "fernando+botero+artist", "frank+stella", "donald+judd+artist", "helen+frankenthaler", "roy+lichtenstein", "claes+oldenburg", "chuck+close", "leon+golub+artist", "joan+miro", "paul+klee", "tatlin", "francisco+goya", "edouard+manet", "camille+pissarro", "paul+gauguin", "henri+matisse", "die+brucke", "fauvism", "fernand+leger", "jean+arp", "mies+van+der+rohe", "le+corbusier", "barnett+newman", "carolee+schneemann", "bruce+nauman", "alexis+carrington+colby+dexter", "audrey+flack+artist", "richard+serra", "eero+saarinen", "barbara+kruger", "cindy+sherman", "wave", "cola", "brasilla" ];
			return searchTerms[Math.floor(Math.random() * searchTerms.length)];  
	  }
	  
	  function getPhotoSite(){
		  	var searchTerms = ["flickr.com","photobucket.com", "corbisimages.com", null];
			return searchTerms[Math.floor(Math.random() * searchTerms.length)];  
	  }
	  
	  function createSearchTerm(){
		var prefixArray = ["ar", "ba", "ca", "di", "bra", "reac", "lea", "bur", "trav", "scent", "art", "lib" ];
		var sufficeArray = ["tion", "est", "ect", "er", "ay" ];
		
		var newWord = prefixArray[Math.floor(Math.random() * prefixArray.length)] + sufficeArray[Math.floor(Math.random() * sufficeArray.length)];
		  
		  return newWord;
		  
	  }
	  
	  
