function create_link(link) {
  $(link).click(function() {
      $('a').removeClass('current');
      $(link).addClass('current');
      $('body').addClass('activity');
      $('#main_content').fadeOut('slow', function() {
        $.get(link.href, ' ', function(data){
          $('#main_content').html(data).show('slow');
          $('body').removeClass('activity');
        }, 'text');
      });
      return false;
  });
}

$.fn.image = function(src, f){ 
  return this.each(function(){ 
    var i = new Image(); 
      i.src = src; 
      i.onload = f; 
      this.appendChild(i);
  }); 
} 

function setup_product_show_page() {
      // Image Selection
      //check_orientation($('#current_image img'));
      $('#image_subnav a#image_link-1').addClass('current');
      $('#image_subnav a').click(function() {
        var image = $('#current_image img');
        var href = $(this).attr('href');
        image.fadeTo(400, 0.8, function() { 
          jQuery.get(href, function() {
            image.attr('src', href);
            setTimeout(function() {
                //check_orientation($("#current_image img"));
                image.fadeTo(600, 1);
            }, 100);
          });
          });
      $('#image_subnav a').removeClass('current');
      $(this).addClass('current');
      return false;
      });

      $('#current_image a').click(function() {
          next = $('#image_subnav a.current').attr('id');
          next = next.split('image_link-')[0];
          //console.log(next);
          next = parseInt(next) + 1;
          //console.log(next);
          $('#image_subnav a#image_link-'+next).click()
      });
  
      function check_orientation(image) {
        var w = parseInt(image.css('width'));
        var h = parseInt(image.css('height'));
        var margin = 16;
        var thumb_w = 75;
        if (w > h) {
          //$('#thumbs li').css('clear', 'none');
          var viewer_width = w + 2;
        } else if (h > w) {
          //$('#thumbs li').css('clear', 'left');
          var viewer_width = w + thumb_w + margin;
        }
        $('#product_viewer').css('width', viewer_width);
      }
}

$(document).ready(function() {
  $('form').submit(function() {
    var submit = $(this).find(':submit');
    submit.wrap('<span class="activity"></span>').attr('value', 'Doing it...');
  });
});
