(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery)

// we will add our javascript code here           

$(document).ready(function(){
						   
	var randomImages = ["/images/backgroundphotos/exported/1-crab.jpg", "/images/backgroundphotos/exported/2-Skatepark.jpg", "/images/backgroundphotos/exported/3-Waves.jpg", "/images/backgroundphotos/exported/4-hangar.jpg","/images/backgroundphotos/exported/5-BC Ferries.jpg", "/images/backgroundphotos/exported/6-bwscene.jpg", "/images/backgroundphotos/exported/7-Woods.jpg", "/images/backgroundphotos/exported/8-Skatepark.jpg", "/images/backgroundphotos/exported/9-sunset.jpg",  "/images/backgroundphotos/exported/10-Chilling in water.jpg", "/images/backgroundphotos/exported/11-flipflop.jpg"];
	
	var COOKIE_NAME = 'background_cookie';
	var COOKIE_FADE = 'fade_cookie';
	var options = { path: '/', expires: 10 };
	
	var value = $.cookie(COOKIE_NAME);
	
	if (value != null) {
		if (value == 10) {
		var value = 0;
		} else {
		var value = parseInt(value) + 1;	
		}
		
	$.cookie(COOKIE_NAME, value, options);	
	} else {            
	$.cookie(COOKIE_NAME, '0', options);
	value = 0;
	}
	
	
    $("body").css('background-image', ('url("'+randomImages[value]+'")'));
	
	var fade = $.cookie(COOKIE_FADE);
	
	if (fade == null) {    
	$.cookie(COOKIE_FADE, '1', options);
	var fade = 1;
	}
	$("#one").click(function() {$.cookie(COOKIE_FADE, '1', options); $("#two").attr("style", "background-position: top center;"); $("#one").attr("style", "background-position: center -35px;");});
	$("#two").click(function() {$.cookie(COOKIE_FADE, '0', options); $("#two").attr("style", "background-position: center -35px;");	$("#one").attr("style", "background-position: top center;");});
	
	if (fade > 1) {
		var fade = 1;	
	}
	
	if (fade == 1) {
		$("#wrapper").fadeIn(3000);
		$("#two").attr("style", "background-position: top center;");
		$("#one").attr("style", "background-position: center -35px;");
	} else {
		$("#wrapper").show();
		$("#two").attr("style", "background-position: center -35px;");
		$("#one").attr("style", "background-position: top center;");
	}
	
	$("#connected_hide").click(function() {
		$("#connected_nav").slideToggle();
	});
						   
$("#myForm").submit(function(){

var str = $("#myForm").serialize();

$.ajax({
type: "POST",
url: "/signup.php",
data: str,
success: function(msg){

$("#note").ajaxComplete(function(event, request, settings){

if(msg == 'OK') // Message Sent? Show the 'Thank You' message and hide the form
{
result = '<div class="notification_ok">You have been signed up. Thank you!</div>';
$("#sign_up_section").hide();
}
else
{
result = msg;
}

$(this).html(result);

});

}

});

return false;

});

});
// uses jquery fade 
function killIt(item){
		$(function(){
			$('#'+item).fadeOut(1000);
		});
	}	
