// PRINT ICON INSERTION (SO THAT ONLY JAVASCRIPT-ENABLED BROWSERS GET IT)
$(document).ready(function() {
	$('#page_footer p').append('<span class="no-print"> | <a href="#" id="print-page">Print This Page</a></span>');
	$('#page_footer a#print-page').click(function() {
		window.print();
		return false;
	});
});

// JAVASCRIPT IMPLMENTATIONS OF CSS PSEUDO CLASSES
function addHover(els, hoverClass) { // function to add/remove hoverClass from els accordingly (:hover pseudo class)
	if ($(els).length) { // the element(s) exist
		$(els).hover(function() { // add the class on mouse over
			$(this).addClass(hoverClass);
		},
		function() { // remove the class on mouse out
			$(this).removeClass(hoverClass);
		});
	}
}

function addFocus(els, focusClass) {
	if ($(els).length) {
		$(els).focus(function() {
			$(this).addClass(focusClass);
		});
		$(els).blur(function() {
			$(this).removeClass(focusClass);
		});
	}
}

$(document).ready(function() { // list of elements to add pseudo classes to
	//addHover('#c_main ul.features li', 'features-hover'); // #c_main ul.features li:hover
	addFocus('#c_main form input', 'field-focus');
	addFocus('#c_main form select', 'field-focus');
	addFocus('#c_main form textarea', 'field-focus');
});






// PAGE HIGHLIGHTING
function highlightElement(el) { // function for highlighting el
	if ($(el).length) { // el exists
		$(el).highlightFade({ // apply a highlight fade
			color: 'yellow', // start the fade at yellow
			end: 'white', // fade to white
			speed: 1500, // take 1500 milliseconds to complete the fade
			complete: function() { // when the fade completes, remove the leftover style attribute so normal CSS will resume
				$(this).attr('style', '');
			}
		});
	}
}

$(document).ready(function() { // checks to see if the URL contains an anchor...if so, highlights the linked-to element
	var theAnchor = window.location.toString().lastIndexOf('#'); // see if there is a '#' character (anchor) in the current URL
	if (theAnchor != -1) { // the anchor exists
		highlightElement(window.location.toString().substr(theAnchor)); // highlight the linked-to element
	}
});

$(document).ready(function() { //hooks all links that have an anchor name HREF with a function to highlight the appropriate header on click
	var pageLinks = $('a'); // find all link elements
	for (var i = 0; i < pageLinks.length; i++) { // go through the list of link elements
		if ($(pageLinks[i]).attr('href').substr(0, 1) == '#') { // if the first character of the HREF attribute is '#', hook it for highlighting
			$(pageLinks[i]).click(function() { // trim the HREF property to just the id of the element to highlight
				highlightElement($(this).attr('href'));
			});
		}
	}
});


