
//init a google search object
google.load('search', '1');
//init a search object
var gSearch;

function searchComplete() {
  // Check that we got results
  if (gSearch.results && gSearch.results.length > 0) {
    // Grab our content div, clear it.
    var contentDiv = document.getElementById('content');
    contentDiv.innerHTML = '';

    // Loop through our results, printing them to the page.
    var results = gSearch.results;
    for (var i = 0; i < results.length; i++) {
      // For each result write it's title and image to the screen
      var result = results[i];
      var resultContainer = document.createElement('div');

	  //check for, and display mini-player, if youtube
	  var strYTref = '';
	  var position = result.unescapedUrl.indexOf('youtube.com/watch?v=');
	  if (position!=-1)
	  {
	    strYTref = result.unescapedUrl.substring(position+20,position+31);
// strYTobj = '<div style="width:auto;float:left;margin:4px;border:2px solid black;"><object type="application/x-shockwave-flash" style="width:300px; height:247px;" data="http://www.youtube.com/v/' +strYTref+ '&fs=1"><param name="movie" value="http://www.youtube.com/v/'+strYTref+'&fs=1"/></object></div>';
	  
strYTobj = '<div style="width:auto;float:left;margin:4px;border:2px solid black;"><object width="300" height="247"><param name="movie" value="http://www.youtube.com/v/' +strYTref+ '"</param><param name="allowFullScreen" value="true"></param><embed src="http://www.youtube.com/v/' +strYTref+ '&fs=1&autoplay=0"  type="application/x-shockwave-flash"  allowfullscreen="true"  width="300" height="247"></embed></object></div>';	  
	  }
	  
	  //check again for youtube
	  position2 = result.unescapedUrl.indexOf('youtube.com/v/');
	  if (position2!=-1)
	  {
	  strYTref = result.unescapedUrl.substring(position2+14,position2+25);
// strYTobj = '<div style="width:auto;float:left;margin:4px;border:2px solid black;"><object type="application/x-shockwave-flash" style="width:300px; height:247px;" data="http://www.youtube.com/v/' + strYTref + '&fs=1"><param name="movie" value="http://www.youtube.com/v/'+strYTref+'&fs=1"/></object></div>';
strYTobj = '<div style="width:auto;float:left;margin:4px;border:2px solid black;"><object width="300" height="247"><param name="movie" value="http://www.youtube.com/v/' +strYTref+ '"</param><param name="allowFullScreen" value="true"></param><embed src="http://www.youtube.com/v/' +strYTref+ '&fs=1&autoplay=0"  type="application/x-shockwave-flash"  allowfullscreen="true"  width="300" height="247"></embed></object></div>';	
	  }
	  
	  //if neither youtube, then use a thumbnail
	  if ((position==-1)&&(position2==-1))
	  {
	  strYTobj="<img style='float:left;margin:4px;border:2px solid black;width:120px;height:90px;' src='http://www.shrinktheweb.com/xino.php?embed=1&STWAccessKeyId=c4ce7a3898d6307&Size=sm&stwUrl=" + result.url + "'>";
	  }	  

      resultContainer.innerHTML = 
	  "<div class='presult' onclick='location.href=\""+result.unescapedUrl+"\";'>"+strYTobj+"<h3><a href='" + result.unescapedUrl + "'>" + result.title + "</a></h3>" + result.content +"<br><span style='color:#286e38;font-style:italic'>"+result.unescapedUrl+"</span></div>";

      contentDiv.appendChild(resultContainer);
	  strYTobj = '';
    }

    // Now add the paging links so the user can see more results.
    addPaginationLinks(gSearch);
  }
}

function OnLoad() {
//displayFloatingDiv('windowcontent','BurpChat',400,247,20,(screen.height/4));
  // Our gSearch instance.
  gSearch = new google.search.WebSearch();

  gSearch.setSearchCompleteCallback(this, searchComplete, null);
  gSearch.setResultSetSize(google.search.Search.LARGE_RESULTSET)

  searchterm=querySt('s');
  if (searchterm!=null && searchterm!="")
  {
	document.getElementById('s').value = searchterm;
  }else{
	searchterm=window.location.hash.replace(/#/gi, "");
	if (searchterm!=null && searchterm!="")
	{
		document.getElementById('s').value = searchterm;
	} else {	
		searchterm=getCookie('sterm');
		if (searchterm!=null && searchterm!="")
		{
			document.getElementById('s').value = searchterm;
		}
	}
  } 
  
  if(document.getElementById('s').value=='Search'){
      gSearch.execute("blocsoft.com pingrange.zip");
  }else{
      gSearch.execute(document.getElementById('s').value);
  }
     document.getElementById('s').focus();
	 // here is the new search code
	currenthash = '';
	searchtype = '1';
	timedSearch();
}
google.setOnLoadCallback(OnLoad);