var album    = 'story';
var counter  = 1;
var playItem = 0;

var track_max   = 10;
var myimages    = new Array();
var titles      = new Array();
var myPlayList  = new Array();
var pageHeaders = new Array('music', 'shows', 'news', 'bio', 'contact'); 

titles['ballad'] = new Array( 'The Ballad of Minton Quigley', 'Better Place', 'The Well', 'Opti-Missed/Belle View Kampfire Song');
titles['hotel'] = new Array( 'Adelaide', 'Nightingale Floors', 'Botanique / Canberra Gravel');
titles['story'] = new Array( 'Gold Fever', 'Here Comes Dragonfish', 'Scopolamine');
titles['aardvark'] = new Array( 'Dear Bourg', 'Simon Says', 'Naashar');
titles['glubglub'] = new Array( 'Seashell On Fire', 'Let The Flower Grow', 'Big M And Danz');
titles['slow'] = new Array( 'Beautiful Dralo', 'Slow', 'Planet Caravan');
titles['suzy'] = new Array( 'Suzy Lattimore', 'Fade', 'Mr. Venus');

function loadPlayList(album) {
  counter = 1;
  myPlayList = [];

  for (x in titles) {
      $("#" + x + "_active").css('display', 'none');
  }

  for (x in titles[album]) {
      myPlayList.push({ name: titles[album][x], mp3: "audio/" + album + "/" + counter + ".mp3" });
      counter++;
  }

  $("#" + album + "_active").css('display', 'block');
                
  displayPlayList();
}

function displayPlayList() {
    $("#playlist_list ul li").remove();
    for (i=0; i < myPlayList.length; i++) {

        $("#playlist_list ul").append("<li id='playlist_item_"+i+"'>"+ myPlayList[i].name + "<img src='imgs/album_active.jpg' style='padding-left: 5px; padding-bottom: 1px; display: none;' id='" + i + "_active' alt='' /></li>");

        $("#playlist_item_"+i).data( "index", i ).hover(
            function() {
                //if (playItem != $(this).data("index")) {
                    $(this).addClass("playlist_hover");
                //}
            },
            function() {
                $(this).removeClass("playlist_hover");
            }
        ).click( function() {
            var index = $(this).data("index");
            //if (playItem != index) {
                playListChange( index );
            //}
        });
    }
}

function playListInit(autoplay) {
    if(autoplay) {
        playListChange( playItem );
    } else {
        playListConfig( playItem );
    }
}

function playListConfig( index ) {
//    $("#playlist_item_"+playItem).removeClass("playlist_current");
//    $("#playlist_item_"+index).addClass("playlist_current");
    playItem = index;
    $("#jquery_jplayer").setFile(myPlayList[playItem].mp3, myPlayList[playItem].ogg);
}

function playListChange( index ) {
    playListConfig( index );
    
    for (i = 0; i < track_max; i++) {
        $("#" + i + "_active").css("display", "none");
    }

    $("#" + index + "_active").css("display", "");
    $("#jquery_jplayer").play();
}

function playListNext() {
    var index = (playItem+1 < myPlayList.length) ? playItem+1 : 0;
    playListChange( index );
}

function playListPrev() {
    var index = (playItem-1 >= 0) ? playItem-1 : myPlayList.length-1;
    playListChange( index );
}

function current_page() {
    var path = window.location.pathname;
    var longPage = path.substring(path.lastIndexOf('/') + 1);
    var shortPage = longPage.substring(0, longPage.lastIndexOf('.'));

    setActive(shortPage);
}

function setActive(activeMe){
    for (var headCounter = 0; headCounter < pageHeaders.length; headCounter++){
      var currIndex = pageHeaders[headCounter];

      if (currIndex == activeMe){
        $("#" + currIndex + "_nav").attr("src", "imgs/nav/" + currIndex + "_active.png");
      } else {
        $("#" + currIndex + "_nav").attr("src", "imgs/nav/" + currIndex + ".png");
      }
    }
}

function preloading(){
    for (x=0; x<preloading.arguments.length; x++){
        myimages[x] = new Image();
        myimages[x].src = preloading.arguments[x];
    }
}
