//
//  Copyright 2009 http://www.authoratory.com 
//
	
	google.load('search', '1');

	function oyImageResults(imageSearch, id){
		this.imageSearch = imageSearch;
		this.id = id;
	}

	oyImageResults.prototype.vote = function(idx, imageUrl){  
		var can = confirm("Confirm this picture?");
		if (can){
			var vote = document.getElementById('gis_vote');  
			var uri = "/vote/cast_vote.php?verb=confirm&ctx=" + this.id + "&key=image&value=" + imageUrl;

			vote.src = uri;
		}
	} 

	oyImageResults.prototype.createLambda = function(i, url){
		var oThis = this;
		return function(){
			oThis.vote(i, url);
			return false;  
		};  
	}

	oyImageResults.prototype.searchComplete = function(){  
	  var contentDiv = document.getElementById('gis_content');
	  if (this.imageSearch.results && this.imageSearch.results.length > 0) {	
		contentDiv.innerHTML = '';
            
        // loop results
		var results = this.imageSearch.results;
        for (var i = 0; i < results.length && i < 6; i++) {
          var result = results[i];
            
		  // div
		  var imgContainer = document.createElement('div');
		  imgContainer.className = 'gis_img';

		  // a
		  var newA = document.createElement('a')
		  newA.href = '';   		 
		  newA.onclick = this.createLambda(i, result.tbUrl);

		  // img
          var newImg = document.createElement('img');
		  newImg.className = 'gis_img';
          newImg.src = result.tbUrl;
		  newImg.border = "0";

		  // commit
		  newA.appendChild(newImg);
		  imgContainer.appendChild(newA);
          contentDiv.appendChild(imgContainer);
		}
      } else {
		  contentDiv.innerHTML = 'none';
	  }
	}    
  
    function inlineImages(term, id) {
      var imageSearch = new google.search.ImageSearch();

	  imageSearch.setRestriction(
	  	google.search.ImageSearch.RESTRICT_IMAGETYPE,
	  	google.search.ImageSearch.IMAGETYPE_FACES
	  );  

	  imageSearch.setResultSetSize(google.search.Search.LARGE_RESULTSET);

	  var results = new oyImageResults(imageSearch, id);
      imageSearch.setSearchCompleteCallback(
			results, oyImageResults.prototype.searchComplete, null
	  );
      imageSearch.execute(term);
    } 

	function oyVoteUp(id){
		var can = confirm("Accurate information, makes sense to me. Right?");
		if (can){			      
			var vote = document.getElementById('gis_vote');  
			var uri = "/vote/cast_vote.php?verb=vote&ctx=" + id + "&key=summary&value=up";

			vote.src = uri;
		}
	}
  
	function oyVoteDown(id){
		var can = confirm("Inaccurate information, needs improvement. Right?");
		if (can){			
			var vote = document.getElementById('gis_vote');  
			var uri = "/vote/cast_vote.php?verb=vote&ctx=" + id + "&key=summary&value=down";

			vote.src = uri;
		}
	}  

	google.load("elements", "1", {packages : ["newsshow"]});

	function inlineNews(term) {
      var options = {
        "queryList" : [
          {
            "q" : "science news",
            "scoring" : "d"
          }
        ]
      }
      var content = document.getElementById('gnews_content');
	  content.innerHTML = '';
      var newsShow = new google.elements.NewsShow(content, options);	
	}