// Effect. (this includes prototype for effects)
var MECU = {
	init: function(){
		if ($$('.page-nav li ul').length > 0) {
			var subnavs = $$('.page-nav li>ul');
			subnavs.each(function(ul){
				if (!ul.up('li').hasClassName('active')){
					ul.addClassName('sub-hide');
				}
			});
		}
		if ($$('.mecu-form form').length > 0) {
			$$('.mecu-form form').each(function(f){
				var input = f.select('input[type="text"]')[0],
					initval = $F(input);
				input.observe('focus',function(){ if ($F(input) === initval){ input.setValue(''); } }).observe('blur',function(){ if ($F(input) === ''){ input.setValue(initval); } });
				if (f.hasClassName('olb-login')) {
					f.observe('submit',function(event){ if ($F(input) === initval){ alert('Please enter your username.'); event.stop(); return false; } else { f.submit(); input.setValue(initval); } });
				} else {
					f.observe('submit',function(event){ MECU.getMap(event); event.stop(); return false; });
				}
			});
		}
		$$('#nav>li').each(function(li){
			var poptext = '';
			switch(li.id){
				case 'nav_what-s-the-deal-':
					poptext = 'Deals, News & Local Info for Members';
					break;
				case 'nav_personal-services':
					poptext = 'Checking, Savings, Loans, Credit Cards, Investing & Insurance';
					break;
				case 'nav_business-services':
					poptext = 'Business Checking, Savings, Credit Cards, Loans & More';
					break;
				case 'nav_convenience-services':
					poptext = '24/7 Account Access, Banking, Bill Pay, ATMs & E-Statements';
					break;
			}
			li.insert({bottom: '<div class="pop-text" style="display:none;"><span>' + poptext + '</span></div>'});
			li.observe('mouseover',function(){this.select('div.pop-text')[0].show();}).observe('mouseout',function(){this.select('div.pop-text')[0].hide();});
		});
		$$('a[href^=http]:not([class~=whitelist])').each(function(a){a.observe('click',MECU.speedBump);});
	},
	getMap:function(event){
		var f = Event.element(event),
			input = f.select('input[type="text"]')[0],
			userval = $F(input),
			ci = '',
			st = '',
			zi = '';
		switch (f.hasClassName('search-zip')) {
			case true:
				if (isNaN(userval) || userval.length !== 5) {
					alert('Please enter a 5-digit numeric zip code.');
					event.stop();
					return false;
				}
				zi = $F(input);
				break;
			case false:
				if (userval.length === 0 || userval === 'Enter city') {
					alert('Please provide the city to search in.');
					event.stop();
					return false;
				}
				ci = $F(input);
				st = $F(f.down('select'));
				break;
		}
		var bmurl = 'http://www.branchmap.com/mapserver.php?client=mecunew&zip=' + encodeURIComponent(zi) + '&city=' + encodeURIComponent(ci) + '&state=' + encodeURIComponent(st);

		Modalbox.show('<iframe id="BranchMap" name="BranchMap" src="' + bmurl + '" framespacing="0" frameborder="no" scrolling="no" align="left" width="750" height="625"></iframe><p style="clear:both;"><a href="javascript:;" onclick="Modalbox.hide();">Close</a></p>',{title:'Find a MECU Branch or ATM', height:750,width:770, overlayClose:true, autoFocusing:false });
		event.stop();
		return false;
	},
	speedBump: function(event){
		var link = Event.findElement(event,'a');
		Modalbox.show('<p>When accessing any third party content within, or through, the MECU of Baltimore Inc. website, we encourage you to review the privacy policy and security offered on that site before providing any personal information. MECU of Baltimore Inc. does not guarantee or assume liability for any third party product or service obtained through our website. MECU of Baltimore Inc. does not represent either the third party or the member if the two enter into a transaction.</p><p><strong>' + link.href + '</strong></p><p><a href="' + link.href + '" target="_blank" onclick="Modalbox.hide();">Continue</a> <span>or</span> <a href="javascript:;" onclick="Modalbox.hide();">Cancel</a></p>',{title:'Warning: You are about to leave MECU\'s website', width:500, overlayClose:true, autoFocusing:false });
		event.stop();
		return false;
	}
};
document.observe('dom:loaded',MECU.init);
