$(document).ready(function() {
	var e = window.location.href;
	var index = e.indexOf('index.php');
	var personal = e.indexOf('personal');
	var business = e.indexOf('business');
	var rate = e.indexOf('rate');
	var j = e.substring(index - 1);
	var closeLink =  $('<a class="close" title="close" href="#">close</a>');
	var onlineVisible = false;

	//alert(pString);
	/* employment application */
		var $allpanes = $(".tab-pane");
		$allpanes.hide();
		
		if ($('.form-error').length > 0)
		{
			$(".tab-pane:last").show();
		}
		else
		{
			$(".tab-pane:first").show();
		}
		
		$('.appnav a').click(function() {
			var $tab = $($(this).attr('href'));
			$allpanes.hide();
			$tab.show();
			return false;
		});

	//NAVIGATION TWEEKS ///////////////////////////////////////////
	$('#subNavWrap a')
	  .removeClass('current');
	  
	$('#subNavWrap a[href=' + j +']')
		.addClass('current');
		
	if(personal > 0){
		$('#subNavWrap a').eq(0).addClass('current');	
	}
	if(business > 0){
		$('#subNavWrap a').eq(1).addClass('current');	
	}
	if(rate > 0){
		$('#subNavWrap a').eq(3).addClass('current');	
	}
	
	$('#footer #menuwrapper a')
	  .removeClass('menuactive');
	  
	$('#footer #menuwrapper a[href=' + j +']')
		.addClass('menuactive');	
	
	
	$('.cssform, #search form').defaultvalues({focusaction:"clear"});
	//$('#projectsTable tr:even').addClass('grey');
	
	$('#accordian #box div').hide();
	$('#accordian #box div div').show();
	//$('#accordian #text').hide();
	$('#accordian h1 a').click(function(e){
		e.preventDefault();
		//$('#accordian #text').slideToggle('fast');
		$(this).parent().next().slideToggle('fast');
	});
	
	$('#onlineBanking').append(closeLink);
	$(closeLink).hide();
	$('#onlineBanking .online')
		.click(function(e){
			e.preventDefault();
			if(onlineVisible == false){
				onlineVisible = true;
				$('#onlineBanking').css({'border':'solid 1px #E3DFD6','background-color':'#FFF'});
				$('#onlineBanking .online').css({'color':'#8E7D4F','padding':'11px 19px 12px 21px'});
				$('#onlineBanking #onlineForm').fadeIn();
				$(closeLink).show();
			}else{
				onlineVisible = false;
				$('#onlineBanking').css({'border':'none','background-color':'transparent'});
				$('#onlineBanking .online').css({'color':'#DBCCB9','padding':'12px 20px'});
				$('#onlineBanking #onlineForm').hide();
				$(closeLink).hide();
			}
		})
		.hover(function(){
			if(onlineVisible == false){
		      $(this).css({'color':'#DBCCB9'});
			}
		},function(){
			if(onlineVisible == false){
		      $(this).css({'color':'#473C28'});
			};
		});
	$(closeLink).click(function(e){
		onlineVisible = false;
		e.preventDefault();
		$('#onlineBanking').css({'border':'none','background-color':'transparent'});
		$('#onlineBanking .online').css({'color':'#DBCCB9','padding':'12px 20px'});
		$('#onlineBanking #onlineForm').hide();
		$(this).hide();
	});
		
	$('#cod tr:even').addClass('on');
	

	/*///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	STANDARD SLIDESHOW
	///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	arrangeStack();
	LoadMarket();
});
function LoadMarket() {
        $.ajax({
          url: "stock.php",
          success: function(html){
            $("#stock").html(html);
          }
        });
}

/*///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
STANDARD SLIDESHOW
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
function arrangeStack(){
	var slideshow = $('#standardShow img');
	var numberOfSlides = slideshow.length;
	
	if (numberOfSlides > 1){
		$(slideshow).each(function(i){
			$(this).css({
				'z-index' : 0
			});
		});
		$(slideshow).eq(0).css({'z-index' : 2});
		$(slideshow).eq(1).css({'z-index' : 1});
		setTimeout(function() {standardSlideShow(0);}, 8000);
	}else{
		return;	
	}
	
};
function standardSlideShow (currentSlide){
	var slideshow = $('#standardShow img');
	var numberOfSlides = slideshow.length;
	currentSlide = currentSlide % numberOfSlides;
	
	$(slideshow).eq(currentSlide).fadeOut(function(){
		if(currentSlide == numberOfSlides - 2){
			$(slideshow).eq(currentSlide + 1).css({'z-index': 2});
			$(slideshow).eq(0).css({'z-index': 1});
		}else if(currentSlide == numberOfSlides - 1){
			$(slideshow).eq(0).css({'z-index': 2});
			$(slideshow).eq(1).css({'z-index': 1});
		}else{
			$(slideshow).eq(currentSlide + 1).css({'z-index': 2});
			$(slideshow).eq(currentSlide + 2).css({'z-index': 1});
		}
		
		$(this).show().css({'z-index' : 0});
		setTimeout(function() {standardSlideShow(++currentSlide);}, 8000);
		
	});
}
function popup(location_href) {
  F = window.open("offsite.php?loc="+location_href,"popup","width=400,height=300");
  return false;
}
function f_open_window_max( aURL, aWinName )
{
   var wOpen;
   var sOptions;


   sOptions = 'directories=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,toolbar=yes';
   sOptions = sOptions + ',width=' + (screen.availWidth - 10).toString();
   sOptions = sOptions + ',height=' + (screen.availHeight - 122).toString();
   sOptions = sOptions + ',screenX=0,screenY=0,left=0,top=0';

   wOpen = window.open( '', aWinName, sOptions );
   wOpen.location = aURL;
   wOpen.focus();
   wOpen.moveTo( 0, 0 );
   wOpen.resizeTo( screen.availWidth, screen.availHeight );
   return wOpen;
}

// External link warn
$(document).ready(function() {
	 // Creating custom :external selector
	/*$.expr[':'].external = function(obj){
      return !obj.href.match(/^mailto\:/)
      	&& (obj.hostname.replace(/^www./, '') != location.hostname.replace(/^www./,''));
	  };

	  // Add 'external' CSS class to all external links
	  $('a:external').addClass('external');*/

	  $('a[href*="www.deluxe-check-order.com"]').addClass('external');


	  $('.external').click(function(e) {
	    var link = $(this).attr('href');
	    var position = $(this).position();

	    // fix for chrome/safari browsers that don't support html scrollTo height
	    if($.browser.safari) bodyelem = $("body");
	    else bodyelem = $("html,body");
	    
	    $('<div class="externalLink">By accessing the noted link you will be leaving the Peoples National Bank website and entering a website hosted by another party. Your financial institution has not approved this as a reliable partner site. Please be advised that you will no longer be subject to, or under the protection of, the privacy and security policies of your financial institution\'s website. We encourage you to read and evaluate the privacy and security policies of the site you are entering, which may be different than those of your financial institution\'s.<br /><br /><div class="outsideLink">'+(link)+'</div></div>').dialog({
	      title: "External Link",
	      modal : true,
	      resizable: false,
	      width: 400,
	      draggable: false,
	      position: [position.left, position.top - bodyelem.scrollTop()],
	      overlay: {
	        backgroundColor: '#000',
	        opacity: 0.5
	      },
	      buttons: {
	        'Continue': function() {
	          $(this).dialog('close').remove();
	          window.open(link);
	        },
	        'Cancel': function() {
	          $(this).dialog('close').remove();
	          return false;
	        }
	      }
	    });

    return false;
	});
});

