
function extendSqueezeBox() {


    SqueezeBox.extend( {
  
      fitToContent: function( contentEl, contentDoc, instantly ) {
            var size = { y: contentEl.getScrollSize().y, x: contentDoc.getScrollSize().x };
            this.options.size = size;
            if( Browser.Engine.trident4 ) {
              size.x += 10;
              size.y += 10;
            }
            this.fx.content = { cancel: function() { return this }, set: function() { return this }, start: function() { return this } };
            this.fitToSize( size, instantly );
            (function() { this.asset.setStyles( { 'height': size.y, 'width': size.x, 'overflow': 'hidden' } ); this.bound.window() }).delay(20, this);
            
      },
      
      fitToSize: function( size, instantly ) {
    	  this.showTimer = $clear(this.showTimer || null);
    		var box = this.doc.getWindow().getSize(), scroll = this.doc.getScroll();
    		this.size = $merge((this.isLoading) ? this.options.sizeLoading : this.options.size, size);
    
    		windowSize = { x: ( box.x.toInt() - 50 ), y: ( box.y.toInt() - 50 ) };
    		if( this.size.x > windowSize.x ) {
    		  this.size.x = windowSize.x;
    		}
    		if( this.size.y > windowSize.y ) {
    		  this.size.y = windowSize.y;
    		}
    		var to = {
    			width: this.size.x,
    			height: this.size.y,
    			left: (scroll.x + (box.x - this.size.x - this.options.marginInner.x) / 2).toInt(),
    			top: (scroll.y + (box.y - this.size.y - this.options.marginInner.y) / 2).toInt()
    		};
  
    		if (!instantly) {
    			this.fx.win.start(to).chain(this.showContent.bind(this));
    		} else {
    			this.win.setStyles(to).setStyle('display', '');
    			this.showTimer = this.showContent.delay(50, this);
    		}
    		return this.repositionOverlay();
    	},
    	
    	fitToView: function( instantly ) {
    	  this.showTimer = $clear(this.showTimer || null);
    		var box = this.doc.getSize(), scroll = this.doc.getScroll();
    		this.size = $merge((this.isLoading) ? this.options.sizeLoading : this.options.size, size);
    		this.size = { x: ( box.x.toInt() - 70 ), y: ( box.y.toInt() - 30 ) };
    		var to = {
    			width: this.size.x,
    			height: this.size.y,
    			left: (scroll.x + (box.x - this.size.x - this.options.marginInner.x) / 2).toInt(),
    			top: (scroll.y + (box.y - this.size.y - this.options.marginInner.y) / 2).toInt()
    		};
    		this.hideContent();
    		if (!instantly) {
    			this.fx.win.start(to).chain(this.showContent.bind(this));
    		} else {
    			this.win.setStyles(to).setStyle('display', '');
    			this.showTimer = this.showContent.delay(50, this);
    		}
    		return this.reposition();
    	},
    
    	repositionOverlay: function() {
    	  var ssize = this.doc.getScrollSize();
    		this.overlay.setStyles({
    			width: ssize.x + 'px',
    			height: ssize.y + 'px'
    		});
    	},
    
    	reposition: function() {
    		var size = this.doc.getSize(), scroll = this.doc.getScroll();
    		this.repositionOverlay();
    		this.win.setStyles({
    			left: (scroll.x + (size.x - this.win.offsetWidth) / 2 - this.scrollOffset).toInt() + 'px',
    			top: (scroll.y + (size.y - this.win.offsetHeight) / 2).toInt() + 'px'
    		});
    		return this.fireEvent('onMove', [this.overlay, this.win]);
    	},
    
      initialize: function(presets) {
    		if (this.options) return this;
    
    		this.presets = $merge(this.presets, presets);
    		this.doc = this.presets.document || document;
    		this.options = {};
    		this.setOptions(this.presets).build();
    		this.bound = {
    			window: this.fitToSize.bind(this, [null]),
    			scroll: this.checkTarget.bind(this),
    			close: this.close.bind(this),
    			key: this.onKey.bind(this)
    		};
    		this.isOpen = this.isLoading = false;
    		return this;
    	},
    	
    	applyContent: function(content, size) {
    		if (!this.isOpen && !this.applyTimer) return;
    		this.applyTimer = $clear(this.applyTimer);
    		this.hideContent();
    		if (!content) {
    			this.toggleLoading(true);
    		} else {
    			if (this.isLoading) this.toggleLoading(false);
    			this.fireEvent('onUpdate', [this.content], 20);
    		}
    		if (content) {
    			if (['string', 'array'].contains($type(content))) this.content.set('html', content);
    			else if (!this.content.hasChild(content)) this.content.adopt(content);
    		}
    		this.callChain();
    		if (!this.isOpen) {
    			this.toggleListeners(true);
    			this.fitToSize(size, true);
    			this.isOpen = true;
    			this.fireEvent('onOpen', [this.content]);
    		} else {
    			this.fitToSize(size);
    		}
    	}
    });
    $extend( SqueezeBox.handlers, {
    
    	iframe: function(url) {
  
    	  //if( Object.isEqual( this.options.size, { x: 600, y: 450 } ) ) this.options.size = { x: 1600, y: 1200 };
    		this.asset = new Element('iframe', $merge({
    			src: url,
    			frameBorder: 0,
    			width: '100%',
    			height: '100%'
    		}, this.options.iframeOptions));
    		if (this.options.iframePreload) {
    			this.asset.addEvent('load', function() {
    				this.applyContent(this.asset.setStyle('display', ''));
    			}.bind(this));
    			this.asset.setStyle('display', 'none').inject(this.content);
    			return false;
    		}
    		return this.asset;
    	}

    });
}