$(document).ready(function() {
	if ($("a.inline").fancybox){
		$("a.inline").fancybox();
	}

	if ($('#SearchText').length > 0) showFieldTitle('#SearchText');

	if ($('#PressDate').length > 0) $('#PressDate').change(function() {
		if (this.value.length > 0) document.location = '/element-in-the-news/' + this.value.substr(5, 2) + '/' + this.value.substring(0, 4);
	});

	$('.fileDownloads').change(function(){
		
		var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
		
		if (!is_chrome)
		{
			if ($(this).val() != 'Select a Fund Sheet to view' && $(this).val() != 'Select a newsletter to view') {
				window.open($(this).val());
			}
		}
		else
		{
			if ($(this).val() != 'Select a Fund Sheet to view' && $(this).val() != 'Select a newsletter to view') {
				location.href = $(this).val();
			}
		}		
	});

	$('li.pdfIcon a, a.blank').attr('target', '_blank');

	$('.voteCompanies').change(function(){
		if (this.value != '') {
			document.location = '/responsible-investment/voting-record/archive/view/' + this.value;
		}
	});
	
	$(".videoColorbox").colorbox({iframe:true, innerWidth:425, innerHeight:344});
	
	$(".hiddenFlow").click(function(){
		var podId = $(this).attr('rel'),
			htmlBox = "#hidden" + podId;		
		
		$(".hiddenFlow").colorbox({width:"492px", inline:true, href:htmlBox});	
	});
});

function showFieldTitle(fieldId)
{
	var title = $(fieldId).attr('title');

	$(fieldId).val(title);

	$(fieldId).focus(function() {
		if ($(fieldId).val() == title) $(fieldId).val('');
	});

	$(fieldId).blur(function() {
		if ($(fieldId).val().length == 0) $(fieldId).val(title);
	});
}