function background() {
	var b = $('#background .image img');

	var img_w = 1920;
	var img_h = 1080;
	var win_w = $(window).width();
	var win_h = $(window).height();
	var h = img_h * (win_w / img_w);
	
	if (win_h >= h) {
		h = win_h;
		w = img_w * (h / img_h);
		b.css('width', 'auto').css('height', win_h + 'px');
	} else {
		w = img_w * (h / img_h);
		h = img_h * (w / img_w);
		b.css('width', win_w + 'px').css('height', 'auto');
	}
		
	b.css('left', ((win_w - 600 - w) / 2) + 'px');
//	b.css('top', ((win_h - h) / 2) + 'px');
}

$(function() {
	background();
	$(window).resize(function() {
		background();
	});

	$('a[rel="prettyPhoto"]').prettyPhoto();

	if($.browser.msie && $.browser.version.substr(0, 1) < 7) { 
		$('.how-it-works .mix').css('width', '105px');
		$('#content').css('margin', '-101px 0 0 0');
	}

	Cufon.replace('h2',  {
		fontFamily: 'Gotham Medium',
		hover: 'true'
	});
	
	Cufon.replace('h2, h3, .reasons li, .how-it-works li, .how-it-works h4, .pod-text p, .reasons ul li, .large-marge, .showdown, .non-disposable li, .old-new li, .the-cleaner li, .the-labels h4, .the-benefits h4, .press h4, .pledge-copy p, .happening-item h4', {
		fontFamily: 'Gotham Medium',
		hover: 'true'
	});


	$('.header li a').objectBGFade();

	$('.the-badge').hover(function() {
		$('.the-badge').stop().animate({rotate: '15deg'}, 300);
	},function() {
		$('.the-badge').stop().animate({rotate: '0deg'}, 300);
	});
});

(function($){	
	$.fn.extend({   
		objectBGFade: function(options) {  
			var defaults = {  
				animateSpeedOn: 600,
				animateSpeedOff: 250
			};
			var options = $.extend(defaults, options);  
			return this.each(function() {  
				$(this).css({
					position:"relative",
					backgroundPosition:"0px 0px",
					cursor:"pointer"
				});

				var o = options;  
				var obj = $(this);
				var items = $("li", obj);
				var spanObj = document.createElement('span');
				var myBG = $(this).css("background-image");

				spanObj.className = "background_change";

				$(this).append(spanObj);

				var bgImg = $(this).css("background-image");
				var spanWidth =  $(this).css("width");
				var spanHeight =  $(this).css("height");

				$(this).find(".background_change").css({
					backgroundImage:bgImg,
					backgroundPosition:"bottom right",
					position:"absolute",
					display:"block",
					cursor:"pointer",
					top:"0px",
					left:"0px",
					width:spanWidth,
					height:spanHeight,
					opacity:0,
					visibility:"visible"
				});

				$(this).find("span").hover(function() {
					$(this).stop();
					$(this).animate({opacity: 1}, o.animateSpeedOn);
				},
				function() {
					$(this).animate({opacity: 0},o.animateSpeedOff);
				});
			});  
		}
	});
})(jQuery);
