$ = jQuery.noConflict();
$(document).ready(function() {

	var _ie7 = $.browser.msie && parseInt($.browser.version, 10) == 7;

	// remove brackets from links
	$("#main .content h2 .all-link a").each(function() {
		$(this).text($(this).text().replace("(", "").replace(")", ""));
		if($(this).attr("href") == "/support/event-calendar") $(this).text("View calendar");
	});
	
	// remove util nav images and replace with text
	$("#top-tools a").each(function() {
		$(this).text($(this).children("img:first").attr("alt"));
	});
	$("#top-tools").css("visibility", "visible");
	
	// add uniform spacing to footer links
	$("#footer .footer_left a").each(function() {
		$(this).before(" ").after(" ");
	});
	
	// flip dropdown menu orientation on far right
	var menuLeft = $("#main-menu").offset().left;
	var menuWidth = $("#main-menu").width();
	var menuItemWidth = 200;
	$("#main-menu ul.nice-menu > li.menuparent").each(function() {
		var menuItem = $(this);
		if(menuItem.offset().left - menuLeft > menuWidth - menuItemWidth) menuItem.addClass("right");
		$("li.menuparent", menuItem).each(function() {
			if(menuItem.offset().left - menuLeft > menuWidth - 2*menuItemWidth) $(this).addClass("right");
		});
	});
	// remove "index" items
	$("#main-menu ul.nice-menu > li.menuparent > ul > li").each(function() {
		if($(this).text().toLowerCase() == "index") $(this).remove();
	})
	$("#leftCol ul.menu li").each(function() {
		if($(this).text().toLowerCase() == "index") $(this).remove();
	})
		
	// make home page links into block display
	$("#main .bottom-left a, #main .bottom-right a").each(function() {
		if($(this).next("br").length || $(this).prev("br").length) $(this).addClass("block");
	});
	
	// get rid of inline styles
	$("#top-home .top-right .features_details_inner img").attr("style", "");
	
	// fix dog/cat buttons
	$("#feature_dog #btnFeatDog").each(function() {
		var textButton = $('<a href="#" class="button">Featured Dogs</a>');
		textButton.click($(this).attr("onclick"));
		$(this).before(textButton).remove();
	});
	$("#feature_dog #btnAllDog").each(function() {
		var textButton = $('<span>All Dogs</span>');
		$(this).before(textButton).remove();
		textButton.parent().addClass("button");
	});
	$("#feature_cat #btnFeatDog").each(function() {
		var textButton = $('<a href="#" class="button">Featured Cats</a>');
		textButton.click($(this).attr("onclick"));
		$(this).before(textButton).remove();
	});
	$("#feature_cat #btnAllDog").each(function() {
		var textButton = $('<span>All Cats</span>');
		$(this).before(textButton).remove();
		textButton.parent().addClass("button");
	});
	$(".animal_intro .animal_img_intro").remove();
	
	// content utility links
	$("#rightCol .utility a, #content .utility a").addClass("button");
	$("#rightCol .utility, #content .utility").css("visibility", "visible");
	
	// selected menu item
	$("#main-menu ul.nice-menu > li > a").each(function() {
		if(location.href.indexOf($(this).attr("href")) != -1 && $(this).text().toLowerCase() != "home") $(this).css("color", "#c60738");
	});
	
	// dump empty paragraphs
	$("#content .node-content p").each(function() {
		if(!$.trim($(this).text())) $(this).remove();
	});
	
	// move pet images out of meta list
	$("#content .pet-detail > strong > img").each(function() {
		$(this).parent().parent().before($(this).addClass("pet-photo"));
	});
	$("#content .pet-detail > img").each(function() {
		$(this).parent().before($(this).addClass("pet-photo"));
	});
	
	// file lists
	$("#content .view-library a[href$='pdf']").parent().addClass("pdf");
	$("#content .view-library a[href$='doc']").parent().addClass("doc");
	$("#content .view-library a[href$='docx']").parent().addClass("doc");
	$("#content .view-library a[href$='xls']").parent().addClass("xls");
	
	// fix formatting on extra long titles
	$("#content h1.title").each(function() {
		var titleHeight = $(this).height() + 31;
		$(this).css("margin-top", -titleHeight);
		$("#soContainer").css("margin-top", titleHeight);
		if(_ie7) $("#rightCol").css("margin-top", titleHeight);
	});
	
	$("#content ul.view-week li .views-field-start-day").each(function() {
		if(!$.trim($(this).text())) $(this).remove();
	});
	
	// fix broken event status messages
	$('#crm-container > .messages').insertAfter('h1.title');
	
	
});
