function has_flash() {

  var MM_contentVersion = 5;
  var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;

  if (plugin) {
    var words = navigator.plugins["Shockwave Flash"].description.split(" ");
    for (var i = 0; i < words.length; ++i) {
      if (isNaN(parseInt(words[i])))
        continue;
      var MM_PluginVersion = words[i]; 
    }
    var MM_FlashCanPlay = MM_PluginVersion >= MM_contentVersion;
  } else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0 && (navigator.appVersion.indexOf("Win") != -1)) {
    document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n'); 
    document.write('on error resume next \n');
    document.write('MM_FlashCanPlay = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & MM_contentVersion)))\n');
    document.write('</SCR' + 'IPT\> \n');
  }

  return MM_FlashCanPlay;
}


function videoclick(clicked) {

  if (! clicked) {
    // Called with null, kill whatever is showing.
    $('.videolist').children('.current').removeClass('current');

    $('.video').filter('.current').fadeOut('normal', function() {
      $(this).removeClass('current');
      $(this).hide();
    });

    return;
  }

  var cur_name = clicked.parent().attr('id');

  if (clicked.parent().hasClass('current')) {
    return;
  }

  var cur_size = clicked.parent().parent().children('.current').size();

  // Change the menus
  clicked.parent().parent().children('.current').removeClass('current');
  clicked.parent().addClass('current');

  // In the case of there is no current album shown, at the start.
  if (cur_size >= 1) {
    // In the case that we have a current one.
    $('.video').filter('.current').fadeOut('normal', function() {
      $(this).removeClass('current');
      $('.video').filter('#' + cur_name).fadeIn('slow', function() {
        $(this).addClass('current');
      });
    });
  } else {
    $('.video').filter('#' + cur_name).fadeIn('slow', function() {
      $(this).addClass('current');
    });
  }
}


function musicalbumclick(clicked) {

  if (! clicked) {

    // Called with null, kill whatever is showing.
    $('.musicalbumlist').children('.current').removeClass('current');

    $('.musicalbum').filter('.current').fadeOut('normal', function() {
      $(this).removeClass('current');
      $(this).hide();
    });

    return;
  }

  var cur_name = clicked.parent().attr('id');

  if (clicked.parent().hasClass('current')) {
    return;
  }

  var cur_size = clicked.parent().parent().children('.current').size();

  // Change the menus
  clicked.parent().parent().children('.current').removeClass('current');
  clicked.parent().addClass('current');

  // In the case of there is no current album shown, at the start.
  if (cur_size >= 1) {
    // In the case that we have a current one.
    $('.musicalbum').filter('.current').fadeOut('normal', function() {
      $(this).removeClass('current');
      $('.musicalbum').filter('#' + cur_name).fadeIn('slow', function() {
        $(this).addClass('current');
      });
    });
  } else {
    $('.musicalbum').filter('#' + cur_name).fadeIn('slow', function() {
      $(this).addClass('current');
    });
  }
}

function photoclick(clicked) {

  // gets called with <anchor> tag that was clicked
  // looks at the href and loads an img tag into the slideshow div
  // the img tag will also have an <a around it.
  // also take caption from thumb and display it

  if (!clicked) {
    var img_str = '';
    var caption_str = '';
  } else {                  // take out this '/' later!!!
    var img_str = '<img src="/' + clicked.attr('href') + '" alt="' + 
        clicked.children('img').attr('alt') + '" />';
    var caption_str = clicked.children('img').attr('alt');
  }

  $('.photoalbum').filter('.current').children('.slideshow').html(img_str);
  $('.photoalbum').filter('.current').children('.caption').html(caption_str);
}


function photoalbumclick(clicked) {

  if (! clicked) {

    // Called with null, kill whatever is showing.
    $('.albumlist').children('.current').removeClass('current');

    $('.photoalbum').filter('.current').slideUp('normal', function() {
      $(this).removeClass('current');
      $(this).hide();
    });

    return;
  }

  var cur_name = clicked.parent().attr('id');

  if (clicked.parent().hasClass('current')) {
    return;
  }

  // Change the menus
  clicked.parent().parent().children('.current').removeClass('current');
  clicked.parent().addClass('current');

  // In the case of there is no current album shown, at the start.
  if ($('.photoalbum').filter('.current').size() == 1) {
    // In the case that we have a current one.
    $('.photoalbum').filter('.current').slideUp('normal', function() {
      $(this).removeClass('current');
      $('.photoalbum').filter('#' + cur_name).slideDown('slow', function() {
        $(this).addClass('current');
      });
    });
  } else {
    $('.photoalbum').filter('#' + cur_name).slideDown('slow', function() {
      $(this).addClass('current');
    });
  }

}


function menuclick(clicked) {

  var curChildIndex = clicked.parent().prevAll().length + 1;

  // Do nothing if we're already here
  if (clicked.parent().hasClass('current')) {
    return;
  }

  // Change the menus
  clicked.parent().parent().children('.current').removeClass('current');
  clicked.parent().addClass('current');

  if (clicked.parent().parent().next('.tabcontainer').children('.current').size() == 1) {
    clicked.parent().parent().next('.tabcontainer').children('.current').slideUp('normal', function() {
      $(this).removeClass('current');
      $(this).parent().children('div:nth-child('+curChildIndex+')').slideDown('slow',function() {
        $(this).addClass('current');
      });
    });
  } else {
    clicked.parent().parent().next('.tabcontainer').children('div:nth-child('+curChildIndex+')').slideDown('slow',function() {
      $(this).addClass('current');
    });
  }

  return false;
}

function newsclick () {
  var curChildIndex = $(this).parent().prevAll().length + 1;

  if ($(this).parent().hasClass('showing')) {
    $(this).parent().removeClass('showing');
    $(this).next().slideUp();
    $(this).next().next().slideUp();
  } else {
    $(this).parent().addClass('showing');
    $(this).parent().slideDown();
  }
}


function blogclick () {
  var curChildIndex = $(this).parent().prevAll().length + 1;

  if ($(this).parent().hasClass('showing')) {
    $(this).parent().removeClass('showing');
    $(this).next().slideUp();
    $(this).next().next().slideUp();
  } else {
    $(this).parent().addClass('showing');
    $(this).parent().slideDown();
  }
}

function playtrack(n, t) {

  $("#trackname").fadeOut(function(){
    $("#trackname").text(t);
    $("#trackname").fadeIn();
  });

  $("#jquery_jplayer").setFile('/music/' + n).play();

}

function songplay() {

//  playtrack($(this).attr('href'), 'Foo Bar');
  playtrack($(this).attr('id'), $(this).text());
  return false;

}


$(document).ready(function() {

  $.address.change(function(event) {
    // check if prefaced with photos/ or music/ or videos/

    if (event.path == '/') {
      menuclick($('a[href=about]'));
    } else {
      menuclick($('a[href=' + event.pathNames[0] + ']'));
    }

    if (event.pathNames[0] == 'music') {
      if (event.pathNames[1]) {
        musicalbumclick($('.musicalbumlist a[href=' + event.pathNames[1] + ']'));
      } else {
        // Clear it
        musicalbumclick(null);
      }
    }
    if (event.pathNames[0] == 'photos') {
      if (event.pathNames[1]) {
        photoalbumclick($('.albumlist a[href=' + event.pathNames[1] + ']'));

        if (event.pathNames[2]) {
          photoclick($('a[href=' + event.path + ']'));
        } else {
          photoclick(null);
        }
      } else {
        // Clear it
        photoalbumclick(null);
      }
    }
    if (event.pathNames[0] == 'videos') {
      if (event.pathNames[1]) {
        videoclick($('.videolist a[href=' + event.pathNames[1] + ']'));
      } else {
        // Clear it
        videoclick(null);
      }
    }

  });

  $("a.songplay").live('click', songplay);
  $('ul.menu li a').live('click', function() {
    location.hash = $(this).attr('href');
    return false;
  });
  $('ul.albumlist li a').live('click', function() {
    location.hash = 'photos/' + $(this).attr('href');
    return false;
  });
  $('ul.musicalbumlist li a').live('click', function() {
    location.hash = 'music/' + $(this).attr('href');
    return false;
  });
  $('ul.videolist li a').live('click', function() {
    location.hash = 'videos/' + $(this).attr('href');
    return false;
  });
  $('ul.thumbs li a').live('click', function() {
    location.hash = $(this).attr('href');
    return false;
  });

  $('ul.news li a').live('click', newsclick);
  $('ul.blog li a').live('click', blogclick);

  if (! window.location.hash) {
    menuclick($('a[href=about]'));
  }


  //$("#news").load("news.php", {start: 0, count: 10});
  //$("#blog").load("blog.php", {start: 0, count: 10});

/*
  $('#schubas').galleriffic('#schubas div.navigation', {
    numThumbs: 100,
    imageContainerSel: '#schubas div.slideshow',
    captionContainerSel: '#schubas div.embox',
    enableHistory: true,
    renderSSControls: false
  });

  $('#studio').galleriffic('#studio div.navigation', {
    numThumbs: 100,
    imageContainerSel: '#studio div.slideshow',
    captionContainerSel: '#studio div.embox',
    enableHistory: true,
    renderSSControls: false
  });

  $('#promo').galleriffic('#promo div.navigation', {
    numThumbs: 100,
    imageContainerSel: '#promo div.slideshow',
    captionContainerSel: '#promo div.embox',
    enableHistory: true,
    renderSSControls: false
  });
*/

  // has_flash should go here.
  if (true) {

    // J Player usual code after this.
    $("#jquery_jplayer").jPlayer({oggSupport: false, ready: function() {
      var track = $('#trackname');

      $("#jquery_jplayer").setFile('/music/' + track.attr('defaulttrack'));

      if ((track.attr('playonload')) && (! window.location.hash)) {
        playtrack(track.attr('defaulttrack'), track.text());
      }

    }})

    .jPlayerId("loadBar", "loadbar")
    .jPlayerId("playBar", "playbar")
    .jPlayerId("volumeBar", "volumebar")
    .jPlayerId("volumeBarValue", "volumebarvalue")
    .jPlayerId("play", "play")
    .jPlayerId("pause", "pause")
    .jPlayerId("stop", "stop")
    .jPlayerId("volumeMin", "vmin")
    .jPlayerId("volumeMax", "vmax")
    .onProgressChange(function (lp, ppr, ppa, pt, tt) {
      var myPlayedTime = new Date(pt);
      var ptMin = (myPlayedTime.getUTCMinutes() < 10) ? "0" +
          myPlayedTime.getUTCMinutes() : myPlayedTime.getUTCMinutes();
      var ptSec = (myPlayedTime.getUTCSeconds() < 10) ? "0" +
          myPlayedTime.getUTCSeconds() : myPlayedTime.getUTCSeconds();
      $("#progress #elapsed").text(ptMin+":"+ptSec);

      var myTotalTime = new Date(tt);
      var ttMin = (myTotalTime.getUTCMinutes() < 10) ? "0" +
          myTotalTime.getUTCMinutes() : myTotalTime.getUTCMinutes();
      var ttSec = (myTotalTime.getUTCSeconds() < 10) ? "0" +
          myTotalTime.getUTCSeconds() : myTotalTime.getUTCSeconds();
      $("#progress #total").text(ttMin+":"+ttSec);

    });
  }

  /* Changed default Speed from 2 to 1 in jquery.marquee.js */
  $('#trackmarquee').marquee();

});

