$(document).ready(function(){

	// show hide for extra info panel
	$(".moredetailsbtn").click(function(){
	var aTime = 'slow';
	var paddingAmount = 650;
	$("#content").animate({paddingTop:paddingAmount+20},aTime);
	$("#hanging").animate({paddingTop:paddingAmount+1},aTime);
	$("#specials").animate({paddingTop:paddingAmount},aTime);
	$("#moredetails").slideDown(aTime);
	});
	
	$("#closemoredetailsbtn").click(function(){
	var aTime = 'normal';
	var paddingAmount = 0;
	$("#content").animate({paddingTop:paddingAmount+20},aTime);
	$("#hanging").animate({paddingTop:paddingAmount},aTime);
	$("#specials").animate({paddingTop:paddingAmount},aTime);
	$("#moredetails").slideUp(aTime);
	});
	// END show hide for extra info panel
	
	// animation for popup slide in
	$('#announcement').css({opacity:0}); //set the initial opacity of the popup
	$('#closeannouncement').click(function(){closeAnnouncement(); });
	
	var oHeight = $('#announcement').css('height');
	var oWidth = $('#announcement').css('width');
	var oLeft = $('#announcement').css('left');
	
	setTimeout(openAnnouncement, 5000); //start a timer to run the pop up function
	
	function openAnnouncement(){
		if ($.cookie('announcement') == null || $.cookie('announcement') != 'off'){
			setTimeout(autoCloseAnnouncement, 15000); //start a timer to run the pop up function
			$('#announcement').animate({opacity: 1.0, left: 10},
								  1000,
								  'swing');
		}
	};
	
	function closeAnnouncement(){
		$.cookie('announcement', 'off');
		$('#announcement').animate({opacity: 0, left: 1000, width:0, height:0},
							  500,
							  'swing');
	};
	
	function autoCloseAnnouncement(){
		$('#announcement').animate({opacity: 0, left: 1000, width:0, height:0}, 
							  500,
							  'swing',
							  function (){
								  var cssObj = {
								  'height' : oHeight,
								  'width' : oWidth,
								  'left' : oLeft
								  }
								  $('#announcement').css(cssObj);
							  });
	};
	
	// END animation for popup slide in
	
	// news subscription form JSON function

	$('#subbtn').click(function(){
		var n = $('#n').val();
		var e = $('#e').val();
	
		$.get("http://www.thatchedtavern.co.uk/_newshound/_subscriberJSON.asp", { n: n, e: e },
		//$.post("http://evesham/newshound/newshound/WTGAction/_subscriberJSON.asp", { n: sname, e: semail },
		//$.get("http://evesham:8080/the_thatched_tavern/assets/includes/jsproxy.php", { n: name, e: email },
					 function(data){
						 var message = data['message']
						 var name = data['name']
						 var email = data['email']
						 if (data['message']== 'success'){
							// clear input fields and set message to success
							
							$('#n').val(''); // clear the field value
							$('#e').val(''); // clear the field value
							$('#nameerror').hide(); // hide error
							$('#emailerror').hide(); //hide error
							
							$('#successmessage').show();
							
						 } else if (data['message']== 'error') {
							 $('#successmessage').hide();
							// leave input field values and show errors
								if (name == false){
									// set the name field error to visible
									$('#nameerror').show(); 
								} else if (name == true){
									// set the name field error to hidden
									$('#nameerror').hide();
								}
								
								if (email == false){
									// set the name field error to visible
									$('#emailerror').show(); 
								} else if (email == true){
									// set the name field error to hidden
									$('#emailerror').hide();
								}
						 }
						}, "json");
	});
	// END news subscription form JSON function
	

});