(function($) {
    $.fn.subnav_useHash = function() {
		// setup initial vars
		var LinkHash = location.hash;
		var clicked = "";
		var currentItem = "";
		var previousItem = "";
		ua = navigator.userAgent.toLowerCase();
		
		/* Give unique id to each item (subnav_#)
		     - ID used to track current vs previous items
		   Check for initial url hash value and
		     - setNav as needed
		*/
		$(this).each(function (itemCount) {
			$(this).attr('id','subnav_' + itemCount);
			if(LinkHash == $(this).attr('href')) {
				$(this).parent().addClass('subon');
				previousItem = $(this);
			}
		});
		
		// create click event | call setNav on click
        $(this).click(function(event) {
			setNav(this);
		});
		
		// FUNCTION: setNav
		function setNav(itemClicked) {
			// setup current vs previous items
			currentItem = '#' + $(itemClicked).attr('id');
			if (clicked != "") {
				previousItem = clicked;
			}

			// Set subon class to clicked items
			clicked = '#' + $(itemClicked).attr('id');
			$(clicked).parent().addClass('subon');
			if(previousItem != "") {
				$(previousItem).parent().removeClass('subon');
			}
			
			if (ua.indexOf("safari") != -1) {
				var pathName = location.pathname;
				var hashVal = $(itemClicked).attr('href');
				var newURL = pathName + hashVal;
				location.assign(newURL);
				location.reload();
			}

		}
    }
})(jQuery);