var homeSpotlight = homeSpotlight || {};

$(function(){
	if ($("body").hasClass("home")) {
		homeSlideShow();
		homeSpotlight.init();		
	} else if ($("body").hasClass("about-us") && $(".biographies")) {
		teamOpeners();
	} else if ($("body").hasClass("asset-management") && $(".approach")) {
		approachOpeners();
	} else if ($("body").hasClass("media") && $(".mediaSubmenu")) {
		$("#mediaSubmenu").children().last().prev().addClass("current_page_item");
	}	
	
	doSearchPlaceholder();
});


/*
	Spotlight section of homepage
*/
homeSpotlight.init = function() {
    
	$(".spotlight-titles > li").hover(function() {
		homeSpotlight.resetSelectedStates();
		homeSpotlight.selectItem($(this));
	});
	
	homeSpotlight.resetSelectedStates = function() {
		$(".spotlight-titles > li").each(function() {
			$(this).removeClass("selected");
		});
		$(".spotlight-details > div").each(function() {
			$(this).removeClass("selected");
		});		
	}
	
	homeSpotlight.selectItem = function(titleElement) {
		titleElement.addClass("selected");
		$(".spotlight-details > #detail-" + titleElement.attr("id")).addClass("selected");
	}	
	
}


/*
	Slideshow section of homepage
*/
function homeSlideShow() {   
	lastBlock = $("#a1");
    maxWidth = 620;
    minWidth = 160;	
	$(".home-slideshow ul li div").hover(function(){
		$(lastBlock).animate({width: minWidth+"px"}, { queue:false, duration:500, easing:"easeOutQuint" });
		$(this).animate({width: maxWidth+"px"}, { queue:false, duration:500, easing:"easeOutQuint"});
		lastBlock = this;
	});	
}


/*
	Cross-browser placeholder text for search field
*/
function doSearchPlaceholder() {
	$("#search input[type='text']").each(function(){
	    var origValue = $(this).val(); // Store the original value
	    $(this).focus(function(){
	        if($(this).val() == origValue) {
	            $(this).val('');
	        }
	    });
	    $(this).blur(function(){
	        if($(this).val() == '') {
	            $(this).val(origValue);
	        }
	    });
	});	
}


/*
	Management team accordions
*/
function teamOpeners(targetClass, targetBody) {
	var body = $(".biography .body");
	var header = $(".biography .header");
	
	$("<div></div>")
		.addClass("closeButton")
		.text("close")
		.appendTo(body)
		.click(function() {
			$(this).parent().parent().find(".body").slideUp();
			$(this).parent().parent().find(".header .arrow").slideDown();
		});

	header.click(function() {
		$(this).parent().find(".body").slideDown();
		$(this).find(".arrow").slideUp();
	});
	
	$("<div></div>")
		.addClass("arrow")
		.appendTo(header);
}


/*
	Asset management approach accordions
*/
function approachOpeners(targetClass, targetBody) {
	var body = $(".step .body");
	var header = $(".step .header");
	
	$("<div></div>")
		.addClass("closeButton")
		.text("close")
		.appendTo(body)
		.click(function() {
			$(this).parent().parent().find(".body").slideUp();
			$(this).parent().parent().find(".header .arrow").slideDown();
		});

	header.click(function() {
		$(this).parent().find(".body").slideDown();
		$(this).find(".arrow").slideUp();
	});
	
	$("<div></div>")
		.addClass("arrow")
		.appendTo(header);
}
