String.prototype.endsWith = function(str) {
	return (this.match(str+"$")==str);
};
try {
  document.execCommand("BackgroundImageCache", false, true);
} catch(e) {}

var newmessages = 0;

$().ready(function() {
	if($('.message  p').size() > 0){
		$('#message_container').show();
		$('h3#messages').show();
		$('#message_container div.message').each(function() {
			var d = $('span.date', this).html();
			d = Date.parse(d);
			var n = Date.parse(new Date());
			d = (n - d) / 1000 / 60 / 60 / 24;
			if(d < 30) {
				$(this).addClass('new');
				newmessages++;
			}
		});
		var append = '';
		if(newmessages > 0) {
			if(newmessages > 1) { append = 's'; }
			$('#messagealert').html('<a href="#messages" class="new">You have '+newmessages+' new message'+append+'</a>');
			$('#messagealert').show();
			
		}
	}
	
	$('.fundLink').click(function() {
		var id = $(this).attr('href');
		$('.fundLink').removeClass('selected');
		$(this).addClass('selected');			
		$('.fund').hide();
		$('.loading').show();
		setTimeout( function(){
			$('.loading').hide();
			$('#standard_reports p.teaser').hide();	
			$('#standard_reports .reportBlock').show();
			$('#standard_reports h2').show();
			$('#standard_reports h3').removeClass('contracted');
			$(id).show('slow');
		}, 2000);
		return false;
	});
		
	$('ul.select').each(function() {
		var classString = 'fundSelect';
		if($(this).hasClass('doc')) { classString += ' doc'; } 	
		if($(this).hasClass('additional')) { classString += ' additional'; }
		var select =  "<form><select class=\""+classString+"\">\n";
		
		$('li > a', this).each(function() {
			
			select += "<option value=\""+ $(this).attr('href') +"\">"+$(this).html()+"</option>";
		});
		
		select += "</select><input type=\"button\" class=\"fundButton\" value=\"Go\"/></form>";
		
		$(this).before(select).remove(); 
		
		
		
		
		
	});
	$('#fund_1').find('.reportBlock').show();
	
	$('.fundButton').click(function() {
		var parent = $(this).parent();
		
		var href = $('select', parent).val();
		
		if(mam.util.env.isTeamsite()) {
			href = href.replace(/^(.*?\/clients\/)(.)([^\/].*)$/, "$1$2/$2$3");
		}

		if(href != '#') {
			if($('select', parent).hasClass('additional')) {   
				window.open(href);
			} else if(href.endsWith('.html')) {
				window.location.href = href;
			} else {
				window.open(href);
			}
		}
		
	});
	
	$('.infotext a').click(function() {
			var href=$(this).attr('href');
			window.open(href);
			return false;
	});
	
	$('#clientReporting h4').click(function() {
		$('#messages').removeClass('contracted');
		$('#messages').parent().find('.reportBlock').show('slow');
		$('#messages').parent().find('h2').show();
	});
	
	$('#clientReporting h3').click(function() {
		if($(this).attr('id') == 'reportsHeader') {
			$('div.fund:first', this.parent).show();	
		} 
		if($(this).hasClass('contracted')) {
			$(this).removeClass('contracted');
			$(this).parent().find('.reportBlock').show();
			$(this).parent().find('h2').show();
		} else {
			$(this).addClass('contracted');
			$(this).parent().find('.reportBlock').hide();
			$(this).parent().find('h2').hide();
		}
	});
	
	$("div#standard_reports div.reportBlock:even").css("background", "#eaeaea");
	$("tbody tr:even").css("background", "#eaeaea");
	$("div#document_center div.reportBlock:even").css("background", "#eaeaea");
	$("div#additional_client_reporting div.reportBlock:even").css("background", "#eaeaea");
	$("div#audio_review div.reportBlock:even").css("background", "#eaeaea");
	$("div#other_reports div.reportBlock:even").css("background", "#eaeaea");
	$("div#proxy_reports div.reportBlock:even").css("background", "#eaeaea");

	//not great - but if header spans, then reposition
	if ($('#client_reporting_section h1 span').height() > 45) {;
		$('#client_reporting_section #main-content').css("top","-24px");
	}
});

var mi0 = {};
mi0.hideStatements = false;




