function addslashes(str) {
str=str.replace(/\'/g,'`');
str=str.replace(/\"/g,'``');
return str;
}

<!--
var cleanReturn = 1; //do you want a full youtube return, or just an image list
var inlineVideo = 1; //do you want to redirect to youtube, or play inlinevideo

var timer;
var i =0;
var youtubediv = new Array();

function clearList(ul){
	var list = document.getElementById(ul);
	while (list.firstChild) 
	 {
	    list.removeChild(list.firstChild);
	 }		
}

function hideOverlay(){

	var overlay = document.getElementById('youtubeoverlay');
	overlay.style.display = 'none';
	overlay.innerHTML = "";
}

function videoOverlaya(id){
	var objBody = document.getElementsByTagName("body").item(0);
	if(objBody){
    var video = document.createElement('div');
	video.setAttribute('id', 'youtubeoverlay');
	video.innerHTML = '<div id="youtubecontent"><a href="javascript:hideOverlay()" id="close">Close</a><br /><object width="510" height="420"><param name="movie" value="http://www.youtube.com/v/'+id+'"></param><param name="autoplay" value="1"><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/'+id+'&autoplay=1" type="application/x-shockwave-flash" wmode="transparent" width="510" height="420"></embed></object></div>';
	objBody.insertBefore(video, objBody.firstChild);
	}else{
		alert('no body element. please add');
	}

}
function videoOverlay(id,titlea){
document.getElementById('thevideo').innerHTML = '<b><a href="http://keepvid.com/?url=youtube.com%2Fwatch%3Fv%3D'+id+'" target=_blank>></a> '+titlea+' <a href=javascript:void(0) onclick="document.getElementById(\'thevideo\').innerHTML=\'\'" title="Close Screen">[x]</a></b><div style="margin-left:50px;"><object width="510" height="380"><param name="movie" value="http://www.youtube.com/v/'+id+'"></param><param name="autoplay" value="1"><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/'+id+'&color1=0x4E97BE&color2=2B5B75&autoplay=1" type="application/x-shockwave-flash" wmode="transparent" width="510" height="380"></embed></object></div>';
}

function mousOverImage(name,id,nr){

	if(name)
		imname = name;
	//make border orange
	imname.style.border = 	'3px solid #4AA5FF';

	imname.src = "http://img.youtube.com/vi/"+id+"/"+nr+".jpg";
	nr++;
	if(nr > 3)
		nr = 1;
	timer =  setTimeout("mousOverImage(false,'"+id+"',"+nr+");",1000);

}


function mouseOutImage(name){

	if(name)
		imname = name;
	//make border back to greyish
	imname.style.border = 	'1px solid #aaaaaa';
	if(timer)
		clearTimeout(timer)

}

function getVideoId(url){

    var match = url.lastIndexOf('=');
    if (match) {
      id = url.substring(match+1);
      return id;
    }
}

function getId(string){

    var match = string.lastIndexOf("'s Videos");
    if (match != -1) {
      id = string.substring(0,match);
      return id.toLowerCase();
    }

    var match = string.lastIndexOf("query");
    if (match != -1) {
      id = string.substring(match+7);
      return id.toLowerCase();
    }

}
function listVideos(json,divid) {
  divid.innerHTML = '';
  var ul = document.createElement('ul');
  ul.setAttribute('id', 'youtubelist');
  if(json.feed.entry){
	  for (var i = 0; i < json.feed.entry.length; i++) {
	    var entry = json.feed.entry[i];
	
	    for (var k = 0; k < entry.link.length; k++) {
	      if (entry.link[k].rel == 'alternate') {
	        url = entry.link[k].href;
	        break;
	      }
	    }
   	

   	var thumb = entry['media$group']['media$thumbnail'][1].url;
	var thu_id=thumb.substring(22,33);


    var li = document.createElement('li');

    li.setAttribute('id', 'youtubebox');
    if(cleanReturn == 1){
		if(inlineVideo == 1){
        	li.innerHTML = '<div style="border-bottom:2px solid #242424; padding-top:3px; padding-bottom:3px"><font size=1><a href="javascript:videoOverlay(\''+thu_id+'\',\''+addslashes(entry.title.$t)+'\');" class=la><img src="'+thumb+'" id="youtubethumb" alt="'+entry.title.$t+'"  onmouseout="clearTimeout(timer);mouseOutImage(this)" onmouseover="mousOverImage(this,\''+thu_id+'\',2)"><br>'+entry.title.$t+'</a></div>';

		}else{

        	li.innerHTML = '<a href="'+url+'"><img src="'+thumb+'" id="youtubethumb" alt="'+entry.title.$t+'" onmouseout="mouseOutImage(this)" onmouseover="mousOverImage(this,\''+thu_id+'\',2)"></a>';
		}
    }else{
        li.innerHTML = entry.content.$t;
    }

    ul.appendChild(li);
	}
  }else{
  	divid.innerHTML = 'No Results Found';

  }

  document.getElementById(divid).appendChild(ul);
}

function youtubeInit(root) {
  //this hacks the layer for mutiple json queries
  id = getId(root.feed.title.$t);
  listVideos(root, youtubediv[id]);

}


function insertVideos(div,typ,q,results,overlay){
  inlineVideo = overlay;
  youtubediv[q.toLowerCase()] = div;

  var script = document.createElement('script');
  if(typ == "search")
  	script.setAttribute('src', 'http://gdata.youtube.com/feeds/videos?vq='+q+'&max-results='+results+'&alt=json-in-script&callback=youtubeInit');

  if(typ == "user")
  	script.setAttribute('src', 'http://gdata.youtube.com/feeds/users/'+q+'/uploads?max-results='+results+'&alt=json-in-script&callback=youtubeInit');

  if(typ == "playlist"){
	//doesn't function
	alert('oops.. working on it');
  	script.setAttribute('src', 'http://gdata.youtube.com/feeds/playlists/'+q+'?max-results='+results+'&alt=json-in-script&callback=youtubeInit');
  }

  script.setAttribute('id', 'jsonScript');
  script.setAttribute('type', 'text/javascript');
  document.documentElement.firstChild.appendChild(script);
}

//-->

/*
<div id="youtubeDiv"> </div>
<script>
insertVideos('youtubeDiv','search','$searchterm','$resultsnumber','$useoverlay');
</script>
*/

