function css_browser_selector(u){var ua=u.toLowerCase(),is=function(t){return ua.indexOf(t)>-1},g='gecko',w='webkit',s='safari',o='opera',m='mobile',h=document.documentElement,b=[(!(/opera|webtv/i.test(ua))&&/msie\s(\d)/.test(ua))?('ie ie'+RegExp.$1):is('firefox/2')?g+' ff2':is('firefox/3.5')?g+' ff3 ff3_5':is('firefox/3.6')?g+' ff3 ff3_6':is('firefox/3')?g+' ff3':is('gecko/')?g:is('opera')?o+(/version\/(\d+)/.test(ua)?' '+o+RegExp.$1:(/opera(\s|\/)(\d+)/.test(ua)?' '+o+RegExp.$2:'')):is('konqueror')?'konqueror':is('blackberry')?m+' blackberry':is('android')?m+' android':is('chrome')?w+' chrome':is('iron')?w+' iron':is('applewebkit/')?w+' '+s+(/version\/(\d+)/.test(ua)?' '+s+RegExp.$1:''):is('mozilla/')?g:'',is('j2me')?m+' j2me':is('iphone')?m+' iphone':is('ipod')?m+' ipod':is('ipad')?m+' ipad':is('mac')?'mac':is('darwin')?'mac':is('webtv')?'webtv':is('win')?'win'+(is('windows nt 6.0')?' vista':''):is('freebsd')?'freebsd':(is('x11')||is('linux'))?'linux':'','js']; c = b.join(' '); h.className += ' '+c; return c;}; css_browser_selector(navigator.userAgent);

var mlink = '';
var timer = null;
$(document).ready(function() {
 
 //PNG Transparency fix for IE6
  $('body').supersleight({shim: '/images/blank.gif'});
	
	//Decent Blockquotes!
	$('blockquote').prepend(" <span class='bqstart'>&#8220;</span> ");
	$('blockquote').append(" <span>&nbsp;</span><span class='bqend'>&#8221;</span> ");
	
  // Creating custom :external selector
  $.expr[':'].external = function(obj){
      return !obj.href.match(/^mailto\:/) && !obj.href.match(/\.gov/) && !obj.href.match(/\.state\.mo\.us/) && !obj.href.match(/\.us/) && !obj.href.match(/^javascript\:/) && !obj.href.match(/\.youtube\.com/) ;
  };

 // Add 'external' CSS class to all external links
  $('a:external').addClass('external');
 
  $('.external').click(function() {
    var link = $(this).attr('href');
        mlink = link;
        timer = setTimeout('leaveSite()', 10000);
        
    $('<div>You are currently exiting to a site that is not part of the government(.gov) domain. Web sites are places where diverse groups of people interact, so please be aware that you will be subject to a wide variety of experiences beyond our control. Always use good judgment when using these platforms and when following links to other web sites.<br/> <br/>You are headed towards: <br /> '+(link)+' <br /></div>').dialog({
      title: "External Link",
      modal : true,
      overlay: {
        backgroundColor: '#000',
        opacity: 0.5
      },
      buttons: {
        'Okay': function() {
                       clearTimeout(timer);
          $(this).dialog('close').remove();
          window.location.href = link;
        },
        'Cancel': function() {
                       clearTimeout(timer);
          $(this).dialog('close').remove();
          return false;
        }
      }
    });
 
    return false;
  });
});
function leaveSite()
{

        window.location.href = mlink;

}

        //clear text fields
        function clearText(field){
    if (field.defaultValue == field.value) field.value = '';
    else if (field.value == '') field.value = field.defaultValue;
        }
jQuery(function($) {
	$.fn.search = function() {
		return this.focus(function() {
			if( this.value == this.defaultValue ) {
				this.value = "";
			}
		}).blur(function() {
			if( !this.value.length ) {
				this.value = this.defaultValue;
			}
		});
	};
	$(".cleartxt"||".clearText").search();
	
  // Add external link indicator
	$('.external').addClass("external-link");
});

//initialize basic jqueryui tabs wherever #tabs is present
	$(function() {
		if ($('#tabs').length) {
    		$( "#tabs" ).tabs({	});
	} else {
		};
	});



//open fully qualified urls in new window
$(function() {
$("a[href*='http://']:not([href*='"+location.hostname+"'])").not(".external").click( function() {
window.open(this.href);
return false;
});

	// hide #back-top first
	$("#back-top").hide();

	// fade in #back-top
	$(function () {
		$(window).scroll(function () {
			if ($(this).scrollTop() > 100) {
				$('#back-top').fadeIn();
			} else {
				$('#back-top').fadeOut();
			}
		});
	});



function filterPath(string) {
                        return string
                        .replace(/^\//,'')
                        .replace(/(index|default).[a-zA-Z]{3,4}$/,'')
                        .replace(/\/$/,'');

                }

        

                var locationPath = filterPath(location.pathname);
                var scrollElem = scrollableElement('html', 'body');

                // Any links with hash tags in them (can't do ^= because of fully qualified URL potential)
                $('a[href*=#]').not('#tabs a[href*=#]').each(function() {

                        // Ensure it's a same-page link
                        var thisPath = filterPath(this.pathname) || locationPath;
                        if (  locationPath == thisPath
                                && (location.hostname == this.hostname || !this.hostname)
                                && this.hash.replace(/#/,'') ) {

        

                                        // Ensure target exists
                                        var $target = $(this.hash), target = this.hash;
                                        if (target) {

        

                                                // Find location of target
                                                var targetOffset = $target.offset().top;
                                                $(this).click(function(event) {

        
                                                        // Prevent jump-down
                                                        event.preventDefault();

                                                        // Animate to target
                                                        $(scrollElem).animate({scrollTop: targetOffset}, 800, function() {
        

                                                                // Set hash in URL after animation successful
                                                                location.hash = target;
                                                        });
                                                });
                                        }
                        }
                });
                // Use the first element that is "scrollable"  (cross-browser fix?)
                function scrollableElement(els) {
                        for (var i = 0, argLength = arguments.length; i <argLength; i++) {
                                var el = arguments[i],
                                $scrollElement = $(el);
                                if ($scrollElement.scrollTop()> 0) {
                                        return el;
                                } else {
                                        $scrollElement.scrollTop(1);
                                        var isScrollable = $scrollElement.scrollTop()> 0;
                                        $scrollElement.scrollTop(0);
                                        if (isScrollable) {
                                                return el;
                                        }
                                }
                        }
                        return [];
                }
});

// Fires a special css file for those with javascript disabled
        $(function() {
            $("link[href*='nojs.css']").remove();
        });

/**
* Styleswitch stylesheet switcher built on jQuery
* Under an Attribution, Share Alike License
* By Kelvin Luck ( http://www.kelvinluck.com/ )
**/

(function($)
{
	$(document).ready(function() {
		$('.styleswitch').click(function()
		{
			switchStylestyle(this.getAttribute("rel"));
			return false;
		});
		var c = readCookie('style');
		if (c) switchStylestyle(c);
	});

	function switchStylestyle(styleName)
	{
		$('link[rel*=style][title]').each(function(i) 
		{
			this.disabled = true;
			if (this.getAttribute('title') == styleName) this.disabled = false;
		});
		createCookie('style', styleName, 365);
	}
})(jQuery);
// cookie functions http://www.quirksmode.org/js/cookies.html
function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function eraseCookie(name)
{
	createCookie(name,"",-1);
}
// /cookie functions
(function($) {
	$.fn.ellipsis = function(enableUpdating){
		var s = document.documentElement.style;
		if (!('textOverflow' in s || 'OTextOverflow' in s)) {
			return this.each(function(){
				var el = $(this);
				if(el.css("overflow") == "hidden"){
					var originalText = el.html();
					var w = el.width();
					
					var t = $(this.cloneNode(true)).hide().css({
                        'position': 'absolute',
                        'width': 'auto',
                        'overflow': 'visible',
                        'max-width': 'inherit'
                    });
					el.after(t);
					
					var text = originalText;
					while(text.length > 0 && t.width() > el.width()){
						text = text.substr(0, text.length - 1);
						t.html(text + "...");
					}
					el.html(t.html());
					
					t.remove();
					
					if(enableUpdating == true){
						var oldW = el.width();
						setInterval(function(){
							if(el.width() != oldW){
								oldW = el.width();
								el.html(originalText);
								el.ellipsis();
							}
						}, 200);
					}
				}
			});
		} else return this;
	};
})(jQuery);

