$(document).ready(function(){
    
	setArrowPos();
    
    $("#nextPage").click(function(){
    	$(".arrow").hide();
        $("#pagesWrap").animate({ left: '-100%' }, { duration: 1000 } );
		$("#socialOuter").animate({ left: '-100%' }, { duration: 1000 } );
        changeBackground("images/reesebadda_site_bg3.jpg", 1);
    });
    
    $("#prevPage").click(function(){
    	$(".arrow").hide();
        $("#pagesWrap").animate({ left: '0%' }, { duration: 1000 } );
		$("#socialOuter").animate({ left: '0%' }, { duration: 1000 } );
        changeBackground("images/reesebadda_site_bg7.jpg", 0);
    });

	$(window).resize(function(){
		setArrowPos();
	})
    
    function changeBackground(changeTo, pageNum){
    	var imageCode = $("#backstretch img").clone();
    	imageCode.css("display", "none");
    	imageCode.attr("src", changeTo);
    	
    	$("#backstretch img").fadeOut('slow',function(){
            $("#backstretch img").remove();                 
            $("#backstretch").append(imageCode);            
            $("#backstretch img").fadeIn('slow');
            if(pageNum == 1) 
            	$("#prevPage .arrow").fadeIn();   
            else
            	 $("#nextPage .arrow").fadeIn(); 
        });
    }

	function setArrowPos(){
		var arrowPos = $(window).height()/2 - 62;
		$("#nextPage, #prevPage").css('top', arrowPos);
	}
});
