<!--
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 lastdiv;
var mainVideo;
var sideVideo;
var thumVideo;
var wj = 400;
var hj = 325;
var readyChange = 1;
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 chagereadyState(){
	
	readyChange =1;
}
function clearList(ul){
	var list = document.getElementById(ul);
	while (list.firstChild) 
	 {
	    list.removeChild(list.firstChild);
	 }		
}

function changeMainID(div){
	if(readyChange == 1){
	if(sideVideo != div){ 
	mainVideo = div+'-showvideo';
sideVideo = div;
thumVideo = div+'-tubeple';
div = div+'Div';}
	
	}
	}
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 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 textmv ='<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>';
 var text ='<embed src="'+web+'" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="'+wj+'" height="'+hj+'"></embed>';
// 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(mainVideo).innerHTML =text;
}
function runopenvideo(web){
	//EP_stop('ep_player');

	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 textmv ='<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>';
  var text ='<embed src="'+web+'" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="'+wj+'" height="'+hj+'"></embed>';
document.getElementById(mainVideo).innerHTML =text;

}
function openyoutube(keyname){
	var keywordinput = document.getElementById(keyname).value;
	var keytubeple = keyname+'-tubeple';
	if(keywordinput){
		insertVideos(keyname,'search',keywordinput,'9',0);

		}
	
}
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);
}
var newfileurl = "http://keepvid.com/?url="+url;
	var idvdo = thumVideo+"-sidetube"+i;

if(i<3){
	document.getElementById(thumVideo).innerHTML = "";
       	li.innerHTML = '<div id="'+idvdo+'" style="float:left; display:block; border:#6699FF 2px solid; margin:7px 3px 0px 0px; width:228px; background:#FFFFFF url(cutting/lingpicture.jpg); padding:3px;" onmouseover="changetoyellow(this);" onmouseout="changetoblue(this);"><div style="float:left;"><a onclick="runopenvideo('+"'"+url+"'"+')" style="cursor:pointer;" title="'+entry.title.$t+'"><img src="'+thumb+'" id="youtubethumb" alt="'+entry.title.$t+'" ></a></div><div style="float:left; color:#000099; margin-left:3px; font-size:12px; width:129px; height:83px; overflow:hidden; ">'+entry.title.$t+'</div></div>';
}else{
	var donovantube = document.getElementById(thumVideo).innerHTML;
		donovantube += '<div id="'+idvdo+'" style="float:left; margin:3px 7px 3px 0; background:url(cutting/lingpicture.jpg) 10px 60px; padding:2px; border:#6699FF 2px solid;" onmouseover="changetoyellow(this);" onmouseout="changetoblue(this);" ><a onclick="runopenvideo('+"'"+url+"'"+')" style="cursor:pointer;" title="'+entry.title.$t+'" class="hoverbright"><img src="'+thumb+'" id="youtubethumb" alt="'+entry.title.$t+'"   ></a></div>';
		document.getElementById(thumVideo).innerHTML= donovantube;
}
		
		//keepmv(entry.title.$t,url);
		}
    }else{
        li.innerHTML = entry.content.$t;
    }

    ul.appendChild(li);
	}
  }else{
  	//div.innerHTML = 'No Results Found';
		document.getElementById(thumVideo).innerHTML= "";

  }

  div.appendChild(ul);
}
function changetoblue(id){
	var divtable = id.id;
	document.getElementById(divtable).style.borderColor = "#6699FF";
	}
	function changetoyellow(id){
	var divtable = id.id;
	document.getElementById(divtable).style.borderColor = "#33ccff";
	}
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){
mainVideo = div+'-showvideo';
sideVideo = div;
thumVideo = div+'-tubeple';
div = div+'Div';

  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+'');
  }
  if(typ == "recent"){
  	script.setAttribute('src', 'http://gdata.youtube.com/feeds/base/standardfeeds/most_recent?client=ytapi-youtube-browse&alt=rss&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);
}

//-->
