<!--
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 getVideoId(url){

    var match = url.lastIndexOf('=');
    if (match) {
      id = url.substring(match+1);
      return id;
    }
}

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 videoOverlay(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 mousOverImage(name,id,nr){

	if(name)
		imname = name;
	//make border orange
	imname.style.border = 	'4px solid orange';

	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 = 	'4px solid #333333';
	if(timer)
		clearTimeout(timer)

}
function openvideo(web){
	var wj = "99%";
	var hj = 344;
	var oldweb = web;
		oldweb = "http://keepvid.com/?url="+web;

	web = web.replace("http://www.youtube.com/watch?v=","http://www.youtube.com/v/");
	web = web+"&hl=en&fs=1";
	//oldweb = oldweb.replace("http://www.youtube.com","http://www.kickyoutube.com");
//var text='<object width="'+wj+'" height="'+hj+'"><param name="movie" value="'+web+'&hl=en&fs=1"><'+"/"+'param><param name="allowFullScreen" value="true"><'+"/"+'param><param name="allowscriptaccess" value="always"><'+"/"+'param><embed src="'+web+'&hl=en&fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="'+wj+'" height="'+hj+'"><'+"/"+'embed><'+"/"+'object>';
// var text ='<object width="'+wj+'" height="'+hj+'"><param name="movie" value="'+web+'"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="'+web+'" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="'+wj+'" height="'+hj+'"></embed></object>';
 /*var text ='<embed src="'+web+'" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="'+wj+'" height="'+hj+'"></embed>';*/
 var text ='<embed src="'+web+'" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="'+wj+'" height="'+hj+'"></embed><div id="download_mv" class="downloadscreen" style="margin-top:10px;"><a href="'+oldweb+'" title="Download MV" target="_blank"><img src="http://www.kzshare.com/image/download.gif"/></a></div><p>Link Download MV  for IE6 : <a href="'+oldweb+'" title="Download MV" target="_blank">Download MV</a></p>';
// text = '<h3><a href="http://download.kzshare.com/download-video-from-youtube-t5722.html#5733" title="how to download mv" target="_blank">How to download MV</a></h3>';
document.getElementById("showvideo").innerHTML =text;
}
function runopenvideo(web){
	EP_stop('ep_player');
	var wj = "99%";
	var hj = 344;
	var oldweb = web;
	oldweb = "http://keepvid.com/?url="+web;

	web = web.replace("http://www.youtube.com/watch?v=","http://www.youtube.com/v/");
	//oldweb = oldweb.replace("http://www.youtube.com","http://www.kickyoutube.com");
	web = web+"&hl=en&fs=1&autoplay=1";

//var text='<object width="'+wj+'" height="'+hj+'"><param name="movie" value="'+web+'&hl=en&fs=1&autoplay=1"><'+"/"+'param><param name="allowFullScreen" value="true"><'+"/"+'param><param name="allowscriptaccess" value="always"><'+"/"+'param><embed src="'+web+'&hl=en&fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="'+wj+'" height="'+hj+'"><'+"/"+'embed><'+"/"+'object>';
// var text ='<object width="'+wj+'" height="'+hj+'"><param name="movie" value="'+web+'"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="'+web+'" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="'+wj+'" height="'+hj+'"></embed></object>';
 var text ='<embed src="'+web+'" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="'+wj+'" height="'+hj+'"></embed><div id="download_mv" class="downloadscreen" style="margin-top:10px;"><a href="'+oldweb+'" title="Download MV" target="_blank"><img src="http://www.kzshare.com/image/download.gif"/></a></div><h3><a href="http://www.kzshare.com/how-to-download-mv.php" title="how to download mv" target="_blank">How to download MV</a></h3>';
document.getElementById("showvideo").innerHTML =text;

}

function listVideos(json,divid) {
  div = document.getElementById(divid);
  div.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 li = document.createElement('li');

    li.setAttribute('id', 'youtubebox');
    if(cleanReturn == 1){
		if(inlineVideo >2){
			var ts = EP_getTrackInfo('ep_player');
				var id =ts.title;
				var oldid;
					id = id.replace(' ',"");
				id = id.replace('track',"");
						id = id.replace('Powered',"");
				id = id.replace('by',"");
				id = id.replace('Kzshare',"");
				id = id.replace('.mp3',"");
			if(oldid != id){
				if(id){
//sendmv(id);
				}
}
		}
		if(inlineVideo == 1){
    //	li.innerHTML = '<a href="javascript:videoOverlay(\''+getVideoId(url)+'\');"><img src="'+thumb+'" id="youtubethumb" alt="'+entry.title.$t+'"  onmouseout="mouseOutImage(this)" onmouseover="mousOverImage(this,\''+getVideoId(url)+'\',2)"></a>';
if(i==0){
openvideo(url);

}
		}else{
if(i==0){
openvideo(url);
}

       	li.innerHTML = '<a onclick="runopenvideo('+"'"+url+"'"+')" title="'+entry.title.$t+'"><img src="'+thumb+'" id="youtubethumb" alt="'+entry.title.$t+'" ></a>';
		
		//keepmv(entry.title.$t,url);
		}
    }else{
        li.innerHTML = entry.content.$t;
    }

    ul.appendChild(li);
	}
  }else{
  	//div.innerHTML = 'No Results Found';

  }

  div.appendChild(ul);
}
function keepmv(title,linkget){
	/*
	var ajax1=createAjax();   
     ajax1.onreadystatechange=function(){  
        if(ajax1.readyState==4 && ajax1.status==200){  
				//ajax1.responseText = ajax1.responseText.replace(/""/g,"");
		//alert(textshow);
            // document.getElementById('reporttext').innerHTML=ajax1.responseText; 
			 //alert(ajax1.responseText);
        }else{  
           return false;  
        }  
     }  
     ajax1.open("POST","script/update-mv.php",true);  
     ajax1.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");  
	 ajax1.send("update="+id);

*/
}
var l = 1;
var youtubeInit = new Array();
var youtubeDiv = new Array();
function insertVideos(div,typ,q,results,overlay){
  inlineVideo = overlay;
  l++;
  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['+l+']');

  if(typ == "user")
  	script.setAttribute('src', 'http://gdata.youtube.com/feeds/users/'+q+'/uploads?max-results='+results+'&alt=json-in-script&callback=youtubeInit['+l+']');

  if(typ == "playlist"){
  	script.setAttribute('src', 'http://gdata.youtube.com/feeds/playlists/'+q+'?max-results='+results+'&alt=json-in-script&callback=youtubeInit['+l+']');
  }
  if(typ == "hot"){
  	script.setAttribute('src', 'http://gdata.youtube.com/feeds/api/standardfeeds/recently_featured?alt=json-in-script&callback=youtubeInit['+l+']&start-index=1&max-results='+results+'');
  }
  youtubeDiv[l] = div;
  youtubeInit[l] = function(root) { listVideos(root,div);  };
  script.setAttribute('id', 'jsonScript');
  script.setAttribute('type', 'text/javascript');
  document.documentElement.firstChild.appendChild(script);
}

//-->