var mouseScrollEnabled = false;
var speed_x;
var speed_y;
var temp_x;
var temp_y;

function startMouseScroll() {
  mouseScrollEnabled = true;
  $("#enlarged_catalog_image").mousemove(function (e) {
    speed_x = parseInt((e.pageX - $(window).width() / 2 - document.documentElement.scrollLeft)/($(window).width()/200));
    speed_y = parseInt((e.pageY - $(window).height() / 2 - document.documentElement.scrollTop)/($(window).height()/200));
  });
  doMouseScroll();
}

function doMouseScroll() {
  if (!mouseScrollEnabled) return;
  temp_x = document.documentElement.scrollLeft;
  temp_y = document.documentElement.scrollTop;
  document.documentElement.scrollLeft += speed_x;
  document.documentElement.scrollTop += speed_y;
  if (temp_x == document.documentElement.scrollLeft) speed_x = 0;
  if (temp_y == document.documentElement.scrollTop) speed_y = 0;
  if (speed_x != 0 || speed_y != 0) {
    $("#zoom_out").hide();
    $("#enlarged_catalog_image").css("cursor", "all-scroll, move, crosshair");
  }
  else {
    $("#zoom_out").show();
    $("#enlarged_catalog_image").css("cursor", "none");
  }
  setTimeout("doMouseScroll();", 1);
}

function endMouseScroll() {
  mouseScrollEnabled = false;
  $("#enlarged_catalog_image").unbind("mousemove");
}

function getViewableWidth() {
  if (typeof window.innerWidth != 'undefined') {
    return window.innerWidth;
  } else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) {
    return document.documentElement.clientWidth;
  } else {
    return document.getElementsByTagCategoryName('body')[0].clientWidth;
  }
}

function getViewableHeight() {
  if (typeof window.innerWidth != 'undefined') {
    return window.innerHeight;
  } else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) {
    return document.documentElement.clientHeight
  } else {
    return document.getElementsByTagCategoryName('body')[0].clientHeight
  }
}

function padZeros(number, length) {
  if (isNaN(number)) number = 0;
  var str = "" + number;
  var logval = parseInt(Math.log(number) / Math.log(10));
  if (isNaN(logval)) logval = 0;
  for (var i = logval; i < length - 1; i++) str = "0" + str;
  return str;
}

function scrollToTop() {
  var current = parseInt(document.documentElement.scrollTop);
  if (current == 0) return;
  var moveHeight = parseInt(current/Math.pow(current,0.25));
  if (moveHeight < 1) moveHeight = 1;
  document.documentElement.scrollTop = current - moveHeight;
  setTimeout("scrollToTop();", 30);
}
$(window).resize(function () {
  if ($(window).width() < 1000) $("#button-to-top").css("right", "0px");
  else $("#button-to-top").css("right", parseInt(($(window).width() - 1000) / 2) + "px");
});
$("#button-to-top").click(function () { scrollToTop(); });

/*
$(window).resize(function () {
  if (document.location.href.indexOf(".test") >= 0) return; // _new
  var max_height = $(window).height();
  //if (max_height > 750) max_height = 750;
  if ($("#main-body").length > 0) {
    var margin = (max_height - 155 - $("#main-body").height());
    if (margin < 0) margin = 0;
    var margin_top = parseInt(margin * 0.0);
    var margin_bottom = margin - margin_top
    $("#main-body").css({ "padding-top": margin_top + "px", "padding-bottom": margin_bottom + "px" });
  } else {
    var margin = (max_height - 155 - $("#main").height());
    if (margin < 0) margin = 0;
    var margin_top = parseInt(margin * 0.0);
    var margin_bottom = margin - margin_top
    $("#main").css({ "margin-top": margin_top + "px", "margin-bottom": margin_bottom + "px" });
  }
});

$(window).resize(function () {
  $("body").css("height", "");
  var height_body = $("body").height();
  var height_window = $(window).height();
  if (height_body < height_window) height_body = height_window;
  $("body").css("height", height_body + "px");
});
*/

$(document).ready(function () { setTimeout('$(window).resize();', 350); });
