﻿var animation =
{
  thumbNumber: 1,

  thumbOrder: [null, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45],

  totalAnimationVariations: 11, //11,

  typeName: [null, "Default", "Reverse", "Random", "OutwardSpiral", "InwardSpiral", "Waterfall", "Snake", "TwoHeadedSnake", "DiagonalOne", "DiagonalTwo", "BC"],

  type: [
  // Array index zero - unused.
    [null],

  // Default - top-right to bottom left.
    [null, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45],

  // Reverse - bottom-left to top-right.
    [null, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],

  // Random order - set through code.
    [null],

  // Outward spiral.
    [null, 21, 22, 23, 24, 25, 34, 33, 32, 31, 30, 29, 20, 11, 12, 13, 14, 15, 16, 17, 26, 35, 44, 43, 42, 41, 40, 39, 38, 37, 28, 19, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 18, 27, 36, 45],

  // Inward spiral.
    [null, 1, 2, 3, 4, 5, 6, 7, 8, 9, 18, 27, 36, 45, 44, 43, 42, 41, 40, 39, 38, 37, 28, 19, 10, 11, 12, 13, 14, 15, 16, 17, 26, 35, 34, 33, 32, 31, 30, 29, 20, 21, 22, 23, 24, 25],

  // Waterfall.
    [null, 1, 10, 19, 28, 37, 2, 11, 20, 29, 38, 3, 12, 21, 30, 39, 4, 13, 22, 31, 40, 5, 14, 23, 32, 41, 6, 15, 24, 33, 42, 7, 16, 25, 34, 43, 8, 17, 26, 35, 44, 9, 18, 27, 36, 45],

  // Snake.
    [null, 1, 2, 3, 4, 5, 6, 7, 8, 9, 18, 17, 16, 15, 14, 13, 12, 11, 10, 19, 20, 21, 22, 23, 24, 25, 26, 27, 36, 35, 34, 33, 32, 31, 30, 29, 28, 37, 38, 39, 40, 41, 42, 43, 44, 45],

  // Two-headed Snake.
    [null, 1, 45, 10, 36, 19, 27, 28, 18, 37, 9, 38, 8, 39, 7, 40, 6, 41, 5, 42, 4, 43, 3, 44, 2, 35, 11, 26, 20, 17, 29, 16, 30, 15, 31, 14, 32, 13, 33, 12, 34, 21, 25, 22, 24, 23],

  // Diagonal, top right to bottom left.
    [null, 1, 2, 10, 3, 11, 19, 4, 12, 20, 28, 5, 13, 21, 29, 37, 6, 14, 22, 30, 38, 7, 15, 23, 31, 39, 8, 16, 24, 32, 40, 9, 17, 25, 33, 41, 18, 26, 34, 42, 27, 35, 43, 36, 44, 45],

  // Diagonal, bottom left to top right.
    [null, 45, 44, 36, 43, 35, 27, 42, 34, 26, 18, 41, 33, 25, 17, 9, 40, 32, 24, 16, 8, 39, 31, 23, 15, 7, 38, 30, 22, 14, 6, 37, 29, 21, 13, 5, 28, 20, 12, 4, 19, 11, 3, 10, 2, 1],

  // Write out the letters BC.
    [null, 1, 10, 19, 28, 37, 2, 3, 13, 21, 20, 31, 39, 38, 9, 8, 7, 6, 15, 24, 33, 42, 43, 44, 45, 11, 29, 12, 30, 4, 22, 40, 5, 14, 23, 32, 41, 16, 25, 34, 17, 26, 35, 18, 27, 36]
  ],

  getRandomNumber: function ()
  {
    var rand = Math.floor(Math.random() * this.totalAnimationVariations) + 1;

    // Don't use the BC animation on the intro screen.
    if (rand == 11)
    {
      rand = Math.floor(Math.random() * (this.totalAnimationVariations - 1)) + 1;
    }

    return rand;
  },

  selectRandomAnimation: function ()
  {
    var randomAnimationNumber = this.getRandomNumber();

    if (animation.typeName[randomAnimationNumber] != "Random")
    {
      animation.thumbOrder = animation.type[randomAnimationNumber];
    }
    else
    {
      // Random order.
      animation.thumbOrder.sort(function ()
      {
        return 0.5 - Math.random();
      });

      animation.thumbOrder.splice($.inArray(null, animation.thumbOrder), 1);

      animation.thumbOrder.unshift(null);
    }
  }
};

var portfolio =
{
  currentPage: "01"
};

var about =
{
  currentAboutSection: null,
  whoWeAre: 11,
  whatWeBelieve: 25,
  whatWeCanDo: 31,
  A: 37,
  B: 38,
  O: 39,
  U: 40,
  T: 41
};

var contact =
{
  currentContactSection: null,
  lookingForAnAgency: 11,
  lookingForAJob: 32,
  C: 37,
  O: 38,
  N: 39,
  T: 40,
  A: 41,
  C2: 42,
  T2: 43
};

var green =
{
  currentGreenSection: null,
  greenExpo365: 12,
  environmentallySpeaking: 33,
  environMental: 8,
  G: 37,
  R: 38,
  E: 39,
  E2: 40,
  N: 41
};

var introThumbs, introThumbsHref;

var thumbs, thumbsHref;

var firstLoad = true;

function showNav()
{
  $("#arrowLeft img").animate({ marginLeft: '-=30px' }, 1000);
  $("#arrowRight img").animate({ marginLeft: '+=30px' }, 1000);

  $("#footer").slideDown(1000);

  if (firstLoad)
  {
    $("#iconWork").animate({ opacity: 0.0 }, 1200, function ()
    {
      $("#iconWork").animate({ opacity: 1, marginTop: "+=30px" }, 300, function ()
      {
        $("#iconAbout").animate({ opacity: 1, marginTop: "+=30px" }, 300, function ()
        {
          $("#iconContact").animate({ opacity: 1, marginTop: "+=30px" }, 300, function ()
          {
            $("#iconGreen").animate({ opacity: 1, marginTop: "+=30px" }, 300);
          });
        });
      });
    });
  }
}

function hideNav()
{
  $("#arrowLeft img").animate({ marginLeft: '+=30px' }, 1000);
  $("#arrowRight img").animate({ marginLeft: '-=30px' }, 1000);

  $("#footer").slideUp(1000);
}

function showArrows()
{
  $("#arrowLeft").fadeIn(800);
  $("#arrowRight").fadeIn(800);
}

function hideArrows()
{
  $("#arrowLeft").fadeOut(800);
  $("#arrowRight").fadeOut(800);
}

var state =
{
  pages: ["work", "about", "contact", "green"],

  pageLoaded: [true, false, false, false], // So we know if we need to pre-load thumb images for each page by calling LoadThumbs().

  currentPage: 0,
  nextPage: 1,
  previousPage: 3,

  inPageTransition: false,

  jumpedToWork: false,
  jumpedToWorkAll: false,
  jumpedToAbout: false,
  jumpedToContact: false,
  jumpedToGreen: false,

  workFilter: "",

  goToNextPage: function ()
  {
    this.inPageTransition = true;

    $(thumbs).removeClass("disabled");

    $("#arrowLeft").fadeOut(400, function ()
    {
      $("#arrowLeft").css("width", "30px");
      $("#arrowLeft").css("left", "-68px");
    });

    $("#arrowRight").fadeOut(400, function ()
    {
      $("#arrowRight img").css("margin-left", "0px");
    });

    var tempCurrentPage = state.currentPage;
    var tempNextPage = state.nextPage;

    $(".portfolio").slideUp(600);

    $("#portfolioArrowLeft").fadeOut(800);
    $("#portfolioArrowRight").fadeOut(800);

    $("#" + this.pages[this.currentPage]).delay(2000).fadeOut(1200);

    $("#thumbs a").delay(2000).stop(true, true).animate({ opacity: 0.01 }, 1200);

    $("#rotationRight").fadeIn(1200, function ()
    {
      $("#thumbs img").attr("src", function ()
      {
        return this.src.replace(state.pages[tempCurrentPage], state.pages[tempNextPage]);
      });

      $("#copyright").animate({ opacity: "1.0" }, 1600, function ()
      {
        animation.thumbNumber = 1;

        animation.selectRandomAnimation();

        $("#intro a").animate({ opacity: 1 }, 600);

        fadeInThumb();

        $("#rotationRight").fadeOut(800, function ()
        {
          state.inPageTransition = false;

          $("#arrowLeft").delay(3000).fadeIn(1000);
          $("#arrowRight").delay(3000).fadeIn(1000);
        });
      });
    });

    state.currentPage += 1;
    state.nextPage += 1;
    state.previousPage += 1;

    if (state.currentPage == 4)
    {
      state.currentPage = 0;
    }
    else if (state.nextPage == 4)
    {
      state.nextPage = 0;
    }
    else if (state.previousPage == 4)
    {
      state.previousPage = 0;
    }
  },

  goToPreviousPage: function ()
  {
    this.inPageTransition = true;

    $(thumbs).removeClass("disabled");

    $("#arrowLeft").fadeOut(400, function ()
    {
      $("#arrowLeft").css("width", "30px");
      $("#arrowLeft").css("left", "-68px");
    });

    $("#arrowRight").fadeOut(400, function ()
    {
      $("#arrowRight img").css("margin-left", "0px");
    });

    var tempCurrentPage = state.currentPage;
    var tempPreviousPage = state.previousPage;

    $("#" + this.pages[this.currentPage]).delay(1100).fadeOut(100);

    $(".portfolio").slideUp(600);

    $("#portfolioArrowLeft").fadeOut(800);
    $("#portfolioArrowRight").fadeOut(800);

    $("#thumbs a").stop(true, true).animate({ opacity: 0.01 }, 1200);

    var tempJumpedToWork = state.jumpedToWork;
    var tempJumpedToAbout = state.jumpedToAbout;
    var tempJumpedToContact = state.jumpedToContact;
    var tempJumpedToGreen = state.jumpedToGreen;

    $("#rotationLeft").fadeIn(1200, function ()
    {
      $("#thumbs img").attr("src", function ()
      {
        return this.src.replace(state.pages[tempCurrentPage], state.pages[tempPreviousPage]);
      });

      $("#copyright").animate({ opacity: "1.0" }, 1600, function ()
      {
        if (!tempJumpedToWork)
        {
          animation.thumbNumber = 1;

          animation.selectRandomAnimation();

          $("#intro a").animate({ opacity: 1 }, 600);

          fadeInThumb();
        }

        $("#rotationLeft").fadeOut(800, function ()
        {
          state.inPageTransition = false;

          $("#arrowLeft").delay(3000).fadeIn(1000);
          $("#arrowRight").delay(3000).fadeIn(1000);
        });
      });
    });

    state.currentPage -= 1;
    state.nextPage -= 1;
    state.previousPage -= 1;

    if (state.currentPage == -1)
    {
      state.currentPage = 3;
    }
    else if (state.nextPage == -1)
    {
      state.nextPage = 3;
    }
    else if (state.previousPage == -1)
    {
      state.previousPage = 3;
    }

    if (state.jumpedToWork || state.jumpedToWorkAll)
    {
      state.currentPage = 0;
      state.nextPage = 1;
      state.previousPage = 3;


      if (!state.jumpedToWorkAll)
      {
        $(thumbs).addClass("disabled");

        //$(thumbsHref).css("cursor", "pointer");

        $(thumbsHref).delay(1000).animate({ opacity: 0.1 }, 400);

        $("." + state.workFilter).delay(1000).animate({ opacity: 1 }, 600);

        $("." + state.workFilter).css("cursor", "pointer");
      }

      $(thumbsHref).unbind();

      $(thumbsHref).hover(
        function ()
        {
          if ($(thumbs).attr("class") != "disabled")
          {
            $(this).animate({ opacity: 1 }, 300);
          }
        },
        function ()
        {
          if ($(thumbs).attr("class") != "disabled")
          {
            $(this).animate({ opacity: 0.3 }, 1200);
          }
        }
      );

      $(thumbsHref).click(function ()
      {
        if (state.pages[state.currentPage] == "work")
        {
          portfolio.currentPage = $(this).attr("href").substring(1);

          $("#loading").fadeIn(800);

          $("#p" + portfolio.currentPage + " div.closeups img.c1").load(function ()
          {
            $("#loading").fadeOut(400);

            $("#p" + portfolio.currentPage).slideDown(800);

            hideArrows();

            $("#portfolioArrowLeft").delay(800).fadeIn(800).animate({ opacity: 0.6 }, 600);
            $("#portfolioArrowRight").delay(800).fadeIn(800).animate({ opacity: 0.6 }, 600);
          })
          .each(function ()
          {
            if (this.complete)
            {
              $(this).trigger("load");
            }
          });
        }
      });

      state.jumpedToWork = false;
      state.jumpedToWorkAll = false;
    }
    else if (state.jumpedToAbout)
    {
      state.currentPage = 1;
      state.nextPage = 2;
      state.previousPage = 0;

      state.jumpedToAbout = false;

      if (about.currentAboutSection != "All.html")
      {
        $("#about").delay(2000).load(about.currentAboutSection, function ()
        {
          $("#about").css("background-image", "url(images/about/" + about.currentAboutSection.replace("html", "jpg") + ")").fadeIn(1000);
        });
      }
    }
    else if (state.jumpedToContact)
    {
      state.currentPage = 2;
      state.nextPage = 3;
      state.previousPage = 1;

      state.jumpedToContact = false;

      if (contact.currentContactSection != "All.html")
      {
        $("#contact").delay(2000).load(contact.currentContactSection, function ()
        {
          $("#contact").css("background-image", "url(images/contact/" + contact.currentContactSection.replace("html", "jpg") + ")").fadeIn(1000);
        });
      }
    }
    else if (state.jumpedToGreen)
    {
      state.currentPage = 3;
      state.nextPage = 0;
      state.previousPage = 2;

      state.jumpedToGreen = false;

      if (green.currentGreenSection != "All.html")
      {
        $("#green").delay(2000).load(green.currentGreenSection, function ()
        {
          $("#green").css("background-image", "url(images/green/" + green.currentGreenSection.replace("html", "jpg") + ")").fadeIn(1000);
        });
      }
    }
  }
};

function fadeInIntroThumb()
{
  $("#intro #intro" + animation.thumbOrder[animation.thumbNumber]).animate({ opacity: 1 }, 400, function ()
  {
    
  });

  animation.thumbNumber++;

  if (animation.thumbNumber <= 45)
  {
    if (animation.thumbNumber == 45)
    {
      $("#preloadIcon").fadeIn(function ()
      {
        $("#preloadIcon").fadeOut(function ()
        {
          $("#preloadIcon").css("left", "100px");
          $("#preloadIcon").attr("src", "images/iconAbout.png");

          $("#preloadIcon").fadeIn("slow", function ()
          {
            $("#preloadIcon").fadeOut("slow", function ()
            {
              $("#preloadFlash").load("preloadFlash.html", function ()
              {
                $("#preloadabout").load("preloadAbout.html");

                //$("#portfolio").load("portfolio.html");

                /*$("#preloadabout").load("aboutWhatWeBelieve.html");
                $("#preloadabout").load("aboutWhatWeCanDo.html");
                $("#preloadabout").load("aboutWhoWeAre.html");*/

                $("#preloadIcon").fadeOut(function ()
                {
                  $("#preloadIcon").css("left", "180px");
                  $("#preloadIcon").attr("src", "images/iconContact.png");

                  $("#preloadIcon").fadeIn(function ()
                  {
                    $("#preloadcontact").load("preloadContact.html", function ()
                    {
                      /*$("#preloadcontact").load("contactLookingForAJob.html");
                      $("#preloadcontact").load("contactLookingForAnAgency.html");*/

                      $("#preloadIcon").fadeOut(function ()
                      {
                        $("#preloadIcon").css("left", "260px");
                        $("#preloadIcon").attr("src", "images/iconGreen.png");

                        $("#preloadIcon").fadeIn(function ()
                        {
                          $("#preloadgreen").load("preloadGreen.html", function ()
                          {
                            /*$("#preloadgreen").load("greenEnvironMental.html");
                            $("#preloadgreen").load("greenEnvironmentallySpeaking.html");
                            $("#preloadgreen").load("greenGreenExpo365.html");*/

                            //$("#preloadwork").load("portfolio.html");

                            //$("#portfolio").load("portfolio.html");

                            $("#preloadIcon").fadeOut("slow");

                            $("#intro img").fadeOut(4000);

                            $("#copyright").animate({ opacity: "1.0" }, 4000, function ()
                            {
                              $(thumbs).removeClass("disabled");

                              animation.selectRandomAnimation();

                              $("#intro img").remove();

                              animation.thumbNumber = 1;

                              fadeInThumb();
                            });
                          })
                          .each(function ()
                          {
                            if (this.complete)
                            {
                              $(this).trigger("load");
                            }
                          });
                        })
                        .each(function ()
                        {
                          if (this.complete)
                          {
                            $(this).trigger("load");
                          }
                        });
                      })
                      .each(function ()
                      {
                        if (this.complete)
                        {
                          $(this).trigger("load");
                        }
                      });
                    })
                    .each(function ()
                    {
                      if (this.complete)
                      {
                        $(this).trigger("load");
                      }
                    });
                  })
                  .each(function ()
                  {
                    if (this.complete)
                    {
                      $(this).trigger("load");
                    }
                  });
                })
                .each(function ()
                {
                  if (this.complete)
                  {
                    $(this).trigger("load");
                  }
                });
              })
              .each(function ()
              {
                if (this.complete)
                {
                  $(this).trigger("load");
                }
              });
            })
            .each(function ()
            {
              if (this.complete)
              {
                $(this).trigger("load");
              }
            });
          })
          .each(function ()
          {
            if (this.complete)
            {
              $(this).trigger("load");
            }
          });
        })
        .each(function ()
        {
          if (this.complete)
          {
            $(this).trigger("load");
          }
        });
      })
      .each(function ()
      {
        if (this.complete)
        {
          $(this).trigger("load");
        }
      });
    }

    $("#copyright").animate({ opacity: "1.0" }, 80, function ()
    {
      fadeInIntroThumb();
    });
  }
}

function fadeInThumb()
{
  if (animation.thumbOrder === undefined)
  {
    alert(animation.thumbNumber);
  }

  var tempThumbNumber = animation.thumbNumber;

  $("#intro #intro" + animation.thumbOrder[tempThumbNumber]).animate({ opacity: 0 }, 400);
  $("#thumbs #thumb" + animation.thumbOrder[tempThumbNumber]).animate({ opacity: 1 }, 400, function ()
  {
    if (state.pages[state.currentPage] != "work")
    {
      $("#thumbs #thumb" + animation.thumbOrder[tempThumbNumber]).animate({ opacity: 0.7 }, 1000);
    }
    else
    {
      $("#thumbs #thumb" + animation.thumbOrder[tempThumbNumber]).delay(4000).animate({ opacity: 0.3 }, 2000);
    }
  });

  animation.thumbNumber++;

  if (animation.thumbNumber <= 45)
  {    
    if (animation.thumbNumber == 45 && firstLoad)
    {
      showNav();

      firstLoad = false;
    }
    else if (animation.thumbNumber == 45)
    {
      if (state.pages[state.currentPage] == "work")
      {
        $(thumbsHref).unbind();

        $(thumbs).removeClass("disabled");

        $(thumbsHref).css("cursor", "pointer");

        $(thumbsHref).hover(
          function ()
          {
            if ($(thumbs).attr("class") != "disabled")
            {
              $(this).animate({ opacity: 1 }, 300);
            }
          },
          function ()
          {
            if ($(thumbs).attr("class") != "disabled")
            {
              $(this).animate({ opacity: 0.3 }, 1200);
            }
          }
        );

        $(thumbsHref).click(function ()
        {
          if (state.pages[state.currentPage] == "work")
          {
            portfolio.currentPage = $(this).attr("href").substring(1);

            $("#loading").fadeIn(800);

            $("#p" + portfolio.currentPage + " div.closeups img.c1").load(function ()
            {
              $("#loading").fadeOut(400);

              $("#p" + portfolio.currentPage).slideDown(800);

              hideArrows();

              $("#portfolioArrowLeft").delay(800).fadeIn(800).animate({ opacity: 0.6 }, 600);
              $("#portfolioArrowRight").delay(800).fadeIn(800).animate({ opacity: 0.6 }, 600);
            })
            .each(function ()
            {
              if (this.complete)
              {
                $(this).trigger("load");
              }
            });
          }
        });
      }
      if (state.pages[state.currentPage] == "about")
      {
        $(thumbs).addClass("disabled");

        $(thumbsHref).css("cursor", "default");

        $("#thumb" + about.whoWeAre).animate({ opacity: 1 }, 400, function ()
        {
          $("#thumb" + about.whatWeCanDo).animate({ opacity: 1 }, 400, function ()
          {
            $("#thumb" + about.whatWeBelieve).animate({ opacity: 1 }, 400, function ()
            {
              $("#thumb" + about.A).animate({ opacity: 1 }, 400, function ()
              {
                $("#thumb" + about.B).animate({ opacity: 1 }, 400, function ()
                {
                  $("#thumb" + about.O).animate({ opacity: 1 }, 400, function ()
                  {
                    $("#thumb" + about.U).animate({ opacity: 1 }, 400, function ()
                    {
                      $("#thumb" + about.T).animate({ opacity: 1 }, 400);
                    });
                  });
                });
              });
            });
          });
        });

        $(thumbsHref).unbind();

        $("#thumb" + about.whoWeAre).css("cursor", "pointer");

        $("#thumb" + about.whoWeAre).click(function ()
        {
          $("#about").css("background-image", "url(images/about/aboutWhoWeAre.jpg)");

          $("#about").load("aboutWhoWeAre.html").fadeIn(1500);
        });

        $("#thumb" + about.whatWeCanDo).css("cursor", "pointer");

        $("#thumb" + about.whatWeCanDo).click(function ()
        {
          $("#about").css("background-image", "url(images/about/aboutWhatWeCanDo.jpg)");

          $("#about").load("aboutWhatWeCanDo.html").fadeIn(1500);
        });

        $("#thumb" + about.whatWeBelieve).css("cursor", "pointer");

        $("#thumb" + about.whatWeBelieve).click(function ()
        {
          $("#about").css("background-image", "url(images/about/aboutWhatWeBelieve.jpg)");

          $("#about").load("aboutWhatWeBelieve.html").fadeIn(1500);
        });
      }
      else if (state.pages[state.currentPage] == "contact")
      {
        $(thumbs).addClass("disabled");

        $(thumbsHref).css("cursor", "default");

        $("#thumb" + contact.lookingForAnAgency).animate({ opacity: 1 }, 400, function ()
        {
          $("#thumb" + contact.lookingForAJob).animate({ opacity: 1 }, 400, function ()
          {
            $("#thumb" + contact.C).animate({ opacity: 1 }, 400, function ()
            {
              $("#thumb" + contact.O).animate({ opacity: 1 }, 400, function ()
              {
                $("#thumb" + contact.N).animate({ opacity: 1 }, 400, function ()
                {
                  $("#thumb" + contact.T).animate({ opacity: 1 }, 400, function ()
                  {
                    $("#thumb" + contact.A).animate({ opacity: 1 }, 400, function ()
                    {
                      $("#thumb" + contact.C2).animate({ opacity: 1 }, 400, function ()
                      {
                        $("#thumb" + contact.T2).animate({ opacity: 1 }, 400);
                      });
                    });
                  });
                });
              });
            });
          });
        });

        $(thumbsHref).unbind();

        $("#thumb" + contact.lookingForAnAgency).css("cursor", "pointer");

        $("#thumb" + contact.lookingForAnAgency).click(function ()
        {
          $("#contact").css("background-image", "url(images/contact/contactLookingForAnAgency.jpg)");

          $("#contact").load("contactLookingForAnAgency.html").fadeIn(1500);
        });

        $("#thumb" + contact.lookingForAJob).css("cursor", "pointer");

        $("#thumb" + contact.lookingForAJob).click(function ()
        {
          $("#contact").css("background-image", "url(images/contact/contactLookingForAJob.jpg)");

          $("#contact").load("contactLookingForAJob.html").fadeIn(1500);
        });
      }
      else if (state.pages[state.currentPage] == "green")
      {
        $(thumbs).addClass("disabled");

        $(thumbsHref).css("cursor", "default");

        $("#thumb" + green.environMental).animate({ opacity: 1 }, 400, function ()
        {
          $("#thumb" + green.environmentallySpeaking).animate({ opacity: 1 }, 400, function ()
          {
            $("#thumb" + green.greenExpo365).animate({ opacity: 1 }, 400, function ()
            {
              $("#thumb" + green.G).animate({ opacity: 1 }, 400, function ()
              {
                $("#thumb" + green.R).animate({ opacity: 1 }, 400, function ()
                {
                  $("#thumb" + green.E).animate({ opacity: 1 }, 400, function ()
                  {
                    $("#thumb" + green.E2).animate({ opacity: 1 }, 400, function ()
                    {
                      $("#thumb" + green.N).animate({ opacity: 1 }, 400);
                    });
                  });
                });
              });
            });
          });
        });

        $(thumbsHref).unbind();

        $("#thumb" + green.environMental).css("cursor", "pointer");

        $("#thumb" + green.environMental).click(function ()
        {
          $("#green").css("background-image", "url(images/green/greenEnvironMental.jpg)");

          $("#green").load("greenEnvironMental.html").fadeIn(1500);
        });

        $("#thumb" + green.environmentallySpeaking).css("cursor", "pointer");

        $("#thumb" + green.environmentallySpeaking).click(function ()
        {
          $("#green").css("background-image", "url(images/green/greenEnvironmentallySpeaking.jpg)");

          $("#green").load("greenEnvironmentallySpeaking.html").fadeIn(1500);
        });

        $("#thumb" + green.greenExpo365).css("cursor", "pointer");

        $("#thumb" + green.greenExpo365).click(function ()
        {
          $("#green").css("background-image", "url(images/green/greenGreenExpo365.jpg)");

          $("#green").load("greenGreenExpo365.html").fadeIn(1500);
        });
      }
    }

    $("#copyright").animate({ opacity: "1.0" }, 80, function ()
    {
      fadeInThumb();
    });
  }
}

function LoadIntroThumbs(introThumbs, introThumbsHref)
{
  $("#intro45 img").load(function ()
  {
    $("#loading").fadeOut(400);

    fadeInIntroThumb();
  })
  .each(function ()
  {
    if (this.complete)
    {
      $(this).trigger("load");
    }
  });
}

$(document).ready(function ()
{
  var ie = $.browser.msie;
  
  if (ie)
  {
    if ($.browser.version == "6.0")
    {
      $("#container").before("<div id=\"upgrade\"><a id=\"closeUpgradeWarning\" href=\"#\">close [x]</a><img src=\"images/upgrade.jpg\" width=\"501\" height=\"346\" alt=\"\" usemap=\"#upgradeImage\" /><map name=\"upgradeImage\"><area shape=\"rect\" coords=\"20,20,470,100\" href=\"http://www.microsoft.com/windows/internet-explorer/default.aspx\" alt=\"Internet Explorer\" target=\"_blank\" /><area shape=\"rect\" coords=\"270,140,430,180\" href=\"http://www.google.com/chrome\" alt=\"Google Chrome\" target=\"_blank\" /><area shape=\"rect\" coords=\"270,190,430,225\" href=\"http://www.mozilla.com/en-US/firefox/\" alt=\"Mozilla Firefox\" target=\"_blank\" /><area shape=\"rect\" coords=\"270,230,430,270\" href=\"http://www.opera.com/\" alt=\"Opera\" target=\"_blank\" /><area shape=\"rect\" coords=\"270,275,430,315\" href=\"http://www.apple.com/safari/\" alt=\"Apple Safari\" target=\"_blank\" /></map></div>");
    }
    // Check and see if this is necessary for IE.
    /* 
    $.ajaxSetup(
    {
      cache: false
    });*/ 

    $("#closeUpgradeWarning").click(function ()
    {
      $("#upgrade").fadeOut(1000);
    });
  }

  // Open external website links in a new tab.
  $('a[rel="external"]').live("click", function ()
  {
    window.open($(this).attr('href'));
    return false;
  });
  /*
  $(window).load(function ()
  {
    $("#portfolio").load("portfolio.html");
  });*/

  $("#loading").fadeIn(800);

  animation.selectRandomAnimation();

  var arrowLeft = $("#arrowLeft");

  $(arrowLeft).hover(
    function ()
    {
      if (!state.inPageTransition)
      {
        $(arrowLeft).stop(true, true).animate(
        {
          width: '+=10px',
          left: '-=10px'
        }, 200);
      }
    },
    function ()
    {
      if (!state.inPageTransition)
      {
        $(arrowLeft).stop(true, true).animate(
        {
          width: '-=10px',
          left: '+=10px'
        }, 200);
      }
    }
  );

  $("#arrowRight").hover(
    function ()
    {
      if (!state.inPageTransition)
      {
        $("#arrowRight img").stop(true, true).animate(
        {
          marginLeft: '+=10px'
        }, 200);
      }
    },
    function ()
    {
      if (!state.inPageTransition)
      {
        $("#arrowRight img").stop(true, true).animate(
        {
          marginLeft: '-=10px'
        }, 200);
      }
    }
  );

  $("#portfolioArrowLeft").hover(
    function ()
    {
      $(this).stop().animate({ opacity: 1.0 }, 400);
    },
    function ()
    {
      $(this).stop().animate({ opacity: 0.6 }, 200);
    }
  );

  $("#portfolioArrowRight").hover(
    function ()
    {
      $(this).stop().animate({ opacity: 1.0 }, 400);
    },
    function ()
    {
      $(this).stop().animate({ opacity: 0.6 }, 200);
    }
  );

  $("#portfolioArrowLeft").click(function (event)
  {
    event.preventDefault();

    if (!state.inPageTransition)
    {
      state.inPageTransition = true;

      $("#p" + portfolio.currentPage).slideUp(600, function ()
      {
        $(".closeups div").css("left", "0");

        if (ie)
        {
          var player = $f();

          player.pause();
        }

        portfolio.currentPage--;

        if (portfolio.currentPage < 10 && portfolio.currentPage !== 0)
        {
          portfolio.currentPage = "0" + portfolio.currentPage;
        }
        else if (portfolio.currentPage === 0)
        {
          portfolio.currentPage = "45";
        }

        $("#p" + portfolio.currentPage).slideDown(800, function ()
        {
          state.inPageTransition = false;
        });
      });
    }
  });

  $("#portfolioArrowRight").click(function (event)
  {
    event.preventDefault();

    if (!state.inPageTransition)
    {
      state.inPageTransition = true;

      $("#p" + portfolio.currentPage).slideUp(600, function ()
      {
        $(".closeups div").css("left", "0");

        if (ie)
        {
          var player = $f();

          player.pause();
        }

        portfolio.currentPage++;

        if (portfolio.currentPage < 10)
        {
          portfolio.currentPage = "0" + portfolio.currentPage;
        }
        else if (portfolio.currentPage == 46)
        {
          portfolio.currentPage = "01";
        }

        $("#p" + portfolio.currentPage).slideDown(800, function ()
        {
          state.inPageTransition = false;
        });
      });
    }
  });

  $(arrowLeft).click(function ()
  {
    state.goToPreviousPage();
  });

  $("#arrowRight").click(function ()
  {
    state.goToNextPage();
  });

  introThumbs = $("#intro");

  introThumbsHref = $("#intro a");

  LoadIntroThumbs(introThumbs, introThumbsHref);

  $("#portfolio").load("portfolio.html");

  thumbs = $("#thumbs");

  thumbsHref = $("#thumbs a");

  $(thumbs).addClass("disabled");

  $(thumbsHref).hover(
    function ()
    {
      if ($(thumbs).attr("class") != "disabled")
      {
        $(this).animate({ opacity: 1 }, 300);
      }
    },
    function ()
    {
      if ($(thumbs).attr("class") != "disabled")
      {
        $(this).animate({ opacity: 0.3 }, 1200);
      }
    }
  );

  $(thumbsHref).click(function ()
  {
    if (state.pages[state.currentPage] == "work")
    {
      portfolio.currentPage = $(this).attr("href").substring(1);

      $("#loading").fadeIn(800);

      $("#p" + portfolio.currentPage + " div.closeups img.c1").load(function ()
      {
        $("#loading").fadeOut(400);

        $("#p" + portfolio.currentPage).slideDown(800);

        hideArrows();

        $("#portfolioArrowLeft").delay(800).fadeIn(800).animate({ opacity: 0.6 }, 600);
        $("#portfolioArrowRight").delay(800).fadeIn(800).animate({ opacity: 0.6 }, 600);
      })
      .each(function ()
      {
        if (this.complete)
        {
          $(this).trigger("load");
        }
      });
    }
  });

  $(".icons a").live("click", function (event)
  {
    event.preventDefault();

    $(".icons a").removeClass("current");

    $(this).addClass("current");

    var imageNumber = $(this).attr("href");

    imageNumber = imageNumber.substring($.inArray("#", imageNumber) + 1);

    var newLeft = -(imageNumber * 853) + 853;

    $(".closeups div").stop(true, true).animate({ left: newLeft }, 1200);
  });

  $(".portfolio .close a").live("click", function (event)
  {
    event.preventDefault();

    $(this).parent().parent().slideUp(600, function ()
    {
      $(".closeups div").css("left", "0");

      if (ie)
      {
        var player = $f();

        player.pause();
      }
    });

    $("#portfolioArrowLeft").fadeOut(600);
    $("#portfolioArrowRight").fadeOut(600, function ()
    {
      showArrows();
    });
  });

  $("#footer .linkSection").css("margin-top", "-30px");

  $("#footer .linkSection").hoverIntent(
    function ()
    {
      $(this).animate({ paddingRight: '+=60px' }, 200);
      $(".links", this).animate({ opacity: 1, height: '190' }, 400);

    },
    function ()
    {
      var currentLinkSection = $(this);

      $(".links", this).animate({ opacity: 0, height: '0' }, 400);
      currentLinkSection.animate({ paddingRight: '-=60px' }, 400);
    }
  );

  $("#iconWork .links a").click(function ()
  {
    if (state.pages[state.currentPage] != "work")
    {
      if ($(this).attr("href") != "#All")
      {
        state.jumpedToWork = true;

        state.workFilter = $(this).attr("href").substring(1);
      }
      else if ($(this).attr("href") == "#All")
      {
        state.jumpedToWorkAll = true;
      }

      state.previousPage = 0;
      state.goToPreviousPage();
    }
    else
    {
      $(".portfolio").slideUp(600);

      $("#portfolioArrowLeft").fadeOut(800);
      $("#portfolioArrowRight").fadeOut(800, function ()
      {
        showArrows();
      });

      $(thumbs).addClass("disabled");

      $(thumbsHref).animate({ opacity: 0.1 }, 400);

      var currentSection = $(this).attr("href");

      $("." + currentSection.substring(1)).animate({ opacity: 1 }, 600);

      $("." + currentSection.substring(1)).css("cursor", "pointer");

      if ($(this).attr("href") == "#All")
      {
        $(thumbs).removeClass("disabled");

        $(thumbsHref).animate({ opacity: 0.3 }, 600);
      }
    }
  });

  $("#iconAbout .links a").click(function ()
  {
    about.currentAboutSection = $(this).attr("href").substring(1) + ".html";

    if (state.pages[state.currentPage] != "about")
    {
      state.jumpedToAbout = true;

      state.previousPage = 1;
      state.goToPreviousPage();
    }
    else
    {
      $("#about").fadeOut(800, function ()
      {
        if (about.currentAboutSection != "All.html")
        {
          $("#about").load(about.currentAboutSection, function ()
          {
            $("#about").css("background-image", "url(images/about/" + about.currentAboutSection.replace("html", "jpg") + ")").fadeIn(1200);
          });
        }
      });
    }
  });

  $("#iconContact .links a").click(function ()
  {
    contact.currentContactSection = $(this).attr("href").substring(1) + ".html";

    if (state.pages[state.currentPage] != "contact")
    {
      state.jumpedToContact = true;

      state.previousPage = 2;
      state.goToPreviousPage();
    }
    else
    {
      $("#contact").fadeOut(800, function ()
      {
        if (contact.currentContactSection != "All.html")
        {
          $("#contact").load(contact.currentContactSection, function ()
          {
            $("#contact").css("background-image", "url(images/contact/" + contact.currentContactSection.replace("html", "jpg") + ")").fadeIn(1200);
          });
        }
      });
    }
  });

  $("#iconGreen .links a").click(function ()
  {
    green.currentGreenSection = $(this).attr("href").substring(1) + ".html";

    if (state.pages[state.currentPage] != "green")
    {
      state.jumpedToGreen = true;

      state.previousPage = 3;
      state.goToPreviousPage();
    }
    else
    {
      $("#green").fadeOut(800, function ()
      {
        if (green.currentGreenSection != "All.html")
        {
          $("#green").load(green.currentGreenSection, function ()
          {
            $("#green").css("background-image", "url(images/green/" + green.currentGreenSection.replace("html", "jpg") + ")").fadeIn(1200);
          });
        }
      });
    }
  });
});

/**
* hoverIntent r5 // 2007.03.27 // jQuery 1.1.2+
* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
*/
(function ($) { $.fn.hoverIntent = function (f, g) { var cfg = { sensitivity: 7, interval: 100, timeout: 0 }; cfg = $.extend(cfg, g ? { over: f, out: g} : f); var cX, cY, pX, pY; var track = function (ev) { cX = ev.pageX; cY = ev.pageY; }; var compare = function (ev, ob) { ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t); if ((Math.abs(pX - cX) + Math.abs(pY - cY)) < cfg.sensitivity) { $(ob).unbind("mousemove", track); ob.hoverIntent_s = 1; return cfg.over.apply(ob, [ev]); } else { pX = cX; pY = cY; ob.hoverIntent_t = setTimeout(function () { compare(ev, ob); }, cfg.interval); } }; var delay = function (ev, ob) { ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t); ob.hoverIntent_s = 0; return cfg.out.apply(ob, [ev]); }; var handleHover = function (e) { var p = (e.type == "mouseover" ? e.fromElement : e.toElement) || e.relatedTarget; while (p && p != this) { try { p = p.parentNode; } catch (e) { p = this; } } if (p == this) { return false; } var ev = jQuery.extend({}, e); var ob = this; if (ob.hoverIntent_t) { ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t); } if (e.type == "mouseover") { pX = ev.pageX; pY = ev.pageY; $(ob).bind("mousemove", track); if (ob.hoverIntent_s != 1) { ob.hoverIntent_t = setTimeout(function () { compare(ev, ob); }, cfg.interval); } } else { $(ob).unbind("mousemove", track); if (ob.hoverIntent_s == 1) { ob.hoverIntent_t = setTimeout(function () { delay(ev, ob); }, cfg.timeout); } } }; return this.mouseover(handleHover).mouseout(handleHover); }; })(jQuery);
