/*
*  How to search for images and restrict them by size.
*  This demo will also show how to use Raw Searchers, aka a searcher that is
*  not attached to a SearchControl.  Thus, we will handle and draw the results
*  manually.
*/

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

function searchComplete(searcher) {
  if (searcher.results && searcher.results.length > 0) {
    var contentDiv = document.getElementById('pics');
    contentDiv.innerHTML = '';
    var results = searcher.results;
    for (var i = 0; i < results.length; i++) {
      var result = results[i];
      var newImg = document.createElement('img');
      newImg.src = result.tbUrl;
      newImg.setAttribute('title', result.titleNoFormatting);
      newImg.setAttribute('class', 'rotate'+Math.floor(Math.random()*9));
      contentDiv.appendChild(newImg);
    }
  }
}

function OnLoad() {
  var imageSearch = new google.search.ImageSearch();
  imageSearch.setRestriction(google.search.ImageSearch.RESTRICT_IMAGESIZE,
                             google.search.ImageSearch.IMAGESIZE_MEDIUM);
  imageSearch.setRestriction(google.search.ImageSearch.RESTRICT_RIGHTS,
                             google.search.ImageSearch.RIGHTS_COMMERCIAL_MODIFICATION);
  imageSearch.setSearchCompleteCallback(this, searchComplete, [imageSearch]);
  imageSearch.setResultSetSize(google.search.Search.LARGE_RESULTSET);
  imageSearch.execute(query);
}
google.setOnLoadCallback(OnLoad);