var myFxOver;
var myFxOut;

window.addEvent('domready', function(){

	// Select Contact_Name field if on contact form page
	if($('Contact_Name')){
		$('Contact_Name').focus();
		// Attach focus and blur events to form fields
		$$('.text').each(function(el){
			el.addEvent('focus', function(e){
				$(this).addClass('sel');
			});
			el.addEvent('blur', function(e){
				$(this).removeClass('sel');
			});
		});
	}
	
	InitContactInfo();
	
});

function showContactInfo(e){
	if(myFxOver != undefined && myFxOver.cancel) myFxOver.cancel();
	if(myFxOut != undefined && myFxOut.cancel) myFxOut.cancel();
	myFxOver = new Fx.Tween($('contact-info'));
	myFxOver.start('top', 0);
}
function hideContactInfo(e){
	if (!e) var e = window.event;
	var tg = (window.event) ? e.srcElement : e.target;
	if (tg.nodeName != 'DIV') return;
	var reltg = (e.relatedTarget) ? e.relatedTarget : e.toElement;
	if(reltg.id == 'talk-button') return;
	while (reltg != tg && reltg.nodeName != 'BODY'){
		reltg= reltg.parentNode;
	}
	if (reltg== tg) return;

	// Mouseout took place when mouse actually left layer, handle event
	if(myFxOver != undefined && myFxOver.cancel) myFxOver.cancel();
	if(myFxOut != undefined && myFxOut.cancel) myFxOut.cancel();
	active = true;
	myFxOut = new Fx.Tween($('contact-info'));
	myFxOut.start('top', -315);
}
function hideContactInfoFromButton(e){
	if (!e) var e = window.event;
	var reltg = (e.relatedTarget) ? e.relatedTarget : e.toElement;
	if(reltg && reltg.id == 'outer-wrapper') hideContactInfo(e);
}
function forceHideContactInfo(e){
	if(myFxOver != undefined && myFxOver.cancel) myFxOver.cancel();
	if(myFxOut != undefined && myFxOut.cancel) myFxOut.cancel();
	myFxOut = new Fx.Tween($('contact-info'));
	myFxOut.start('top', -315);
}
function InitContactInfo(){
	if($('talk-button') && $('contact-info')){
		$('talk-button').onmouseover = showContactInfo;
		$('talk-button').onmouseout = hideContactInfoFromButton;
		$('contact-info').onmouseout = hideContactInfo;
		window.onfocus = forceHideContactInfo;
	}
}


