function clearText(thefield){
	if (thefield.defaultValue==thefield.value){	
		thefield.value = "";
	};
}
function clearSearchText(thefield){
	if (thefield.defaultValue==thefield.value){	
		thefield.value = "";
		var element = document.getElementById('search');
		element.className = "searchactive searchbox";
	};
}

function validateLoginIE(id)
{
	id = document.getElementById(id)
	if(id.value == '' || id.value == 'ACCESS ID')
	{
		id.focus();
		alert("Please enter an Access ID")
		return false;
	}else{
		var x = document.forms.logID;
		var y = document.getElementById('AccessID')
		y.value = id.value;
		id.value = "";
		x.action = 'https://web1.secureinternetbank.com/pbi_pbi1961/Pbi1961.ashx?WCI=RemoteLogin&RT=275971825&LogonBy=connect3&PRMACCESS=Portfolio';
		_gaq.push(['_trackPageview', '/onlinebanking/personal']);
	}
}

window.addEvent('domready', function(){		
	
	// Set navigation page
    $$('#primary-nav a').each(function(el,index) {
        if(('/' + el.getAttribute('href')) == (location.pathname + location.hash) || ('/westburybank/' + el.getAttribute('href')) == (location.pathname + location.hash)) { 
            el.addClass('selected'); 
            el.setStyle('color', '#4db145');
            var elId = 'selectedPageArrow' + index;
            var selectedPageArrow = new Element ( 'div' , { 'id' : elId, 'class' : 'selectedPageArrows' });
            selectedPageArrow.injectInside(el);
            var markereffect = new Fx.Morph(elId, {duration: 'long', transition: Fx.Transitions.Bounce.easeOut});
			markereffect.start({
				'height': 16
			});
        }
    });



	//Slideshow
	var gallery1 = new slideGallery($$(".gallery1"), {
		steps: 1,
		mode: "circle",
		random: true,
		autoplay: true,
		stop: ".stop",
		start: ".start",
		duration: 13000,
		stopOnHover: false,
		speed: 2000
	});				 
									 
	// Scrollspy
	new SmoothScroll({duration:500});
	
	$('gototop').set('opacity','0').setStyle('display','block');
	
	var ss = new ScrollSpy({
		min: 90,
		onEnter: function(position,enters) {
			//if(console) { console.log('Entered [' + enters + '] at: ' + position.x + ' / ' + position.y); }
			$('gototop').fade('in');
			if ($('leftnav')){
				$('leftnav').morph({'margin-top': 25});
				$$('a.leftnav-backtotop').morph({'background-position': '0 0'});
				$$('a.leftnav-logotab').morph({'background-position': '0 0'});
			}
		},
		onLeave: function(position,leaves) {
			//if(console) { console.log('Left [' + leaves + '] at: ' + position.x + ' / ' + position.y); }
			$('gototop').fade('out');
			if ($('leftnav')){
				$('leftnav').morph({'margin-top': 84});
				$$('a.leftnav-backtotop').morph({'background-position': '0 -116px'});
				$$('a.leftnav-logotab').morph({'background-position': '0 85px'});
			}

		},
		onTick: function(position,state,enters,leaves) {
			//if(console) { console.log('Tick  [' + enters + ', ' + leaves + '] at: ' + position.x + ' / ' + position.y); }
		},
		container: window
	});	
								 
	// Table Alternating colors
	function updateTableColors() {
		var count = 0;
		$$('table.styledtable tr').each(function(el) {
			el.addClass(count++ % 2 == 0 ? 'odd' : 'even');
		});
	};
	updateTableColors();
	
	// Homepage Primary Navigation 
	if ($defined($('nav')) && $(document.body).hasClass('home')){
		$$('.nav-item').each(function(el, index) {
			el.addEvents({
				mouseenter: function(){
					el.set('morph', {duration: 'short'});
					this.morph({
						'margin-left': 10
					});
					//this.getChildren('img').morph({'margin-left': '0px'});
				},
				mouseleave: function(){
					el.set('morph', {duration: 'normal'});
					this.morph({
						'margin-left': 0
					});
					//this.getChildren('img').morph({'margin-left': '-265px'});

				}

			});
		});
	}
	
}); 

window.addEvent('load', function(){
	// Tutorial popup 
	if ($defined($('obtutorialxy')) && $(document.body).hasClass('home')){
		function initializetutorial() {
			$('obtutorialxy').setStyle('display', 'block');
			var tutorialeffect = new Fx.Morph('obtutorialxy', {duration: 'long', transition: Fx.Transitions.Bounce.easeOut});
			tutorialeffect.start({
				'margin-top': 75
			});
		};
		var loginToSelected = Cookie.read('bypasstutorial');
		if ( $chk(loginToSelected) ) {
		 
		} else {
			initializetutorial();
		}
		
		var tutorialclose = $$('.tutorialclose');
		tutorialclose.each(function(el, index) {
			el.addEvents({
				click: function(){
					var tutorialCookie = Cookie.write('bypasstutorial', 'true');
					//$('obtutorialxy').fade('out');
					$('obtutorialxy').setStyle('display', 'none');
					}
			});
		});
		var tutorialcloseperm = $$('.tutorialcloseperm');
		tutorialcloseperm.each(function(el, index) {
			el.addEvents({
				click: function(){
					var tutorialCookie = Cookie.write('bypasstutorial', 'true', {duration: 120});
					//$('obtutorialxy').fade('out');
					$('obtutorialxy').setStyle('display', 'none');
					}
			});
		});
	}
	
	
}); 


