// JavaScript Document

var Popup = Class.create();

Popup.prototype = {
	
	initialize: function() {	
		opacity = 0.9;
		layer = 'popup';
		color = '#000000';
		$(layer).hide();
	},
	
	loadPopup: function(popup)	{
		new Effect.Fade(layer, { 
			from: 0.0, 
			to: opacity, 
			duration: 0.2,
			beforeStart: function() {
				setTimeout(function() {
					$(layer).show();
					$(layer).style.background = color;
				}, 100);
			},
			afterFinish: function() {
				myPopup.showPopup(popup);	
			}
		});
	},
	
	showPopup: function(popup) {
		var xScroll, yScroll;
		if (self.pageYOffset) {
			yScroll = self.pageYOffset;
			xScroll = self.pageXOffset;
		} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
			yScroll = document.documentElement.scrollTop;
			xScroll = document.documentElement.scrollLeft;
		} else if (document.body) {// all other Explorers
			yScroll = document.body.scrollTop;
			xScroll = document.body.scrollLeft;	
		}
		arrayPageScroll = new Array(xScroll,yScroll);	
		
		nOffsetHeight = document.documentElement.offsetHeight;
		nHeight = $(popup).style.height;
		nHeight = nHeight.replace("px","");

		nTop = Math.ceil(((nOffsetHeight - nHeight) / 2) + yScroll);
		new Effect.Fade(popup, {
			from: 0.0, 
			to: 1.0, 
			duration: 0.4,
			beforeStart: function() {
				$(popup).style.top = nTop + 'px';
				setTimeout(function() {
					$(popup).show();
				}, 100);
			},
			afterFinish: function() {
				setTimeout(function() {
					$(layer).observe('click', function() { myPopup.closePopup(popup) });
					$(popup).down('.close').observe('click', function() { myPopup.closePopup(popup) });
				}, 100);
			}
		});
	},
	
	closePopup: function(popup)	{
		new Effect.Fade(popup, { 
			duration: 0.4, 
			from: 1.0, 
			to: 0.0, 
			afterFinish: function() {
				$(popup).hide();
				new Effect.Fade(layer, { 
					from: opacity, 
					to: 0.0, 
					duration: 0.2, 
					afterFinish: function() {
						$(layer).hide();
					}
				});
			}
		});
	}
}

function initPopup() 
{ 
	myPopup = new Popup(); 
}
