/******************************************************************************
 * Global functions for 1st Security Bank of Washington.
 * jQuery framework is required.
 * 
 * Author: Neal Krouse, Browning & Browning, Inc (neal@jbrowning.biz)
 *
 * NOTES:
 * 16 Aug 2007
 * Started source code
 *
 * 2 Oct 2007
 * Removed animated hover from Online Banking Login, because older vistors
 * had problems with it. The element has a click to show/hide itself
 ******************************************************************************/

jQuery.fn.extend({
  scrollTo : function(speed, easing) {
    return this.each(function() {
      var targetOffset = $(this).offset().top;
      $('html,body').animate({scrollTop: targetOffset}, speed, easing);
    });
  }
});


$(document).ready(function(){
	/* animates the drop-down of the Online Banking Log On 
	$("#online")
	.css({top: "-45px"})
	.hover(
		function(){ $(this).animate({top: 0}, "slow") },
		function(){ $(this).animate({top: -45}, "slow") }
	);
	*/
	$("#online")
	.css({top: "-66px"})
	.click(function(){
		var $this = $(this);
		var n = $this.css("top");
		if ( parseInt(n) < 0 ) {
			$this.animate({top: 0}, "slow", "easeInBack");
		} else {
			$this.animate({top: -66}, "slow", "easeOutBack");
		}
	});
	
	
	
	// for search label
	var searchlabel = $("#searchform label").remove().text();
	$("#searchfor").addClass("placeholder").val(searchlabel)
		.focus(function(){
			if (this.value == searchlabel) {
				$(this).removeClass("placeholder").val("");
			};
		})
		.blur(function(){
			if (this.value == "") {
				$(this).addClass("placeholder").val(searchlabel);
			}
		});
	
	$("#searchform").submit(function(){
		if ( $("#searchfor").val() == searchlabel) {
			$("#searchfor").val("");
		}
	});

	$("p.begining", document.getElementById("primary")).find("a").click(function() {
		$("#top").scrollTo(1000, "linear");
		return false;
	});


	/* hides all sub-level navigation in
	 * secondary menus. Each page adds code
	 * to show specific sub-levels */
	$("#secondary dd").hide();
	$("#secondary dt a").click(function(){
		$("dd:visible").slideUp("slow");
		$(this).parent().next().slideDown("slow");
		return false;
	});

	$("#primary tbody").each(function(){
		$(this).children(":odd").addClass("odd");
	});
});

if (window.attachEvent) {
	if (typeof document.compatMode != 'undefined') {
		 	/* target IE6 only, since it doesn't support :hover */
			$(document).ready(function(){
				$("#primary tbody tr").hover(
					function(){$(this).addClass("hover")},
					function(){$(this).removeClass("hover")}
				);
			});
	}
};

function hideDivs(myArray,b) {
	b = b || false;
	var len = len=myArray.length
	for(var i=0;i<len;i++){
		b ? $(myArray[i]).slideUp() : $(myArray[i]).slideUp("slow");
	}
}


function getPosition(theElement)
{
  var positionX = 0;
  var positionY = 0;

  while (theElement != null)
  {
    positionX += theElement.offsetLeft;
    positionY += theElement.offsetTop;
    theElement = theElement.offsetParent;
  }
  
  return [positionX, positionY];
} // end getPosition()

// make a tooltip
$(document).ready(function(){

	if ( $("#primary a[@href^='http'], #secondary a[@href^='https']").length > 0 ) { // add tooltip only if external URLs are present
	
			var tip = $("<div id=\"tooltip\" style=\"top:-160px;left:0;\">The bank is not endorsing or guaranteeing the products, information, or recommendations provided by linked sites.  The bank is not liable for any failure of products or services advertised on those sites.  Each third party site may have a privacy policy different than that of the bank.  The linked party website may provide less security than the bank's website.<\/div>").appendTo("body").hide(); // tip is created and reused by hover function
			
			$("#primary a[@href^='http'], #secondary a[@href^='https']")
				.not("[@href*='s161.lanxtra.com']")
				.not("[@href*='1stsecurityofwamortgage.com']")
				.not("[@href*='www.1stsecuritybankofwamortgage.com']")
				.not("[@href*='www.1stsecurityofwabb.com/onlineserv/']")
				.not(".no-pop-up")
				//.not("[@href*='maps.google.com']") 23 Oct 2007 google links get pop-ups
				.hover(
					function(){
						var cursorPosition = getPosition($(this)[0]);
						tip.css({left: cursorPosition[0]+"px", top: (cursorPosition[1]-180)+"px"});
						tip.fadeIn("fast");
								},
					function(){
						tip.fadeOut("fast");
					}
				).wrap("<span class=\"external\"><\/span>");
	}
});




// add class pdf to links that end in .pdf
$(document).ready(function(){
	$("#primary a[@href$='.pdf']").addClass("pdf").click(function(e) {
		e.preventDefault();
		window.open(this.href, "", "menubar=no, location=no, toolbar=no, scrollbars=yes, height=800, width=900, resizable=yes");
	});
});


/*************************************************** 
 * 24 September 2007
 * Temporarily remove consumer and equity loan rates,
 * and all links to these tables
 ***************************************************/

$(document).ready(function(){
	$("#primary a[@href$='#autoloan'], #primary a[@href$='#boatloan'], #primary a[@href$='#recreationalloan'], #primary a[@href$='#personalloan'], #primary a[@href$='#equityline'], #primary a[@href$='#mortgage']").remove();
});


