var overlay, remooz;
window.addEvent('domready', function(){
	$$('html').addClass('domready');
	
	$$('a.target-blank').addEvent('click', function(){
		return !window.open(this.href);
	});
	
	$$('#container section').addEvents({
		'mouseenter': function(){
			this.addClass('hover');
		},
		'mouseleave': function(){
			this.removeClass('hover');
		}
	});
	
	overlay = new Overlay(document.body, {
		opacity: .75,
		duration: 250,
		zIndex: 100,
		onClick: function(){
			this.close();
			$$('a.remooz-btn-close').fireEvent('click');
		}
	});
	
	$$('a.popup').each(function(element) {
        remooz = new ReMooz(element, {
            centered: true,
            origin: element.getParent('section') ? element.getParent('section') : element.getFirst(),
			cutOut: false,
			opacityLoad: 0,
			opacityResize: 0,
			shadow: false,
			dragging: false,
			type: 'iFrame',
			fixedSize: {
				x: 800,
				y: 600
			},
			onOpen: function(){
				overlay.open();
			},
			onClose: function(){
				overlay.close();
			}
        });
 
    });
	
	Cufon.replace('#container h2, #container li');
});

ReMooz.implement({
	openIFrame: function() {
		if (!this.options.fixedSize) {
			this.fireEvent('onError').close();
			return;
		}
		this.iFrame = new IFrame({
			src: this.link,
			styles: {
				border: 0,
				margin: 0,
				padding: 0,
				width: this.options.fixedSize.x,
				height: this.options.fixedSize.y
			},
			frameborder: 0
		});
		this.options = $extend(this.options, {
			closeOnClick:false,
			onOpen: function(){
				this.iFrame.set('scrollbar', false);
			},
			onOpenEnd: function(){
				this.iFrame.set('scrollbar', true);
			},
			onClose: function(){
				this.iFrame.set('scrollbar', false);
			}
		});
		if (!this.content) this.content = this.iFrame.inject(this.body);
		this.loading = null;
		this.zoomTo(this.options.fixedSize);
	}
});
