// JavaScript Document
// Load the xml file using ajax 
/*$.ajax({
    type: "GET",
    url: "data://playlist.xml",
    dataType: "xml",
    success: function (xml) {

        // Parse the xml file and get data
        var xmlDoc = $.parseXML(xml),
            $playList = $(xmlDoc);
        $xml.find('category[name="My t"] logo').each(function () {
            $("#news-container").append($(this).text() + "<br />");
        });
    }
});*/

/*var dataXml = "<rss version='2.0'><channel><title>RSS Title</title></channel></rss>";
playlist = $.parseXML( dataXml );
$dataXml = $(playlist);
$dataXml.find('video').each(function(index, element) {
    console.log(element);
});
$title = $dataXml.find("title");
$(".playlist_ul>li").each(function(index, element) {
   element.append($title.text());
});*/
//console.log($(".playlist_ul>li:first-child"));
//$("li:nth-child(2)").append($title.text());
//console.log($title.text());

/*
 * Este codigo permite tomar la primera fuente
 * de video desde el listado y reproducir automaticamente
 * el primer video
*/
var videoSrc = $(".playlist_ul>li:nth-child(2)")
var videoList = document.getElementById("videoList");

function videoActive (obj) {
	//console.log($(obj).data('video'));
	if($(obj).data('video') != null) {
		videoList.src = $(obj).data('video');
		videoList.play();
	}
	else
		videoList.pause();
	return true;
}


console.log(videoSrc);
/*if(videoSrc != null ) {
	$(videoSrc).attr('style','background-color: #535353');
	videoActive(videoSrc);
}*/

$(".playlist_ul>li").click( function() {
	$(".playlist_ul>li").each(function(index, element) {
        $(element).removeAttr('style');
    });
	if($(this).attr('style') == undefined) {
		$(this).attr('style','background-color: #535353');
		videoActive($(this));
	}
});
