$(document).ready(function() {
	
	var email = 'lpc1'
	email += '.co.uk'; 
	email = 'debbie' + '@' + email;
	//var test = 'fred'

	
	//contact form
	$('#container').append('<div id="contactLayer" class="contactLayer">' +
	'<h5 class="btnMenuContact"><a href="#">Contact</a></h5>' +
'<div class="part1">' +
'<h3>Contact: Debbie Mason</h3>' +
	'<h3>LPC Living</h3>' +
	'<div class="col1">' +
		'<h3>Ground Floor,</h3>' +
		'<h3>Optimum House,</h3>' +
		'<h3>Clippers Quay,</h3>' +
		'<h3>Salford</h3>' +
		'<h3>M50 3XP</h3>' +
		'<h3>T: +44 (0) 161 872 2622</h3>' +
		'<h3>F: +44 (0) 161 872 2633</h3>' +
		'e-mail: <a href="mailto:debbie@lpc1.co.uk">' + 'debbie' + String.fromCharCode(64) + 'lpc1.co.uk</a></p>' +
	'</div>' +

'</div>' +
'<form action="" method="post" class="part2" id="contact_form">' +
	'<fieldset>' +
		
	
		'<div class="col3">' +
			
			'<h5 class="btnCancel"><a href="#">Close</a></h5>' +
		'</div>' +
	'</fieldset>' +
'</form></div>');
	
	var contactFormLoaded = false;
	$('#mainnav .contact a').click(function() {
		$('#contactLayer').slideDown('normal', function() {
			if (!contactFormLoaded) {
				contactFormLoaded = true;
				$('#contactLayer .btnCancel').bind('click', function() {
					$('#mask').click();
					closeContactLayer();
					return false; 
				});

				$('#contact_send').bind('click', function() {
					var errMsg = "";

					if (!isValidString($('#contact_name').val()))
						errMsg += "Please enter your email.\n";
					else if (!isValidEmail($('#contact_email').val()))
						errMsg += "Email address is invalid.\n";
				
					if (!isValidString($('#contact_name').val()))
						errMsg += "Please enter your name.\n";

					if (!isValidString($('#contact_message').val()))
						errMsg += "Please enter your message.\n";
				
					if (errMsg.length > 0) {
						alert(errMsg);
					}
					else {
							alert('Thanks for your message. We will contact you shortly.')
						//$.post('', {
							//name : $('#contact_name').val(), 
							//field2 : $('#contact_message').val(),
							//field1 : $('#contact_email').val()
							//},
							//function(text) {
								//if (text == 'OK') {
								//alert('Thanks for your message.')
								$('#mask').click();
								closeContactLayer();
								//}
								//else {
							//		alert('Your message has not been sent.\n\n Please try again or send an email to ' + email);
								//}
							//}
					//	);
					}
					return false;
				});
			}
		});
		
		$('#contactLayer').expose({api: true, maskId:'mask', loadSpeed: 'slow', onClose: function() { closeContactLayer(); }}).load();
		return false;
	});
	
	function isValidEmail(email) {
		var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if (filter.test(email))
			return true;
		else
			return false;		
	}
	
	function isValidString(str) {
		return (str.replace(/[^0-9a-z]/gi, '').length > 0);
	}

	function closeContactLayer() {
		$('#contactLayer').slideUp('fast');			
	}
	
	if ($('.featuredBox').hasClass('featuredBoxH')) $('body').addClass('withFeaturedBoxH');
	
	$('input.text, textarea').focus(function() {
		$(this).addClass('focus');
	}).blur(function() {
		$(this).removeClass('focus');
	});
	
	$('.paymentOptions li').hover(function() {
		$(this).addClass('hover');
	}, function() {
		$(this).removeClass('hover');
	}).click(function() {
		$(this).find("input").attr("checked", true);
	});
	
	$('.tooltip:not(.delayed) strong').css('cursor', 'pointer')
	.hover(function() {
		$(this).addClass('hover').parent().find('em').fadeIn('fast');
	}, function() {
		$(this).removeClass('hover').parent().find('em').fadeOut('fast');
	});

	var timeoutId = null;
	$('.delayed strong').css('cursor', 'pointer')
	.hover(function() {
		if ( timeoutId )
			clearTimeout(timeoutId);
		$(this).addClass('hover').parent().find('em').fadeIn('fast');
	}, function() {
		var thisC = this;
		timeoutId = setTimeout(function() {$(thisC).removeClass('hover').parent().find('em').fadeOut('slow');}, 5000);
	});

	$("input[type='checkbox'].error").parent().each(function(){
		$(this).addClass('checkboxError');
	});
	
	var ppLiMinWidth = '198px';
	var ppLiMinHeight = '100px';
	var ppLiMaxWidth = '428px';
	var ppLiMaxHeight = '232px';
	var ppDuration = 300;
	var paramBottom = 0;
	var paramRight = 0;	
	$('.ppList > ul > li').hover(function() {
		if ($(this).hasClass('lastRow')) { paramBottom = '132px'; }
		if ($(this).hasClass('lastCol')) { paramRight = '230px'; }
		$(this).addClass('hover').find('.inside').css('z-index', '6').stop().animate({
			width: ppLiMaxWidth,
			height: ppLiMaxHeight,
			bottom: paramBottom,
			right: paramRight
		}, ppDuration, function() { });
		$(this).find('.more').fadeIn(200);
	}, function() {
		if ($(this).hasClass('lastRow')) { paramBottom = 0; }
		if ($(this).hasClass('lastCol')) { paramRight = 0; }
		$(this).removeClass('hover').find('.inside').stop().animate({
			width: ppLiMinWidth,
			height: ppLiMinHeight,
			bottom: paramBottom,
			right: paramRight
		}, ppDuration, function() { $(this).css('z-index', '5'); });
		$(this).find('.more').hide();
	});
	
	//IE6 fixes
	if ($.browser.msie && $.browser.version.substr(0,1) < 7) {
		$('#mainnav li').hover(function() {
			$(this).find('div').show();
			if ($(this).hasClass('products')) {
				$(this).find('a:first').css('background-position', '-242px -40px');	
			}
		}, function() {
			$(this).find('div').hide();
			if ($(this).hasClass('products')) {
				$(this).find('a:first').css('background-position', '-242px bottom');	
			}
		});
	}

	$('input.image, .btnBack a, h5.readMore a, h5.readMoreWhite a, .featuredBox .subPart h5.btn a, .btnCancel a, .aboutUsBoxes a.icon').hover(function() {
		$(this).fadeTo(200, '0.8');
	}, function() {
		$(this).stop().fadeTo(200, '1');
	});

	

	function showPager(activeId) {
		if (!$('#pagUL').length)
			$('#mainHeader').after('<div class="pagination pagTR"><ul id="pagUL"></ul></div>');
		else
			$('#pagUL').html('');

		$('div.page').each(function(){
			if (this.id != activeId)
			{
				$(this).hide();
				$('#pagUL').append('<li><a href="#">' + this.id.replace(/[^0-9]/g, '') + '</a></li>');
			}
			else
				$('#pagUL').append('<li><strong>' + this.id.replace(/[^0-9]/g, '') + '</strong></li>');
		});

		$('#pagUL a').bind("click", function() {
				var activeId = 'page' + $(this).html();
				$('div.page').each(function(){
					if ($(this).is(':visible')) {
						$(this).hide();
					}
				});
				$('#' + activeId).fadeIn();
				showPager(activeId);
				return false;
		});
	}

	if ($('#page1').length) {
		showPager('page1');
	}
	
	

	});;

