function slideSwitch() {
    var $active = $('#slideshow IMG.active');

    if ( $active.length == 0 ) $active = $('#slideshow IMG:last');

    var $next =  $active.next().length ? $active.next()
        : $('#slideshow IMG:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}


function translateTo(a) {
    $("body").translate(a, {
        not: "pre, .jq-translate-ui, #primary-links, #footer",
        start: function () {
            $("#language-loading").show()
        },
        complete: function () {
            $("#language-loading").hide()
        }
    })
}


$(document).ready(function () {
  var cache = [];
  var cacheImage = document.createElement('img');
  cacheImage.src = "images/css/navsprite.gif";
  cache.push(cacheImage);

  if ($('body').attr('id')=='home' ) {
    setInterval( "slideSwitch()", 5000 );
  }
  if ($('body').attr('id')=='portfolio' ) {
    $("a[rel='kingscross']").colorbox({transition:"none", width:"85%", height:"85%"});
    $("a[rel='sheptonmallet']").colorbox({transition:"none", width:"85%", height:"85%"});
    $("a[rel='radartower']").colorbox({transition:"none", width:"85%", height:"85%"});
  }

  $.translate(function(){ //when the Google Language API is loaded

  $.translate.ui({
    tags: ["select", "option"],
    filter: $.translate.isTranslatable,
    label: $.translate.toNativeLanguage ||
    function (c, b) {
      return $.translate.capitalize(b)
    },
    includeUnknown: false
    }).change(function () {
      var b = $(this).val();
      translateTo(b);
      $.cookie("destLang", b, { path: "/"})
      }).val("English").prependTo("#language");
      $.translate.getBranding('vertical').appendTo($("#powered"));
      var a = $.cookie("destLang");
      if (a && a != "en") {
        translateTo(a)
      $(".jq-translate-ui").val(a);
      }
  });
});

