<!--
var win=null;
function NewWindow(mypage,myname,w,h,scroll,pos){
if(pos=="random"){LeftPosition=(screen.availWidth)?Math.floor(Math.random()*(screen.availWidth-w)):50;TopPosition=(screen.availHeight)?Math.floor(Math.random()*((screen.availHeight-h)-75)):50;}
if(pos=="center"){LeftPosition=(screen.availWidth)?(screen.availWidth-w)/2:50;TopPosition=(screen.availHeight)?(screen.availHeight-h)/2:50;}
if(pos=="default"){LeftPosition=50;TopPosition=50}
else if((pos!="center" && pos!="random" && pos!="default") || pos==null){LeftPosition=0;TopPosition=20}
settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
win=window.open(mypage,myname,settings);
if(win.focus){win.focus();}}
function CloseNewWin(){if(win!=null && win.open)win.close()}
window.onfocus=CloseNewWin;
function memberbox(){
	document.getElementById("memberbox").style.display = "block";
	return;
}
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 setCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return 1;
}


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 = "";
}
var autoplay = parseInt(readCookie("autoplay"));
var onofftext = "";
function action(){
	if(autoplay == "1"){
		onofftext = "Turn off auto play";
	} else {
		onofftext = "Turn on auto play";
	}
	
}

var clickThumb = 0;


function thumbClick(id){
	if(autoplay == 1){
		clickThumb = 0;
	} else {
		clickThumb = 1;
	}
	videoOverlay(id);
	
}

function setautoplay(){
	if(autoplay==1){
		autoplay = 0;
		videoOverlay(currentID);	
	}else {
		autoplay = 1;
		
	}
	setCookie("autoplay",autoplay,"1");
	action();
	document.getElementById("onoff").innerHTML = onofftext;


}

var zoomcurrent = 0;
var flashwidth = 250;
var flashheight = 217;
function zoom(){
if(zoomcurrent == 0){
document.getElementById("flashEmbed").width = 464;
document.getElementById("flashEmbed").height = 355;
flashwidth = 464;
flashheight = 355;
document.getElementById("azoom").innerHTML = "Zoom Out";
document.getElementById("videozoom").innerHTML = document.getElementById("youtubeDiv").innerHTML;
document.getElementById("videozoom").style.display = "block";
document.getElementById("youtubeDiv").style.display = "none";
zoomcurrent = 1;
}else{
document.getElementById("videozoom").style.display = "none";
document.getElementById("youtubeDiv").style.display = "block";
document.getElementById("youtubeDiv").innerHTML = document.getElementById("videozoom").innerHTML;
document.getElementById("flashEmbed").width = 250;
document.getElementById("flashEmbed").height = 217;
flashwidth = 250;
flashheight = 217;
document.getElementById("azoom").innerHTML = "Zoom In";
zoomcurrent = 0;
}
action();
return false;
}

function videoOverlay(id){
	action();
	var overlay;
if(zoomcurrent == 0){ 
overlay = document.getElementById('youtubeDiv');
}else{
overlay = document.getElementById('videozoom');
}
	overlay.innerHTML = '<table cellpadding="0" bgcolor="white" cellspacing="0"><tr><td><span style="float:left;font-size:8pt;">&nbsp;<a id="onoff" href="javascript:setautoplay();"></a></span><span style="float:right;font-size:8pt;"><a href="/ytd.php?id=' + id + '" target="_blank">Download video</a>&nbsp;</span><br /><embed id="flashEmbed" src="http://www.youtube.com/v/'+id+'&autoplay=' + (autoplay + clickThumb) + '&hl=en&fs=1" type="application/x-shockwave-flash"  allowfullscreen="true" width="' + flashwidth + '" height="' + flashheight + '"></embed><br><span style="float:left;font-size:8pt;">&nbsp;<a href="http://youtube.com/watch?v=' + id + '" target="_blank">View on Youtube</a></span><span style="float:right;font-size:8pt;"><a href="javascript:{};" onclick = "zoom()" id="azoom">Zoom IN</a>&nbsp;</span></td></tr></table>';
	document.getElementById("onoff").innerHTML = onofftext;
}

function mousOverImage(name,id,nr){

	if(name)
		imname = name;
	//make border orange
	imname.style.border = 	'2px 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 = 	'2px solid #333333';
	if(timer)
		clearTimeout(timer)

}

function getVideoId(url){

    var match_start = url.indexOf('=');
    var match_end = url.indexOf('&');
    if (match_start) {
      id = url.substring(match_start+1,match_end);
      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();
    }

}
var currentID = 0;
var searchfullrelated = "";
var totalVideo = 0;
function listVideos(json,divid) {

var listVideo ="<table width='425' cellpadding='0' cellspacing='2'>";

  var ul = document.createElement('ul');


  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;

		      }

		    }

	   	
totalVideo += 1;


   	var thumb = entry['media$group']['media$thumbnail'][1].url;


    if(cleanReturn == 1){



		if(inlineVideo == 1){

        				

			if(i == 0) { 

				currentID = getVideoId(url);
	

			}

			if(i==6 || i==12 || i==18 || i==24 || i==30 || i==36 || i==42 || i==48 || i==54){

				listVideo += "<tr>";

			}

			listVideo += '<td><a style="padding:0px" href="javascript:{};" onclick="thumbClick(\''+getVideoId(url)+'\')"><img style="border:2px solid #333333" height="54" src="'+thumb+'" id="youtubethumb" alt="'+entry.title.$t+'"  onmouseout="mouseOutImage(this)" onmouseover="mousOverImage(this,\''+getVideoId(url)+'\',2)"></a></td>';

			



		}else{



        //	listVideo += '<a href="'+url+'"><img src="'+thumb+'" id="youtubethumb" alt="'+entry.title.$t+'" onmouseout="mouseOutImage(this)" onmouseover="mousOverImage(this,\''+getVideoId(url)+'\',2)"></a>';

		}

    }else{

        //li.innerHTML = entry.content.$t;

		//

    }



    //ul.appendChild(li);

//

	}

  }else{

  	//divid.innerHTML = 'No Results Found';

		document.getElementById('youtubeDiv').style.display = "none";	

  }

	if(currentID != 0 && searchfullrelated != "" && searchfullrelated != "normal"){

		document.getElementById('youtubeDiv').style.display = "block";

		videoOverlay(currentID);
insertVideos('youtubeDivList','search',searchfullrelated,'24','1','');

	} else if (currentID == 0 && searchfullrelated != "" && searchfullrelated != "normal"){

insertVideos('youtubeDivList','search',searchfullrelated,'24','1','normal');

}
else if (searchfullrelated == "normal") {
document.getElementById('youtubeDiv').style.display = "block";

		videoOverlay(currentID);
document.getElementById("youtubeDivList").innerHTML = listVideo + "</table>";
}
else {

  document.getElementById("youtubeDivList").innerHTML = listVideo + "</table>";
}
if(currentID == 0){
document.getElementById('youtubeDiv').style.display = "none";	
}

}



function youtubeInit(root) {

  //this hacks the layer for mutiple json queries

  id = getId(root.feed.title.$t);

  listVideos(root, youtubediv[id]);



}



var divview = "";

function insertVideos(div,typ,q,results,overlay,searchrelated){

searchfullrelated = searchrelated;

  inlineVideo = overlay;

  youtubediv[q.toLowerCase()] = div;

  divview = 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);

}


//-->