var Toggling = {
	  
		config: {
	    toggler : '.toggler',
			toggled : '.toggled',
			duration : 500
		},
		
		init: function(options){
			  
				options = Object.extend(this.config, options || {});
				
				var togglers = $$(options.toggler);
				var slides = $$(options.toggled);

				togglers.each(function(element){
				    
						// css
						
						var slideFx = new Fx.Slide(slides[togglers.indexOf(element)], { duration: options.duration, transition: Fx.Transitions.Cubic.easeOut }).hide();
						
						element.addEvent('click', function(e){
					      slideFx.toggle();
								this.toggleClass('on');
						});
						
				});
				
		}
};

var GOverlay = {
	
	  init: function(){
			
			this.overlay = $('overlay');
			this.content = $('overlay-position');
			this.closeButton = $('closebox');
			this.openButtons = $$('.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.openButtons.each(function(button){
				button.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 = $('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);
		}
		
};

// overlay na historii

var GOverlay2 = {
	
	  init: function(){
			
			this.overlay = $('overlay2');
			this.content = $('overlay2-position');
			this.closeButton = $('closebox2');
			this.openButtons = $$('.show-history');
			
			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.openButtons.each(function(button){
				button.addEvent('click', function(event){
			  	event.stop();
					GOverlay2.show();
				});
			});
			
			// close events
			this.closeButton.addEvent('click', function(event){
			  event.stop();
				GOverlay2.hide();
			});
			
			this.overlay.addEvent('click', function(event){
			  event.stop();
				GOverlay2.hide();
			});
			
		},
		
		show: function(){
			// position
			var size = $('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);
		}
		
};


// overlay na odkazy

var GOverlay3 = {
	
	  init: function(){
			
			this.overlay = $('overlay3');
			this.content = $('overlay3-position');
			this.closeButton = $('closebox3');
			this.openButtons = $$('.show-links');
			
			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.openButtons.each(function(button){
				button.addEvent('click', function(event){
			  	event.stop();
					GOverlay3.show();
				});
			});
			
			// close events
			this.closeButton.addEvent('click', function(event){
			  event.stop();
				GOverlay3.hide();
			});
			
			this.overlay.addEvent('click', function(event){
			  event.stop();
				GOverlay3.hide();
			});
			
		},
		
		show: function(){
			// position
			var size = $('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 ($$('.toggler').length) {
		Toggling.init();
	}
	
	if ($('overlay')){
		GOverlay.init();
	}

	if ($('overlay2')){
		GOverlay2.init();
	}

	if ($('overlay3')){
		GOverlay3.init();
	}

	
	// target=_blank replacement
	$$('a.blank').each(function(anchor){
	  anchor.set('target', '_blank');
	});
			
	//hp seo help
	if($('tip-toggler')) {	
		$('tip-toggler').addEvent('mouseover', function(e){
			$('tip-box').setStyle('display', 'block');
		});
		$('tip-toggler').addEvent('mouseout', function(e){
			$('tip-box').setStyle('display', 'none');		
		});
	}
});

// remooz
window.addEvent('load', function() {
 
	/**
	 * Some options for the large photos.
	 *
	 * The first argument is the argument for $$ (can be an array of elements or a selector)
	 */
 if ($$('.gallery a')) { 
	ReMooz.assign('.gallery a', {
		'origin': 'img',
		'shadow': 'onOpenEnd', // fx is faster because shadow appears after resize animation
		'resizeFactor': 0.8, // resize to maximum 80% of screen size
		'cutOut': false, // don't hide the original
		'opacityResize': 0.4, // opaque resize
		'dragging': false, // disable dragging
		'centered': true // resize to center of the screen, not relative to the source element
	});
 }
	/**
	 * Note on "shadow": value can be true, onOpenEnd (appear after resize) and false, to disable shadow
	 * WebKit (Safari 3) uses (great looking) CSS shadows, so it ignores this option.
	 */
 
});
