var brickSpeed = 150;      // time it takes a small brick to slide in
var blurbSpeed = 2000;     // time for the blurb (top paragraph) to fade in (used for nav, paperclips, and newsletter box as well)
var optionSpeed = 300;     // time for the left side "buttons" (two choices) to fade in
var leedShowSpeed = 1000;  // time for the leed notice and sullivan office photo to fade in
var leedDelay = 4000;      // time delay before the leed notice and sullivan office photo fade out
var leadInSpeed = 1000;    // time for the "we're building relationships" text to fade out
var brickInSpeed = 1000;   // time for the three large images to fade in
var startDelay = 1500;     // time delay before any animation begins

var brickImages = new Array(
//  "#fourth-row-six",
//  "#fourth-row-five",
  "#fourth-row-four",
  "#fourth-row-three",
  "#fourth-row-two",
  "#fourth-row-one",
//  "#third-row-five",
  "#third-row-three",
  "#third-row-two",
  "#third-row-one",
  "#third-row-four",
  "#second-row-two",
  "#first-row-five",
  "#first-row-three",
  "#first-row-two",
  "#first-row-one"
//  "#landscape",
//  "#front-parking",
//  "#office-three",
//  "#entrance",
//  "#school",
//  "#house",
//  "#frame",
//  "#main-entrance",
//  "#parking-area",
//  "#office-building",
/*  "#hospital",*/
//  "#kitchen",
/*  "#laconia",*/
//  "#ct-scan",
//  "#community-center",
//  "#commercial-office",
//  "#landscape-entry",
//  "#classroom"
);

$.urlParam = function(name){
  var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
  if (!results) { return 0; }
  return results[1] || 0;
}

function showBricks() {
  $(brickImages.join()).css({
    'top': "0px",
    'left': "0px"
  });
  
  $('#nav_bar_tmp').remove();
  $('#blurb,#already-have-a-relationship,#thinking-about-it').css('visibility','visible');
  $('div.large-brick, img.large-brick, #nav_bar,#blurb,  #already-have-a-relationship, #thinking-about-it, .paperclip, #news-panel, #news-panel-top-border').show();
}

function showBrick(i, max) {
  if( i < max ) {
    $(brickImages[i]).stop().animate({
      top: "0px",
      left: "0px"
    }, brickSpeed, "swing", function() {
      showBrick(++i,max);
    });
  }
  else {
    $('#nav_bar_tmp').remove();
    $('#nav_bar')
      .stop()
      .fadeIn(blurbSpeed);

    $('#blurb') // fade in top message blurb
      .stop()
      .fadeTo(0,0)
      .css('visibility','visible')
      .fadeTo(blurbSpeed,1,function () {
      });
      
    $('#already-have-a-relationship') // fade in first button
      .stop()
      .fadeTo(0,0)
      .css('visibility','visible')
      .fadeTo(optionSpeed,1,function() {

        $('#thinking-about-it') // fade in second button
          .stop()
          .fadeTo(0,0)
          .css('visibility','visible')
          .fadeTo(optionSpeed,1);
      });

    $('.paperclip,#news-panel,#news-panel-top-border')
      .fadeIn(blurbSpeed);
  }
}

$(document).ready(function () {
  
  if( ! ($.urlParam('s')) ) {
    var fadeTimer = $.timer(startDelay,function() {
      $('#leed-blurb,#intro-building').fadeIn(leedShowSpeed);

      var fade2Timer = $.timer(leedDelay,function () {
        $('#leed-blurb,#intro-building').fadeOut(leadInSpeed);
        $('div.large-brick,img.large-brick').fadeIn(brickInSpeed, function () {
          $('#lead-in').fadeOut(leadInSpeed);
          showBrick(0,brickImages.length);
        });
      });
    });
  }
  else {
    $('#leed-blurb,#intro-building,#lead-in').hide();
    showBricks();
  }

  $('#already-have-a-relationship').hover(function() {
    $('#have-rel-clip:not(.static)').show();
  }, function () {
    $('#have-rel-clip:not(.static)').hide();
  });
  
  $('#already-have-a-relationship').click(function () {
    if( $('#thinking-about-it').attr('src') == "images/thinking-about-it-sel.png") {
      $('#still-think-clip').hide().removeClass('static');
      $('#thinking-about-it').attr('src','images/thinking-about-it.png');
      $('.still-think:not(.have-rel, .hover-box, .hover-box-bg)').removeClass('trans');      
      $('.still-think.hover-box, .still-think.hover-box-bg').hide();
    }
    
    if( $(this).attr('src') == "images/already-have-a-relationship.png" ) {
      $('#have-rel-clip').addClass('static');
      $(this).attr('src','images/already-have-a-relationship-sel.png');
      $('.have-rel:not(.hover-box, .hover-box-bg)').addClass('trans');
      $('.have-rel.hover-box, .have-rel.hover-box-bg').show();
    }
  });

  $('#thinking-about-it').hover(function () {
    $('#still-think-clip:not(.static)').show();
  }, function () {
    $('#still-think-clip:not(.static)').hide();
  });

  $('#thinking-about-it').click(function () {
    if( $('#already-have-a-relationship').attr('src') == "images/already-have-a-relationship-sel.png" ) {
      $('#have-rel-clip').hide().removeClass('static');
      $('#already-have-a-relationship').attr('src','images/already-have-a-relationship.png');
      $('.have-rel:not(.still-think, .hover-box, .hover-box-bg)').removeClass('trans');
      $('.have-rel.hover-box, .have-rel.hover-box-bg').hide();
    }

    if( $('#thinking-about-it').attr('src') == "images/thinking-about-it.png" ) {
      $('#still-think-clip').addClass('static');
      $(this).attr('src','images/thinking-about-it-sel.png');
      $('.still-think').addClass('trans');
      $('.still-think.hover-box, .still-think.hover-box-bg').removeClass('trans');
      $('.still-think.hover-box, .still-think.hover-box-bg').show();
    }
  });
});
