var typographyinitial = 'true';
var typographyperiodical = $empty;

window.addEvent('domready',function() {
	$$('.menuItem').addEvent('click',function(e) {
		e.preventDefault();
		var id = this.get('id').replace('_menu','');
		window.location = "/page/"+id; 
	});
	$$('.languageItem').addEvent('click',function(e) {
		e.preventDefault();
		var id = this.get('id').replace('_lang','');
		var location = 'http://www.sophievankempen.'+id+$('languageLink').get('value');
		location = location.replace('l//','l/');
		location = location.replace('m//','m/');
		location = location.replace('l//','l/');
		location = location.replace('m//','m/'); 
		window.location = location;
	});
	$$('.abs').each(function(item) {
		var xy = item.getPosition();
		item.setStyles({
			'margin-left': 0,
			'left': xy.x,
			'top': xy.y
		});
	});
	$$('.dragger').makeDraggable({
		snap: 0,
		onSnap: function(el){
			$$('.dragger').setStyle('z-index',1);
			el.setStyle('z-index',99);
		}
	});
	if($('intro_news_box'))	{
		var newsbox = $('intro_news_box');
		var newscontent = $('intro_news_content');
		var newsfx = new Fx.Morph('intro_news_box', {duration:300,transition:Fx.Transitions.Sine.easeOut});
		$('intro_news_box').set('morph',{'duration':300});
		$('intro_news_box').addEvent('mouseover',function() {
			newsfx.start({ 
				'margin-left': 94,
				'width': 0 
			}).chain(function(){
				if(newsbox.get('background-color') == 'white') {
					newsbox.set('border-color','#252BDE');
					newsbox.setStyle('background-color','#000000');
				} else {
					newsbox.setStyle('border-color','black');
					newsbox.setStyle('background-color','white');
				}
				this.start({
					'margin-left': 0,
					'width': 188
				});
			});
		});
	}
	if($('intro_typography_box')) {
		var typographybox = $('intro_typography_box');
		var typographywrapper = $('intro_typography_wrapper');
		typographybox.addEvent('mouseover',function() {
			var typographyimage = typographywrapper.getFirst('img');
			var typographyfxone = new Fx.Morph(typographywrapper.getFirst('img'), {'duration':300});
			var typographyscroll = new Fx.Morph('intro_typography_wrapper',{'duration':300});
			var typographyfxtwo = function() {
				typographyscroll.start({
					'margin-left': -190
				}).chain(function(){
					typographywrapper.grab(typographywrapper.getFirst('img').clone());
					typographywrapper.getFirst('img').dispose();
					typographywrapper.setStyle('margin-left',0);						
				});
			}
			typographywrapper.getFirst('img').set('morph',{'duration':300});
			if(typographyinitial == 'true') {
				typographyinitial = 'inbetween';
				typographyfxone.start({ 
					'margin-left': 94,
					'width': 0,
					'margin-right': 200
				}).chain(function(){
					typographywrapper.getFirst('img').set('src',$('intro_typography_image_1').get('src'));
					this.start({
						'margin-left': 0,
						'width': 190,
						'margin-right': 0
					});
				}).chain(function(){
					var i = 2;
					var width = 190;
					while($('intro_typography_image_'+i)) {
						if($('intro_typography_image_'+i).get('alt') != 'done') {
							typographywrapper.grab($('intro_typography_image_'+i).clone().removeClass('hidden'));
							$('intro_typography_image_'+i).set('alt','done');
						}
						i++;
						width = width + 190;
					}
					typographywrapper.setStyle('width',width + 190);
					typographyinitial = 'false';
					typographyperiodical = typographyfxtwo.periodical(3600);
				});
			} else {
				if(typographyinitial == 'false') {
					typographyinitial = 'inbetween';
					clearInterval(typographyperiodical);
					typographyfxone.start({ 
						'margin-left': 94,
						'width': 0,
						'margin-right': 200
					}).chain(function(){
						$('intro_typography_image_1').set('src',typographywrapper.getFirst('img').get('src'))
						typographywrapper.getFirst('img').set('src','/images/bluebox.png');
						this.start({
							'margin-left': 0,
							'width': 190,
							'margin-right': 0
						});
						typographyinitial = 'true';
					})
				}
			}
		});
	}
});
