Cufon.replace('.treplace, #content h1, #content h2:not(.norep), #content h3');

$(document).ready(function(){
	$navItems = $('#navMain li');
	$navBg = $('<div class="bg"></div>').css('opacity',0);
	$navItems.prepend($navBg);
	$navItems.hover(
		function() {
			$(this).find('.bg').fadeTo(200, 1);
		},
		function() {
			$(this).find('.bg').fadeTo(100, 0);
		}
	);

	openInNewWindow = function(e) {
		e.preventDefault();
		window.open($(this).attr('href'));
	};
	
	var host = window.location.protocol + '//' + window.location.hostname;

	$('a.docsviewer').each(function(){
		href = $(this).attr('href');
		$(this).attr({
			href: 'http://docs.google.com/viewer?url=' + host + href
		}).click(openInNewWindow);
	});

	$('a[rel=external]').click(openInNewWindow);

	$('#banners').carousel({
		sizeBigWidth: 154,
		sizeBigHeight: 170,
		sizeSmallWidth: 92,
		sizeSmallHeight: 102,
		nextEl: '#banners-next',
		pause: 4000,
		speed: 1000,
		autostart: true
	});

	$('#banners-next').css('opacity', 0.4)
					.hover(function() {
						$(this).css('opacity', 0.8)
					}, function() {
						$(this).css('opacity', 0.4)
					});


	$('#newsletter-subscribe').submit(function(e){
		e.preventDefault();

		$inputs = $('input', this).attr('disabled', 'disabled');
		$response = $('#newsletter-response').html('');
		$error = $('#newsletter-error').html('');
		$me = $(this);
		$mask = $('#boxNewsletter').find('.loadingMask');

		$mask.fadeIn();

		setTimeout(function(){
			$.ajax({
				type: 'POST',
				url: $me.attr('action'),
				data: { 'email':  $('#email-newsletter').val() },
				dataType: 'json',
				success: function(data) {
					if (data.success) {
						$response.html(data.response);
						$response.fadeIn();
					} else {
						$error.html(data.response);
						$inputs.removeAttr('disabled');
					}

					$mask.fadeOut();
				}
			});
		}, 1000);

		return false;
	});


	$('#searchForm').submit(function(e){
		e.preventDefault();
		if (this.q.value == '') return false;
		window.open(this.action+'?sitesearch='+this.sitesearch.value+'&q='+this.q.value);
		return false;
	});

});
