$().ready(function() {
  
  var active_option;
  var iframes_loaded = 0;
  
  var select_option = function(selector) {
    if(!selector) {
      return;
    }
    
    if(active_option) {
      $('#form a[href=' + active_option + ']').removeClass('selected');
      $(active_option).hide()
    }
    
    active_option = selector;
    $('#form a[href=' + active_option + ']').addClass('selected');
    $(active_option).show();
  }
  
  var readyAfterIFrames = function() {
    iframes_loaded ++;
    
    if(iframes_loaded == $('iframe').length) {
      $('#form a[href^=#]').click(function() {
        select_option($(this).attr('href'));
        return false;
      });
            
      $('#form .option').hide();
      select_option(document.location.hash || '#buy');
      
      // Remember to unbind, lest the user click submit in an iFrame
      $('iframe').unbind('load', readyAfterIFrames)
    }
  }
  
  // Some browsers won't render hidden iFrames correctly,
  // so we'll wait until everything's loaded
  $('iframe').bind('load', readyAfterIFrames);
  
  $("a.zoom").fancybox({
		'zoomSpeedIn':	500,
		'zoomSpeedOut':	500,
		'overlayShow':	false
	});
  
});
