jQuery(document).ready(function(){			

	function lockModeTime(){				
		var option = {
			timeNotation: '12h'
		};
			jQuery('#lock-mode .time').jclock(option);
	}
	
	
	// Screen Hide
	function screenHide(){
		jQuery('#lock-mode').css('display', 'none')
		jQuery('.sleep').css('display', 'none');
	}
	
		
	var check_slider = Get_Cookie('chckslider');
	
	if(check_slider == 0)
	{
	}
	else
	{
		lockModeTime();
		screenLock();
	}
	
	
	// Screen Locked
	function screenLock(){
		jQuery('.icon-lock').css('display', 'block');
		jQuery('.handle').css('left', '2px');
		jQuery('#lock-mode .unlock-slider').css('bottom', 0);
		jQuery('#lock-mode .top').css('top', 0);
		jQuery('#lock-mode').fadeIn();
		jQuery('.unlock-slider .text').show();
		jQuery('.sleep').css('display', 'block');
		screenUnlocked();
	}
	
	// Screen Unlocked
	
		var i = 0;
		jQuery(".unlock-slider .handle").click(function(){
			if (i==0) {
				jQuery('.unlock-slider .cant-unlock').fadeTo('slow', 1, function() {});
				i=1;
			} else if (i==1) {
				jQuery('.unlock-slider .cant-unlock').fadeTo('slow', 0.1, function() {});
				i=0;
			}
		});

function Unlocking(){
	Set_Cookie( 'chckslider', '0', 30, '/', '', '' );
	
	jQuery('.icon-lock').css('display', 'none');
	
	jQuery('#lock-mode .unlock-slider').animate({
		bottom: '-=80',
		}, 550, function() {
		// Animation complete.
	});
	
	jQuery('#lock-mode .top').animate({
		top: '-=80',
		}, 550, function() {
		// Animation complete.
	});
	
					  
	jQuery('#lock-mode').fadeOut('slow', function()
		{
		jQuery(this).css('display', 'none');
		}
	);
	
	jQuery('.sleep').fadeIn('slow').fadeOut('slow', function()
		{
		jQuery(this).css('display', 'none');
		}
	);
}


	jQuery('.unlock-slider .cant-unlock').click(function(){
		Unlocking();
	});
	
	function screenUnlocked(){
		jQuery(".unlock-slider .handle").draggable({
			
			axis: 'x',
			containment: 'parent',
			
			drag : function (event, ui){ //Get Position Numbers
//					jQuery('.position').html(ui.position.left);
				jQuery('.unlock-slider .text').fadeOut();
			},
			
			stop : function (event, ui){
				
				if (ui.position.left == 190) {					
					Unlocking();
				}
				else { //send back to handle button
					jQuery('.unlock-slider .handle').animate({
						left: '2px'
						}, 400, function() {
						// Animation complete.
					});
					jQuery('.unlock-slider .text').fadeIn();
				}
			}
		});
	}
	
	
	
	//Initialize first screens
//	lockModeTime();
//	screenUnlocked();
	
	
	
	jQuery('.btn-sleep').click(function(){
		lockModeTime();
		screenLock();
		Set_Cookie( 'chckslider', '1', 30, '/', '', '' );
	});
	
	
});

function Set_Cookie( name, value, expires, path, domain, secure )
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

/*
if the expires variable is set, make the correct
expires time, the current script below will set
it for x number of days, to make it for hours,
delete * 24, for minutes, delete * 60 * 24
*/
if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
( ( path ) ? ";path=" + path : "" ) +
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}

// this fixes an issue with the old method, ambiguous values
// with this test document.cookie.indexOf( name + "=" );
function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );


		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}

