$(function() {

	// check for any cookies at all
	if( ($.cookie('Popped') || $.cookie('Your Name')) == null ) {
		
		$('.yourName').text('NO COOKIES AT ALL!');

		// set the virgin cookie
		$.cookie('Popped', 'Cherry', { expires: 365, path: '/', domain: 'dukeofcheese.com' });
		
	} else if( $.cookie('Popped') ) { // if there is a POPPED cookie
		
		// fill the P with new content
		$('.yourName').html('Welcome back <input type="text" value="enter your name and press enter" class="nameField" />,');
		
		// drop the P down
		$('.yourName').animate({top: '-51'}, 2000);
		
		// change styles on text field focus
		$('.yourName').click(function() {
			$('input:focus').attr('value', '').addClass('inherit');
		});

		// set a cookie with the users name
		$('.yourName').keyup(function() {
			if (event.keyCode == '13') {
			
				// get the value the user types in
				var value = $('input').val();
	
				var name = value;
				// create a cookie to save the users name
				$.cookie('Your Name', name, { expires: 365, path: '/', domain: 'dukeofcheese.com' });
				
				// delete the virgin cookie
				$.cookie('Popped', null, { path: '/', domain: 'dukeofcheese.com' });
				
				// display the users name
				$('.yourName').css('top', '-40px').text('Welcome back ' + name + ',');
			}
		});	

	} else if( $.cookie('Your Name') ) { // if there is a NAME cookie
		
		// set the name variable
		var name = $.cookie('Your Name');

		// fill the P with the users name
		$('.yourName').css('top', '-40px').text('Welcome back ' + name + ',');
		
	}

});
