function textAdjust(target, minSize, maxSize, defSize){
	//Read cookie & sets the fontsize
	if ($.cookie != undefined) {
		var cookie = target.replace(/[#. ]/g,'');
		var value = $.cookie(cookie);
		if (value !=null) {
			$(target).css('font-size', parseInt(value));
		}
	}
	//small button function
	$sTxt = $('.smTxt a');
	$mTxt = $('.mdTxt a');
	$sTxt.click(function(){ 
		curSize = parseInt($(target).css("font-size"));
		newSize = curSize - 1;
		if (newSize >= minSize) {
			$(target).css('font-size', newSize);
		} 
		if (newSize <= minSize) {
			$sTxt.addClass("sDis");
		}
		if (newSize < maxSize) {
			$mTxt.removeClass("mDis");
		}
		updateCookie(target, newSize); //sets the cookie 
		return false;
	});
	//large button function
	$mTxt.click(function(){ 
		curSize = parseInt($(target).css("font-size"));
		newSize = curSize + 1;
		if (newSize <= maxSize) {
			$(target).css('font-size', newSize);
		} 
		if (newSize > minSize) {
			$sTxt.removeClass("sDis");
		}
		if (newSize >= maxSize) {
			$mTxt.addClass("mDis");
		}
		updateCookie(target, newSize);
		return false;
	});
	function updateCookie(target, size) {
		if ($.cookie != undefined) { //If cookie plugin available, set a cookie
			var cookie = target.replace(/[#. ]/g,'');
			$.cookie(cookie, size, { expires: 7, path: '/'});
		} 
	}
};
//Based on work by Adrian Mato Gondelle
var popupStatus = 0;
//loading popup
function loadPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#feedBackWrap").css({
			"opacity": "0.9"
		});
		$("#feedBackWrap").fadeIn("slow");
		$("#feedBackSuccess").fadeIn("slow");
		popupStatus = 1;
	}
}
//disabling popup
function disablePopup(){
	if(popupStatus==1){
		$("#feedBackWrap").fadeOut("slow");
		$("#feedBackSuccess").fadeOut("slow");
		popupStatus = 0;
	}
}
//centering popup
function centerPopup(){
	var windowWidth = $(window).width();
	var windowHeight = $(window).height();
	var documentHeight = $(document).height();
	var documentWidth = $(document).width();
	var popupHeight = $("#feedBackSuccess").height();
	var popupWidth = $("#feedBackSuccess").width();
	$("#feedBackSuccess").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2-120,
		"left": documentWidth/2-popupWidth/2-80
	});
	//only need force for IE6

	$("#feedBackWrap").css({
		"height": documentHeight
	});	
}

//Scripts to run the pageTools
$(function() {	
	$("#feedbackContent").click(function() {	
		if ($("#feedbackContent").val().substring(0,1)==' ')
		{
			$("#feedbackContent").val($("#feedbackContent").val().substring(1))
		}
    });
	$(".feedBackSubmitButton").click(function() {	
		var formContent = $("textarea#feedbackContent").val();
		if (formContent.length > 1)
		{
			var dataString = 'requestType=PageToolFeedback&toEmail=webmaster@imail.org&fromEmail=webmaster@imail.org&subject=Feedback Submission from Intermountainhealthcare.org&formContent=Feedback submitted from: ' + escape(location.href) + "\n\nFeedback Text:\n" + escape(formContent);
			//alert (dataString);return false;
			$.ajax({
				type: "POST",
			    url: "/ProcessAJAX.aspx",
			    data: dataString,
			    success: function() {
			    	feedBackGood();
			    }
			});
		}
		return false;	
    });
	//Display page tools
	function showTools(){
		$(this).children('.toolDetails').slideDown();
	};
	function hideTools(){
		$(this).children('.toolDetails').slideUp();
	};	
	//Hover tools
	var hoverConfig = {sensitivity: 3, interval: 50, over: showTools, timeout: 500, out: hideTools};
	$('li.toolBtn').hoverIntent(hoverConfig);
	$('li.toolBtn a.toolBtnLnk').click(function(){
		return false;
		$(this).blur();
	});
	//Swap text
	$('.fontWrap a').each(function(){
		var lnkText = $(this).children('span').text();
		$(this).hover(function(){
			$('#buttonText').text(lnkText);
		}, function(){
			$('#buttonText').text(' ');
		});
	});
	//Text controls
	textAdjust('#ih-pgContent', 9, 18, 13);
	
	//Scripts for sharing
	var pageAddress = document.location;
	var pageTitle = $('#ih-currentLnk').text();
	var pageDesc = document.title;
	// Facebook
	var facebookURL = 'http://www.facebook.com/share.php?u='+encodeURIComponent(document.location.href);
	$('.ihFacebook').attr('href',facebookURL).attr('target','_blank');
	//Digg
	var diggURL = 'http://digg.com/submit?phase=2&url='+encodeURIComponent(document.location.href)+'&title='+pageTitle+'&bodytext='+pageDesc;
	$('.ihDigg').attr('href',diggURL).attr('target','_blank');
	// reddit
	var redditURL = 'http://reddit.com/submit?url='+encodeURIComponent(document.location.href)+'&title='+pageTitle;
	$('.ihReddit').attr('href',redditURL).attr('target','_blank');
	// stumbleupon
	var stumbleuponURL = 'http://www.stumbleupon.com/submit?url='+encodeURIComponent(document.location.href)+'&title='+pageTitle;
	$('.ihStumbleUpon').attr('href',stumbleuponURL).attr('target','_blank');
	// myspace
	var myspaceURL = 'http://www.myspace.com/Modules/PostTo/Pages/?' + 't=' + pageTitle + '&c=' + pageDesc + '&u=' + encodeURIComponent(document.location.href);
	$('.ihMyspace').attr('href',myspaceURL).attr('target','_blank');
	// twitter
	var twitterURL = 'http://twitter.com/home?status=Currently reading ' + encodeURIComponent(document.location.href);
	$('.ihTwitter').attr('href',twitterURL).attr('target','_blank');
	$('.ihEmail').attr('href','#').click(function(){
		this.blur();
		mailpage();
		return false;
	});
		//LOADING POPUP
	//Click the button event!
	function feedBackGood() {
		centerPopup();
		loadPopup();
		$("#feedbackContent").val("");
	};
	$("#button").click(function(){
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
	});
	//Email this page
	function mailpage() {
		var docTitle = escape(document.title);
		mail_str = "mailto:?subject=Please read: " + docTitle;
		mail_str += "&body=I thought you might be interested in the " + docTitle;
		mail_str += ". You can view it at, " + document.location.href; 
		location.href = mail_str;
	};
				
	//CLOSING POPUP
	//Click the x event!
	$("#feedBackSuccessClose").click(function(){
		disablePopup();
	});
	//Click out event!
	$("#feedBackWrap").click(function(){
		disablePopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});
});

