google.load('visualization', '1', {packages:['corechart']});
google.load('jquery', '1.6.1');

google.setOnLoadCallback(function() {
	$('li.drop-down a.target').mouseenter(function() {
		$(this).addClass('open');
		$(this).next().show();
	});

	$('li.drop-down').mouseleave(function() {
		if ($(this).children('a.target').hasClass('open')) {
			$(this).children('a.target').removeClass('open');
			$(this).children('ul').hide();
		}
	});

	$('#search-text').focus(function() {
		$(this).filter(function() {
			return $(this).val() == '' || $(this).val() == 'Search...';
		}).removeClass('watermark').val('');
	});

	$('#search-text').blur(function() {
		$(this).filter(function() {
			return $(this).val() == '';
		}).addClass('watermark').val('Search...');
	});

	$('a#top').click(function(e) {
		e.preventDefault();
		window.scrollTo(0, 0);
	});

	$('div#metals a').click(function(e) {
		e.preventDefault();
		window.scrollTo(0, 0);
	});

	$('a[rel="external"]').click(function(e) {
		e.preventDefault();
		window.open($(this).attr('href'));
	});

	if ($('input.coverage-trigger:checked').val() == 'Yes') {
		$('fieldset#coverage-fields').show();
	}

	if ($('input.investor-trigger').is(':checked')) {
		$('fieldset#investor-fields').show();
	}

	if ($('input.analyst-trigger').is(':checked')) {
		$('fieldset#analyst-fields').show();
	}

	if ($('input.media-trigger').is(':checked')) {
		$('fieldset#media-fields').show();
	}
	
	if (($('select[name="Status"]').val() == 'Producer') || ($('select[name="Status"]').val() == 'Developer')) {
		$('span#production-required').show();
	}

	$('input.coverage-trigger').click(function() {
		if ($(this).val() == 'Yes') {
			$('fieldset#coverage-fields').show();
		}
		else {
			$('fieldset#coverage-fields').hide();
			$(':input', 'fieldset#coverage-fields').val('').removeAttr('checked');
		}
	});

	$('input.investor-trigger').click(function() {
		if ($('input.investor-trigger').is(':checked')) {
			$('fieldset#investor-fields').show();
		}
		else {
			$('fieldset#investor-fields').hide();
			$(':input', 'fieldset#investor-fields').val('').removeAttr('checked').removeAttr('selected');
		}
	});

	$('input.analyst-trigger').click(function() {
		if ($('input.analyst-trigger').is(':checked')) {
			$('fieldset#analyst-fields').show();
		}
		else {
			$('fieldset#analyst-fields').hide();
			$(':input', 'fieldset#analyst-fields').val('');
		}
	});

	$('input.media-trigger').click(function() {
		if ($('input.media-trigger').is(':checked')) {
			$('fieldset#media-fields').show();
		}
		else {  
			$('fieldset#media-fields').hide();
			$(':input', 'fieldset#media-fields').val('');
		}
	});

	$('select[name="Status"]').change(function() {
		if (($(this).val() == 'Producer') || ($(this).val() == 'Developer')) {
			$('span#production-required').show();
		}
		else {
			$('span#production-required').hide();
		}
	});

	if ($('span.error').length) {
		$('div#content form').prepend('<p class="error">Some errors were detected in your form.</p>');
	}

	$('div#marquee div').bind('marquee', function(e, sRight) {
		var iDuration;
	
		if (sRight == 'new') {
			$(this).css('right', '-' + $(this).width() + 'px');
			iDuration = (256 + $(this).width()) / 40;
		}
		else {
			sRight = sRight.substring(0, sRight.length - 2);
			iDuration = (256 - sRight) / 40;
		}

		$(this).animate({ right: $(this).parent().width() }, iDuration * 1000, 'linear', function() {
			$(this).trigger('marquee', ['new']);
		});
	}).trigger('marquee', ['new']);

	$('div#marquee').mouseenter(function() {
		$('div#marquee div').stop();
	});

	$('div#marquee').mouseleave(function() {
		$('div#marquee div').trigger('marquee', [$('div#marquee div').css('right')]);
	});
	
	$('div#upcoming-events div.event:last').css({ 'border': 0, 'margin-bottom': 0, 'padding-bottom': 0 });
	
	$('div.side-bar-item:last').css({ 'background-image': 'none', 'padding-bottom': '10px' });
});
