(function() {
//note fixed media path current URL and removed .remove from jPlayer
  var $loading, allowed_pages, media_path, current_url, enter_site, get_content, init_content, init_cycle, init_fan_form, init_masthead, init_player, init_player_2, init_pp, init_tweet, j, set_track, splash_is_visible, start_album;
  splash_is_visible = true;
  allowed_pages = new Array('home', 'bio', 'media', 'tour', 'merch', 'contact');
  $loading = $('<img></img>').attr('src', '/img/layout/loading.gif').css('margin-left', '300px');
  if (location.href.indexOf('http://localhost') > -1) {
    current_url = 'http://yellowdubmarine.com';
  } else {
    current_url = 'http://yellowdubmarine.com';
  }
  
  media_path = 'http://s3.amazonaws.com/yellowdubmarine/media';
  
  enter_site = function() {
    $("#jquery_jplayer_intro").jPlayer('stop');//.remove();
    $("#jquery_jplayer_1").jPlayer('play');
    return $('#splash').animate({
      left: '-1000px',
      height: '0'
    }, 200, function() {
      $('#splash').css({
        height: '1px'
      });
      splash_is_visible = false;
      $('#bg-shimmer').animate({
        height: '400px'
      });
      $('header').animate({
        height: '400px',
        backgroundPosition: '(50% -500px)'
      }, 500, function() {
        return $('#nav, #player').fadeIn();
      });
      return start_album();
    });
  };
  get_content = function(name) {
    var html_file;
    if ($.inArray(name, allowed_pages) === -1) {
      name = 'home';
    }
    $('#drop_target').html($loading);
    $('#nav a').removeClass('active');
    $('#nav_' + name).addClass('active');
    html_file = '/pages/' + name;
    return $.get(html_file, function(data) {
      $('#drop_target').html(data);
      $('#content').show();
      switch (name) {
        case 'home':
          init_tweet();
          init_cycle();
          init_pp();
          return init_fan_form();
        case 'media':
          return init_pp();
        case 'merch':
          return init_pp();
      }
    });
  };
  init_content = function() {
    return $.history.init((function(hash) {
      var name;
      if (hash === "") {
        return $("#content, #nav, #player").hide();
      } else {
        if (splash_is_visible) {enter_site();}
        name = hash.replace(/\//, '');
        return get_content(name);
      }
    }), {
      unescape: ",/"
    });
  };
  init_pp = function() {
    var $modal;
    $modal = $('a.modal');
    if ($modal.size() > 0) {
      $modal.prettyPhoto({
        deeplinking: false
      });
    }
    return $('a[rel^=prettyPhoto]').prettyPhoto({
      deeplinking: false
    });
  };
  init_masthead = function() {
    return $('#masthead').click(function() {
      return location.href = current_url;
    });
  };
  init_tweet = function() {
    var $lt;
    $lt = $('#latest_tweet');
    if ($lt.size() > 0) {
      return $.get('/lib/get_tweets.php', function(data) {
        return $lt.html(data);
      });
    }
  };
  j = {};
  init_player_2 = function() {
    window.j = new jPlayerPlaylist({
      jPlayer: "#jquery_jplayer_1"
    }, [
      
		
	{
        title: "Something",
        mp3: "http://yellowdubmarine.com/uploads/music/02-Something.mp3",
        oga: "http://yellowdubmarine.com/uploads/music/02-Something.ogg"
      },
	{
        title: "Oh Darling",
        mp3: "http://yellowdubmarine.com/uploads/music/04-Oh-Darling.mp3",
        oga: "http://yellowdubmarine.com/uploads/music/04-Oh-Darling.ogg"
      },
	{
        title: "Octopus Garden",
        mp3: "http://yellowdubmarine.com/uploads/music/05-Octopus-Garden.mp3",
        oga: "http://yellowdubmarine.com/uploads/music/05-Octopus-Garden.ogg"
      }
    ], {
      swfPath: "/lib/jplayer/",
      supplied: "oga, mp3",
      wmode: "window",
      loopOnPrevious: true,
      play: set_track
    });
    return set_track();
  };
  set_track = function() {    
    return $('#jp-track-title .title').html(window.j.playlist[window.j.current].title);
  };
  start_album = function() {
    return window.j.play(0);
  };
  init_player = function() {
    return $("#jquery_jplayer_intro").jPlayer({
      ready: function(event) {
        $(this).jPlayer("setMedia", {
          mp3: media_path + '/mp3/Ocean-Sounds.mp3',
          oga: media_path + '/ogg/Ocean-Sounds.ogg'
        });
        return $(this).jPlayer('play');
      },
      swfPath: "/lib/jplayer/",
      supplied: "mp3, oga",
      wmode: "window",
      volume: .6
    });
  };
  init_cycle = function() {
    return $('#slideshow').cycle({
      next: 'a.arrow.left',
      prev: 'a.arrow.right'
    });
  };
  init_fan_form = function() {
    $('#add_fan_form input').each(function() {
      $(this).data('orig', $(this).val());
      return $(this).focus(function() {
        if ($(this).val() === $(this).data('orig')) {
          return $(this).val('');
        }
      });
    });
    return $('#add_contact_button').click(function(e) {
      var $f, form_data;
      $f = $('#add_fan_form');
      $f.html('<br/><br/><center><img src="/img/layout/loading.gif" /></center>');
      
      form_data = $f.serialize();
      $.post('/lib/email.php', form_data, function() {
        $f.find('input, select').fadeOut();
        return $f.html('<br/><br/><center><h3>Thanks!</h3></center>');
      });
      return false;
    });
  };
  window.exp = {
    init_pp: init_pp
  };
  $(function() {
    init_content();
    init_masthead();
    init_tweet();
    init_player();
    return init_player_2();
  });
}).call(this);

