$(function(){
	//Each of these hover functions are for the social box on Salem Health's websites
	//As the mouse hovers over the image or the div of the topic 
	//(font, share, feedback), a class "active" is added to said topic displaying the contents
	//#social-wrap-home is hidden initially to prevenet interference with other divs.
	$("#font,#font-box").hover(function(){
        $('#social-wrap-home').css('display', 'block');
		$(this).addClass("active");
        $('#font-box').css('display', 'block');
    }, function(){
        $(this).removeClass("active");
        $('#font-box').css('display', 'none');
    	$('#social-wrap-home').css('display', 'none');
    });
	$("#share,#share-box").hover(function(){
		$('#social-wrap-home').css('display', 'block');
        $(this).addClass("active");
        $('#share-box').css('display', 'block');
    }, function(){
        $(this).removeClass("active");
        $('#share-box').css('display', 'none');
    	$('#social-wrap-home').css('display', 'none');
    });
	$(".feedback,.feedback-box,.feedback-form").hover(function(){
		$('#social-wrap-home').css('display', 'block');
        $(this).addClass("active");
        $('.feedback-box').css('display', 'block');
    }, function(){
        $(this).removeClass("active");
        $('.feedback-box:first').css('display', 'none');
		$('#social-wrap-home').css('display', 'none');
    });
	$('#print-btn').live('click', function() {
		window.print();
	});
	//When the mouse hovers over the font images, the corresponding text displays
	$("#little-font").hover(function() {
		$("#font-text").text("Decrease the font size.");
	});
	$("#big-font").hover(function() {
		$("#font-text").text("Increase the font size.");
	});
	//This allows the search to happen anywhere on the website
	$("#form1,.btn").submit(function() {
		var keyword = $("input#searchBox").val();
		
		var URL = "http://www.salemhealth.org/home.php#!search.home?q=" + encodeURIComponent(keyword) + "&button=Go";
		location.href = URL;
		//alert('You searched for ' + URL);
		return false;
	});
	//This calls for on the class "clearfooter" to expand the big footer
	$("#expand").live('click', function() {
		$("#footer-wrap").slideDown(500);
		$("#shrink").show();
		$(this).hide();
	});
	$("#shrink").live('click', function() {
		$("#footer-wrap").slideUp(500);
		$("#expand").show();
		$(this).hide();
	});
	//this hides the text in the searchbar once a key is pressed.
	$('#searchBox').keypress(function() {
		$('#searchBoxLabel').hide();
	});
	$('.feedback-submit').live('click', function() {
		var feedback = "feedback";
		// This if then is only for the second feedback box on the page.
		if ($('.feedback-message:eq(1)').val()==null) {
			message2 = " ";
		}
		else {
			message2 = $('.feedback-message:eq(1)').val();
		}
		var message = $('.feedback-message:first').val() + message2;
		var page = window.location.href;
		$.post("/home/feedback.php", { feedback: "feedback", message:message, page:page }, function(data) {
			$('.feedback-box').html(data);
		});
	});
});
