
//
// Custom Behaviour for Image Design Kitchens
// Matthew Smith-Stubbs 2008-12-22

$(function() {
  // custom scrolling behaviour for content areas
  var scrollValue = {
      up:    "+=310px",
      down:  "-=310px"
    }

  var viewport = $('#column1');
  var content = $('.inner');

  function showOrHideControls() { // show or hide up/down arrows to prevent user overscrolling
    if ( content.offset().top + content.height() < viewport.offset().top + viewport.height()  ) {
      $('a.down').hide();
    } else {
      $('a.down').show();
    }

    if ( content.offset().top >= viewport.offset().top ) {
      $('a.up').hide();
    } else {
      $('a.up').show();
    }
  }

  if ( $('a.up, a.down').length > 0) {
    showOrHideControls(); 
  };
  
  $('a.down, a.up').click(function() { // scroll content
    content.animate({
      marginTop: $(this).hasClass('up') ? scrollValue.up : scrollValue.down
    }, {
      speed: "fast",
      easing: "swing",
      complete: showOrHideControls
    });
    return false;
  });
  
  $('#thumbnails a').each(function() {
    $(this).click(function() {
      $('img#main').attr('src', $(this).attr('href'));
      return false;
    })
  })
  
  
});