// JavaScript Document

var cookieVal;

function init(bg) {	
	
	cookieVal = bg;
	
	$("#top-nav").animate({
        marginTop: "0px"
      }, 1500, "swing" );
	
	
	$("#bottom-nav").animate({
		bottom: "0px"
	  }, 1500);
	
	$("a[name='"+bg+"']").removeClass("up");
	$("a[name='"+bg+"']").addClass("down");
	
	$("#bg > *").attr({ 
          src: "wallpapers/"+bg
      });

	
	$("#bg > img").load(function() {
		  $("#loading").fadeOut("slow");							 
	  });
	
	$("a.up").live("click", function() {
		  bgChange($(this).attr('name'), $(this).attr('rel'));			
	  });
	
	$("#return a").bind("click", function() {
		  returnMenu();
	});

}

function bgChange(name, photoCredit) {
	
	
	$("#photo-credit").html(photoCredit);
	
	$("a[name='"+cookieVal+"']").removeClass("down");
	$("a[name='"+cookieVal+"']").addClass("up");
	
	$.ajax({
   			type: "POST",
  			url: "sections/update-bg.php",
  	 		data: "bg="+name,
   			success: function(msg){
	   		}
 	});
	
	cookieVal = name;
	
	$("a[name='"+name+"']").removeClass("up");
	$("a[name='"+name+"']").addClass("down");
	
	$("#content").hide();
	
	$("#return").animate({
		top: "-100px"
	 }, "slow");
	
	$("#top-nav").animate({
        marginTop: "-49px"
      }, "slow");
	
	$("p.loading-text").text("Changing Background");
	$("#loading").fadeIn("fast");
	
	$("#bg > *").attr({ 
          src: "wallpapers/"+name
      });
	
	$("#bg > img").load(function() {
		  $("#loading").fadeOut("fast");
		  
		$("#return").animate({
			top: "-10px"
		 }, "slow");
	  });
}

function returnMenu() {
	$("#content").show();
	
	$("#return").animate({
		top: "-100px"
	 }, "fast");
	$("#top-nav").animate({
		marginTop: "0px"
		}, "slow");
}
