// written by Stuart Ross, 29 July 2010
$(document).ready(function(){
$('div.view-id-media_by_topic ul').each(function(i,n){
//gets the list of videos
var videos = $(n).children('li');
//hides all but the first
videos.not(':first').hide();
//iterate through the titles and create a ul html element
var titles = '
Video Selection
';
$(n).find('div.views-field-title span.field-content').each(function(o,l){
//adds the index of each video to the href for easier traversal later
titles += '- '+$(l).text()+'
';
});
titles += '
';
//inserts the titles of the videos on the page and adds a click handler to each title
$(titles).insertBefore($(n).parents('div.view-id-media_by_topic')).children('li').click(function(){
//position of the video in the list
var index = $(this).children('a').attr('href');
//get/set video element
var vid = $(videos.get(index[1]));
//only perform action when the video is not visible
if(!vid.is(':visible')){
videos.hide();
vid.show();
}
return false;
});
});
});