$(document).ready(function() {
	
	var benefitsScrollerPos = 1
	
	$('#selectBoxContainer span:eq(1)').click(function() {
		
		if (benefitsScrollerPos < 10) {
			$(".benefitsScroller").animate({
				marginLeft: parseInt($(".benefitsScroller").css("margin-left")) - 900 + "px"
			}, {
				duration: 1000,
				easing: 'easeInOutSine'
			});
			benefitsScrollerPos = benefitsScrollerPos+1
		
		} else {
			$(".benefitsScroller").animate({
				marginLeft: "0px"
			}, {
				duration: 1000,
				easing: 'easeInOutSine'
			});
			benefitsScrollerPos = 1
		}
		
		$("#selectBoxContainer img").css({"background-color":"#FFF"});
		$("#selectBoxContainer img:eq("+(benefitsScrollerPos-1)+")").css({"background-color":"#000"});
		
 	});
	
	$('#selectBoxContainer span:eq(0)').click(function() {
		
		if (benefitsScrollerPos > 1) {
			$(".benefitsScroller").animate({
				marginLeft: parseInt($(".benefitsScroller").css("margin-left")) + 900 + "px"
			}, {
				duration: 1000,
				easing: 'easeInOutSine'
			});
			benefitsScrollerPos = benefitsScrollerPos-1
		
		} else {
			$(".benefitsScroller").animate({
				marginLeft: "-8100px"
			}, {
				duration: 1000,
				easing: 'easeInOutSine'
			});
			benefitsScrollerPos = 10
		}
		$("#selectBoxContainer img").css({"background-color":"#FFF"});
		$("#selectBoxContainer img:eq("+(benefitsScrollerPos-1)+")").css({"background-color":"#000"});
		
 	});
	
	$("#benefitsToProperties").live('click', function() {
		$("#selectBoxContainer").fadeOut( function() {
			$("div.forgottenpassword").slideUp( function() {
				$("div.blackout").delay(500).fadeTo("fast", 1.0, function() {
					window.location = "/properties"
				});
			});
		});
	});
	
	$("#benefitsToHowItWorks").live('click', function() {
		$("#selectBoxContainer").fadeOut( function() {
			$("div.forgottenpassword").slideUp( function() {
				$("div.blackout").delay(500).fadeTo("fast", 1.0, function() {
					window.location = "/howitworks"
				});
			});
		});
	});
	
	$("#selectBoxContainer img:first").css({"background-color":"#000"});
	
	$("#selectBoxContainer img").live("click", function() {
		$("#selectBoxContainer img").css({"background-color":"#FFF"});
		$(this).css({"background-color":"#000"});
		benefitsScrollerPos = $("#selectBoxContainer img").index(this) + 1;
			//$('.benefitsScroller > div').append(benefitsScrollerPos);
			$(".benefitsScroller").animate({
				marginLeft: 0 - (900 * (benefitsScrollerPos - 1)) + "px"
			}, {
				duration: 1000,
				easing: 'easeInOutSine'
			});
	});
	
	$("#closeBenefits").live("click", function() {
		$("#selectBoxContainer").fadeOut( function() {
			benefitsScrollerPos = 1
			setTimeout(function(){
    			$(".benefitsScroller").css({"margin-left":"0px"});
				$("#selectBoxContainer img").css({"background-color":"#FFF"}); 
				$("#selectBoxContainer img:eq(0)").css({"background-color":"#000"});
			},3000);
		});
	});
	
	
	
	$("#benefitsToHolidayPoints").live("click", function() {
		$("#selectBoxContainer").fadeOut();
		$("div.forgottenpassword").delay(500).slideUp( function() {
			$("div.benefits").appendTo('div.forgotContainer');
			$("div.holidayPoints").appendTo("div.forgottenpassword");
			$("div.holidayPoints").find(".closeBrochureRequest").addClass("benefitsToHolidayPointsClose").removeClass("closeBrochureRequest");
			$("div.forgottenpassword").css({"width":"600px", "margin-left":"-300px"}).delay(500).slideDown();
		})
	});
	
	
	$(".benefitsToHolidayPointsClose").live("click", function() {
		$("div.forgottenpassword").delay(500).slideUp( function() {
			$("div.holidayPoints").appendTo('div.forgotContainer');
			$("div.benefits").appendTo("div.forgottenpassword");
			$("div.holidayPoints").find(".benefitsToHolidayPointsClose").addClass("closeBrochureRequest").removeClass("benefitsToHolidayPointsClose");
			$("div.forgottenpassword").css({"width":"900px", "margin-left":"-450px"}).delay(500).slideDown(function() {
				$("#selectBoxContainer").fadeIn();
			});
		})
	});
	
	
	
	$("#benefitsToSatisfaction").live("click", function() {
		$("#selectBoxContainer").fadeOut();
		$("div.forgottenpassword").delay(500).slideUp( function() {
			$("div.benefits").appendTo('div.forgotContainer');
			$("div.satisfaction").appendTo("div.forgottenpassword");
			$("div.satisfaction").find(".closeBrochureRequest").addClass("benefitsToSatisfactionClose").removeClass("closeBrochureRequest");
			$("div.forgottenpassword").css({"width":"600px", "margin-left":"-300px"}).delay(500).slideDown();
		})
	});
	
	
	$(".benefitsToSatisfactionClose").live("click", function() {
		$("div.forgottenpassword").delay(500).slideUp( function() {
			$("div.satisfaction").appendTo('div.forgotContainer');
			$("div.benefits").appendTo("div.forgottenpassword");
			$("div.satisfaction").find(".benefitsToHolidayPointsClose").addClass("closeBrochureRequest").removeClass("benefitsToSatisfactionClose");
			$("div.forgottenpassword").css({"width":"900px", "margin-left":"-450px"}).delay(500).slideDown(function() {
				$("#selectBoxContainer").fadeIn();
			});
		})
	});
	
	
	
	
	$("#benefitsToSafeguards").live("click", function() {
		$("#selectBoxContainer").fadeOut();
		$("div.forgottenpassword").delay(500).slideUp( function() {
			$("div.benefits").appendTo('div.forgotContainer');
			$("div.safeguards").appendTo("div.forgottenpassword");
			$("div.safeguards").find(".closeBrochureRequest").addClass("benefitsToSafeguardsClose").removeClass("closeBrochureRequest");
			$("div.forgottenpassword").css({"width":"600px", "margin-left":"-300px"}).delay(500).slideDown();
		})
	});
	
	
	$(".benefitsToSafeguardsClose").live("click", function() {
		$("div.forgottenpassword").delay(500).slideUp( function() {
			$("div.safeguards").appendTo('div.forgotContainer');
			$("div.benefits").appendTo("div.forgottenpassword");
			$("div.safeguards").find(".benefitsToHolidayPointsClose").addClass("closeBrochureRequest").removeClass("benefitsToSafeguardsClose");
			$("div.forgottenpassword").css({"width":"900px", "margin-left":"-450px"}).delay(500).slideDown(function() {
				$("#selectBoxContainer").fadeIn();
			});
		})
	});
	
	$("#benefitsToBrochure").live("click", function() {
		$("#selectBoxContainer").fadeOut();
		$("div.forgottenpassword").delay(500).slideUp( function() {
			$("div.benefits").appendTo('div.forgotContainer');
			$(".brochureRequestForm").appendTo("div.forgottenpassword");
			$(".brochureRequestForm").find(".closeBrochureRequest").addClass("benefitsToBrochureClose").removeClass("closeBrochureRequest");
			$("div.forgottenpassword").css({"width":"500px", "margin-left":"-250px"}).delay(500).slideDown();
		})
	});
	
	
	$(".benefitsToBrochureClose").live("click", function() {
		$("div.forgottenpassword").delay(500).slideUp( function() {
			$(".brochureRequestForm").appendTo('div.forgotContainer');
			$("div.benefits").appendTo("div.forgottenpassword");
			$(".brochureRequestForm").find(".benefitsToHolidayPointsClose").addClass("closeBrochureRequest").removeClass("benefitsToBrochureClose");
			$("div.forgottenpassword").css({"width":"900px", "margin-left":"-450px"}).delay(500).slideDown(function() {
				$("#selectBoxContainer").fadeIn();
			});
		})
	});
	
	$("#pointsToBrochure").live("click", function() {
		$("div.forgottenpassword").delay(500).slideUp( function() {
			$(".holidayPoints").appendTo('div.forgotContainer');
			$(".brochureRequestForm").appendTo("div.forgottenpassword");
			$(".brochureRequestForm").find(".closeBrochureRequest").addClass("pointsToBrochureClose").removeClass("closeBrochureRequest");
			$("div.forgottenpassword").css({"width":"500px", "margin-left":"-250px"}).delay(500).slideDown();
		})
	});
	
	
	$(".pointsToBrochureClose").live("click", function() {
		$("div.forgottenpassword").delay(500).slideUp( function() {
			$(".brochureRequestForm").appendTo('div.forgotContainer');
			$(".holidayPoints").appendTo("div.forgottenpassword");
			$(".brochureRequestForm").find(".pointsToBrochureClose").addClass("closeBrochureRequest").removeClass("pointsToBrochureClose");
			$("div.forgottenpassword").css({"width":"900px", "margin-left":"-450px"}).delay(500).slideDown(function() {
				$("#selectBoxContainer").fadeIn();
			});
			$("html, body").animate({ scrollTop: 0 }, 500);
		})
	});
	
	
		
});
