$(document).ready(function() {

  // show submenus on header navigation
  $("#header-navigation li.level1").hover(function(){
    if ($(this).hasClass("activeFreeze")) {
    
    } else {
      $(this).addClass("active");
      $("#header-navigation li.activeFreeze ul").hide();
    }
  }, function(){
    $(this).removeClass("active");
    $("#header-navigation li.activeFreeze ul").show();
  });
  
    
  moveBgAround();
  
  if ($("#viewport2").length) {
    $("#viewport2").mapbox({
      mousewheel: true,
      layerSplit: 8
    });
  }
  
  $(".map-control a").click(function() {
    var viewport = $("#viewport2");
    
    //this.className is same as method to be called
    if (this.className == "zoom" || this.className == "back") {
      viewport.mapbox(this.className, 2);//step twice
    } else {
      viewport.mapbox(this.className);
    }
    
    return false;
  });


});


// clear textfield onFocus, used for search field
function clearInput (field) {
  field.value = "";
}

// move background of map
function moveBgAround() {
  var x = Math.floor(Math.random()*1200);
  var y = Math.floor(Math.random()*900);
  var time =  7000;
  
  $('.scrollBg').animate({
    backgroundPosition: '(' + (x * -1) + 'px ' + (y * -1) + 'px)'
  }, time, "swing", function() {
      moveBgAround();
  });
}
