/*
Copyright (c) 2009 Dimas Begunoff, http://www.farinspace.com
Licensed under the MIT license
http://en.wikipedia.org/wiki/MIT_License
*/
function imgpreload(a,b){if(b instanceof Function){b={all:b}}if(typeof a=="string"){a=[a]}var c=[];var t=a.length;var i=0;for(i;i<t;i++){var d=new Image();d.onload=function(){c.push(this);if(b.each instanceof Function){b.each.call(this)}if(c.length>=t&&b.all instanceof Function){b.all.call(c)}};d.src=a[i]}}if(typeof jQuery!="undefined"){(function($){$.imgpreload=imgpreload;$.fn.imgpreload=function(b){b=$.extend({},$.fn.imgpreload.defaults,(b instanceof Function)?{all:b}:b);this.each(function(){var a=this;imgpreload($(this).attr('src'),function(){if(b.each instanceof Function){b.each.call(a)}})});var c=[];this.each(function(){c.push($(this).attr('src'))});var d=this;imgpreload(c,function(){if(b.all instanceof Function){b.all.call(d)}});return this};$.fn.imgpreload.defaults={each:null,all:null}})(jQuery)}

$(document).ready(function() {
  $.imgpreload(function(){
    // Determine the current height and set it to allow all colums to be same height
    var h = $("#page_body").height();
    $("#page_body").height(h);  
  });
});


// home
var hs = {
  hId: null,
  hNavId: null,
  hNavItemId: null,
  hList: new Array(),
  hImgList: new Array(),
  hCurrIndex: 0,
  hDelay: 8000,
  heroTimer: null, // hero spot timer
  heroTimer_is_on: false,
  debug: false,
  init: function() {
    $.ajax({
      url: '/index.php/shared/hs_json',
      dataType: 'json',
      error: function(r, t, e) { if(hs.debug) {}},
      success: function(data) {
        hs.hId = data.hero_id;
        hs.hNavId = data.hero_nav_id;
        hs.hNavItemId = data.hero_nav_parts_id;      
        $.each(data.heroes, function(index) {
          hs.hList.push(this);
          hs.hImgList.push(this.path);
        });
        hs.preload(hs.hImgList);
        if(hs.debug) {  }
        hs.createNav();
      }
    });
  },
  createNav: function() {
    for(i = 0; i < hs.hList.length; i++) {      
      var e = "<li id='" + hs.hNavItemId + i +"'><a href='javascript:hs.updateNav(" + i + ");'></a></li>";
      $("#" + hs.hNavId).append(e);
    }
    hs.updateNav(0);
  },
  updateNav: function(ind) {
    hs.hCurrIndex = ind;
    for(i = 0; i < hs.hList.length; i++) { $("#" + hs.hNavItemId + i + " a").removeClass("active"); }
    $("#" + hs.hNavItemId + hs.hCurrIndex + " a").addClass("active");
    hs.rotate();
  },
  rotate: function() {
    var hero;
    $("#" + hs.hId).fadeOut("slow", function(){
      hero = hs.hList[hs.hCurrIndex];
      $("#hs_info a").fadeOut(function(){
        $("#hs_info a").attr("href", hero.url).html(hero.title).fadeIn();
      });
     $(this).html("<img src='" + hero.path + "' alt='slideshow' width='388' height='308'/>");   
      $("#" + hs.hId).fadeIn("slow");
    });
    hs.setTimer();    
  },
  setTimer: function() {
    if (hs.heroTimer_is_on == true) clearInterval(hs.heroTimer);
    hs.heroTimer = setInterval('hs.nextHero()', hs.hDelay);
    hs.heroTimer_is_on = true;
  },
  nextHero: function() {
    if(++hs.hCurrIndex >= hs.hList.length) { hs.hCurrIndex = 0; }
    hs.updateNav(hs.hCurrIndex);  
  },
  preload: function(arr) {
    $.imgpreload(arr, { 
      all: function() {}}); 
  }
}









var agSlides = {
  hId: null,
  hNavId: null,
  hNavItemId: null,
  hList: new Array(),
  hImgList: new Array(),
  hCurrIndex: 0,
  hDelay: 8000,
  heroTimer: null, // hero spot timer
  heroTimer_is_on: false,
  debug: false,
  init: function() {
    $.ajax({
      url: '/index.php/shared/ag_json',
      dataType: 'json',
      error: function(r, t, e) { if(hs.debug) {}},
      success: function(data) {
        hs.hId = data.hero_id;
        hs.hNavId = data.hero_nav_id;
        hs.hNavItemId = data.hero_nav_parts_id;      
        $.each(data.heroes, function(index) {
          hs.hList.push(this);
          hs.hImgList.push(this.path);
        });
        hs.preload(hs.hImgList);
        if(hs.debug) {  }
        hs.createNav();
      }
    });
  },
  createNav: function() {
    for(i = 0; i < hs.hList.length; i++) {      
      var e = "<li id='" + hs.hNavItemId + i +"'><a href='javascript:hs.updateNav(" + i + ");'></a></li>";
      $("#" + hs.hNavId).append(e);
    }
    hs.updateNav(0);
  },
  updateNav: function(ind) {
    hs.hCurrIndex = ind;
    for(i = 0; i < hs.hList.length; i++) { $("#" + hs.hNavItemId + i + " a").removeClass("active"); }
    $("#" + hs.hNavItemId + hs.hCurrIndex + " a").addClass("active");
    hs.rotate();
  },
  rotate: function() {
    var hero;
    $("#" + hs.hId).fadeOut("slow", function(){
      hero = hs.hList[hs.hCurrIndex];
      $("#hs_info a").fadeOut(function(){
        $("#hs_info a").attr("href", hero.url).html(hero.title).fadeIn();
      });
       $(this).html("<img src='" + hero.path + "' alt='slideshow' width='388' height='308'/>");
      $("#" + hs.hId).fadeIn("slow");
    });
    hs.setTimer();    
  },
  setTimer: function() {
    if (hs.heroTimer_is_on == true) clearInterval(hs.heroTimer);
    hs.heroTimer = setInterval('hs.nextHero()', hs.hDelay);
    hs.heroTimer_is_on = true;
  },
  nextHero: function() {
    if(++hs.hCurrIndex >= hs.hList.length) { hs.hCurrIndex = 0; }
    hs.updateNav(hs.hCurrIndex);  
  },
  preload: function(arr) {
    $.imgpreload(arr, { 
      all: function() {}}); 
  }
}









var concreteSlides = {
  hId: null,
  hNavId: null,
  hNavItemId: null,
  hList: new Array(),
  hImgList: new Array(),
  hCurrIndex: 0,
  hDelay: 8000,
  heroTimer: null, // hero spot timer
  heroTimer_is_on: false,
  debug: false,
  init: function() {
    $.ajax({
      url: '/index.php/shared/concrete_json',
      dataType: 'json',
      error: function(r, t, e) { if(hs.debug) {}},
      success: function(data) {
        hs.hId = data.hero_id;
        hs.hNavId = data.hero_nav_id;
        hs.hNavItemId = data.hero_nav_parts_id;      
        $.each(data.heroes, function(index) {
          hs.hList.push(this);
          hs.hImgList.push(this.path);
        });
        hs.preload(hs.hImgList);
        if(hs.debug) {  }
        hs.createNav();
      }
    });
  },
  createNav: function() {
    for(i = 0; i < hs.hList.length; i++) {      
      var e = "<li id='" + hs.hNavItemId + i +"'><a href='javascript:hs.updateNav(" + i + ");'></a></li>";
      $("#" + hs.hNavId).append(e);
    }
    hs.updateNav(0);
  },
  updateNav: function(ind) {
    hs.hCurrIndex = ind;
    for(i = 0; i < hs.hList.length; i++) { $("#" + hs.hNavItemId + i + " a").removeClass("active"); }
    $("#" + hs.hNavItemId + hs.hCurrIndex + " a").addClass("active");
    hs.rotate();
  },
  rotate: function() {
    var hero;
    $("#" + hs.hId).fadeOut("slow", function(){
      hero = hs.hList[hs.hCurrIndex];
      $("#hs_info a").fadeOut(function(){
        $("#hs_info a").attr("href", hero.url).html(hero.title).fadeIn();
      });
      $(this).html("<img src='" + hero.path + "' alt='slideshow' width='388' height='308'/>"); 
      $("#" + hs.hId).fadeIn("slow");
    });
    hs.setTimer();    
  },
  setTimer: function() {
    if (hs.heroTimer_is_on == true) clearInterval(hs.heroTimer);
    hs.heroTimer = setInterval('hs.nextHero()', hs.hDelay);
    hs.heroTimer_is_on = true;
  },
  nextHero: function() {
    if(++hs.hCurrIndex >= hs.hList.length) { hs.hCurrIndex = 0; }
    hs.updateNav(hs.hCurrIndex);  
  },
  preload: function(arr) {
    $.imgpreload(arr, { 
      all: function() {}}); 
  }
}









var constructionSlides = {
  hId: null,
  hNavId: null,
  hNavItemId: null,
  hList: new Array(),
  hImgList: new Array(),
  hCurrIndex: 0,
  hDelay: 8000,
  heroTimer: null, // hero spot timer
  heroTimer_is_on: false,
  debug: false,
  init: function() {
    $.ajax({
      url: '/index.php/shared/construction_json',
      dataType: 'json',
      error: function(r, t, e) { if(hs.debug) {}},
      success: function(data) {
        hs.hId = data.hero_id;
        hs.hNavId = data.hero_nav_id;
        hs.hNavItemId = data.hero_nav_parts_id;      
        $.each(data.heroes, function(index) {
          hs.hList.push(this);
          hs.hImgList.push(this.path);
        });
        hs.preload(hs.hImgList);
        if(hs.debug) {  }
        hs.createNav();
      }
    });
  },
  createNav: function() {
    for(i = 0; i < hs.hList.length; i++) {      
      var e = "<li id='" + hs.hNavItemId + i +"'><a href='javascript:hs.updateNav(" + i + ");'></a></li>";
      $("#" + hs.hNavId).append(e);
    }
    hs.updateNav(0);
  },
  updateNav: function(ind) {
    hs.hCurrIndex = ind;
    for(i = 0; i < hs.hList.length; i++) { $("#" + hs.hNavItemId + i + " a").removeClass("active"); }
    $("#" + hs.hNavItemId + hs.hCurrIndex + " a").addClass("active");
    hs.rotate();
  },
  rotate: function() {
    var hero;
    $("#" + hs.hId).fadeOut("slow", function(){
      hero = hs.hList[hs.hCurrIndex];
      $("#hs_info a").fadeOut(function(){
        $("#hs_info a").attr("href", hero.url).html(hero.title).fadeIn();
      });
      // $(this).css("background", "url('" + hero.path + "') no-repeat");  
      $(this).html("<img src='" + hero.path + "' alt='slideshow' width='388' height='308'/>");
      $("#" + hs.hId).fadeIn("slow");
    });
    hs.setTimer();    
  },
  setTimer: function() {
    if (hs.heroTimer_is_on == true) clearInterval(hs.heroTimer);
    hs.heroTimer = setInterval('hs.nextHero()', hs.hDelay);
    hs.heroTimer_is_on = true;
  },
  nextHero: function() {
    if(++hs.hCurrIndex >= hs.hList.length) { hs.hCurrIndex = 0; }
    hs.updateNav(hs.hCurrIndex);  
  },
  preload: function(arr) {
    $.imgpreload(arr, { 
      all: function() {}}); 
  }
}
