//PopOver, Copyright (c) 2008 Regis Gaughan, III. All Rights Reserved

var PopOver = new Class({

	Implements: [Chain, Events, Options],

	options: {	},

	initialize: function(){
		this.modal = new Element('div',{'class':'modal'}).setStyles({'z-index':99,'position':'absolute','top':0,'left':0,'width':'100%','height':0,'opacity':0}).inject(document.body);
		this.theme = '';
		this.step = 0;
		this.popover = {};
		this.popover.container = new Element('div',{'class':'popover'}).setStyles({'z-index':100,'opacity':0,'position':'absolute','top':0,'left':'50%'}).inject(document.body);
		this.popover.title = new Element('div',{'class':'popover_topmid'}).inject(new Element('div',{'class':'popover_topright'}).inject(new Element('div',{'class':'popover_topleft'}).inject(this.popover.container)));
		this.popover.body = new Element('div',{'class':'popover_midmid'}).inject(new Element('div',{'class':'popover_midright'}).inject(new Element('div',{'class':'popover_midleft'}).inject(this.popover.container)));
		new Element('div',{'class':'popover_bottommid'}).inject(new Element('div',{'class':'popover_bottomright'}).inject(new Element('div',{'class':'popover_bottomleft'}).inject(this.popover.container)));
		this.popover.title.set('text','RG3 Theme-O-Matic');
		//this.popover.content = new Element('div',{'class':'popover_message'}).inject(this.popover.body);
		this.popover.close = new Element('div',{'class':'popover_close'}).inject(this.popover.container);
		this.fx = {};
		this.fx.modal = new Fx.Morph(this.modal, {'link':'cancel'});
		this.fx.popover = new Fx.Morph(this.popover.container, {'link':'cancel'});
		this.fx.body = new Fx.Morph($('body'), {'link':'cancel'});
	},
	setTitle: function(str){
		this.popover.title.empty().set('html',str);
	},
	setBody: function(str){
		this.popover.body.empty().set('html',str);
	},
	show: function(){
	    this.step = 0;
		this.modal.addEvent('click',this.hide.bind(this));
		this.popover.close.addEvent('click',this.hide.bind(this));
		this.popover.close.removeClass('popover_close_disabled');
		this.modal.setStyles({'height':Window.getScrollSize().y,'opacity':0});
		this.modal.addClass('clickable');
		var bodyscroll = Window.getScroll();
		var bodysize = Window.getSize();
		this.popover.container.setStyle('opacity',.05);
		var popoversize = this.popover.container.getCoordinates();
		var top = ((bodyscroll.y+(bodysize.y/2)-(popoversize.height/2))).toInt();
		this.popover.container.setStyles({'margin-left':(popoversize.width/2).toInt()*-1,'top':(top<0?10:top)});
		this.fx.modal.start({'opacity':.7});
	    this.fx.popover.start({'opacity':1});
	},
	hide: function(){
	    this.fx.modal.start({'opacity':0}).chain(function(){this.modal.setStyles({'height':0});}.bind(this));
	    this.fx.popover.start({'opacity':0});
	}
		
});
