// JavaScript Document
	_gadgetID=37;  
	if(typeof(google) != undefined)
		google.load("feeds", "1");
 	function xmlError(e) {
		setErrorMsg();                
	}
	
	
	function setErrorMsg(){
		
		//alert("Error fetching content");
	}
	
	//parse the rss
	function parseRSS(response) {
	
		if (response == null) {
			setErrorMsg();
			return;
        }
        if (response.error) {
			setErrorMsg();
			return;
		}
		
		response = response.xmlDocument;
        var itemList = response.getElementsByTagName("item");
        for (var i = 0; i < itemList.length && i< 9 ; i++) { 
             
             var item = itemList.item(i);
             var itemDetails = item.childNodes;
             var thumbElm = document.getElementById("thumbnail_"+i);
             
             for (var j=0;j < itemDetails.length; j++) {
				var innerItem = itemDetails.item(j);
				
				if (innerItem.nodeName == "title") {
					thumbElm.cliptitle = innerItem.firstChild.nodeValue;
					thumbElm.title = innerItem.firstChild.nodeValue;
				}
				else if (innerItem.nodeName == "media:thumbnail") {
					thumbElm.src = innerItem.getAttribute("url");
				}
				else if (innerItem.nodeName == "enclosure") {
					thumbElm.clipurl = innerItem.getAttribute("url");
				}
             }
         }        
	}
	
	function playClip(obj,clipWidth, clipHeight) {
	
		var curl = (obj.clipurl+"&autoplay=1");
		curl = curl.replace(".swf","");

		document.getElementById("clipTitle").innerHTML = obj.cliptitle;
		document.getElementById("clipTD").innerHTML = '<div><object width="' + clipWidth + '" height="'+ clipHeight +'">'+
									'<param name="movie" value="'+curl+'"></param>'+
									'<param name="wmode" value="transparent"></param>'+
									'<embed src="'+curl+'" type="application/x-shockwave-flash" wmode="transparent" width="'+ clipWidth +'" height="'+ clipHeight +'"></embed>'+
									'</object></div>';
		document.getElementById("clipDiv").style.display = "block";
		document.getElementById("thumbnailDiv").style.display = "none";
		hideMenu();
		hideTagSeachBox();
	}
	
	function displayThumbnailView() {
	
		hideMenu();
		hideTagSeachBox();
		document.getElementById("clipTD").innerHTML = "";
		document.getElementById("clipDiv").style.display = "none";
		document.getElementById("thumbnailDiv").style.display = "block";
	}
	
	function hideMenu() {
	
		var menuTableEl = document.getElementById("RSSMenuTable");
		//menuTableEl.style.top = "-400px";
		menuTableEl.style.visibility = "hidden";
					
	}
	
	function openMenu(obj) {
	
		hideTagSeachBox();
		
		var menuTableEl = document.getElementById("RSSMenuTable");
		if (menuTableEl.style.visibility != "hidden") {
			hideMenu();
		} else {
			
			/*var ps = lp_getObjectPos(obj);
			menuTableEl.style.top = ps.top + 15 + "px";
			menuTableEl.style.left = ps.left - 78 + "px";*/
			menuTableEl.style.visibility = "visible";
			
		}
	}
	
	function hideTagSeachBox() {
		
		var tagSearchBoxEl = document.getElementById("tagSearchBoxTable");
		//tagSearchBoxEl.style.top = "-400px";
		tagSearchBoxEl.style.visibility = "hidden";
		
	}
	
	function mouseOverMenu(wh) {
	
		wh.className = "style4";
	}
	
	function mouseOutOfMenu(wh) {
	
		wh.className = "style3";
	}
	
	
	function openTagSeachBox() {
		
		hideMenu();
		var tagSearchBoxEl = document.getElementById("tagSearchBoxTable");
		/*var ps = lp_getObjectPos(document.getElementById("thumbnailDiv"));
		tagSearchBoxEl.style.top = ps.top + 80 + "px";
		tagSearchBoxEl.style.left = ps.left + 60 + "px";*/
		tagSearchBoxEl.style.visibility = "visible";
		document.getElementById("queryStringIn").select();
		return false;
	}
	
	function changeFeedTo(feedname, feedurl) {
	
		//search by tag name
		hideTagSeachBox();
		if (feedname == null || feedname.length < 1) {
			feedname = document.getElementById("queryStringIn").value;
			if (feedname.length < 1) {
				alert("Please enter a single tag word.");
				return;
			}
			feedurl = "http://www.youtube.com/rss/tag/"+feedname+".rss";
		}
		
		//update the screen
		document.getElementById("RSSMenuTable").style.visibility = "hidden";
		document.getElementById("rssCategoryTitle").innerHTML = feedname;
		for (var i = 0; i < 9 ; i++) {
             document.getElementById("thumbnail_"+i).src = "extlib/youtubeRSS/transparent.gif";
        }
        
        var feed = new google.feeds.Feed(feedurl);
		feed.setResultFormat(google.feeds.Feed.XML_FORMAT);
		feed.setNumEntries(9);
		feed.load(parseRSS);
		return false;
	
	}
	
	function lp_getObjectPos(a){
		
		var b={},c=a;
		b.left=c.offsetLeft;
		b.top=c.offsetTop;
		while(c.offsetParent!=null){
			var d=c.offsetParent;
			b.left+=d.offsetLeft;
			b.top+=d.offsetTop;
			c=d;
		}
		return b
	}
	
	
	function parseCurrentFeed(){
		
		var url = "http://youtube.com/rss/global/recently_added.rss";
		var name = "Recently Added";
		changeFeedTo(name, url);
		
	}

