// JavaScript Document
var GOverlay = {
	
	  init: function(){
			
			this.overlay = $('overlay');
			this.content = $('overlay-position');
			this.closeButton = $('closebox');
			this.openButton = $('show-agreement');
			
			this.overlayFx = new Fx.Tween(this.overlay, { property: 'opacity', duration: 100, link: 'cancel' });
			this.overlayFx.set(0);
			this.overlay.setStyles({
			  'display' : 'block',
				'cursor' : 'pointer'
			});
			
			this.contentFx = new Fx.Tween(this.content, { property: 'opacity', duration: 100, link: 'cancel' });
			this.contentFx.set(0);
			this.content.setStyle('display', 'block');
			
			// open event
			this.openButton.addEvent('click', function(event){
			  event.stop();
				GOverlay.show();
			});
			
			// close events
			this.closeButton.addEvent('click', function(event){
			  event.stop();
				GOverlay.hide();
			});
			
			this.overlay.addEvent('click', function(event){
			  event.stop();
				GOverlay.hide();
			});
			
		},
		
		show: function(){
			// position
			var size = $('page-wrapper').getSize();
      var scrolled = $(document.body).getScroll();
			var viewPort = $(window).getSize();
			this.overlay.setStyles({
				'height' : Math.max(size.y, viewPort.y)
			});
			this.content.setStyle('top', Math.round(viewPort.y/2) + scrolled.y);
			
			// show
			this.overlayFx.start(0.2);
			this.contentFx.start(1);
		},
		
		hide: function(){
			this.overlayFx.start(0);
			this.contentFx.start(0);
		}
		
};


window.addEvent('domready', function(){

  if ($('giant')){
		$('giant').getElement('strong').setStyle('cursor', 'pointer');
		$('giant').getElement('strong').addEvent('click', function(){
		  window.open('http://www.giant.cz');
		});
	}
  
	if ($('toggle')){
		var info = new Fx.Slide('info',{ duration: 500 });
		info.hide();
		$('toggle').addEvent('click', function(e){
			info.toggle();
			e.stop();
		});
	}
	
	if ($('overlay')){
		GOverlay.init();
	}

});