function youtubeLink(artist, title)
{
	   var youtubeSearchScriptURL  = 'http://gdata.youtube.com/feeds/api/videos?q=' + escape(artist) + " - " + escape(title) +'&alt=json-in-script&callback=showMyVideos&max-results=30&format=5&client=ytapi-ShazamEntertainm-ShazamWebsite-buak0i4g-2&key=AI39si6WqJb0Pbzi0lVyf3RMFS0DKg23xVBcBXDwnkzZGEMWP_JKsMQ47-6P8rV4BRkre3YNjhvXuSJ6dWeInyweJ2vmlOBJtw';
	   youtubeScript = document.createElement("script");
	   youtubeScript.setAttribute("type", "text/javascript");
	   youtubeScript.setAttribute("src",youtubeSearchScriptURL);
	   document.getElementsByTagName('head')[0].appendChild(youtubeScript);
}

    
var feed;
var entries;                                                                                                                                           


function showMyVideos(data) {
  feed = data.feed;
  entries = feed.entry || [];
  
  if (entries.length > 0)
  {
    $("youtubeLink").style.visibility = "visible";
  }
  

} 

var lightboxBackup;

function showYoutube2(url,title) {

var snippet = "<span onmouseover=\"this.style.cursor='pointer'\" title=\"close\"><a onclick=\"hideYoutube();\"><img src=\"/music/images/s/buttons/del_sm_white.png\" style=\"width:12px; height:12px;\" alt=\"close\"></a></span>&nbsp;&nbsp;<span onmouseover=\"this.style.cursor='pointer'\" title=\"back\"><a onclick=\"youtubeList();\"><img src=\"/music/images/s/buttons/reply_sm_white.png\" alt=\"Back to list\" style=\"width:12px; height:12px;\"></a></span><div style=\"height:390px;\"><object id=\"movie\" width=\"100%\" height=\"100%\"><param name=\"movie\" "
        + "value=\"" +url + "&autoplay=1\"></param><embed "
        + "src=\"" + url + "&autoplay=1\" name=\"movie\" type=\"application/x-shockwave-flash\" width=\"100%\" "
        + "height=\"100%\" bgcolor=\"#000000\"></embed></object></div>";
        $("lightbox").innerHTML = snippet;
}

function youtubeList()
{
  $("lightbox").innerHTML = lightboxBackup;
  $("lightbox").innerHTML += videoList;
}

function hideYoutube() {
                          $("lightbox").innerHTML = lightboxBackup;
                          
                          
	lb = new lightbox();
lb.initCallable('youtube');
lb.deactivate();


}

var videoList;

      function dequote(qstring)
      {
        charToRemove = '"';
        regExp = new RegExp("["+charToRemove+"]","g");
        return dequote2(qstring.replace(regExp,""));
       }

      function dequote2(qstring)
      {
        charToRemove = "'";
        regExp = new RegExp("["+charToRemove+"]","g");
        return qstring.replace(regExp,"&rsquo;");
       }


      function showPage(page)
      {
    
            videoList="<div id=\"main\"><h1><span class=\"black\">Videos found</span></h2><div><table width=\"100%\">";
  var html = ['<ul>'];
  var i=0;
  var entriesLength = 0;
  if (entries.length < ((page + 1) * 4))
  {
    entriesLength = entries.length - ((page + 0) * 4);
  }
  else
  {
    entriesLength = 4;
  }
  if (page != 0)
  {
    videoList += "<a onclick=\"showPage(" + (page-1) + ");\" onmouseover=\"this.style.cursor='pointer'\">&lt;Prev</a>";
  }
  if (entries.length > ((page + 1)* 4))
  {
    videoList +=  "&nbsp;&nbsp;<a onclick=\"showPage(" + (page+1) + ");\" onmouseover=\"this.style.cursor='pointer'\">Next&gt;</a>";
  }
  for (var i = (page * 4); i < (page * 4) + entriesLength; i++) {
    var entry = entries[i];
    var title = entry.title.$t;
		var playerUrl = entries[i].media$group.media$content[0].url;
		var thumbnailImage = entries[i].media$group.media$thumbnail[0].url;

	  videoList += "<tr><td colspan=\"3\"><div class=\"list_row_separator\"></div></td></tr><tr class=\"list_row\"><td><a onclick=\"showYoutube2('" + playerUrl + "','" + dequote(title) + "');\" onmouseover=\"this.style.cursor='pointer'\"><img src=\""+thumbnailImage+"\" style=\"width:75px;height:56px;\"></a></td><td colspan=\"2\"><p><a onclick=\"showYoutube2('" + playerUrl + "','" + dequote(title) + "');\" onmouseover=\"this.style.cursor='pointer'\">" + dequote(title) + "</a></p></td></tr>";  
  
  }
  videoList+="<tr><td colspan=\"3\"><div class=\"list_row_separator\"></div></table></div>";
  
  $("lightbox").innerHTML = lightboxBackup;
  $('lightbox').innerHTML += videoList;     
}


function showYoutube() {


lb = new lightbox();
lb.initCallable('youtube');
lb.activate();
$('lightbox').style.width = '537px';
$('lightbox').style.height = '420px';
lightboxBackup = $("lightbox").innerHTML;
             
//	showYoutube2(playerUrl,title);
showPage(0);
	

}

