///////////////////////////////////////////////////////////////
//
//  Script: Photo Masking
//  Version: 1.0
//  Author: Craig Nelson / Classic Labs Development
//
//  Notes: oo version
//

  var Ascribe = Ascribe || {};
  
  Ascribe.PhotoMasking = function (config) {
    // vars
    var that = this; // scope correction
    this.photoWrapperClassName = config.photoWrapperClassName || "photo-wrapper";
    this.photoWraps = $$("." + that.photoWrapperClassName);
    this.photoClassName = config.photoClassName || "photo";
    this.maskClassName = config.maskClassName || "mask";
    this.defaultPhotoID = config.defaultPhotoID || "default-photo";
    
    // methods
    this.setMask = function (element, source) {
      if (element && source) {
        Element.clonePosition(element, source);
      }
      return;
    };
    
    if (this.photoWraps.length > 0) { // are there any photo wrappers on this page?
      if (this.photoWraps.length > 1) { // if multiple large images gallery
        this.photoWraps.each(function (e) {
          var img = e.down("." + that.photoClassName);
          var mask = e.down("." + that.maskClassName);
          that.setMask(mask, img);
        });
      }
      else { // if single large image gallery with thumbnails
        this.setMask(this.photoWraps[0].down("." + this.maskClassName), this.photoWraps[0].down("." + this.photoClassName));
        Event.observe(this.defaultPhotoID, 'load', function () {
          that.setMask(that.photoWraps[0].down("." + that.maskClassName), that.photoWraps[0].down("." + that.photoClassName));
        });
      }
    }
  }; // constructor
