<?php
$house = $this->_data['property'];
$title = $this->html($house['street'] . ', ' . $house['city']);
?>

<div id="nomis-property">

	<div class="text">
		<div class="details">
			<?php nomisDetails($house, get_option('nomis_property_details')); ?>
		</div>

		<div class="clear"></div>

		<div class="description">
			<?php echo nl2br($this->html($house['description'])); ?>
		</div>

		<?php if (get_option('nomis_property_contact') == '1' ||
				  get_option('nomis_property_addthis') == '1' ||
				  get_option('nomis_property_mailtofriend') == '1' ||
				  get_option('nomis_property_print') == '1'): ?>
		<div class="controls">
			<script type="text/javascript">
				function isValidEmailAddress(emailAddress)
				{
					var pattern = new RegExp(/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/);
					return pattern.test(emailAddress);
				}

				function send(datastr, url)
				{
					$.ajax(
					{
						type: 'POST',
						url: url,
						data: datastr,
						cache: false,
						success: function(html)
						{
							$('#response').fadeIn('slow');
							$('#response').html(html);
							setTimeout('$(\'#response\').fadeOut(\'slow\')', 999999);
						}
					});
				}
			</script>
			<ul>
				<?php if (get_option('nomis_property_contact') == '1'): ?>
				<li class="contact">
					<a href="javascript:;" id="contact-about-house"><?php _e('Contact us about this house', 'nomis'); ?></a>
					<script type="text/javascript">
						$(document).ready(function()
						{
							$("a#contact-about-house").colorbox({inline:true, href:"#contact-about-house-form"});
						});

						$(document).ready(function()
						{
							$('#contact-about-house-submit').click(function()
							{
								var error = '';

								if (!isValidEmailAddress($('#email').val()))
								{
									error += '<?php _e('Please enter a valid emailaddress.', 'nomis'); ?> ';
								}

								if ($('#name').val() == '')
								{
									error += '<?php _e('Please enter your name.', 'nomis'); ?> ';
								}

								if (error != '')
								{
									$('#response').html(error);
								}
								else
								{
									var datastr ='name-sender=' + $('#name-sender').val() + '&email-sender=' + $('#email-sender').val() + '&email-recipient=' + $('#email-recipient').val() + '&name-recipient=' + $('#name-recipient').val() + '&link=<?php echo get_home_url() . '/property/' . $this->html($house['city'] . '/' . $house['street']) . '/' . $house['id']; ?>';
									$('#response').css('display', 'block');
									$('#response').html('Sending message');
									$('#response').fadeIn('slow');
									setTimeout('send("'+datastr+'", "<?php echo WP_PLUGIN_URL . '/nomis/mailtofriend.php'; ?>")', 2000);
								}

								return false;
							});
						});
					</script>
					<div style="display:none;">
						<div id="contact-about-house-form">
							<h3><?php _e('Contact us about this house', 'nomis'); ?></h3>
							<span id="response"></span><br /><br />
							<dl>
								<dt><?php _e('Your name', 'nomis'); ?> *</dt>
								<dd><input type="text" name="name" id="name" /></dd>
								<dt><?php _e('Your email', 'nomis'); ?> *</dt>
								<dd><input type="text" name="email" id="email" /></dd>
								<dt><?php _e('Message', 'nomis'); ?></dt>
								<dd><textarea name="message" cols="50" rows="7" id="message"></textarea></dd>
								<dt>&nbsp;</dt>
								<dd><input type="submit" value="<?php _e('Send'); ?>" name="mailtofriend" class="submit" id="contact-about-house-submit" /></dd>
							</dl>
							<span><?php _e('Fields with a * are required', 'nomis'); ?></span>
						</div>
					</div>
				</li>
				<?php endif; ?>
				<?php if ('1' == '1'): ?>
				<li class="addthis">
					<!-- AddThis Button BEGIN -->
					<div class="addthis_toolbox addthis_default_style ">
						<a href="http://www.addthis.com/bookmark.php?v=250&amp;username=xa-4d0cce3f64bb55ab" class="addthis_button_compact">Share</a>
						<span class="addthis_separator">|</span>
						<a class="addthis_button_preferred_1"></a>
						<a class="addthis_button_preferred_2"></a>
						<a class="addthis_button_preferred_3"></a>
						<a class="addthis_button_preferred_4"></a>
					</div>
					<script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#username=xa-4d0cce3f64bb55ab"></script>
					<!-- AddThis Button END -->
				</li>
				<?php endif; ?>
				<?php if (get_option('nomis_property_mailtofriend') == '1'): ?>
				<li class="mailtofriend">
					<a href="javascript:;" id="nomis_property_mailtofriend"><?php _e('Mail to friend', 'nomis'); ?></a>
					<script type="text/javascript">
						$(document).ready(function()
						{
							$("a#nomis_property_mailtofriend").colorbox({inline:true, href:"#mailtofriend"});
						});

						$(document).ready(function()
						{
							$('#mailtofriend-submit').click(function()
							{
								var error = '';

								if (!isValidEmailAddress($('#email-recipient').val()))
								{
									error += '<?php _e('Please enter a valid emailaddress for the recipient.', 'nomis'); ?> ';
								}

								if (!isValidEmailAddress($('#email-sender').val()))
								{

									error += '<?php _e('Please enter a valid emailaddress for the sender.', 'nomis'); ?> ';
								}

								if ($('#name-sender').val() == '')
								{
									error += '<?php _e('Please enter a senders name.', 'nomis'); ?> ';
								}

								if ($('#name-recipient').val() == '')
								{
									error += '<?php _e('Please enter a recipients name.', 'nomis'); ?> ';
								}

								if (error != '')
								{
									$('#response').html(error);
								}
								else
								{
									var datastr ='name-sender=' + $('#name-sender').val() + '&email-sender=' + $('#email-sender').val() + '&email-recipient=' + $('#email-recipient').val() + '&name-recipient=' + $('#name-recipient').val() + '&street=<?php echo $house['street']; ?>&city=<?php echo $house['city']; ?>&link=<?php echo get_home_url() . '/property/' . $this->html($house['city'] . '/' . $house['street']) . '/' . $house['id']; ?>';
									$('#response').css('display', 'block');
									$('#response').html('Sending message');
									$('#response').fadeIn('slow');
									setTimeout('send("'+datastr+'", "<?php echo WP_PLUGIN_URL . '/nomis/mailtofriend.php'; ?>")', 2000);
								}

								return false;
							});
						});
					</script>
					<div style="display:none;">
						<div id="mailtofriend">
							<h3><?php _e('Mail to a friend', 'nomis'); ?></h3>
							<span id="response"></span><br /><br />
							<dl>
								<dt><?php _e('Name sender', 'nomis'); ?> *</dt>
								<dd><input type="text" name="name-sender" id="name-sender" /></dd>
								<dt><?php _e('Email sender', 'nomis'); ?> *</dt>
								<dd><input type="text" name="email-sender" id="email-sender" /></dd>
								<dt><?php _e('Name recipient', 'nomis'); ?> *</dt>
								<dd><input type="text" name="name-recipient" id="name-recipient" /></dd>
								<dt><?php _e('Email recipient', 'nomis'); ?> *</dt>
								<dd><input type="text" name="email-recipient" id="email-recipient" /></dd>
								<dt><?php _e('Message', 'nomis'); ?></dt>
								<dd><textarea name="message" cols="50" rows="7" id="message"></textarea></dd>
								<dt>&nbsp;</dt>
								<dd><input type="submit" value="<?php _e('Send', 'nomis'); ?>" name="mailtofriend" class="submit" id="mailtofriend-submit" /></dd>
							</dl>
							<span><?php _e('Fields with a * are required', 'nomis'); ?></span>
						</div>
					</div>
				</li>
				<?php endif; ?>
				<?php if (get_option('nomis_property_print') == '1'): ?>
				<li class="print">
					<a href="javascript:print();"><?php _e('Print'); ?></a>
				</li>
				<?php endif; ?>
			</ul>
		</div>
		<?php endif; ?>

	</div>

	<?php if ($house['photos'][0] !== null): ?>
	<div class="photos">
		<ul>
			<?php foreach ($house['photos'] as $photo): ?>
			<li>
				<a href="<?php echo $photo['big']; ?>" title="<?php echo $title; ?>" rel="lightbox-property">
					<img src="<?php echo $photo['small']; ?>" alt="<?php echo $title; ?>" />
				</a>
			</li>
			<?php endforeach; ?>
		</ul>
		<div class="clear"></div>
	</div>
	<?php endif; ?>

	<div class="clear"></div>

	<?php if ($house['lat'] != '' && get_option('nomis_property_googlemaps') == '1' || $house['lat'] != '' && get_option('nomis_property_streetview') == '1'): ?>
	<div class="location">		
		<div class="location-controls">
			<?php if (get_option('nomis_property_googlemaps') == '1'): ?>
			<a href="javascript:;" id="show-maps" class="location-first"><span><?php echo __('Show maps', 'nomis'); ?></span></a>
			<?php endif; if (get_option('nomis_property_streetview') == '1'): ?>
			<a href="javascript:;" id="show-streetview"<?php if (get_option('nomis_property_googlemaps') == '0') echo ' class="location-first"'; ?>><span><?php echo __('Show streetview', 'nomis'); ?></span></a>
			<?php endif; ?>
			<div class="clear"></div>
		</div>
		<div id="media-holder">
			<?php if (get_option('nomis_property_googlemaps') == '1'): ?>
			<div id="nomis-maps" class="maps" data-lat="<?php echo $house['lat']; ?>" data-lng="<?php echo $house['lng']; ?>" data-title="<?php echo $title; ?>">&nbsp;</div>
			<?php endif; if (get_option('nomis_property_streetview') == '1'): ?>
			<div id="nomis-streetview" class="streetview" data-lat="<?php echo $house['lat']; ?>" data-lng="<?php echo $house['lng']; ?>">&nbsp;</div>
			<?php endif; ?>
		</div>
		<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
	</div>
	<?php endif; ?>
	
</div>