window.addEvent('domready', function() {

	var header = document.id('header');
	header.getElements('li.has-sub > ul').each(function(ul){
		ul.setStyle('display', 'block');
		ul.store('height', ul.getStyle('height'));
		ul.set('morph', {
			duration: 250
		});
		ul.setStyles({
			height: 0,
			opacity: 0,
			overflow: 'hidden'
		});
	});
	header.addEvents({
		'mouseover:relay(li.has-sub)': function(){
			var ul = this.getElement('ul');
			ul.morph({
				height: ul.retrieve('height'),
				opacity: 1
			});
		},
		'mouseout:relay(li.has-sub)': function(){
			this.getElement('ul').morph({
				height: 0,
				opacity: 0
			});
		}
	});

	var login = document.id('login');
	if (login){
		login.getElements('#auth_user').addEvents({
			'focus': function() {
				if (this.value == 'e-mail adres') {
					this.value = '';
				}
			},
			'blur': function() {
				if (this.value == '') {
					this.value = 'e-mail adres';
				}
				}
		});
		login.getElements('#auth_pass').addEvents({
			'focus': function() {
				if (this.value == 'wachtwoord') {
					this.value = '';
				}
			},
			'blur': function() {
				if (this.value == '') {
					this.value = 'wachtwoord';
				}
			}
		});
	}

	document.id('container').getElements('#carrousel .galimg').addEvents({
		'click': function(e) {
			if (e) { e.stop(); }
			document.id('carrousel').getElements('img').removeClass('active');
			this.getElements('img').addClass('active');
			if (document.id('firstimage').hasClass('active')) {
				document.id('secondimage').getElements('img').setProperty('src',this.href);
				document.id('secondimage').getElements('a').setProperty('href',this.href);
				document.id('secondimage').addClass('active');
				document.id('secondimage').tween('opacity', 1);
				document.id('firstimage').removeClass('active');
				document.id('firstimage').tween('opacity', 0);
				if (document.id('secondimage').getElements('img').getSize().x > document.id('secondimage').getElements('img').getSize().y) {
					if (document.id('secondimage').getElements('img').getSize().x > 380) {
						document.id('secondimage').getElements('img').setStyles({
							'height': 'auto',
							'width': 380
						});
					} else {
						document.id('secondimage').getElements('img').setStyles({
							'height': 'auto',
							'width': 'auto'
						});
					}
				} else {
					if (document.id('secondimage').getElements('img').getSize().y > 295) {
						document.id('secondimage').getElements('img').setStyles({
							'height': 295,
							'width': 'auto'
						});
					} else {
						document.id('secondimage').getElements('img').setStyles({
							'height': 'auto',
							'width': 'auto'
						});
					}
				}
			} else {
				document.id('firstimage').getElements('img').setProperty('src',this.href);
				document.id('firstimage').getElements('a').setProperty('href',this.href);
				document.id('firstimage').addClass('active');
				document.id('firstimage').tween('opacity', 1);
				document.id('secondimage').removeClass('active');
				document.id('secondimage').tween('opacity', 0);
				if (document.id('firstimage').getElements('img').getSize().x > document.id('firstimage').getElements('img').getSize().y) {
					if (document.id('firstimage').getElements('img').getSize().x > 380) {
						document.id('firstimage').getElements('img').setStyles({
							'height': 'auto',
							'width': 380
						});
					} else {
						document.id('firstimage').getElements('img').setStyles({
							'height': 'auto',
							'width': 'auto'
						});
					}
				} else {
					if (document.id('firstimage').getElements('img').getSize().y > 295) {
						document.id('firstimage').getElements('img').setStyles({
							'height': 295,
							'width': 'auto'
						});
					} else {
						document.id('firstimage').getElements('img').setStyles({
							'height': 'auto',
							'width': 'auto'
						});
					}
				}
			}
		}
	});
	document.id('container').getElements('#secondimage').setStyle('opacity', 0);
	document.id('container').getElements('#firstimage img').addEvents({
		'load': function() {
			if (this.getSize().x > this.getSize().y) {
				if (this.getSize().x > 380) {
					this.setStyles({
						'width': 380
					});
				}
			} else {
				if (this.getSize().y > 295) {
					this.setStyles({
						'height': 295
					});
				}
			}
		}
	});
	document.id('container').getElements('.new_classic_cat').addEvents({
		'click': function(e) {
			var checkcount = 0;
			document.id('container').getElements('.new_classic_cat').each(function(box) {
				if (box.getProperty('checked') == true) {
					checkcount++;
				}
			});
			if (checkcount > 4) {
				this.setProperty('checked', false);
			} 
		}
	});
	document.id('container').getElements('.young_fashion_cat').addEvents({
		'click': function(e) {
			var checkcount = 0;
			document.id('container').getElements('.young_fashion_cat').each(function(box) {
				if (box.getProperty('checked') == true) {
					checkcount++;
				}
			});
			if (checkcount > 4) {
				this.setProperty('checked', false);
			} 
		}
	});
});
