var image_path = 'http://img.drugsounds.ru/images/';
var Popup = Class.create({
	overlay: null,
	popup: null,
	initialize: function(content){
		this.content = content;
		Event.observe(window, "resize", this.resizeOverlay.bindAsEventListener(this));
		Event.observe(window, "scroll", this.resizeOverlay.bindAsEventListener(this));
		this.overlay = new Element('div',{'class':'overlay',style:'display: none;'});
		var c_button = new Element('img',{src:image_path+'wcb-trans.png','class': 'wcb',width:29,height:29,alt:'Закрыть',title:'Закрыть'});
		c_button.observe('click',this.close.bindAsEventListener(this));
		this.popup = new Element('table',{'class' : 'wind',style:'display: none;'}).insert(new Element('tbody').insert(
			new Element('tr').insert(
				new Element('td',{'class': 'w_caption'}).insert(c_button)
			)
		).insert(
			new Element('tr').insert(
				new Element('td',{'class' : 'w_content_1'}).insert(new Element('div',{'class': 'w_content_2'}).insert(new Element('div',{'class': 'w_content_3'}).update($(this.content).innerHTML))))
		).insert(
			new Element('tr').insert(
				new Element('td',{'class': 'w_bottom'})
			)
		));
		$('body').insert(this.overlay).insert(this.popup);
		$(this.content).remove();
	},
	show: function(){
		new Ajax.Request('http://drugsounds.ru/main/activity',{method:'GET'});
		this.resizeOverlay();
		new Effect.Appear(this.overlay, {from: 0, to: 0.8});
		new Effect.Appear(this.popup);
	},
	resizeOverlay: function(e){
		if (this.overlay){
			var scroll_h = document.viewport.getScrollOffsets();
			scroll_h = scroll_h[1];
			var viewport = document.viewport.getDimensions();
			this.overlay.style.width = viewport.width+'px';
			this.overlay.style.height = viewport.height+scroll_h+'px';
		}
		if (this.popup){
			this.popup.style.top = Math.round(viewport.height/2+scroll_h-this.popup.getHeight()/2)+'px';
			this.popup.style.left = Math.round(viewport.width/2-this.popup.getWidth()/2)+'px';
		}
	},
	close: function(){
		new Effect.Fade(this.overlay, {from: 0.8, to: 0});
		new Effect.Fade(this.popup);
	}
});
var popup = null;
popup = {
	show: function(){
	alert('Пожалуйста подождите. Идет загрука страницы.')
	}
}
document.observe('dom:loaded',function(){
	popup = new Popup('popup_c');
})