$(function() {
 	var feed = $('#feed').text();
});

function showVideo(videoName) {
    $.ajax({
        type: "GET",
        url: "http://www.music.northwestern.edu/media-showcase/media-feed.xml",
        dataType: "xml",
        success: function(xml) {
	    var video = $(xml).find('asset[id="'+videoName+'"]');
            var frame = '';
            var title = video.find("title").text();
            var source = video.find("source").text();
            var desc = video.find("description").text();
            var width = video.find("width").text();
            var height = video.find("height").text();
            var youtube = video.find("youtube").text();
            if(youtube != '') {
            	frame = '<div style="width: '+width+'px; height: '+height+'px;"><object width="640" height="385"><param name="movie" value="'+youtube+'"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="'+youtube+'" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="385"></embed></object></div>';
            } else {
            	frame = '<iframe scrolling="no" src="'+ source +'" height="'+ height +'" width="'+width+'" style="border:none;">';
            }
	    $.modal('<div style="width:750px;"><div class="close-vid"><a class="simplemodal-close">Close</a></div><div class="playback-title">'+title+'</div>'+frame+'</div>', {
                closeHTML: "",
                onOpen: function(dialog) {
                    dialog.overlay.fadeIn('slow', function() {
                        dialog.data.hide();
                        dialog.container.fadeIn('slow', function() {
                            dialog.data.fadeIn('fast');
                        });
                    });
                },
                opacity:60,
                overlayCss:{ backgroundColor:"#000"},
                containerCss:{
                    backgroundColor: "#000",
                    borderColor: "#000",
                    padding: "10px"
                },
                overlayClose:false,
                onClose: function(dialog) {
                    dialog.data.fadeOut(400, function() {
                        dialog.container.hide(400, function() {
                            dialog.overlay.fadeOut(400, function() {
                                $.modal.close();
                            });
                        });
                    });
                }
            });
        }
	});
}

function featureVideo(videoName) {
	$.ajax({
	type: "GET",
	url: "media-feed.xml",
	dataType: "xml",
	success: function(xml) {
		var video = $(xml).find('asset[id="'+videoName+'"]');
           	var title = video.find("title").text();
           	var source = video.find("source").text();
            	var desc = video.find("description").text();
            	var width = video.find("width").text();
            	var height = video.find("height").text();
        	$('#video-title').empty().append(title);
        	$('#video-desc').empty().append(desc);
        	$('#video-window').attr('src', source);
        	$('#video-window').attr('width', width);
        	$('#video-window').attr('height', height);
            $('#vid-q').find('td.active-vid').removeClass('active-vid');
            $('#'+videoName).addClass('active-vid');
	}
	});
}
