
window.addEvent('domready', function() {
    if (window.ie == true || window.gecko == true) {
        new SmoothScroll();
    };

    if ($(document.body).hasClass('onlinebanking')) {
        $('AccessIDVisible').focus();
    };

    var homeloc = "default.aspx"
    
    // Nav1 cookie detector
    var ajaxHomeType = Cookie.read("ajaxhometype");
    if (ajaxHomeType == 'inc_ajax1' || ajaxHomeType == 'inc_ajax2' || ajaxHomeType == 'inc_ajax3' || ajaxHomeType == 'inc_ajax4') {
        //alert('The current ajaxHomeType is ' + ajaxHomeType + '.');
    } else {
        var ajaxHomeType = Cookie.read("ajaxhometypeperm");
        if (ajaxHomeType == 'inc_ajax1' || ajaxHomeType == 'inc_ajax2' || ajaxHomeType == 'inc_ajax3' || ajaxHomeType == 'inc_ajax4') {
            var esolutionsCookie = Cookie.write('ajaxhometype', ajaxHomeType, { duration: 0 });
            var ajaxHomeType = Cookie.read("ajaxhometype");
            //alert('The current ajaxHomeType has been set from ajaxhometypeperm to ' + ajaxHomeType + '.');
        } else {
            var esolutionsCookie = Cookie.write('ajaxhometype', 'inc_ajax1', { duration: 0 });
            var ajaxHomeType = Cookie.read("ajaxhometype");
            //alert('No cookie found so one was set.\najaxHomeType is ' + ajaxHomeType + '.');
        }
        //alert('No cookie found so one was set.\najaxHomeType is ' + ajaxHomeType + '.');
    };

    // nav_ob cookie detector
    var ajaxonlinetype = Cookie.read("ajaxonlinetype");
    if ($defined(ajaxonlinetype)) {
        //var ajaxHomeType = Cookie.get("ajaxhometype");
        //alert('The current ajaxHomeType is ' + ajaxHomeType + '.');
    } else {
        var ajaxonlinetype = Cookie.read("ajaxhometypeperm");
        if (ajaxonlinetype == 'personal' || ajaxonlinetype == 'business') {
            var esolutionsCookie = Cookie.write('ajaxonlinetype', ajaxonlinetype, { duration: 0 });
            var ajaxonlinetype = Cookie.read("ajaxonlinetype");
            //alert('The current ajaxonlinetype is ' + ajaxonlinetype + '.');
        } else {
            var esolutionsCookie = Cookie.write('ajaxonlinetype', 'personal', { duration: 0 });
            var ajaxonlinetype = Cookie.read("ajaxonlinetype");
            //alert('No cookie found so one was set.\najaxHomeType is ' + ajaxHomeType + '.');
        }
        //alert('No cookie found so one was set.\najaxHomeType is ' + ajaxHomeType + '.');
    };

    // Pulls the content of url and places it in the div set in update
        
    function ajaxswitch() {
        var url = ajaxHomeType + ".aspx";

        if ($(document.body).hasClass('home') && ajaxHomeType != false) {
            var req = new Request.HTML({ 
                url: url,
                update: $('homepages'),
				onComplete: function(response) { 
         				if (ajaxHomeType == 'inc_ajax1'){
							function slideShow( Obj ){
								var pass = this;
							    // Initializing
							    this.slides = Obj;
							    pass.curImg = $random(0, this.slides.length - 1);
								this.slides[ pass.curImg ].setStyle('visibility', 'visible');
								this.slides[ pass.curImg ].setStyle('opacity', 1);
								this.slides[ pass.curImg ].setStyle('z-index', 2);
							 
								this.rand = function(){
									randNum = pass.curImg;
									while (randNum == pass.curImg) {
										randNum = $random(0, this.slides.length - 1);
									}
									pass.curImg = randNum;
							        this.slides.each( function( img, index ){ 
							            img.morph({ opacity: 0 });
							        }, this);
							        this.slides[ pass.curImg ].morph({ opacity: 1 });
							    }
							    this.next = function(){
							        pass.curImg++;
							        this.slides.each( function( img, index ){ 
							            img.morph({ opacity: 0 });
							        }, this);
							        if( pass.curImg == this.slides.length ) pass.curImg = 0;
							        this.slides[ pass.curImg ].morph({ opacity: 1 });
							    }
							    this.prev = function(){
							        pass.curImg--;
							        this.slides.each( function( img, index ){ 
							            img.morph({ opacity: 0 });
							        }, this);
							        if( pass.curImg < 0 ) pass.curImg = this.slides.length - 1;
							        this.slides[ pass.curImg ].morph({ opacity: 1 });
							    }
							}
							sshow = new slideShow( $$('#mainimg img') );
							sshow.rand.periodical( 10000, sshow );
						}
				}	
            }).send();
        };
    };
    ajaxswitch();

    function clearhome() {
        ajaxHomeType = Cookie.read("ajaxhometypeperm");
        var esolutionsCookie = Cookie.write('ajaxhometype', ajaxHomeType, { duration: 0 });
        top.location = homeloc;
    };

    function changeObPersonal() {
        $('nav_ob_btn1').addClass('active');
        $('nav_ob_btn2').removeClass('active');
        $('onlinebanking').removeClass('red');
        $('onlinebanking_header').removeClass('red');
        $('ob_firsttimeuser').setStyle('display', 'block');
        $('ob_forgotpassword').setStyle('display', 'block');
        x.action = 'https://secure.westgatebank.com/pbi_pbi1961/Pbi1961.asp?WCI=RemoteLogin&RT=104901584&LogonBy=connect3&PRMACCESS=Portfolio';
    };

    function changeObBusiness() {
        $('nav_ob_btn2').addClass('active');
        $('nav_ob_btn1').removeClass('active');
        $('onlinebanking').addClass('red');
        $('onlinebanking_header').addClass('red');
        $('ob_firsttimeuser').setStyle('display', 'none');
        $('ob_forgotpassword').setStyle('display', 'none');
        x.nmUID.value = x.AccessIDVisible.value; //OLD LINE 92 x.nmUID.value = x.AccessID.value;
        x.nmRTN.value = rtNum;
        x.action = 'https://secure.westgatebank.com//EBC_EBC1961/EBC1961.asp?WCI=Process&WCE=RemoteLogon&IRL=T&mfa=2';
    };

    // Sets the active button state for which tab is select based on the session cookie
    function setactivestate() {

        if ($(document.body).hasClass('home')) {

            if (ajaxHomeType == Cookie.read("ajaxhometypeperm")) {
                $('makehome').removeClass('visible');
            }
            else {
                $('makehome').addClass('visible');
            }

            if (ajaxHomeType == 'inc_ajax1') {
                $('nav1_btn1').addClass('active');
                $('nav1_btn2').removeClass('active');
                $('nav1_btn3').removeClass('active');
                $('nav1_btn4').removeClass('active');
            }
            else if (ajaxHomeType == 'inc_ajax2') {
                $('nav1_btn2').addClass('active');
                $('nav1_btn1').removeClass('active');
                $('nav1_btn3').removeClass('active');
                $('nav1_btn4').removeClass('active');
            }
            else if (ajaxHomeType == 'inc_ajax3') {
                $('nav1_btn2').removeClass('active');
                $('nav1_btn1').removeClass('active');
                $('nav1_btn3').addClass('active');
                $('nav1_btn4').removeClass('active');
            }
            else if (ajaxHomeType == 'inc_ajax4') {
                $('nav1_btn2').removeClass('active');
                $('nav1_btn1').removeClass('active');
                $('nav1_btn3').removeClass('active');
                $('nav1_btn4').addClass('active');
            }
            else {
                $('nav1_btn1').removeClass('active');
                $('nav1_btn2').removeClass('active');
                $('nav1_btn3').removeClass('active');
                $('nav1_btn4').removeClass('active');
            }

        }
        else if ($(document.body).hasClass('personal')) {
            $('nav1_btn1').addClass('active');
            $('nav1_btn2').removeClass('active');
            $('nav1_btn3').removeClass('active');
            $('nav1_btn4').removeClass('active');
        }
        else if ($(document.body).hasClass('business')) {
            $('nav1_btn1').removeClass('active');
            $('nav1_btn2').addClass('active');
            $('nav1_btn3').removeClass('active');
            $('nav1_btn4').removeClass('active');
        }
        else if ($(document.body).hasClass('faq') || $(document.body).hasClass('faqhome')) {
            $('nav1_btn1').removeClass('active');
            $('nav1_btn2').removeClass('active');
            $('nav1_btn3').addClass('active');
            $('nav1_btn4').removeClass('active');
        }
        else if ($(document.body).hasClass('about')) {
            $('nav1_btn1').removeClass('active');
            $('nav1_btn2').removeClass('active');
            $('nav1_btn3').removeClass('active');
            $('nav1_btn4').addClass('active');
        }
    }
    if ($(document.body).hasClass('onlinebanking')) {
        var rtNum = "104901584";
        var x = document.forms.Remote;

        if (ajaxonlinetype == 'personal') {
            changeObPersonal();
        }
        else if (ajaxonlinetype == 'business') {
            changeObBusiness();
        }
        else {
            $('nav_ob_btn1').addClass('active');
            $('nav_ob_btn2').removeClass('active');
        }
    }

    setactivestate();

    $('start').addEvent('click', function(e) {
        e = new Event(e).stop();
        var ajaxHomeType = Cookie.read("ajaxhometype");
        var esolutionsCookie = Cookie.write('ajaxhometypeperm', ajaxHomeType, { duration: 365 });
        var ajaxHomeType = Cookie.read("ajaxhometypeperm");
        top.location = homeloc;
        //alert('The current ajaxHomeType is ' + ajaxHomeType + '.');
    });

    // Link actions for each navigation button
    // Link IDs should be nav1_btn1, nav1_btn2 ... format
    $('nav1_btn1').addEvent('click', function(e) {
        e = new Event(e).stop();
        ajaxHomeType = "inc_ajax1";
        setactivestate();
        var esolutionsCookie = Cookie.write('ajaxhometype', ajaxHomeType, { duration: 0 });
        top.location = homeloc;
    });
    $('nav1_btn2').addEvent('click', function(e) {
        e = new Event(e).stop();
        ajaxHomeType = "inc_ajax2";
        setactivestate();
        var esolutionsCookie = Cookie.write('ajaxhometype', ajaxHomeType, { duration: 0 });
        top.location = homeloc;
    });

    // Link actions for the drilldown
    $('dd_personal_btn').addEvent('click', function(e) {
        e = new Event(e).stop();
        ajaxHomeType = "inc_ajax1";
        setactivestate();
        var esolutionsCookie = Cookie.write('ajaxhometype', ajaxHomeType, { duration: 0 });
        top.location = homeloc;
    });
    $('dd_business_btn').addEvent('click', function(e) {
        e = new Event(e).stop();
        ajaxHomeType = "inc_ajax2";
        setactivestate();
        var esolutionsCookie = Cookie.write('ajaxhometype', ajaxHomeType, { duration: 0 });
        top.location = homeloc;
    });

    //Link actions for the online banking navigation buttons
    if ($('nav_ob_btn1') != null) {
        $('nav_ob_btn1').addEvent('click', function(e) {
            e = new Event(e).stop();
            ajaxonlinetype = "personal";
            setactivestate();
            var esolutionsCookie = Cookie.write('ajaxonlinetype', ajaxonlinetype, { duration: 365 });
            changeObPersonal();
        });
    }
    if ($('nav_ob_btn2') != null) {
        $('nav_ob_btn2').addEvent('click', function(e) {
            e = new Event(e).stop();
            ajaxonlinetype = "business";
            setactivestate();
            var esolutionsCookie = Cookie.write('ajaxonlinetype', ajaxonlinetype, { duration: 365 });
            changeObBusiness();
        });
    }

    //Steps fx
    var stepsfx = $$('#steps li');

    stepsfx.each(function(element) {

        var fx_steps = new Fx.Styles(element, { duration: 200, wait: false });

        element.addEvent('mouseenter', function() {
            fx_steps.start({
                'padding-left': 15, 'background-color': 'E1E5EE'
            });
        });

        element.addEvent('mouseleave', function() {
            fx_steps.start({
                'padding-left': 10, 'background-color': 'D3DBEE'
            });
        });

    });
}); 
	

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  var link = selObj.options[selObj.selectedIndex].value;
  if (link == 'https://www.bonuscheckcard.com/home.asp' || link == 'https://www.scorecardrewards.com' || link == 'https://www.annualcreditreport.com/cra/index.jsp' || link ==  'https://eprimevest.automatedfinancial.com/')
  {
  	if (!confirm('This link is NOT under the control of West Gate Bank,\nbut rather is exclusively controlled by a third party.'))
  	{
  		return false;
  	} 
  	else
  	{
	  	eval("window.open('"+selObj.options[selObj.selectedIndex].value+"','_blank')");
		if (restore) selObj.selectedIndex=0;
  	}
  }
  else
  {
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
  }
}

