 var searcher
  //<![CDATA[
    google.load('search', '1.0');

function OnLoad() {


new RawSearchControl();
 

}



function RawSearchControl() {

      this.searcherform = document.getElementById("searcher");
      this.results = document.getElementById("results");
      this.cursor = document.getElementById("cursor");  
      //this.searchform = document.getElementById("searchform1");
      this.activeSearcher = "perdata";
      this.searchers = new Array();

      
      searcher = new google.search.VideoSearch();
      searcher.setNoHtmlGeneration();
    
      searcher.setResultSetSize(google.search.Search.LARGE_RESULTSET);
      searcher.setSearchCompleteCallback(this,
                                         RawSearchControl.prototype.searchComplete,
                                         [searcher]
                                         );
					
        searcher.execute(primaricerca); 
this.searchers["perdata"] = searcher;

      this.searchForm = new google.search.SearchForm(true, this.searchform);
      //this.searchForm.Input = "query";
      
      this.searchForm.setOnSubmitCallback(this,
                                          RawSearchControl.prototype.onSubmit);
      this.searchForm.setOnClearCallback(this,
                                          RawSearchControl.prototype.onClear);
 
}





RawSearchControl.prototype.onClear = function(form) {
      this.clearResults();
}






RawSearchControl.prototype.searchComplete = function(searcher) {



function submitToHighslide(formvideo) {

    	// identify the submit button to start the animation from
    	var anchor;
    	for (var i = 0; i < formvideo.elements.length; i++) {
    		if (formvideo.elements[i].type == 'submit') {
				anchor = form.elements[i];
				break;
			}
		}

		// open an expander and submit our form when the iframe is ready
		hs.overrides.push('onAfterExpand');
		hs.htmlExpand(anchor, {
			objectType: 'iframe',
			src: 'about:blank',
			width: 800,
			height: 600,
			onAfterExpand: function(expander) {
				formvideo.target = expander.iframe.name;
				formvideo.submit();
			}
		});

		// return false to delay the sumbit until the iframe is ready
		return false;
	}





      // always clear old from the page
      this.clearResults();
      // if the searcher has results then process them
      if (searcher.results && searcher.results.length > 0) {
        // print the result titles
var div = createDiv("", "header");
           this.results.appendChild(div);
           for (var i=0; i<searcher.results.length; i++) {
var result = searcher.results[i];
var titleLine = '<div style="float:right; margin-right:10px; width:101px;"><a href="' + result.playUrl; 



	   titleLine += '&rel=0&fs=1&showsearch=0&ap=%2526fmt%3D18" onclick="return hs.htmlExpand(this, { objectType: \'swf\', objectWidth: 630, objectHeight: 480, width: 630  } )" class="highslide"><img src="' + result.tbUrl + '" style="padding:10px; width:100px; height:100px; "><\/a><div class="highslide-caption" style="display:none;">' + result.title + '</div><\/div> ';
           titleLine += '<div style="padding-top:10px; width:400px;"><a href="' + result.playUrl; 
	   titleLine += '&rel=0&fs=1&showsearch=0&ap=%2526fmt%3D18" onclick="return hs.htmlExpand(this, { objectType: \'swf\', objectWidth: 630, objectHeight: 480, width: 630  } )" class="highslide">';
	   titleLine += '<b>' + result.title + '<\/b><\/a><br />';
   	   titleLine += result.content + '<br />';
	   titleLine += result.published + '<br />';
	   titleLine += '<a href="http://' + result.publisher + '" style="color:green;">' + result.publisher + '<\/a><br />';
	   
	   var str = result.playUrl;
	   
          var re = new RegExp("(http://www.youtube.com/v/)+([a-zA-Z0-9-_]*)+([&fs=1&hl=it&source=uds&autoplay=1]*)", "");
          var myArray = str.replace(re,"$2" );
	  
	  var goog = myArray.match("docid=");
	  
	  var rees = new RegExp("docid=([a-zA-Z0-9-_]*)", "");  
	  var gvurl = str.match(rees);
	  if ( gvurl != null) {
             for ( d = 0; d < 1; d++ ) {
             // results = "gvurl[" + i + "] = " + gvurl[i];
	     var gu = gvurl[0];
          titleLine += 'http://video.google.com/videoplay?'+ gvurl[0];
             }
            }
	  
	  //titleLine += 'http://video.google.com/videoplay?'+ gvurl;
	   
	   
	 //http://video.google.com/videoplay?docid=4023455494152702797  
	 
	//  titleLine += '<a href="/wp/wp-content/plugins/search-video/highslide/2.php?q=http://www.youtube.com/watch?v='+ myArray + '" onclick="return hs.htmlExpand(this, { objectType: \'iframe\', objectWidth: 650, objectHeight: 200, width: 650  } )">click here.</a> ';
	   
	   
	// titleLine += '<form id="formvideo" action="/wp/wp-content/plugins/search-video/highslide/2.php" method="get" onsubmit="return submitToHighslide(this)"><input type="text" name="q" value="http://www.youtube.com/watch?v='+ myArray + '" /><input type="submit" value="OK" /></form>';

	 
	   
	   
	   
	   titleLine += '<div class="highslide-caption" style="display:none;">' + result.title + '</div>';
           titleLine += '<\/div><hr style="clear:both">';
          
          if (result.html) {
            titleLine += " ** html is present **";
          }
          div = createDiv(titleLine);          
          this.results.appendChild(div);
        }

        

        // now, see if we have a cursor, and if so, create the 
        // cursor control
        if (searcher.cursor) {
          var cursorNode = createDiv(null, "gsc-cursor");
          for (var i=0; i<searcher.cursor.pages.length; i++) {
            var className = "gsc-cursor-page";
            if (i == searcher.cursor.currentPageIndex) {
              className = className + " gsc-cursor-current-page";
            }
            var pageNode = createDiv(searcher.cursor.pages[i].label, className);
            pageNode.onclick = methodClosure(this, this.gotoPage, 
                                             [searcher, i]); 
            cursorNode.appendChild(pageNode);
          }
          this.cursor.appendChild(cursorNode);
          //var more = createLink(searcher.cursor.moreResultsUrl,
          //                      GSearch.strings["more-results"] + "&nbsp;&raquo;",
          //                      GSearch.LINK_TARGET_SELF,
          //                      "gsc-trailing-more-results");
          //this.cursor.appendChild(more);
        }
	
      }
    }
    
    RawSearchControl.prototype.searchg = function(form){

        searcher.execute(form)

        }
      RawSearchControl.prototype.searchdata = function(form){
//searcher.setResultOrder(google.search.Search.ORDER_BY_DATE);
searcher.setResultOrder(google.search.Search.ORDER_BY_RELEVANCE);
        searcher.execute(form)
	

        }
	  RawSearchControl.prototype.searchrilevanza = function(form){
searcher.setResultOrder(google.search.Search.ORDER_BY_DATE);
//searcher.setResultOrder(google.search.Search.ORDER_BY_RELEVANCE);
        searcher.execute(form)
	

        }
    
    
    RawSearchControl.prototype.gotoPage = function(searcher, page) {
      searcher.gotoPage(page);
}

RawSearchControl.prototype.clearResults = function() {
      removeChildren(this.results);
      removeChildren(this.cursor);
}

function removeChildren(parent) {
      while (parent.firstChild) {
        parent.removeChild(parent.firstChild);
      }
}

function createDiv(opt_text, opt_className) {
      var el = document.createElement("div");
      if (opt_text) {
        el.innerHTML = opt_text;
      }
      if (opt_className) { el.className = opt_className; }
      return el;
}

function methodClosure(object, method, opt_argArray) {
      return function() {
        return method.apply(object, opt_argArray);
      }
}

function createLink(href, opt_text, opt_target, opt_className, opt_divwrap) {
      var el = document.createElement("a");
      el.href = href;
      if (opt_text) {
        el.innerHTML = opt_text;
      }
      if (opt_className) {
        el.className = opt_className;
      }
      if (opt_target) {
        el.target = opt_target;
      }
      if (opt_divwrap) {
        var div = this.createDiv(null, opt_className);
        div.appendChild(el);
        el = div;
      }
      return el;
}






google.setOnLoadCallback(OnLoad, true);



    //]]>