var RepostOverlay = new Class({
	overlay : null,
	contentDiv : null,
	container : null,
	currentContent : null,
	fxOverlay : null,
	ie6 : false,
	isVisible : false,
	overlayCompatible : false,
	
	bounds : {},
	
	initialize : function()
	{
		
		this.overlay = $('repostOverlay');
		this.ie6 = Browser.Engine.trident4;
		this.ok = this.ie6 || (this.overlay.currentStyle && (this.overlay.currentStyle.position != "fixed"));
		if (this.ok)
			this.overlay.setStyle('position', "absolute");
		this.fxOverlay = new Fx.Tween(this.overlay, {property: "opacity", duration: 400});
		this.fxResize = new Fx.Morph(this.contentDiv, $extend({duration: 400, link: "chain"}, {}));
		this.contentDiv = $('repostCenter');
		this.container = $('repostContainer');
		this.bounds.setup = this.setup.bind(this);
		this.bounds.hide = this.hide.bind(this);
		this.bounds.position = this.setPosition.bind(this);
		this.overlay.addEvent('click', this.bounds.hide);
		closeBtn = $('repostCloseLink');
		closeBtn.addEvent('click', this.bounds.hide);
	},
	
	setContent : function(el)
	{
		if (this.currentContent)
		{
			this.currentContent.setStyle('display', 'none');
			document.body.grab(this.currentContent);
		}
		this.currentContent = el;
		el.setStyle('display', '');
		this.container.grab(el);
	},
	
	show : function()
	{
		//this.overlay.setStyle('display', '');
		this.fxOverlay.set(0).start(0.8);
		this.setup(1);
		this.isVisible = true;
		
		this.contentDiv.setStyle('display', '');
		this.setPosition();
	},
	
	hide : function()
	{
		this.contentDiv.setStyle('display', "none");
		this.fxOverlay.cancel().chain(this.bounds.setup).start(0);
		this.isVisible = false;
		return false;
	},
	
	setPosition : function()
	{
		/*var scroll = window.getScroll(), size = window.getSize();
		this.contentDiv.setStyle("left", scroll.x + (size.x / 2));
		this.contentDiv.setStyle("top", scroll.y + (size.y / 2));
		if (this.ok)
			this.overlay.setStyles({left: scroll.x, top: scroll.y, width: size.x, height: size.y});*/
		var scroll = document.getScroll(),
			offset = document.getSize(),
			size = this.contentDiv.getSize(),
			values = {x: 'left', y: 'top'};
		
		for(var z in values)
		{
			//alert(z + ' = ' + scroll[z] + ' + (' + offset[z] + " - " + size[z] + ')/2');
			var style = scroll[z]+(offset[z]-size[z])/2;
			this.contentDiv.setStyle(values[z], style < 10 ? 10 : style);
		}
	},
	
	setup : function(open) {
		["object", this.ie6 ? "select" : "embed"].forEach(function(tag) {
			Array.forEach(document.getElementsByTagName(tag), function(el) {
				if (open) el._repoverlay = el.style.visibility;
				el.style.visibility = open ? "hidden" : el._repoverlay;
			});
		});

		this.overlay.setStyle("display", open ? "" : "none");

		var fn = open ? "addEvent" : "removeEvent";
		//win[fn]("scroll", position)[fn]("resize", position);
		//document[fn]("keydown", keyDown);
	}
});
