//executed when the page is ready
$(document).ready(function(){
  adjustHeight();
  
  //remove paragraph tag from linked images
  $("p a img").each(function(){
    $(this).parent().parent().replaceWith($(this).parent().parent().html());
  });
  
  //float scroll-up links to the right side
  $("#main a").each(function(){
    if( $(this).html() == "Scroll Up" ){
      $(this).parent().css({ textAlign: "right" });
    }
  });
});

function adjustHeight(){
  //adjusts the main column if it is too short
  quoteAH = $("#q_text_a").height() + $("#q_author_a").height();
  quoteBH = $("#q_text_b").height() + $("#q_author_b").height();
  
  h1 = $("#navbar").height() + quoteAH + quoteBH;
  //if( $.browser.msie && $.browser.version < 7 ){ h1 -= 40; } //needs to be shorter in IE6
  h2 = $("#main div.a").height() + $("#main div.b").height();
  h3 = $("#main div.b").height() + 10;
  if( h1 > h2 ){
    h4 = h3 + h1 - h2;
    $("#main div.b div").css({ height: h4+'px' });
  }
}

function getNextQuote(first){
  //flip content
  $("#q_text_b").html($("#q_text_a").html());
  $("#q_author_b").html($("#q_author_a").html());
  $("#q_b").show();
  $("#q_a").hide();
  
  //prepare next quote
  if( ++currentQuote >= totalQuotes ){
    currentQuote = 0;
  }
  $("#q_text_a").html('"'+quoz[currentQuote][1]+'"');
  $("#q_author_a").html(quoz[currentQuote][0]);
  
  //calculate time delay before next quote
  words1 = quoz[currentQuote][0].split(' ');
  words2 = quoz[currentQuote][1].split(' ');
  pause = (words1.length + words2.length) * 450 + 2500;
  
  //animate switch
  if (first) {
    $("#q_b").fadeOut(1);
    $("#q_a").fadeIn(2000);
  }else{
    $("#q_b").fadeOut(1000);
    $("#q_a").fadeIn(2000);
  }

//  if( first ){
//    $("#q_b").fadeOut(1);
//    $("#q_a").fadeIn(2000);
//  }else{
//    $("#q_b").fadeOut(2000,function(){
//      $("#q_a").css({ top: -1000 }).fadeIn(1, function(){
//        adjustHeight();
//        $("#q_a").css({ top: null }).fadeOut(1).fadeIn(1000);
//      });
//    });
//  }
  setTimeout("getNextQuote(false)", pause); //wait before going to next quote
}
