var toggle = 'hidden';
var Site = {
	init: function() {
		//console.log('Site.init()');
		
		var duration = 3000;
		var container = $('slides');
		var slides = container.getElements('img');
		
		var current_slide = 0;
		var interval;
		
		var start = function() {
			interval = show.periodical(duration);
		}
		
		var stop = function() {
			$clear(interval);
		}
		
		var show = function(to) {
			slides[current_slide].fade('out');
			
			if (current_slide < slides.length -1) {
				current_slide++;
			} else {
				current_slide = 0;
			}
			
			slides[current_slide].fade('in');
		}
		
		slides.each(function(slide, i) {
			if (i != 0) {
				slide.set('opacity', 0);
			}
		});
		
		if ($chk($('introvideo'))) {
			$$('html')[0].addEvent('click', function(e) {
				if (!($(e.target).match('#introvideo') || $(e.target).getParent('#introvideo'))){
					$('introvideo').fade('hide');					
					$('introvideo').set('html', '');
					toggle = 'hidden';
				}
			});
		}
		
		if ($chk($('introvideo'))) {
			$('introvideoClose').addEvents({
				'click': function(e){
					e.stop();
					$('introvideo').fade('hide');
					$('introvideo').set('html', '');
					toggle = 'hidden';
				}
			});
		}
		
		start();
	}
}


window.addEvents({
	'domready': function() {
		//console.log('Window DOM Ready');
		
		if ($chk($('slides'))) {
			Site.init();
		}
		if ($chk($('introvideo'))) {
			$('introvideo').fade('show');
			toggle = 'show';
		}
	},
	
	'load': function(){
		//console.log('Window Locked and Loaded');
	}
	
});

