/*
	
	Verity Credit Union Global Javascript Functions
	By  - ISITE Design

*/


//make sure IE has the abbr and acronym tag
if(document.all){
	document.createElement("abbr");
	document.createElement("acronym");
}

//start the jQuery functions
$(document).ready(function() {

	// Few setups for IE6
	if(document.all){
		//add class to drop downs and buttons 
	    $("#nav li, button").hover(
			function() { $(this).addClass("over"); },
			function() { $(this).removeClass("over"); }
	    );
	}// if document.all
	
	// add class "last" to last li in a group
	$('ul li:last').addClass('last');
	
	/* set up default tab behavior */
    $('dl.tabs dt').click(function () {
        tab = $(this).attr('class').match(/tab-(\w+)/);
        $('dl.tabs dt, dl.tabs dd').removeClass('on');
        $('dl.tabs dt.tab-' + tab[1] + ', dl.tabs dd.pane-' + tab[1]).addClass('on');
    });
    /* go through tabs and turn the first one on if there is no other default */
    if(!$('dl.tabs dt').hasClass('on')) $('dl.tabs dt').filter(':first').trigger('click');
	
	// turn on Input Setter for #sign-on
	$("#sign-on input, #site-search input").inputSetter();
	
	// add inner spans to buttons for growing background
	$("button").addClass('btn').wrapInner("<span></span>");
	
	// main navigation dropdowns. initialize by ripping title and adding to dropdown listing (li.overview), then bind hover behavior.
	// over class simply repositions to bottom left edge of parent li, revealing dropdown.
	$("#nav > li:has(ul)")
	.each(function(){
			var $a = $('a:first', this);
			var overview = $a.attr('title');
			$a.removeAttr('title');
			$('ul',this).append('<li class="overview">'+overview+'</li>');
				   })
	.hover(function() {$(this).addClass('over').find('ul').addClass('active');}, function() {$(this).removeClass('over').find('ul').removeClass('active');});
	
	// callout-listing hover behavior; add over class to li to change background on .description, capture clicks on li to simulate link behavior on entire li.
	
	//inner span for a.button
	$('a.button').wrapInner('<span></span>');
	
	/* nav highlighting */
	var loc = window.location.href;
	//strip the existing current state
	$('#nav a.current').removeClass('active');

	//add class to current section...
	//Personal
	if(loc.indexOf('http://fed.isitedesign.us/content/verity/personal.php') > -1){
		$('#nav-personal').addClass('active');
	}
	//Business
	else if(loc.indexOf('http://fed.isitedesign.us/content/verity/business.php') > -1){
		$('#nav-business').addClass('active');
	}


});// document ready / end jquery functions


/*

	12.19.08 - pdf
	
	Input Setter
	pull label and insert as field. clear with click.	
	optional lower param if == 1, string toLowerCase	

	ex: $("#sitesearch input").inputSetter(1); // makes default text lowercase
		$("#sitesearch input").inputSetter(); // no lowercasing

	see custom validation for jquery.validation.js below

*/

jQuery.fn.inputSetter = function(lower) {	
	return this.each(function() {
		var $input = $(this);
		var $label = $("label[for='"+$input.attr("id")+"']");
		var labeltext = lower && lower==1 ? $label.text().toLowerCase() : $label.text();
		$label.hide();	
		$input.val(labeltext);		
		$input.focus(function() { if (this.value == labeltext) { this.value = ""; }	})
			  .blur(function() { if (!this.value.length) { this.value = labeltext; } });		
	});
};

// end inputSetter


// clean console.log
function cl(logit){ if(window.console&&window.console.firebug) { console.log(logit) } };//cl()
// example: cl("If you use cl() instead of console.log(), it won't break IE when you forget to take it out.");

