/**
 * Example handler for swf, not very configurable
 */

SqueezeBox.parsers.swf = function(preset) {
  return (preset || this.url.test(/\.swf/)) ? this.url : false;
}

SqueezeBox.handlers.swf = function(url) {
  var size = this.options.size;
  var swfobj = new SWFObject(url, 'sbox-swf', size.x, size.y, 9, '#ffffff');
  return swfobj.getSWFHTML();
}

window.addEvent('domready', function() {

  SqueezeBox.initialize( {
    size : {
      x :950,
      y :600
    },
    ajaxOptions : {
      method :'get'
    }
  });

  $$('a.boxed').each( function(el) {
    el.addEvent('click', function(e) {
      new Event(e).stop();
      SqueezeBox.fromElement(el);
    });
  });

  $$('.panel-toggler').each( function(el) {
    var target = el.getLast().setStyle('display', 'none');
    el.getFirst().addEvent('click', function() {
      target.style.display = (target.style.display == 'none') ? '' : 'none';
    });
  });
});

/**
 * This is a dirty 1min hack, it will be cleaner with the next version of
 * SmoothGallery
 */
var openSmooth = function() {
  var from = $('myGallery').clone(), smooth, crsl;
  SqueezeBox.fromElement(from, {
    size : {
      x :465,
      y :350
    }
  }).chain( function() {
    smooth = new gallery(this.content.getFirst(), {
      timed :false
    });
    // dirty hacked ;)
      $(document.body).addClass('jdGallery');
      crsl = smooth.carouselContainer.element;
      crsl.injectAfter(SqueezeBox.window);
      crsl.setStyles( {
        'z-index' :SqueezeBox.options.zIndex + 3
      });
    }).chain( function() {
    $(document.body).removeClass('jdGallery');
    crsl.remove();
  });
}
