function SplitDateText(stringToSplit, charToSplit) {
	var myArray = stringToSplit.split(charToSplit);
	return myArray;
}
function SplitDateHtml(stringToSplit, charToSplit) {
	var myArray = stringToSplit.split(charToSplit);
	return myArray;
}

(function($) {

$.ajaxSetup({cache: false});

$(document).ready(function() {

//add footer information
$.get('/Portals/32549/footerStuff.html', function(data) {
	$('#footer').append(data);
});

//google search box
$("#googlesearchbox").prependTo("#foxboro_header .search");
$("#googlesearchbox .googlesearch").val("Search...");
$("#googlesearchbox .googlesearch").click(function() {
	if($(this).val() == "Search...") $(this).val("");
	$(this).addClass("focused");
});
$("#googlesearchbox .googlesearch").blur(function() {
	if($(this).val() == "") $(this).val("Search...");
	$(this).removeClass("focused");
});


// SHOW BLOG NAVIGATION OPTIONS IF LOGGED IN
if( $("#hsnavigation").length) {
    $("p.hk_menu").show();
}


// Blog module
$("div.block:has(.feedreader_box):contains('Blog')").addClass("blog-block");
$("div.blog-block h3").append(' <a href="http://blog.connectionmodel.com/CMS/UI/Modules/BizBlogger/rss.aspx?tabid=116454&moduleid=141212&maxcount=25&t=3e0cb39e-9837-4f30-90a5-79e9af412701" class="rss-icon" target="_blank">RSS</a> ');

//change date format in blog feed
$("div.blog-block .ItemInfo span").each(function() {

	//Split the to get the dateMonth and dateDay
	var text = $(this).text();
	dateLongDay = SplitDateText(text, ", ")[0];
	dateMonth = SplitDateText(text, " ")[1];
	dateShortDay = SplitDateText(text, " ")[2];
	dateYear = SplitDateText(text, ", ")[3];

	$(this).html("<div class='dateMonth'>" + dateMonth + "</div>" + " " + "<div class='dateDay'>" + dateShortDay + "</div>");

	var dateHtml = $(this).html();
	dateHtmlOutput = SplitDateHtml(dateHtml, ",")[0];

	//output date minus comma
	$(this).html(dateHtmlOutput);

});

//add 0 for single digit dates
$("div.blog-block .dateDay").each(function() {
	var dayText = $(this).html();
	var dayCharLength = $(this).html().length;

	if (dayCharLength < 2) {
		$(this).html("0" + dayText);
	}
});

//show date
$("div.blog-block .ItemInfo").show();

//add read more link to blog
$("div.blog-block div.pad").append(' <a class="orangeBtn" href="/blog/">View All Posts</a> ');


//orange button
$("a.orangeBtn").each(function () {
    $(this).wrapInner("<span></span>");
    $('<div class="clear" />').insertAfter(this);
});


});

})(jQuery);
