$('document').ready(function(){
	$('.navlist').each(function(){
		$(this).click(function(){
			$('.selected').removeClass('selected')
			$(this).addClass('selected');
			if($(this).attr('href') == "photos"){
				$.post('../ifieldcourt/photos.php', {'query': $(this).attr('href'), 'siteid': $('#siteid').val()}, function(data){
					$('.content-inner').html(data);
				})
			} else {
				$.post('../incfiles/main-content.php', {'query': $(this).attr('href'), 'siteid': $('#siteid').val()}, function(data){
					$('.content-inner').html(data);
				})
			}
			return false;
		})
	})
	$("#arrivedates").change(function(){
            //get the arrival date
            var info = $('#arrivedates').val();
            //get the day and add 1 to it;

            //put changed date in
            $('#departdate').val(fn_changdate(info, Number($('#numberofnights').val())));
			$('#carreturndate').val(fn_changdate(info, 8));
       })
	   function fn_changdate(info, addday){
	   	    var day = (Number(info.substring(0, info.indexOf('-')))+addday);
            //get the month selected
            var month = Number(info.substring(info.indexOf('-')+1, info.lastIndexOf('-')))-1;
            //get the year selected
            var year = info.substring(info.lastIndexOf('-')+1);
            //make new date function
            var myDate = new Date(year,month,day);
            //alert(month);
            //make the date look the same as it is there
            var newdate = ((myDate.getDate()).toString().length == 1 ? '0' : '')+(myDate.getDate())+ '-' + ((myDate.getMonth()).toString().length == 1 ? '0' : '')+(myDate.getMonth()+1) + '-' + myDate.getFullYear();
			return(newdate);
	   }
       $('#numberofnights').change(function(){
	   		var info = $('#arrivedate').val();
			$('#departdate').val(fn_changdate(info, Number($('#numberofnights').val())));
	   })
	   // this is for the click of book now to send to the correct location
	   $('#booknow').click(function(){
	   		// &featuredhotel=4 dont believe that we need this 
	   		$(this).attr('href', 'http://www.gatwickhotelswithparking.com/booking3/hotelavailable.php?subdomain='+$('#ifhotelsub').val()+'&hotel='+$('#ifhotelid').val()+'&bookdate='+$('#arrivedate').val()+'&stayonreturn='+$('#stayonreturn').val())
	   })
	   $('#booknowbottom').click(function(){
	   		// &featuredhotel=4 dont believe that we need this 
	   		$(this).attr('href', 'http://www.gatwickhotelswithparking.com/booking3/hotelavailable.php?subdomain='+$('#ifhotelsub').val()+'&hotel='+$('#ifhotelid').val()+'&bookdate='+$('#arrivedatebottom').val()+'&stayonreturn='+$('#stayonreturnbottom').val())
	   })
	   // hide the content div if clicked on outside of content
	  $('.base').click(function(){
	   		$('.content-top').removeClass('content-top-height');
			$('.findoutmore-text').removeClass('closecontent');
			$('.findoutmore-text').removeClass('findoutmore-text-up');
		   	$('.findoutmore-text').html('FIND OUT MORE...<div class="findoutmore-text-arrow"></div>');
	//	   	$('.promo-box').removeClass('promo-box-up');
	   })
	   	  
	   // display the content div
	   $('.content-top').click(function(event){
	   		//event.stopPropagation();
	   		//fn_rollin();
	   			$('.findoutmore-text').html('CLOSE');
				$('.findoutmore-text').addClass('findoutmore-text-up');
				$('.content-top').addClass('content-top-height');
			//	$('.promo-box').addClass('promo-box-up');
				return false;
	   })
	   // this is to make the find out more button work
	$('.findoutmore-text').click(function(){
		if(!$('.content-top').is('.content-top-height')){
			$('.findoutmore-text').html('CLOSE');
	   		$('.findoutmore-text').addClass('findoutmore-text-up');
	   		$('.content-top').addClass('content-top-height');
	   	//	$('.promo-box').addClass('promo-box-up');
	   		 return false;
	   	//	fn_rollout();
		}
	})
	
})

function fn_showmenu(){
	$.post('../ifieldcourt/incfiles-new/menu.php', function(data){
		$('#popup').html(data);
		fn_display()	
	})
	
}
function fn_menuclose(){
	$('#backgroundimage').css({"display" : "none"});
	$('#popup').css({"display" : "none"});
}
function fn_display(){
			
			var winheight = $(window).height();
			var popupheight = $('#popup').height();
			var positionx = (winheight - popupheight)/2
			var winwidth = $(window).width();
			var popupwidth = $('#popup').width();
			var positiony = (winwidth - popupwidth)/2;
			$('#backgroundimage').css({"display" : "block"});
			$('#popup').css({
				"display" : "block",
				"top" : positionx,
				"left" : positiony
			});
		}
