window.addEvent('load', function() {
	/*$$('.main-cat').each(function(item, index){
		$$('.sub-cat')[index].setStyles({
			'height': $$('.sub-cat')[index].getChildren('div')[0].getSize().y
		});
	});*/
});
window.addEvent('domready', function() {
	function validateEmail(email) { 
		var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/ 
		return email.match(re) 
	}
	
	if($chk($('nrb'))){
		var initValue2 = new Array();
		$('nrb').getChildren('input').each(function(item, index){
			initValue2[index] = item.get('value');
		});
		$('nrb').addEvent('submit', function(e){
			var sendForm = true;
			e.stop();
			if(!$('nrb').getChildren('input')[0].get('value') || $('nrb').getChildren('input')[0].get('value') == initValue2[0]){
				$('nrb').getChildren('input')[0].addClass('input-error');
				sendForm = false;
			}
			if(!validateEmail($('nrb').getChildren('input')[1].get('value'))){
				$('nrb').getChildren('input')[1].addClass('input-error');
				sendForm = false;
			}		
			if(sendForm)this.submit();			
		});
		$('nrb').getChildren('input').addEvent('focus', function(e){
			this.removeClass('input-error');
		});
	}
	if($chk($('ksb'))){
		var initValue = new Array();
		var initValueT = $('ksb').getChildren('textarea')[0].get('value');
		$('ksb').getChildren('input').each(function(item, index){
			initValue[index] = item.get('value');
		});
		$('ksb').addEvent('submit', function(e){
			var sendForm = true;
			e.stop();
			if(!$('ksb').getChildren('input')[0].get('value') || $('ksb').getChildren('input')[0].get('value') == initValue[0]){
				$('ksb').getChildren('input')[0].addClass('input-error');
				sendForm = false;
			}
			if(!validateEmail($('ksb').getChildren('input')[1].get('value'))){
				$('ksb').getChildren('input')[1].addClass('input-error');
				sendForm = false;
			}
			if(!$('ksb').getChildren('textarea')[0] || $('ksb').getChildren('textarea')[0].get('value') == initValueT){
				$('ksb').getChildren('textarea')[0].addClass('input-error');
				sendForm = false;
			}
			if(sendForm)this.submit();
			
		});
		$('ksb').getChildren('input').addEvent('focus', function(e){
			this.removeClass('input-error');
		});
		$('ksb').getChildren('textarea').addEvent('focus', function(e){
			this.removeClass('input-error');
		});
	}
//---------
	var subMenuFx = new Array();
	$$('.sub-cat').each(function(item, index){
		item.setStyle('width', item.getChildren('div')[0].getSize().x.toInt());
		subMenuFx[index] = new Fx.Tween(item, {
			link:'cancel',
			duration:250
		});
	});
	$$('.sub-cont').each(function(item, index){
		item.addEvents({
			'mouseenter':function(e){
				//this.getChildren('div')[0].setStyle('height',100);
				this.getParent().addClass('td-over');
				subMenuFx[index].start('height', this.getChildren('div')[1].getChildren('div')[0].getSize().y);
			},
			'mouseleave':function(e){
				this.getParent().removeClass('td-over');
				subMenuFx[index].cancel();
				subMenuFx[index].set('height', 0);
			}
		});
	});

	/*var subMenuFx = new Array();
	var subMenuTimeOut = new Array();
	var hoverTimeOut = new Array();
	$$('.sub-cat-sub').each(function(item, index){
		item.addEvents({
			'mouseenter':function(e){
				//clearTimeout(subMenuTimeOut[index]);
				clearTimeout(hoverTimeOut[index]);
				$$('.main-cat')[index].addClass('td-over');
			},
			'mouseleave':function(e){
				subMenuTimeOut[index] = (function(){subMenuFx[index].cancel();
				subMenuFx[index].set({'width':0})}).delay(50);
				hoverTimeOut[index] = (function(){$$('.main-cat')[index].removeClass('td-over')}).delay(50);
			}
		});
	});
	$$('.main-cat').each(function(item, index){
		subMenuFx[index] = new Fx.Morph($('sub-cat-cont').getChildren('div')[index],{
			link:'cancel',
			duration:350
		});
		if(index < 5)
			$$('.sub-cat')[index].setStyles({
				'left': item.getPosition($('main-cat-cont')).x.toInt(),
				'height': $$('.sub-cat')[index].getChildren('div')[0].getSize().y
			});
		else 
			$$('.sub-cat')[index].setStyles({
				'right': $('main-cat-cont').getSize().x.toInt()-item.getPosition($('main-cat-cont')).x.toInt()-item.getSize().x.toInt(),
				'height': $$('.sub-cat')[index].getChildren('div')[0].getSize().y
			});
		item.addEvents({
			'mouseenter':function(e){
				
				clearTimeout(subMenuTimeOut[index]);
				clearTimeout(hoverTimeOut[index]);
				item.addClass('td-over');
				//$('sub-cat-cont').getChildren('div')[index].setStyle('width',$('sub-cat-cont').getChildren('div')[index].getChildren('div')[0].getSize().x);
				subMenuFx[index].start({'width':$('sub-cat-cont').getChildren('div')[index].getChildren('div')[0].getSize().x});
			},
			'mouseleave':function(e){
				clearTimeout(hoverTimeOut[index]);
				hoverTimeOut[index]=(function(){item.removeClass('td-over');}).delay(50);
				subMenuTimeOut[index] = (function(){subMenuFx[index].cancel();
				subMenuFx[index].set({'width':0})}).delay(50);
			}
		});
	});
	
	*/
	var defaultMenuTop = $('menu-cont').getStyle('top').toInt();
	var minHeightTop = 2;
	var slide_top = new Fx.Scroll(window, {
		duration:1100,
		link:'cancel',
		transition:Fx.Transitions.Expo.easeOut
	});
	
	window.addEvent('scroll', function(e){
			//if(window.getScroll().y.toInt() == 0) $('to-slide-cont').fade(0);
			//else if($('to-slide-cont').getStyle('opacity') != 1) $('to-slide-cont').fade(1);
			if(window.getScroll().y.toInt() > defaultMenuTop-minHeightTop) $('menu-cont').setStyle('top', minHeightTop);
			else $('menu-cont').setStyle('top', defaultMenuTop - window.getScroll().y.toInt());
	});
	/*$('to-slide-cont').addEvent('click', function(e){
		slide_top.start(window.getScroll().x.toInt(), 0);
	});*/
});
