$(document).ready(function() {


    do_magic();

    // initiates Lavalamp thingy
    $(function() {
            $("#1, #2, #3").lavaLamp({
                fx: "backout",
                speed: 700,
                click: function(event, menuItem) {
                    return false;
                }
            });
        });

    // get new info when clicking a link
    
    
    $("#nav li a").click(startstuff);
    function startstuff()
    {
      //$("#container").prepend("<span id='load'>LOADING</span>");
      $("#mic_holder").fadeTo(300, 0.0, focusfade(this));
    }

    // function to get new info
    function focusfade(what) {
         //$(this).parent().attr("class", "current");


         var toLoad = $(what).attr('href')+' #content';
         $('#content').wait(300).hide(500, loadContent);
         showLoader();
         // ajax code to load content from other page


        //window.location.hash = $(this).attr('href').substr(0,$(this).attr('href').length-4);
        function loadContent() {
        //alert("here!");
            //alert("got here. toload = " + toLoad);
			$('#content').load(toLoad,'',showNewContent);  // gets content ready to be shown



		}
		function showNewContent() {
			$('#content').show(500, do_magic);   // displays the new content
		}
		return false;
		// end code to load content
    }
    
    
    
    
    
    
    
    // function to resize mic stand
    function do_magic() {
        var body_height = $("#left").height();

        var mic_middle = body_height - 294;
        var mic_top = 0;
        if(body_height > 317) // if the body height is greater than 317
        {
          $("#mic_body").css("height", mic_middle);    // set the stretchable middle height to the needed length
          $("#mic_top").css("height", 206);            // set the top to the default, just in case
          //alert("bh <= 317. mic_middle = " + mic_middle);
        }
        else if(body_height <= 317)  //>   if the body height is less than 317
        {
          mic_top = body_height - 111;      // calculate how tall the mic_top needs to be
          if(mic_top < 50)
          {
            $("#mic_top").css("height", 50);    //>  // don't let the top height be any less than 50
            $("#mic_body").css("height", 5);
          }
          else
          {
            $("#mic_body").css("height", 5);                 // otherwise, set the stretchable to 5(shortest allowable)
            $("#mic_top").css("height", mic_top);            // and then set the calculated mic top height
            //alert("bh <= 317. mic_top = " + mic_top);
          }
        }
        $("#mic_holder").fadeTo(500, 1.0);
        //alert("body height = " +  body_height + ". mic middle = " + mic_middle + ". mic top = " + mic_top);
        hideLoader();
        
        
    }
    
    ///////////////////////////////////////////////////////
      // SHOW ANIMATION WHEN LOADING
      function hideLoader() {
			$('#load').fadeOut('normal');
		}
		function showLoader() {
	    	$('#load').remove();
            $('#main_top').prepend('<span id="load">LOADING...</span>');
            $('#load').fadeIn('normal');
       }
    
		
});
