﻿/*
	HealthPartners 2010 
	global js
*/

	// Clear Search Box
function checkSearchAutocomplete() {
	if ($("#search-form-container input#search-box").val().length != 0) {
		$("#search-form-container label").removeClass("light").hide();
	}
}

$(document).ready(function() {

		// Adds the class .has-js to <html> if javascript is enabled
	$("html").addClass("has-js");
	
 	 	// Adds the class .mac to <html> if OS is Mac OS X
 	if ($.client.os == "Mac") {
    		$("html").addClass("mac");
 	}
 		// Adds the class .win to <html> if OS is Windows
 	if ($.client.os == "Windows") {
    		$("html").addClass("win");
 	}
 		// Adds the class .moz to <html> if user-agent is mozilla
	if ($.browser.mozilla) {
    	$("html").addClass("moz");
 	}
 		// Adds the class .chrome to <html> if user-agent is chrome
	if ($.client.browser == "Chrome") {
    	$("html").addClass("chrome");
 	}
 	
 	 		// Adds the class .safari to <html> if user-agent is safari
	if ($.client.browser == "Safari") {
    	$("html").addClass("safari");
 	}
 	
 	  	// Adds the class .webkit to <html> if user-agent is webkit
 	if ($.browser.webkit) {
    	$("html").addClass("webkit");
 	}
 		// Adds the class .ipad to <html> if OS is iPad 
 	if ($.client.os == "iPad") {
    		$("html").addClass("ipad");
 	}
 		// Adds the class .iphone to <html> if OS is iPhone/iPod Touch 
 	if ($.client.os == "iPhone") {
    		$("html").addClass("iphone");
 	}
 	
		// Open links in new blank window
 	$("a[rel*=external], a[rel*=nofollow]").live("click", function() {
  		window.open(this.href);
  		return false;
  	});

		// Highlight first input when .focus is present
	$("form input.focus").focus();
		
		// JS only speak text
	$(".required-information-label").addClass("speak-text");
	
		// Content Tabs
	if ($("div#content-tabs").length > 0) {
		$("div#content-tabs").tabs({ cookie: { expires: 1 } });
	}
	
			// Content Tabs
	if ($("div#content-accordion").length > 0) {
		$("div#content-accordion").tabs({ cookie: { expires: 1 } });
	}
	
		// Auto Ledger
	$ ("ul.ledger li:odd, table.ledger tr:odd, ul.ledger-hover li:odd, table.ledger-hover tr:odd").addClass("ledger-style");
	
		// Add class "main-aside-ellipsis" to h1 if class "aside" is present on the page
	if ($("div.aside").length > 0) {
		$("h1").addClass("main-aside-ellipsis");
	}
	
		// Site Search	
		// reset search

		// Only run if "search-form-container" ID is present on the page
	if ($("#search-form-container").length > 0) {
		checkSearchAutocomplete();
		setTimeout ("checkSearchAutocomplete()", 250);
	}
	
	$("#search-form-container input#search-box").val() == "";
	$("#search-form-container .search-box-magnifying-glass").removeClass("active").removeClass("highlight");
		
	$("#search-form-container input#search-box").focus(function() {
		if($("#search-form-container input#search-box").val() == "")
		{
			$("#search-form-container input#search-box").caret(0,0);
			$("#search-form-container label").addClass("light");
		}
	});

	$("#search-form-container input#search-box").keydown(function() {
		if($("#search-form-container input#search-box").val() == "")
		{
			$("#search-form-container input#search-box").caret(0,0);
			$("#search-form-container label").removeClass("light").hide();
			$("#search-form-container .search-box-magnifying-glass").addClass("highlight");
		}
	});

	$("#search-form-container input#search-box").keyup(function() {
		if($("#search-form-container input#search-box").val() == "")
		{
			$("#search-form-container input#search-box").caret(0,0);
			$("#search-form-container label").addClass("light").fadeIn(150);
			$("#search-form-container .search-box-magnifying-glass").removeClass("highlight");
		}
	});
	
	$("#search-form-container input#search-box").blur(function() {
		if($("#search-form-container input#search-box").val() == "")
		{
			$("#search-form-container label").removeClass("light").show();
		
		}
	});
		
	$("#search-form-container .search-box-magnifying-glass").live("click", function() {
  		$("#search-form-container .search-box-magnifying-glass").removeClass("highlight").addClass("active");
  		$("form.search-form").submit();
  		return false;
  	}); 
	
	$("#search-form-container .search-box-magnifying-glass").live("click", function() {
		$("input#search-box").val("");
  		$("#search-form-container input#search-box").caret(0,0);
		$("#search-form-container label").addClass("light").fadeIn(150); 
		$("#search-form-container .search-box-magnifying-glass").removeClass("highlight");
  		return false;
  	}); 
		// Site Search - end


		// Social Links
	var urlToShare = window.location.protocol + "//" + window.location.host + window.location.pathname; 
	var titleToShare = document.title;

	$("a#delicious-redirect").click(function() {
		window.open("http://delicious.com/save?url=" + urlToShare + "&title=" + titleToShare, "top");
		return false;
	}); 
	
	$("a#facebook-redirect").click(function() {
		window.open("http://facebook.com/sharer.php?u=" + urlToShare + "&title=" + titleToShare, "top");
		return false;
	});
	
	$("a#linkedin-redirect").click(function() {
		window.open("http://linkedin.com/shareArticle?mini=true&url=" + urlToShare + "&title=" + titleToShare, "top");
		return false;
	});
	
	$("a#digg-redirect").click(function() {
		window.open("http://digg.com/submit?phase=2&url=" + urlToShare + "&title=" + titleToShare, "top");
		return false;
	});
	
	$("a#twitter-redirect").click(function() {
		window.open("http://twitter.com/home?status=Check out this webpage: " + titleToShare + " " + urlToShare, "top");
		return false;
	});
	
	$("a#mailto-redirect").click(function() {
		location.replace("mailto:?subject=Check out this webpage: " + titleToShare + "&body=" + urlToShare, "top");
		return false;
	});
	
		// Social Links - end	

		// hide Safari Mobile address bar
	if ($.client.os == "iPhone") {
		addEventListener("load", function() {
			setTimeout(hideURLbar, 0);
		}, false);

		function hideURLbar() {
			window.scrollTo(0,1);
		}
	}
	
		// previous and next buttons - return
	$(".previous-button, .next-button").live("click", function() {
		return false;
	});

});