/**
 * @author Davy Kestens
 */

prevHeight = 0;
prevWidth = 0;
prevBg = '';

$(document).ready(function() 
{
	setBanner();
	$(window).resize(setBanner);
	setBackgroundImage();
	$(window).resize(setBackgroundImage);
});

function setBanner() 
{
	bannerWidth = ($(window).width() / 2) + 150;
	
	if (bannerWidth > prevWidth) 
	{ 
		prevWidth = bannerWidth;
		prefix = "http://www.runaddicts.net/wp-content/themes/runaddicts_2010/images/banner";
		suffix = ".png";
		
		if (bannerWidth < 500) {
			imageWidth = 500;
		}
		else 
			if (bannerWidth < 700) {
				imageWidth = 700;
			}
			else 
				if (bannerWidth < 900) {
					imageWidth = 900;
				}
				else 
					if (bannerWidth < 1100) {
						imageWidth = 1100;
					}
					else 
						if (bannerWidth < 1200) {
							imageWidth = 1200;
						} 
						else 
							if (bannerWidth < 1300) {
									
							}
							else {
								imageWidth = 1429;
							}
		
	$("#banner").css("background-image", "url('" + prefix + imageWidth + suffix + "')");
	}

}

function setBackgroundImage() 
{
	
	bodyHeight = $(window).height();
	
	
	if (bodyHeight > prevHeight) 
	{
		prevBg = $("body").css("background-image");
		$("html").css("background-image",prevBg);
		
		prevHeight = bodyHeight;
		prefix = "http://www.runaddicts.net/wp-content/themes/runaddicts_2010/images/bg";
		suffix = ".jpg";
		
		if (bodyHeight < 500) {
			imageHeight = 500;
		}
		else 
			if (bodyHeight < 700) {
				imageHeight = 700;
			}
			else 
				if (bodyHeight < 900) {
					imageHeight = 900;
				}
				else 
					if (bodyHeight < 1100) {
						imageHeight = 1100;
					}
					else 
						if (bodyHeight < 1300) {
							imageHeight = 1300;
						}
						else {
							imageHeight = 1600;
						}
		/*
		if (!$.browser.msie) 
		{
			$("html").css("background-image", "url('" + prefix + imageHeight + suffix + "')");
		}
		else
		{
			$("body").css("background-image", "url('" + prefix + imageHeight + suffix + "')");
			$("span.title").html(bodyHeight + " > "+ prefix + imageHeight + suffix);
		}*/
		$("html").css("background-image", "url('" + prefix + imageHeight + suffix + "')");
		$("body").css("background-color", "transparent");
	}
}
