var id_video = 0;

var youtube = function()
{
}

youtube.prototype.list = function(data)
{
	var feed = data.feed;
	var entries = feed.entry || [];
	
	var ul = '<ul>';
	ul += '<li id="titulo">'+entries[0].title.$t.substr(0, 45)+'</li>';
	for (var i = 0; i < entries.length; i++) 
	{
		ul += '<li id="'+i+'">'+entries[i].title.$t.substr(0, 45)+'</li>';
	}
	ul += '</ul>';
	
	$(document).ready
	(
		function()
		{
			$('#lista_reproducao').html(ul);
			
			$('#lista_reproducao').hover
			(
				function()
				{
					$('#lista_reproducao').animate({height:209});
				}
				,
				function()
				{
					$('#lista_reproducao').animate({height:29});
				}
			);
			
			$('#lista_reproducao ul').find('li').hover
			(
				function()
				{
				}
				,
				function()
				{
				}
			).click
			(
				function()
				{
					id_video = $(this).attr('id');
					$('#thumb_tv').animate
					(
						{
							opacity : 0
						}
						,500,
						function()
						{
							$('#thumb_tv').show();
							$('object').hide();		
							$('#titulo').html(entries[id_video].title.$t.substr(0, 20));
							$('#thumb_tv').attr('src','');		
							$('#thumb_tv').attr('src',entries[id_video].media$group.media$thumbnail[0].url);
							$('#thumb_tv').animate({opacity:1});
						}
					);
				}
			);
			
			$('.play').hover
			(
				function()
				{
					$(this).animate({opacity:1});
				}
				,
				function()
				{
					$(this).animate({opacity:0});
				}
			).click
			(
				function()
				{
					$('#thumb_tv').animate
					  (
						{
							opacity : 0
						}
						,500,
						function()
						{					 
							$('object').show();	
							$('#thumb_tv').hide();
							swfobject.embedSWF(entries[id_video].media$group.media$content[0].url + '&rel=1&border=0&fs=1&autoplay=1', 'tv', '316', '212', '9.0.0', false, false, {allowfullscreen: 'true'});
						}
					);
				}
			);		
				
			$('#thumb_tv').attr('src',entries[0].media$group.media$thumbnail[0].url);
			$('#thumb_tv').animate({opacity:1});
		}
	);
}

youtube.prototype.canal = function(data)
{
	var feed = data.feed;
	var entries = feed.entry || [];
	
	/*
	var entry = entries[i];
	var title = entry.title.$t.substr(0, 20);
	var thumbnail = entries[i].media$group.media$thumbnail[0].url;
	var playerUrl = entries[i].media$group.media$content[0].url;
	*/
	
	var titulo = '';
	var ul = '<ul>';
	for (var i = 0; i < entries.length; i++) 
	{
		//titulo = entries[i].title.$t;
		if(entries[i].title.$t.indexOf('.')!=-1)
		{
		 	titulo = entries[i].title.$t.substr(0,(entries[i].title.$t.length)-4);
		}
		else
		{
			titulo = entries[i].title.$t;
		}
		
		ul += '<li id="'+i+'">'
		/*ul += '<div class="thumb_tempo">'+entries[i].media$group.media$content[0].timer+'</div>';*/
		ul += '<img src="'+entries[i].media$group.media$thumbnail[2].url+'" />';
		ul += '<strong>'+titulo+'</strong>';
		ul += '</li>';
	}
	ul += '</ul>';
	
	$(document).ready
	(
		function()
		{
			$('#playlista').html(ul);
			
			swfobject.embedSWF(entries[id_video].media$group.media$content[0].url + '&rel=1&border=0&fs=1&autoplay=0', 'tv', '780', '400', '9.0.0', false, false, {allowfullscreen: 'true'});
			
			$('#playlista ul li').click
			(
				function()
				{
					id_video = $(this).attr('id');
					swfobject.embedSWF(entries[id_video].media$group.media$content[0].url + '&rel=1&border=0&fs=1&autoplay=1', 'tv', '780', '400', '9.0.0', false, false, {allowfullscreen: 'true'});
					window.scroll(0,150);
				}
			);
			
			/*$('.play').hover
			(
				function()
				{
					$(this).animate({opacity:1});
				}
				,
				function()
				{
					$(this).animate({opacity:0});
				}
			).click
			(
				function()
				{
					$('#thumb_tv').animate
					  (
						{
							opacity : 0
						}
						,500,
						function()
						{					 
							$('object').show();	
							$('#thumb_tv').hide();
							swfobject.embedSWF(entries[id_video].media$group.media$content[0].url + '&rel=1&border=0&fs=1&autoplay=1', 'tv', '316', '212', '9.0.0', false, false, {allowfullscreen: 'true'});
						}
					);
				}
			);		
				
			$('#thumb_tv').attr('src',entries[0].media$group.media$thumbnail[0].url);
			$('#thumb_tv').animate({opacity:1});*/
		}
	);
}
