window.addEvent('domready', function() { // initializes the application object when the page finished loading
	mainMenuAnimation();
	searchBarAnimations();
	newsletterBarAnimations();
	articleGroupsAnimation();
	footerButtonsAnimations()
	forceRedraw.delay(200);
});
function forceRedraw(){
	$E('.footer').setStyle('display', 'none').setStyle('display', 'block');
}

function mainMenuAnimation() {
	$E('.mainMenu').getChildren().each(function(menuItem){
		//var liAnim = new Fx.Styles(menuItem, {duration:1000, onComplete:function(){}, wait:false});
		//var aAnim = new Fx.Styles(menuItem.getFirst(), {duration:1000, wait:false});
		//liAnim.set({
			//'background-position' : '0 39'
		//});
		menuItem.addEvents({
			'mouseenter' : function(event) {
				/*liAnim.start({
					'background-position' : '0 0'
				});
				aAnim.start({
					'background-position' : '100% 0px'
				});*/
				$(this).addClass('mainMenuHover'); 
				$(this).getFirst().addClass('mainMenuHover');
			},
			'mouseleave' : function(event) {
				/*aliAnim.start({
					'background-position' : '0 39'
				});
				Anim.start({
					'background-position' : '100% 39px'
				});*/
				$(this).removeClass('mainMenuHover'); 
				$(this).getFirst().removeClass('mainMenuHover');
			}
		});
	});
}

function searchBarAnimations() {
	$E('.searchBarButton').addEvents({
		'mouseover' : function(event) {
			$(this).addClass('searchBarButtonHover');
		},
		'mouseout' : function(event) {
			$(this).removeClass('searchBarButtonHover');
		}
	});
	$E('.searchBarInput').addEvents({
		'mouseover' : function(event) {
			$(this).addClass('searchBarInputHover');
		},
		'mouseout' : function(event) {
			$(this).removeClass('searchBarInputHover');
		},
		'focus' : function(event) {
			if (this.value.substr(0, 2) == '< ' && this.value.substr(this.value.length - 2, this.value.length) == ' >') {
				this.setProperty('oldValue', this.value);
				this.value = '';
			}
		},
		'blur' : function(event) {
			if (this.value == '') {
				this.value = this.getProperty('oldValue');
				this.setProperty('oldValue', '');
			}
		}
	});
}

function newsletterBarAnimations() {
	$E('.newsletterBarButton').addEvents({
		'mouseover' : function(event) {
			$(this).addClass('newsletterBarButtonHover');
		},
		'mouseout' : function(event) {
			$(this).removeClass('newsletterBarButtonHover');
		}
	});
	$E('.newsletterBarInput').addEvents({
		'mouseover' : function(event) {
			$(this).addClass('newsletterBarInputHover');
		},
		'mouseout' : function(event) {
			$(this).removeClass('newsletterBarInputHover');
		},
		'focus' : function(event) {
			if (this.value.substr(0, 2) == '< ' && this.value.substr(this.value.length - 2, this.value.length) == ' >') {
				this.setProperty('oldValue', this.value);
				this.value = '';
			}
		},
		'blur' : function(event) {
			if (this.value == '') {
				this.value = this.getProperty('oldValue');
				this.setProperty('oldValue', '');
			}
		}
	});
}

function articleGroupsAnimation() {
	$ES('.articleGroupsItem').each(function(group){
		var groupAnim = new Fx.Styles(group.getFirst(), {duration:300, wait:false});
		group.addEvents({
			'mouseenter' : function(event) {
				groupAnim.start({
					'margin-left' : '-8px'
				});
			},
			'mouseleave' : function(event) {
				groupAnim.start({
					'margin-left' : '0px'
				});
			},
			'click' : function(event) {
				var event = new Event(event);
				event.stopPropagation();
				top.location.href = this.getFirst().getProperty('href');
			}
		});
	});
}

function footerButtonsAnimations() {
	var footerBackAnim = new Fx.Styles($E('.footerBackButton'), {duration:300, wait:false});
	$E('.footerBackButton').addEvents({
		'mouseenter' : function(event) {
			footerBackAnim.start({
				'background-position' : '0'
			});
		},
		'mouseleave' : function(event) {
			footerBackAnim.start({
				'background-position' : '5'
			});
		}
	});
	var footerTopAnim = new Fx.Styles($E('.footerTopButton'), {duration:300, unit:'%', wait:false});
	$E('.footerTopButton').addEvents({
		'mouseenter' : function(event) {
			footerTopAnim.start({
				'background-position' : '100%'
			});
		},
		'mouseleave' : function(event) {
			footerTopAnim.start({
				'background-position' : '80%'
			});
		}
	});
}
