
var showcase = {
  
  load: function(value) {
    if (value == null) value = 'index';

    if (value == 'favorites') {
      $('showcase-options-link').getParent().removeClass('checked');
      if ($('showcase-favorites-link')) $('showcase-favorites-link').getParent().addClass('checked');
    } else if (value == 'index') {
      $('showcase-options-link').getParent().addClass('checked');
      if ($('showcase-favorites-link')) $('showcase-favorites-link').getParent().removeClass('checked');
    } else {
      $('showcase-options-link').getParent().removeClass('checked');
      if ($('showcase-favorites-link')) $('showcase-favorites-link').getParent().removeClass('checked');
    }
    
    /*var flash = new SWFObject("/resources/flash/auka.swf", "stuff_flash", "100%", "363", "9");
    flash.addParam("wmode", "transparent");
    flash.addParam("scale", "showall");
    flash.addVariable("url_feed", "/datafeed/" + value + '/');
    flash.write("stuff_place");*/
    
    swfobject.embedSWF("/resources/flash/auka.swf", "stuff_place", "100%", "363", "9.0.0", "expressInstall.swf", {"url_feed": "/datafeed/" + value + '/'}, {"wmode": "transparent", "scale": "showall"});
  },
  
  save: function() {
    var cats = [];
    $('showcase_cats').getElements('input').each(function(el) {
      if (el.checked) cats.push('cat[]=' + el.value);
    });
    new Ajax('/welcome/showcase-options/', {
      useWaiter: true,
      waiterTarget: 'showcase-options',
      method: 'post',
      data: 'showcase_fixed=' + ($('showcase_fixed_price').checked ? 1 : 0) + '&' +
            'showcase_auction=' + ($('showcase_auction').checked ? 1 : 0) + '&' +
            'showcase_auction_mini=' + ($('showcase_auction_mini').checked ? 1 : 0) + '&' +
            cats.join('&'),
      onSuccess: function() {
        showcase.hide();
        showcase.load();
      }
    }).request();
  },
  
  options: function() {
    if ($('showcase-options').getStyle('display') != 'none') {
      showcase.hide();
      return;
    }
    var bounds = $('showcase-options-link').addClass('rolled').getCoordinates();
    $('showcase-options').setStyles({
      'display': 'block',
      'opacity': 0
    });
    $('showcase-options').setStyles({
      'opacity': 1,
      'left': bounds.right - $('showcase-options').offsetWidth,
      'top': bounds.bottom
    });
  },
  
  hide: function() {
    $('showcase-options-link').removeClass('rolled');
    $('showcase-options').setStyle('display', 'none');
  },
  
  toggle_all: function(value) {
    $('showcase_cats').getElements('input').each(function(el) {
      el.checked = value;
    });
  }
  
};
