var $j = jQuery.noConflict();

// Change search input value
$j(function () {
	var v1 = 'How may we help you?';
	var v2 = 'Not sure where to start? Try here!';
	$j('input.ms-sbplain').each(function() {
		if ($j(this).is('#Search input.ms-sbplain')) {this.value = v1;}
		if ($j(this).is('.article_home input.ms-sbplain')) {this.value = v2;}
	});
	$j('input.ms-sbplain').focus(function() {
		if (this.value == v1){this.value = '';}
		if (this.value == v2){this.value = '';}
	});
	$j('input.ms-sbplain').blur(function() {
		if (this.value == ''){
			if ($j(this).is('#Search input.ms-sbplain')) {this.value = v1;}
			if ($j(this).is('.article_home input.ms-sbplain')) {this.value = v2;}
		}
	});
});

// Icons
$j(function () {
	// Print
	$j('.print').click(function () {
		window.print()
	});
	// Bookmark
	$j('.bookmark').click(function () {
		if (window.sidebar) { // Firefox  
			window.sidebar.addPanel(document.title,location.href,""); 
		} else if (document.all){ // IE 
			window.external.AddFavorite(location.href,document.title);
		} else if (window.opera && window.print) { // Opera 
			this.title = document.title; 
			return true; 
		} else { // Not Supported
       		alert("Sorry! Your browser doesn't appear to support this function.");  
    	} 				
	});
});

// adds empty li to beginning of ul (tooltip-content)
$j(function () {
	$j('.tooltip-content').prepend('<li></li>');
});

// Creates Search Page Links

$j(function () {
/*
	// "What We Do" links
	$j('.whatwedo li a').one("mouseenter", function() {
		var linkTxt = $j(this).text();						   
		$j(this).not('.viewMore').attr('href', '/Search/Pages/Results.aspx?k='+linkTxt);
	});
*/	
	// Article tag/topic links
	$j('.searchLinks').each(function() {
		var searchTxt = $j(this).text();
		if ($j(this).children().hasClass('ms-formfieldcontainer')) {
			return false;
		} else if ($j(this).is(":contains(';')")) {
			var oldStr =/; /g;
			var newStr = '</a>; <a>';
			var strResult = searchTxt.replace(oldStr,newStr);
			$j(this).html('<a>'+strResult+'</a>');
		} else {
			$j(this).contents().wrap('<a></a>');
		}
		$j('.searchLinks a').one("mouseenter", function() {
			var linkTxt = $j(this).text();						   
			$j(this).attr('href', '/Search/Pages/Results.aspx?k='+linkTxt);
		});	
	});
});


// Tooltip Settings for IE7 (and lower)
if (jQuery.browser.msie && jQuery.browser.version < 8) {
	$j(function () {
		$j('.tooltip').each(function () {
			var distance = 10;
			var time = 250;
			var hideDelay = 500;
			var hideDelayTimer = null;
			var trigger = $j('.trigger', this);
			var info = $j('.tooltip-container', this);
			$j([trigger.get(0), info.get(0)]).mouseover(function () {
				$j('.tooltip-container, .trigger').not(this).addClass('hide');
				trigger.removeClass('hide');
				info.removeClass('hide');
				$j('.hide').each(function () {
					if ($j('.tooltip-container.hide').is(':visible')) {
						$j(this).stop().css({display: 'none'});
					}
					hideDelay = 50;
				});
				if (hideDelayTimer) clearTimeout(hideDelayTimer);
				if (info.is(':animated,:visible')) {
					return;
				} else {
					info.css({
						top: 10,
						left: 0,
						display: 'block'
					}).animate({
						top: '+=' + distance + 'px'
					}, time, 'swing');
				}
				return false;
			}).mouseout(function () {
				if (hideDelayTimer) clearTimeout(hideDelayTimer);
				hideDelayTimer = setTimeout(function () {
					hideDelayTimer = null;
					info.animate({
						top: '-=' + distance + 'px'
					}, time, 'swing', function () {
						info.css('display', 'none');
					});
				}, hideDelay);
				return false;
			});
		});
	});
// Tooltip Settings for all browsers except IE7
} else {
	$j(function () {
		$j('.tooltip').each(function () {
			var distance = 10;
			var time = 250;
			var hideDelay = 500;
			var hideDelayTimer = null;
			var trigger = $j('.trigger', this);
			var info = $j('.tooltip-container', this).css('opacity', 0);
			$j([trigger.get(0), info.get(0)]).mouseover(function () {			
				$j('.tooltip-container, .trigger').not(this).addClass('hide');
				trigger.removeClass('hide');
				info.removeClass('hide');
				$j('.hide').each(function () {
					if ($j('.tooltip-container.hide').is(':visible')) {
						$j(this).stop().css({opacity: 0, display: 'none'});
					}
					hideDelay = 50;
				});
				if (hideDelayTimer) clearTimeout(hideDelayTimer);
				if (info.is(':animated,:visible')) {
					// don't trigger the animation again
					return;
				} else {
					// reset position of info box
					info.css({
						top: 12,
						left: 0,
						display: 'block'
					}).animate({
						top: '+=' + distance + 'px',
						opacity: 1
					}, time, 'swing');
				}
				return false;
			}).mouseout(function () {
				if (hideDelayTimer) clearTimeout(hideDelayTimer);
				hideDelayTimer = setTimeout(function () {
					hideDelayTimer = null;
					info.animate({
						top: '-=' + distance + 'px',
						opacity: 0
					}, time, 'swing', function () {
						info.css('display', 'none');
					});
				}, hideDelay);
				return false;
			});
		});
	});
}

// Text Resize
$j(document).ready(function() {
	$j('.normalfont').addClass('active');
	// Increase Font Size
  	$j('.largefont').click(function(){
  		$j(this).addClass('active');
  		$j('.normalfont').removeClass('active');
        $j('.article_leftcolumn p, .article_leftcolumn ul, .article_leftcolumn li, .article_leftcolumn h1, .article_leftcolumn h2, .article_leftcolumn h3, .article_leftcolumn h4, .welcome ul li div, .article_leftcolumn div').addClass('largeText');
    });	
	// Decrease Font Size
	$j('.normalfont').click(function() {
		$j(this).addClass('active');
  		$j('.largefont').removeClass('active');
        $j('.article_leftcolumn p, .article_leftcolumn ul, .article_leftcolumn li, .article_leftcolumn h1, .article_leftcolumn h2, .article_leftcolumn h3, .article_leftcolumn h4, .welcome ul li div, .article_leftcolumn div').removeClass('largeText');
	});
});

