$(document).ready(function(){
	
	// if the cookie isn't set, load default background image
	if(!$.cookie('the_cookie')) {
		$("#header").prepend('<img src="/wp-content/themes/JAR/img/backgrounds/bridge.jpg" class="background-image" />');
	}
	
	// change bacground on click
	$(".bg01").click(function(){
		$.cookie('the_cookie', null); // delete cookie
		$.cookie('the_cookie', 'bg01', { expires: 7, path: '/' }); // set cookie
		$(".background-image").attr("src", "/wp-content/themes/JAR/img/backgrounds/bridge.jpg");
		$("head").append('<style type="text/css"> body { background-color:#000; } </style>');
		return false;
	});
	
	$(".bg02").click(function(){
		$.cookie('the_cookie', null); // delete cookie
		$.cookie('the_cookie', 'bg02', { expires: 7, path: '/' }); // set cookie
		$(".background-image").attr("src", "/wp-content/themes/JAR/img/backgrounds/bridge02.jpg");
		$("head").append('<style type="text/css"> body { background-color:#bfbfbf; } </style>');
		return false;
	});
	
	$(".bg03").click(function(){
		$.cookie('the_cookie', null); // delete cookie
		$.cookie('the_cookie', 'bg03', { expires: 7, path: '/' }); // set cookie
		$(".background-image").attr("src", "/wp-content/themes/JAR/img/backgrounds/bridge03.jpg");
		$("head").append('<style type="text/css"> body { background-color:#e4ccc0; } </style>');
		return false;
	});
	
	$(".bg04").click(function(){
		$.cookie('the_cookie', null); // delete cookie
		$.cookie('the_cookie', 'bg04', { expires: 7, path: '/'}); // set cookie
		$(".background-image").attr("src", "/wp-content/themes/JAR/img/backgrounds/bridge04.jpg");
		$("head").append('<style type="text/css"> body { background-color:#000; } </style>');
		return false;
	});
	
	// determine which background to load based on what the cookie is set to
	if ($.cookie('the_cookie') == "bg01") {
		$("#header").prepend('<img src="/wp-content/themes/JAR/img/backgrounds/bridge.jpg" class="background-image" />');
	} 
	else if ($.cookie('the_cookie') == "bg02") {
		$("#header").prepend('<img src="/wp-content/themes/JAR/img/backgrounds/bridge02.jpg" class="background-image" />');
		$("head").append('<style type="text/css"> body { background-color:#bfbfbf; } </style>');
	}
	else if ($.cookie('the_cookie') == "bg03") {
		$("#header").prepend('<img src="/wp-content/themes/JAR/img/backgrounds/bridge03.jpg" class="background-image" />');
		$("head").append('<style type="text/css"> body { background-color:#e4ccc0; } </style>');
	}
	else if ($.cookie('the_cookie') == "bg04") {
		$("#header").prepend('<img src="/wp-content/themes/JAR/img/backgrounds/bridge04.jpg" class="background-image" />');
	}
	
});