$(document).ready(function()
{
	// Set the slider to be sliding
	$("#toogle-handle").slider({
		handle: "#toogle-handle",
		animate:true,
		stop: function(e,ui)
		{
			if($(".ui-slider-handle").css("left") == ("100%"))
			{
				bulb_on();
			}
			if($(".ui-slider-handle").position().left == 0)
			{
				bulb_off();
			}
		}
		}
	);
	var bulb_on = function()
	{
		//$("#iphone-inside").animate({backgroundPosition: '0 40'}, 400, '', function()
		//{	
			$(".on").css("display","block");
			$(".lighton").fadeIn("normal");
			$("#head-dark").fadeOut("normal");
			$("#overlay").fadeOut("normal");
			$(".ui-slider-handle").position().left =100;
			//set cookie
			$.cookie('bulbstate', 'bulbon'); 							  
		//});
	}
	var bulb_off = function()
	{
		//$("#iphone-inside").animate({backgroundPosition: '0 40'}, 400, '', function()
		//{	
			$(".on").css("display","none");
			$(".lighton").fadeOut("normal");
			$("#head-dark").fadeIn("normal");
			$("#overlay").fadeIn("normal");
			$.cookie('bulbstate', 'bulboff'); 							  
		//});
	}
	var bulbstate = $.cookie('bulbstate'); 
	// if cookie is collapsed, then do stuff. Otherwise, cookie expanded is used 
	if (bulbstate == 'bulbon') {
			$(".on").show();
			$(".lighton").show();
			$(".ui-slider-handle").css("left","100%");
			$("#head-dark").hide();
			$("#overlay").hide();
	};
});
