/**
 * Logic colorbox
 */
function LogicColorbox() {
  var self = this;
  
  /**
   * processed
   * @var boolean
   */
  this.processed = false;
  
  /**
   * default inner width
   */
  this.defaultInnerWidth = "480px";
  
  /**
   * default inner height
   */
  this.defaultInnerHeight = "480px";
  
  /**
   * default opacity
   */
  this.defaultOpacity = 0.5;
  
  /**
   * assign
   * 
   * @param string selector
   * @param string href
   * @param string, boolean parentReplaceUrl
   * @param string innerWidth
   * @param string innerHeight
   * @param boolean iframe
   * @param boolean scrolling
   * @param number opacity
   */
  this.assign = function(selector, href, parentReplaceUrl, innerWidth, innerHeight, iframe, scrolling, opacity) {
    this[selector] = new Object();
    this[selector].parentReplaceUrl = parentReplaceUrl;
    innerWidth = (typeof innerWidth == "string") ? innerWidth : this.defaultInnerWidth;
    innerHeight = (typeof innerHeight == "string") ? innerHeight : this.defaultInnerHeight;
    iframe = (typeof iframe == "boolean") ? iframe : true;
    scrolling = (typeof scrolling == "boolean") ? scrolling : false;
    opacity = (typeof opacity == "number") ? opacity : this.defaultOpacity;
    
    var options = {
      href: href,
      innerWidth: innerWidth,
      innerHeight: innerHeight,
      iframe: iframe,
      scrolling: scrolling,
      opacity: opacity,
      overlayClose: false,
      onClosed: function() {
        self.close(selector);
      }
    };
    
    $(selector).colorbox(options);
  };
  
  /**
   * close
   */
  this.close = function(selector) {
    if (!self.processed) {
      return;
    }
    
    if (typeof self[selector].parentReplaceUrl == "string") {
      self.replaceParentOnClosed();
    } else if (self[selector].parentReplaceUrl === true) {
      self.reloadParentOnClosed();
    }
  }
  
  /**
   * replace parent on closed
   */
  this.replaceParentOnClosed = function() {
    window.parent.location.replace(self[selector].parentReplaceUrl);
  }
  
  /**
   * reload parent on closed
   */
  this.reloadParentOnClosed = function() {
    window.parent.location.reload();
  };
}

logic.colorbox = new LogicColorbox();

