// JavaScript Document

var videoWidth = 231;
var videoLeft = 65;

$("body").removeAttr('filter');

$(document).ready(function() {
	$('body').supersleight();	
	
	
	if($('#scrollText').height() > $("#scrollContainer").height()) {
		$('.moveUpContainer').show();
		$('.moveDownContainer').show();
	}
	
	$('.SubNavLand').delay(600).fadeIn(300);
	
	var newPos = $('.CurrentNav').position().left + 298;
	
	$('.SubNavLand').css({ left: newPos });
	$('.SubNav').css({ left: newPos });
	
	$('.MainFade').fadeIn(500);
	
	/// GALLERY ///
	
	var newWIdth = $('.ThumbHolder').size() * 231;
	$('.ThumbScroller').width(newWIdth);
	
	var newVideoWidth = $('.videoHolder').size() * videoWidth;
	$('.videoThumbScroller').width(newVideoWidth);
	
	if ($('.ThumbHolder').size() == 1) {			
		$('.ArrowRight').hide();	
	}
	$('.ArrowLeft').hide();

	
	$('.ThumbDiv').each(function(){						
			$(this).click(function() {
				var theID = $(this).attr('id').split("_");
				if (theID[1] < 10000000) {
					$('.GalleryImages').cycle(parseInt(theID[1])); 	
					$('.ThumbBorder').each(function(){
						$(this).attr('id', '');	
					});
					$(this).find('.ThumbBorder').attr('id', 'SelectedThumb');
				} 			 	
			});
		});
	
	$('.GalleryImages').find('img').each(function(){	
		if ($(this).height() < 460) {
			var margTop = Math.round((460 - $(this).height()) / 2);
			$(this).css({ 'margin-top': margTop + 'px' });
		}
		if ($(this).width() < 629) {
			var margLeft = Math.round((629 - $(this).width()) / 2);
			$(this).css({ 'margin-left': margLeft + 'px' });
		}
	});
	
	$('.videoThumb a img').hover(
		function () {
			$(this).fadeTo('fast', 0.8);
		},
		function () {
			$(this).fadeTo('fast', 1);
		}
	); 
	
	
	$('.GalleryImages').cycle({
			fx: 'fade',
			before:  onBefore, 
   			after:   onAfter 
		});	
	
	$('head').append('<link href="css/jquery.lightbox-0.5.css" rel="stylesheet" type="text/css" />');
	$('head').append('<link href="css/overcast/jquery.ui.all.css" rel="stylesheet" type="text/css" />');
	
	///////////////

	// shows and hides the address details on the enquiry form
	$('#brochureYes').click(function(){
		if(this.checked){
			$('#brochureDetails').stop(true, true).slideDown('slow');
		}else{
			$('#brochureDetails').stop(true, true).slideUp('slow');
		}
	});



	$('.TariffContent .priceLink').click(function(){
		var num = $(this).attr('id').replace(/[^0-9]/g, '');
		var displayTariff = $('#tarrifHolder .TariffContentInner:nth-child(' + num + ')');
		var displayTitle = $('#tariffTitles .title:nth-child(' + num + ')');

		$('#tarrifHolder .TariffContentInner').not(displayTariff).hide();
		$(displayTariff).stop(true, true).fadeIn(500);

		$('#tariffTitles .title').not(displayTitle).hide();
		$(displayTitle).stop(true, true).fadeIn(500);

		$('.TariffContent .priceLink').css('background-position', '0 0');
		$(this).css('background-position', '115px 50%');

		return false;
	});
});	


function ShowMap() {
	$('#form').fadeOut(200, function() { 
		$('#map').fadeIn(400);							 
	}) ;
}

function ShowEnquiry() {
	$('#map').fadeOut(200, function() { 
		$('#form').fadeIn(400, function(){
			$('#brochureYes').triggerHandler('click');
		});
	}) ;
}

function checkRegexp(o,regexp) {

  if ( !( regexp.test( o.val() ) ) ) {	  
	  return false;
  } else {
	  return true;
  }

}

function submitContactFrm(formname) {
	 var passed = true;
  
  if ($('#firstname').val() == "") {
	  $('#error_msg').html('Please enter your first name.');
	  passed = false;
  } else if ($('#surname').val() == "") {
	  $('#error_msg').html('Please enter your last name.');
	  passed = false;
  }/* else if ($('#address').val() == "") {
	  $('#error_msg').html('Please enter your address.');
	  passed = false;
  } else if ($('#town').val() == "") {
	  $('#error_msg').html('Please enter your town.');
	  passed = false;
  } else if ($('#county').val() == "") {
	  $('#error_msg').html('Please enter your county.');
	  passed = false;
  } else if ($('#postcode').val() == "") {
	  $('#error_msg').html('Please enter your post code.');
	  passed = false;
  } else if ($('#telno').val() == "") {
	  $('#error_msg').html('Please enter your telephone number.');
	  passed = false;
  }*/ else if ($('#email').val() == "" && passed == true) {
	  $('#error_msg').html('Please enter your email address.');
	  passed = false;
  }/* else if ($('#message').val() == "" && passed == true) {
	  $('#error_msg').html('Please enter your message / special requirements / questions etc.');
	  passed = false;
  }*/
  
  if (checkRegexp($('#email'),/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i) == false && passed == true) {
	  $('#error_msg').html('Please enter a valid email address.');
	  passed = false;
  }

  
  if (passed == true) {			
	  
	  var formdata = $("#" + formname).serialize();
	   
	   $.post("includes/sendcontact.php?form="+formname+"&" + formdata,
		function(data){
		  
		  var feedback = data.split('|');
		  if (feedback[0] == "Error") {							
			  $('#error_msg').html('An error occured. Please try again.');
		  } else {
			  $('#error_msg').html('');
			  $("#" + formname).fadeOut(400, function() {
				$('#error_msg').html('Thank you very much for your enquiry which we will be dealing with very soon.');
			});	 
			  			  
		  }
		  
	  });

  }
}

function submitCallBackFrm(formname) {
	 var passed = true;
  
  if ($('#Name').val() == "") {
	  $('#error_msg_callback').fadeIn(200).html('Please enter your name.');
	  passed = false;
  } else if ($('#Telephone').val() == "") {
	  $('#error_msg_callback').fadeIn(200).html('Please enter your telephone number.');
	  passed = false;
  } else if ($('#Email').val() == "") {
	  $('#error_msg_callback').fadeIn(200).html('Please enter your email address.');
	  passed = false;
  } else if ($('#DatePickerCall').val() == "") {
	  $('#error_msg_callback').fadeIn(200).html('Please select a date.');
	  passed = false;
  } else if ($('#Time').val() == "Select...") {
	  $('#error_msg_callback').fadeIn(200).html('Please select a time.');
	  passed = false;
  } 
  
  if (checkRegexp($('#Email'),/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i) == false && passed == true) {
	  $('#error_msg_callback').fadeIn(200).html('Please enter a valid email address.');
	  passed = false;
  }

  
  if (passed == true) {			
	  
	  var formdata = $("#" + formname).serialize();
	   
	   $.post("includes/sendcallback.php?form="+formname+"&" + formdata,
		function(data){
		  
		  feedback = data.split('|'); 
		  if (feedback[0] == "Error") {							
			  $('#error_msg_callback').fadeIn(200).html('An error occured. Please try again.');
		  } else {
			  //$("#" + formname).fadeOut(400, function() {
				//$('#error_msg_callback').css({'top' : '74px', 'bottom' : ''});	
				//$('#error_msg_callback').html('Thank you signing up to our newsletter.').fadeIn(1500, function() {
					$("#Overlay").remove();
					$("#TelForm").remove();
				//});
			//});	 
			  			  
		  }
		  
	  });

  }
}

function submitNewsletterFrm(formname) {
	 var passed = true;
  
  if ($('#Name').val() == "") {
	  $('#error_msg_callback').fadeIn(200).html('Please enter your name.');
	  passed = false;
  } else if ($('#Email').val() == "") {
	  $('#error_msg_callback').fadeIn(200).html('Please enter your email address.');
	  passed = false;
  }
  
  if (checkRegexp($('#Email'),/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i) == false && passed == true) {
	  $('#error_msg_callback').fadeIn(200).html('Please enter a valid email address.');
	  passed = false;
  }

  
  if (passed == true) {			
	  
	  var formdata = $("#" + formname).serialize();
	   
	   $.post("includes/sendnewsletter.php?form="+formname+"&" + formdata,
		function(data){
		  
		  feedback = data.split('|'); 
		  if (feedback[0] == "Error") {							
			  $('#error_msg_callback').fadeIn(200).html('An error occured. Please try again.');
		  } else {
			  //$("#" + formname).fadeOut(400, function() {
				//$('#error_msg_callback').css({'top' : '74px', 'bottom' : ''});	
				//$('#error_msg_callback').html('Thank you signing up to our newsletter.').fadeIn(1500, function() {
					$("#Overlay").remove();
					$("#NewsForm").remove();
				//});
			//});	 
			  			  
		  }
		  
	  });

  }
}


function ShowFAQSection(num) {
	$('.FaqsSections').each(function(){
		if ($(this).is(':visible')) {
			$(this).fadeOut(200, function() {
				$('#sec_' + num).fadeIn(400);							  
			});
		}
	});
}

/// GALLERY FUNCTIONS ///

var galleryMoving = false;

function NextGalleryThumbs() {
	if (galleryMoving == false) {
		galleryMoving = true;
		$('.ThumbScroller').animate({   
		left: '-=231'
	  }, 400, function() {
		 if ($('.ThumbScroller').position().left == (-$('.ThumbScroller').width() + 231 + 23)) {
			 $('.ArrowRight').hide();
			 $('.ArrowLeft').show();
		 }
		 galleryMoving = false;
	  });
	}

}

function PrevGalleryThumbs() {
	if (galleryMoving == false) {
		galleryMoving = true;
		$('.ThumbScroller').animate({   
		left: '+=231'
	  }, 400, function() {
		if ($('.ThumbScroller').position().left == 23) {
			 $('.ArrowLeft').hide();	
			 $('.ArrowRight').show();
		 }
		 galleryMoving = false;
	  });
	}
}

function nextVideoThumbs() {
	if (galleryMoving == false) {
		galleryMoving = true;
		$('.videoThumbScroller').animate({   
		left: '-=' + videoWidth
	  }, 400, function() {
		  
		var currentPos = $('.videoThumbScroller').position().left;
		var fullPos = -$('.videoThumbScroller').width() + videoWidth + videoLeft;
		  
		if (currentPos == fullPos) {
			$('.ArrowRight').hide();
			$('.ArrowLeft').show();
		} else {
			$('.ArrowRight').show();
			$('.ArrowLeft').show();
		}
		galleryMoving = false;
	  });
	}

}

function prevVideoThumbs() {
	if (galleryMoving == false) {
		galleryMoving = true;
		$('.videoThumbScroller').animate({   
		left: '+=' + videoWidth
	  }, 400, function() {
		if ($('.videoThumbScroller').position().left == videoLeft) {
			 $('.ArrowLeft').hide();	
			 $('.ArrowRight').show();
		 } else {
			 $('.ArrowLeft').show();	
			 $('.ArrowRight').show();
		 }
		 galleryMoving = false;
	  });
	}
}

function onBefore() { 
  var theID = $(this).attr('id').split("_");
 
  $('.ThumbBorder').each(function(){
	$(this).attr('id', '');	
 });
  $('#thumb_' + theID[1]).find('.ThumbBorder').attr('id', 'SelectedThumb');
  
  if (theID[1] == 26 || theID[1] == 52 || theID[1] == 78 || theID[1] == 104) {
	  var position = $('.ThumbScroller').position().left;
	  if ((theID[1] == 26 && position == 23) || (theID[1] == 52 && position == -208) || (theID[1] == 78 && position == -439) || (theID[1] == 104 && position == -670)) {	  
	  	NextGalleryThumbs();
	  } 
  } else if (theID[1] == 0) {
		$('.ThumbScroller').animate({   
    left: '23'
  }, 400, function() {
   		 $('.ArrowLeft').hide();	
		 $('.ArrowRight').show();	 
  });  
  }
	
} 
function onAfter() { 
	
}

function PlayGallery() {
	$('.GalleryImages').cycle('resume');
	$('#PlayBt').attr("src", "images/testimonials-cross.jpg");
	$('#PauseBt').attr("src", "images/testimonials-dot.jpg");
}

function PauseGallery() {
	$('.GalleryImages').cycle('pause');
	$('#PlayBt').attr("src", "images/play-off.jpg");
	$('#PauseBt').attr("src", "images/testimonials-dot_on.jpg");
}

function loadVideo(code, title) {
	$('.videoLoading').fadeIn(200);
	$('.videoMain').fadeOut(500, function() {
		$('.videoTitle').fadeOut(250, function() {
			$('#videoTitleTd').html(title);
			$('.videoTitle').fadeIn(250);
		});
		$('.videoMain').html('<iframe width="640" height="360" src="http://www.youtube.com/embed/' + code + '?rel=0&autoplay=1" frameborder="0" allowfullscreen></iframe>').delay(1000).fadeIn(300, function() {
			$('.videoLoading').fadeOut(250);
		});
	});
}

////////////////////////

//////////////////////// Popup Forms ////////////////////////

function openTel() {
								   
	$("body").append("<div id='Overlay'>&nbsp;</div>");
	$("#Overlay").width($(window).width()).height($(document).height()).css("opacity", "0.7");		
	$("body").append("<div id='TelForm'></div>");
	$('#TelForm').load('footer-telcallback.php');
	
	$("#TelForm").centerInClient({ container: window });

};

function openNewsletter() {
								   
	$("body").append("<div id='Overlay'>&nbsp;</div>");
	$("#Overlay").width($(window).width()).height($(document).height()).css("opacity", "0.7");		
	$("body").append("<div id='NewsForm'></div>");
	$('#NewsForm').load('footer-newsletter.php');
	
	$("#NewsForm").centerInClient({ container: window });

};

function closeTel() {
	
	$("#NewsForm").remove();
	$("#TelForm").remove();
	$("#Overlay").remove();
	
}

$(window).resize(function() {
						  
  	$("#Overlay").width($(window).width()).height($(document).height());	
	$("#FooterForm").centerInClient({ container: window });

});

////////////////////////

//////////////////////// Tariff Page Change ////////////////////////

function Prices1() {
		
	$('.TariffContentInner2').fadeOut(300, function() { 
		$('.TariffContentInner1').fadeIn(500);							 
	});
	$('#Tariff2').fadeOut(300, function() {
		$('#Tariff1').fadeIn(500);
	});		
	$('.Prices1').css({'background-position' : '115px'});
	$('.Prices2').css({'background-position' : ''});
		
}
	
function Prices2() {
		
	$('.TariffContentInner1').fadeOut(300, function() { 
		$('.TariffContentInner2').fadeIn(500);							 
	});
	$('#Tariff1').fadeOut(300, function() {
		$('#Tariff2').fadeIn(500);
	});	
	$('.Prices2').css({'background-position' : '115px'});
	$('.Prices1').css({'background-position' : ''});
		
}


////////////////////////

//////////////////////// Bedroom Plans ////////////////////////

function LowerFloor() {
		
	$('.MainFade').fadeOut(300, function() { 
		$('.LowerFade').fadeIn(500);							 
	});
		
}

function MainFloor() {
		
	$('.LowerFade').fadeOut(300, function() { 
		$('.MainFade').fadeIn(500);							 
	});
		
}

function Bedroom(num) {
	
	$(".FortPlansmgPop").centerInClient({ container: window });
	$("body").append("<div id='OverlayBed'>&nbsp;</div>");
	$("#OverlayBed").width($(window).width()).height($(document).height()).css("opacity", "0.7");
	var img = new Image();
	$(img).load(function () {
		$('.FortPlansmgPop').append(this);
		if (jQuery.browser.msie) {
			$('.FortPlansmgPop').show(0);
			$('.FortPlansmgPop').supersleight();
		} else {
			$('.FortPlansmgPop').fadeIn(1000);
		}		
	}).error(function () {
	}).attr({'src' : 'images/bedrooms-img-0' + num + '.png', 'id' : 'overlayImage'});
		
}

function closeBedImg() {
	
	$(".FortPlansmgPop").hide(0);
	$("#overlayImage").remove();
	$("#OverlayBed").remove();
	
}

////////////////////////

function PlayT() {
	$('.ConceptTestSlideInner').cycle('resume');
	$('#PlayBt').attr("src", "images/testimonials-cross.jpg");
	$('#PauseBt').attr("src", "images/testimonials-dot.jpg");
};
function PauseT() { 
	$('.ConceptTestSlideInner').cycle('pause');
	$('#PlayBt').attr("src", "images/play-off.jpg");
	$('#PauseBt').attr("src", "images/testimonials-dot_on.jpg");
};
