// Adding in the ability to do smooth scrolling to an element with jQuery
jQuery.fn.extend({
  scrollTo : function(speed) {
    return this.each(function() {
      var targetOffset = jQuery(this).offset().top - 30;
      jQuery('html,body').animate({scrollTop: targetOffset}, speed);
    });
  }
});

// Handles the initial overlay on the home page.
function do_overlay() {
	var ow = 450; // Width of the overlay in px
	var oh = 400; // Height of the overlay in px
	
	if (document.cookie.length > 0) {
		if (document.cookie.indexOf('seenit') != -1) {
			return true;
		}
	}
	var de = document.documentElement;
	var w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
	var h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;
	var t = h / 2 - (oh / 2);
	var l = w / 2 - (ow / 2);
	$('body').append('<div id="overlay" style="display:none;width:'+ow+'px;height:'+oh+'px;top:'+t+'px;left:'+l+'px;"><div style="margin:40px;">\
						<h1>Safety Notice</h1>\
						<p>Computer use can be monitored and it is impossible to completely clear a computer\'s internet history.\
						If you\'re afraid you’re being monitored and/or tracked, please move to a safer computer.\
						If you\'re currently experiencing a crisis, need immediate assistance, or feel your safety is at risk, call our helpline at 808-531-3771 (1-800-690-6200 for neighbor islands) or 911.\
						Note that any blog messages left on this site may be publicly read.\
						Private messages should be sent to our e-mail address to ensure confidentiality.\
						If you are viewing our site and need to quickly get away, click the &quot;Hide Me&quot; button in the top right corner and you will be immediately redirected.\
						Please test this button on your computer right now to make sure it works.</p>\
						<p><a href="#" onclick="document.cookie = \'seenit\'; $(\'#overlay\').fadeOut(\'normal\', function(){$(this).remove();});">Stop showing me this message</a></p>\
					</div></div>').end();
	$('#overlay').fadeIn('slow');
	setTimeout("$(\'#overlay\').fadeOut('normal', function(){$(this).remove();});", 15000);
}

// Anything to be executed when the page loads
$(function() {
	// Add tooltips to people who were helped
	$('.speech-bubble').tooltip({
		track: true,
		delay: 0,
		showURL: false,
		fixPNG: true,
		left: -5,
		top: -105,
		bodyHandler: function(n){
			return '<h3>&quot;' + this.tooltipText + '&quot;</h3><p>Click me to find out more</p>';
		}
	});
	
	// Randomize the header image
	$('#header').css('background-image', 'url(' + header_imgs[Math.ceil(header_imgs.length * Math.random()) - 1] + ')'); // Use a random header
});



