/****************************************
*	NAVIGATION HOVER
*
*	Created by:			Adam Foster
*	Date Created:		2008-02-27
*
*	Copyright 2008 Lightmaker Manchester
*
****************************************/

window.addEvent('load', function() {

	/***************
	* Link hover nav 
	***************/
	var navItems = $$('#navigationList li');
	var activeItem = $E('li.isActive span', 'navigationList');
	navItems.each(function(item) {
		item.$tmp.span = item.getElement('span');
		item.$tmp.span.setStyle('display', 'block');
		item.$tmp.fx = new Fx.Styles(item.$tmp.span, { wait: false, duration: 600, transition: Fx.Transitions.Quad.easeInOut });
		if (activeItem) { activeItem.$tmp.fx2 = new Fx.Styles(activeItem, { wait: false, duration: 600, transition: Fx.Transitions.Quad.easeInOut }); }

		// checks for active link, if its actiive don't animate				
		if (item.hasClass("isActive")) {
			item.$tmp.span.setStyle('opacity', 1);
		} else {
			item.$tmp.span.setStyle('opacity', 0);
			//	Show bg on mouse over	
			item.addEvent('mouseenter', function(event) {
				event = new Event(event).stop();
				this.$tmp.fx.stop();
				if (activeItem) { activeItem.$tmp.fx2.stop(); };
				this.$tmp.fx.start({ 'opacity': '1' });
				if (activeItem) { activeItem.$tmp.fx2.start({ 'opacity': '0', 'color': 'CCCCCC' }); };
			});
			//	Hide bg on mouse leave	
			item.addEvent('mouseleave', function(event) {
				event = new Event(event).stop();
				this.$tmp.fx.stop();
				this.$tmp.fx.start({ 'opacity': '0' });
				if (activeItem) { activeItem.$tmp.fx2.start({ 'opacity': '1', 'color': 'FFFFFF' }); };
			});
		}
	});

	//	Return to current open section when you leave the menu
	if (activeItem) {
		$('navigationList').addEvent('mouseleave', function(event) {
			event = new Event(event).stop();
			activeItem.$tmp.fx2.start({ 'opacity': '1', 'color': 'FFFFFF' });
		});
	}

	/***************
	* Signin Slider  &  Language Selector
	***************/

	/*var hiddenForm = $('signScroll');
	if (hiddenForm != null) {
	hiddenForm.setStyle('left', '-320px');
	hiddenForm.fx = new Fx.Styles(hiddenForm, {wait: false,duration: 300,transition: Fx.Transitions.Quad.easeInOut});
	}*/

	var hiddenLang = $('langScroll');
	var languageWidth = 0;
	if (hiddenLang != null) {
		var langToggle = $('langToggle');
		if (langToggle != null) {
			$('langToggle').setStyle('display', 'block');
			languageWidth = parseInt($$('#languagePanel').getStyle('width')) - (parseInt($('langToggle').getStyle('width')) + parseInt($$('#langScroll strong').getStyle('width')) + 50);

			$('langToggle').addEvent('click', function(event) {
				event = new Event(event).stop();
				//			$$('#langScroll a.langIcon').setStyle('display', 'block');
				//if (hiddenForm != null) {hiddenForm.fx.start({'left': '-320px'});}
				hiddenLang.fx.start({ 'margin-left': '0px' });
			});
		};
		hiddenLang.setStyle('margin-left', languageWidth);

		hiddenLang.fx = new Fx.Styles(hiddenLang, { wait: false, duration: 800, transition: Fx.Transitions.Cubic.easeOut });
		hiddenLang.fx2 = new Fx.Styles(hiddenLang, { wait: false, duration: 400, transition: Fx.Transitions.Cubic.easeOut });

		/*var signInToggle = $('signToggle');
		if (signInToggle != null) {
		signInToggle.addEvent('click', function(event) {
		event = new Event(event).stop();
		hiddenLang.fx.stop();
		hiddenLang.fx2.stop();
		if (hiddenForm != null) {hiddenForm.fx.start({'left': '0px'});}
		hiddenLang.fx2.start({'margin-left': marginLeft+'px'});
		});
		}*/

		$('main').addEvent('mouseleave', function(event) {
			event = new Event(event).stop();
			hiddenLang.fx.stop();
			hiddenLang.fx2.stop();
			hiddenLang.fx2.start.delay(400, hiddenLang.fx2, { 'margin-left': languageWidth + 'px' });
			//if (hiddenForm != null) {hiddenForm.fx.start.delay(400, hiddenForm.fx, {'left': '-320px'});}
		});
	};

	$j('div.atStart').hide();
	$j('.currentTitle').next().css({ display: 'block' })
	
	/* sub nav */
	var navItems = $$('.productsMenu li');
	navItems.each(function(item) {
		item.$tmp.a = item.getElement('a');
		item.$tmp.fx = new Fx.Styles(item.$tmp.a, { wait: false, duration: 200, transition: Fx.Transitions.Quad.easeOut });
		// checks for active link, if its actiive don't animate				
		if (item.hasClass("subIsActive")) {
			item.$tmp.a.setStyles({ 'background-position': '0px', 'color': '#444', 'padding-left': '15px' });
		} else {
			item.$tmp.a.setStyles({ 'background-position': '-15px' });
			//	Show bg on mouse over	
			item.addEvent('mouseenter', function(event) {
				event = new Event(event).stop();
				item.$tmp.fx.stop();
				item.$tmp.fx.start({ 'background-position': '0px', 'padding-left': '15px' });
			});
			//	Hide bg on mouse leave	
			item.addEvent('mouseleave', function(event) {
				event = new Event(event).stop();
				item.$tmp.fx.stop();
				item.$tmp.fx.start({ 'background-position': '-15px', 'padding-left': '0px' });
			});
		}
	});

	var navTitles = $$('.productTitle a');
	navTitles.each(function(n) {
		n.addEvent('mouseenter', function(event) {
			n.getElement('img').setStyle('top', '-40px');
			n.setStyle('cursor', 'pointer');
		});
		n.addEvent('mouseleave', function(event) {
			if (n.hasClass("active")) {
				n.getElement('img').setStyle('top', '-40px');
			} else {
				n.getElement('img').setStyle('top', '0px');
			}
			n.setStyle('cursor', 'default');
		});
	});


	/* Blur input boxes */
	var blurInputs = $$('input[type=text]');
	blurInputs.each(function(inputs) {
		inputs.addEvent('focus', function(event) {
			event = new Event(event).stop();
			if (inputs.value == inputs.defaultValue) { inputs.value = "" }
		});
		inputs.addEvent('blur', function(event) {
			event = new Event(event).stop();
			if (inputs.value == "") { inputs.value = inputs.defaultValue }
		});
	});
});


// print any page
function printpage() {
	window.print();
}


