/**
 * JavaScript behaviors for the construction action controller.
 *
 * @copyright  Copyright (c) 2005-2008 Found Line, Inc. (http://www.foundline.com/)
 * @version    $Id: construction.js 110 2008-08-10 15:05:56Z bradley.holt $
 */


$("document").ready(function() {

    $("dl#construction").empty();

    var locationParamsAndValues = window.location.pathname.split("/");
    locationParamsAndValues = locationParamsAndValues.splice(3, 2);
    var newLocation = locationParamsAndValues.join("/") + "/";
    if (newLocation.length > 1) {
        window.location = "/what-we-do/construction/#" + newLocation;
    } else {
      $.history.init(function (hash) {
          if (hash.length > 0) {
              var paramsAndValues = hash.split("/");
              var params = new Array();
              var param;
              var isParam = true;
              for (var i in paramsAndValues) {
                  var paramOrValue = paramsAndValues[i];
                  if (isParam) {
                      param = paramOrValue;
                  } else {
                      params[param] = paramOrValue;
                  }
                  isParam = !isParam;
              }
              var step = parseInt(params["step"]);
              $("dl#construction").load("/what-we-do/construction/step/" + step + "/ dl#construction dt, dl#construction dd");
              if (step <= 1) {
                  $(".construction a.previous").hide();
                  $(".construction span.previous").show();
              }
              if (step >= 9) {
                  $(".construction a.next").hide();
                  $(".construction span.next").show();
              }
              if (step > 1) {
                  $(".construction a.previous").attr("href", "#step/" + (step - 1) + "/");
                  $(".construction span.previous").hide();
                  $(".construction a.previous").show();
              }
              if (step < 9) {
                  $(".construction a.next").attr("href", "#step/" + (step + 1) + "/");
                  $(".construction a.next").show();
                  $(".construction span.next").hide();
              }
          } else {
              $.history.load("step/1/");
          }
      });
    }
    
});
