var current_span = 1;

var songspan=new Array(1, 2, 3);

$(document).ready(function(){

      $("#loader").fadeTo(1, 0.0);
      $("#links a, #mobile_beat a").click(function() {
         var thing = $(this).attr("href");
         show_loader();
         window.location.hash = thing;
         if(thing != "index.php" && current == "index.php")   // if on home and home isn't clicked
         {
           current = thing;
           $("#box_1").animate({top: "-500px", marginLeft: "-700px"}, 700, "swing", function() {
           $(this).hide();
           });
           $("#box_2").animate({top: "-500px"}, 700, "swing", function() {
           $(this).hide();
           });
           $("#box_3").animate({top: "-500px", marginLeft: "300px"}, 700, "swing", function() {
              $(this).hide();
              do_nav(thing);
              return false;
           });
           $(this).attr("class", "current");
           $("#links a").not(this).attr("class", "");
           
         }
         else if(thing != "index.php" && current != "index.php")   // if not on home and home isn't clicked
         {
              current = thing;
              $(this).attr("class", "current");
              $("#links a").not(this).attr("class", "");
              $("#c_holder").slideUp(500, function() {
                 do_nav(thing);
                 return false;
              });

         }
         else if(thing == "index.php" && current != "index.php")   // if not on home and home is clicked
         {
            current = thing;
            $("#c_holder").slideUp(500);
            //do_nav(thing);
           $("#box_1").show().animate({top: "210px", marginLeft: "-440px"}, 700, "swing");
           $("#box_2").show().animate({top: "220px"}, 700, "swing");
           $("#box_3").show().animate({top: "230px", marginLeft: "140px"}, 700, "swing", function() {
              $("#loader").fadeTo(500, 0.0);

           });
           $(this).attr("class", "current");
           $("#links a").not(this).attr("class", "");
           return false;
         }
         return false;

      });

      //$(".song").hide();
      setInterval("show_song();", 2500);


});

function show_song()
{
     // array is songspan[k];
    $("#songs_box span#song" + current_span).fadeTo(200, 0.0, function() {

          var random_num = Math.floor(Math.random()*200); // find random number 1-15
          random_num++;
          while(random_num == songspan[0] || random_num == songspan[1] || random_num == songspan[2])
          {
             random_num = Math.floor(Math.random()*200);
             random_num++;
          }

          songspan[current_span-1] = random_num;

          var new_text = $("#all_songs span#s" + random_num).html();
          //alert("text is " + new_text);
          $("#songs_box span#song" + current_span).html(new_text);
          $("#songs_box span#song" + current_span).fadeTo(200, 1.0, function() {
               if (jQuery.browser.msie)
               {
                   this.style.removeAttribute('filter');
               }
          current_span++;
          if(current_span == 4) current_span = 1;

        });

    });


}

function do_nav(thing)
{

       var toLoad = thing +' #content';
       $('#c_holder').load(toLoad,'',showNewContent);
}

function showNewContent()
{

     $("#c_holder").slideDown(500, function() {

        if (jQuery.browser.msie)
     {
       this.style.removeAttribute('filter');
     }
     
        hide_loader();
     });



}

function show_loader()
{
$("#loader").fadeTo(1, 0.0).show().fadeTo(500, 1.0);

}

function hide_loader()
{
$("#loader").fadeTo(500, 0.0).hide();

}

