
  var allowScaleImage = true;
  var widths = new Array();
  var imageH = 0;
  var containerH = 0;
  var containerW = 0;
  var imageMargin = 0;
  var multiplyer = 1;
  var containerLeft = 0;

function startScaling() {
  i = 0;
  $('#inner-image-wrapper .image-strip-item').each(function() {
    widths[i] = $(this).width();
    imageH = $(this).height();
    imageMargin = parseInt($(this).css('margin-right'));
    containerH = $('#content-container').height();
    containerW = $('#inner-image-wrapper').width() + 3;
    containerLeft = $('#inner-image-wrapper').position().left;
    i++;
  });
}

function scaleGalleryImage() {
  if (!allowScaleImage) {
    return false;
  }
  allowScaleImage = false;
  //trace($(window).height() + " " + $('#content-container').height());
  multiplyer = Math.max(0.85, Math.min(1, ($(window).height()-130)/imageH));
  i = 0;
  $('#inner-image-wrapper .image-strip-item').each(function() {
    $(this).width(widths[i] * multiplyer);
    $(this).height(imageH * multiplyer);
    $(this).css('margin-right', imageMargin * multiplyer);
    $('#content-container').height(containerH * multiplyer);
    $('#inner-image-wrapper').width(containerW * multiplyer);
    $('#inner-image-wrapper').css('left', containerLeft * multiplyer);
    i++;
  });
  /*
  var $minHeight = 340;
  $img = $('#image img:last');
  if (areaW/areaH < imageW/imageH) {
    $maxWidth = areaW;
    $maxHeight = $maxWidth / imageW * imageH;
  } else {
    $maxHeight = Math.max($minHeight, areaH);
    $maxWidth = $maxHeight / imageH * imageW;
  }
  
  //$('#content-wrapper').css('height',$maxHeight);
  
  $img.css('height',$maxHeight);
  $img.css('width',$maxWidth);
  $img.css('left', (areaW - $maxWidth)/2);
  $img.css('top', Math.max(0, (areaH - $maxHeight)));
  */
  allowScaleImage = true;
}



$(document).ready(function() {
  

  if (pageType == 'node_gallery' && !isMobile()) {
    startScaling();
    $(window).resize(scaleGalleryImage);
    scaleGalleryImage();
  }
  
  $('#front-page-thumb-wrapper a').mouseover(function() {
    $(this).children('img').stop().fadeTo(100,0);
  });
  $('#front-page-thumb-wrapper a').mouseout(function() {
    $(this).children('img').stop().fadeTo(400,1);
  });
  
  $('#prev-btn').click(function() {
    hasAnimated = false;
    prev = 0;
    $('#inner-image-wrapper .image-strip-item').each(function() {
      if (-$('#inner-image-wrapper').position().left - $(this).position().left < $(window).width() && -$('#inner-image-wrapper').position().left - $(this).position().left > 0) {
        containerLeft = -$(this).position().left + 33;
        time = Math.abs(Math.abs($('#inner-image-wrapper').position().left) - Math.abs(containerLeft)) * 0.4 + 200;
        $('#inner-image-wrapper').stop().animate({left:containerLeft}, time, null);
        return false;
      } else if ($('#inner-image-wrapper').position().left + $(this).position().left > 0) {
        containerLeft = prev;
        time = Math.abs(Math.abs($('#inner-image-wrapper').position().left) - Math.abs(containerLeft)) * 0.4 + 200;
        $('#inner-image-wrapper').stop().animate({left:containerLeft}, time, null);
        return false;
      } else {
        prev = -$(this).position().left + 33;
      }
    });
  });
  $('#next-btn').click(function() {
    hasAnimated = false;
    $('#inner-image-wrapper .image-strip-item').each(function() {
      if ($(this).position().left + $(this).width() + $('#inner-image-wrapper').position().left > $(window).width() && $(this).position().left + $('#inner-image-wrapper').position().left > 33) {
        containerLeft = -$(this).position().left + 33;
        time = Math.abs(Math.abs($('#inner-image-wrapper').position().left) - Math.abs(containerLeft)) * 0.4 + 200;
        $('#inner-image-wrapper').stop().animate({left:containerLeft}, time, null);
        hasAnimated = true;
        return false;
      }
    });
    if (!hasAnimated) {
      containerLeft = 0;
      time = Math.abs(Math.abs($('#inner-image-wrapper').position().left) - Math.abs(containerLeft)) * 0.12 + 300;
      $('#inner-image-wrapper').stop().animate({left:containerLeft}, time, null);
    }
  });
  
  
  Cufon.replace('a');
  Cufon.replace('p');
  
  if (isMobile()) {
    $('#outer-image-wrapper').css('overflow','visible');
    $('#inner-image-wrapper').css('overflow','visible');
  }
  

});


