var Page = (
{
	init: function()
	{
		this.squares = $ES('.ob');
		this.FX = [];
		var i = 0;
		this.im = null;
		if (this.squares) 
		{
			for (i = 0; i < this.squares.length; i++) 
			{
				this.squares[i].addEvent('mouseenter', this.SquareFadeIn.pass(i, this));
				this.squares[i].addEvent('mouseleave', this.SquareFadeOut.pass(i, this));
				this.FX[i] = new Fx.Style($E('.ct', this.squares[i]), 'opacity');
			}
		}
		NewsLetter.init();
		this.galDiv = new Element('div').setStyles(
		{
			'position': 'absolute',
			'z-index': '4',
			'left': 0,
			'top': 0,
			'display': 'none',
			'background-color':'#000'
		}).injectInside(document.body);
		this.isGal = false;
		
		this.GalFx = new Fx.Style(this.galDiv, 'opacity', 
		{
			onComplete: this.FixBgD.bind(this)
		});
		this.GalFx.set(0);
	},
	SquareFadeIn: function(sq)
	{
		this.FX[sq].stop();
		this.FX[sq].start(0, 1);
	},
	SquareFadeOut: function(sq)
	{
		this.FX[sq].stop();
		this.FX[sq].start(1, 0);
	},
	ShowGalPic: function(w, h, src, col)
	{
		if (this.im) 
		{
			this.im.remove();
			this.im = null;
		}
		var sz = window.getSize();
		var posx = Math.round((sz.size.x - w) / 2);
		var posy = Math.round((sz.size.y - h) / 2) + sz.scroll.y;
		this.galDiv.setStyles(
		{
			'width': sz.size.x,
			'height': sz.scrollSize.y,
			'background-color':'#'+col
		});
		this.im = new Element('img');
		this.im.src = src;
		this.im.alt = "click to close";
		this.im.title = "click to close";
		this.im.setStyles(
		{
			'position': 'absolute',
			'z-index': '5',
			'left': posx,
			'top': posy
		});
		this.im.addEvent('click', this.RemoveGalPic.bind(this));
		this.galDiv.addEvent('click', this.RemoveGalPic.bind(this));
		this.imD=[w,h];
		this.ShBg();
		window.addEvent('scroll',this.FixImgPos.bind(this));
	},
	FixImgPos:function()
	{
		var sz = window.getSize();
		var posx = Math.round((sz.size.x - this.imD[0]) / 2);
		var posy = Math.round((sz.size.y - this.imD[1]) / 2) + sz.scroll.y;
		this.im.setStyles(
		{
			'left': posx,
			'top': posy
		});
	},
	FixBgD:function()
	{
		if (this.isGal) 
		{
			this.im.injectInside(document.body);	
		}
		else
		{
			this.galDiv.style.display = 'none';
		}
	},
	ShBg: function()
	{
		this.isGal = true;
		this.galDiv.style.display='block';
		this.GalFx.stop();
		this.GalFx.start(0, 0.8);
	},
	HdBg: function()
	{
		this.isGal = false;
		this.GalFx.stop();
		this.GalFx.start(0.8, 0);
	},
	RemoveGalPic: function()
	{
		window.removeEvents('scroll');
		this.galDiv.removeEvent('click');
		if (this.im) this.im.remove();
		this.im = null;
		this.HdBg();
	}
});
var NewsLetter = (
{
	open: false,
	init: function()
	{
		this.frm = $('nlforma');
		this.FX = new Fx.Elements([$('nlform'), $('news'), $('nli')], 
		{
			duration: 750,
			onComplete: this.animated.bind(this),
			transition: Fx.Transitions.linear
		});
		this.el = $E('#menu a.m1');
		this.el.addEvent('click', this.doform.bind(this));
		$('frme1').addEvent('keyup', this.send.bind(this));
		$('frme2').addEvent('keyup', this.send.bind(this));
		$('frme3').addEvent('click', this.cSend.bind(this));
	},
	animated: function()
	{
		this.open = !this.open;
		if (this.open == false) 
		{
			this.el.removeClass('clicked');
		}
		else 
		{
			$('frme1').focus();
		}
	},
	doform: function(e)
	{
		e = new Event(e);
		e.stop();
		if (this.open) this.hide();
		else 
		{
			this.el.addClass('clicked');
			this.show();
		}
	},
	show: function()
	{
		this.FX.stop();
		this.FX.start(
		{
			'0': 
			{
				'height': [20, 70]
			},
			'1': 
			{
				'top': [0, 50]
			},
			'2': 
			{
				'bottom': [20, 10]
			}
		});
	},
	hide: function()
	{
		this.FX.stop();
		this.FX.start(
		{
			'0': 
			{
				'height': [70, 20]
			},
			'1': 
			{
				'top': [50, 0]
			},
			'2': 
			{
				'bottom': [10, 20]
			}
		});
	},
	cSend:function(e)
	{
		if (this.frm.nm.value != '' && this.frm.ml.value != '') 
		{
			this.frm.send();
		}
		this.frm.reset();
		this.hide();
	},
	send: function(e)
	{
		e = new Event(e);
		e.preventDefault();
		e.stop();
		if (e.key == 'enter') 
		{
			if (this.frm.nm.value != '' && this.frm.ml.value != '') 
			{
				this.frm.send();
				this.frm.reset();
				this.hide();
			}
		}
	}
});
window.addEvent('domready', Page.init.bind(Page));
