  /*offset based on html-code*/
  var offset_width = 200;
  var offset_height = 130;

  /*max size of images to prevent scaling above max-size*/
  var max_width = 1500;
  var max_height = 1000;
  
  var new_width = max_width;
  var new_height = max_height;
  

function init_index() {
$(function() {
  var galleries = $('.ad-gallery').adGallery({
  width: 1,
  height: 1,
  animation_speed: 1500,
  display_next_and_prev: false, // Can you navigate by clicking on the left/right on the image?
  display_back_and_forward: false,
  slideshow: {
    enable: true,
    autostart: true,
    speed: 5000
  }
  });
});

jQuery.event.add(window, "resize", resizeImageGallery);
$(document).ready(resizeImageGallery);

}


function init_gallery() {
  $(function() {
      var galleries = $('.ad-gallery').adGallery({
      width: 1,
      height: 1
      });
    });

  jQuery.event.add(window, "resize", resizeImageGallery);
  $(document).ready(resizeImageGallery);
}


function initSimple(minSize) {
  jQuery.event.add( window, "resize", function() {
    resizeSimple(minSize);
  });

  $(document).ready(function() {
    resizeSimple(minSize);
  });
}


function resizeImageGallery()
{ 
  getNewSize();
  
  
  $(".ad-image-wrapper").css('width', new_width);
  $(".ad-image-wrapper").css('height', new_height);
  
  $(".ad-image").css('width', new_width);
  $(".ad-image").css('height', new_height);
  
  $(".current_image").css('width', new_width);
  $(".current_image").css('height', new_height);
  
  $(".ad-gallery").css('width', new_width);
  $("#page").css('width', new_width+180);

  $(".ad-next").css('height', new_height);
  $(".ad-prev").css('height', new_height);
  
  var nav_width = new_width - 371;
  nav_width > 800 ? nav_width=800 : nav_width=nav_width;
  if( nav_width > 90 ) {
    $(".ad-nav").css('width', nav_width);
  }else {
    $(".ad-nav").css('width', 90);
  }
  
}


function resizeSimple(minSize)
{
  getNewSize();
  
  if( new_width+180 > minSize ) {
    $("#page").css('width', new_width+180);
  }else {
      $("#page").css('width', minSize);
  }

}




function getNewSize()
{
  w = $(window).width() - offset_width;
  h = $(window).height() - offset_height;
  x_diff = max_width - w;
  y_diff = max_height - h;

  /*x most important*/
  if( x_diff > 0 && ( y_diff <= 0 || (x_diff) > (y_diff*(1.5)) ) ){
    var fac = max_width / w;
    new_height = max_height/fac;
    new_width = w;
  }
  /*y most important*/
  if( y_diff > 0 && ( x_diff <= 0 || (y_diff) >= (x_diff/(1.5)) ) ){
    var fac = max_height / h;
    new_width = max_width/fac;
    new_height = h;
  }
  /*scale = max-pic-size*/
  if(y_diff < 0 && x_diff < 0) {
    new_width = max_width;
    new_height = max_height;
  }
  /*min size*/
  if(new_width < 720 || new_height < 480) {
    new_width = 720;
    new_height = 480;
  }

}
