/* --------------- STUDIO CONNECTIONS EXTERNAL JAVASCRIPT FILE -------------- */
/*                                                                            */
/*    Description: Display music playlist                                     */
/*         Client: Cloud Studios - info@cloudstudios.com                      */
/*        Website: www.cloudstudios.com                                       */
/*         Author: Colin Abrahams - colin@studioconnections.net.au            */
/*      Copyright: 2008 Colin Abrahams, Studio Connections                    */
/*       Location: Wyong, NSW, Australia                                      */
/*        Version: SC-5.8                                                     */
/*   Last Updated: 2008-11-25                                                 */


// Extract this page name from document title
// Standard SC document title format: websitename + " - " + pagetitle
PageTitl = document.title;
h = PageTitl.indexOf("-");
PageName = h > 0 ? PageTitl.substr(h + 2) : PageTitl;

// Extract artist name from page name
i = PageName.indexOf(":");
Artist = i > 0 ? PageName.substring(0, i) : PageName;

if (top.Upper && top.Upper.Loaded && top.Upper.JukeList) {
  if (Artist == "Music") {
    FoundSong = true;
  }
  else {

    // Check if songs exist for this page
    for (i = 0; i < top.Upper.JukeList.length; i++) {
      if (top.Upper.JukeList[i].Arti.indexOf(Artist) > -1) {
        FoundSong = true;
      }
    }
    if (window.FoundSong) {
      document.write('<h2>' + Artist + ' music samples</h2>\n');
    }
  }
  if (window.FoundSong) {
    document.write('<ul class="Norm">\n');
  }
  for (i = 0; i < top.Upper.JukeList.length; i++) {
    SongStat = "";
    if (top.Upper.JukeSong == i && top.Upper.JukeMode == "Play"
      && top.Upper.JukeStat == "Complete") {
      SongStat = '<b style="color: #00C000">- Now Playing</b>';
    }
    else if (top.Upper.JukeList[i].Stat == "Played") {
      SongStat = ' <b style="color: #F04900">(Played)</b>';
    }
    if (Artist == "Music") {
      document.write('<li>'
        + '<a href="javascript:void(0)" '
        + 'title="Listen to this song" '
        + 'onclick="this.blur ? this.blur() : null; '
        + 'window.JukePick ? JukePick(\''
        + top.Upper.JukeList[i].Addr
        + '\') : null; return false">'
        + top.Upper.JukeList[i].Arti
        + ' - ' + top.Upper.JukeList[i].Song
        + '</a>&nbsp;' + SongStat + '</li>\n');
    }
    else if (top.Upper.JukeList[i].Arti.indexOf(Artist) > -1) {
      document.write('<li>'
        + '<a href="javascript:void(0)" '
        + 'title="Listen to this song" '
        + 'onclick="this.blur ? this.blur() : null; '
        + 'window.JukePick ? JukePick(\''
        + top.Upper.JukeList[i].Addr
        + '\') : null; return false">'
        + top.Upper.JukeList[i].Arti
        + ' - ' + top.Upper.JukeList[i].Song
        + '</a></li>\n');
    }
  }
  if (window.FoundSong) {
    document.write('</ul>\n');
  }
}
else if (Artist == "Music") {
  document.write('<p>This page must be viewed from within the full site '
               + 'to see the playlist and play music.</p>'
               + '<p align="center"><a '
               + 'href="../../index.html" target="_top" '
               + 'title="Go to the full Cloud Studios website with frames" '
               + 'onclick="this.blur ? this.blur() : null; return true">'
               + 'Go to full site</a></p>');
}
