<?php
if(isset($_POST['submitted'])) {
		//Check to make sure that the name field is not empty
		if(trim($_POST['contactName']) === '') {
			$nameError = __("You forgot to enter your name.", "site5framework");
			$hasError = true;
		} else {
			$name = trim($_POST['contactName']);
		}

		//Check to make sure sure that a valid email address is submitted
		if(trim($_POST['email']) === '')  {
			$emailError = __("You forgot to enter your email address.", "site5framework");
			$hasError = true;
		} else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email']))) {
			$emailError = __("You entered an invalid email address.", "site5framework");
			$hasError = true;
		} else {
			$email = trim($_POST['email']);
		}

		//Check to make sure comments were entered
		if(trim($_POST['comments']) === '') {
			$commentError = __("You forgot to enter your comments.", "site5framework");
			$hasError = true;
		} else {
			if(function_exists('stripslashes')) {
				$comments = stripslashes(trim($_POST['comments']));
			} else {
				$comments = trim($_POST['comments']);
			}
		}

		//If there is no error, send the email
		if(!isset($hasError)) {
			$msg .= "------------User Info------------ \r\n"; //Title
			$msg .= "User IP : ".$_SERVER["REMOTE_ADDR"]."\r\n"; //Sender's IP
			$msg .= "Browser Info : ".$_SERVER["HTTP_USER_AGENT"]."\r\n"; //User agent
			$msg .= "User Come From : ".$_SERVER["HTTP_REFERER"]; //Referrer

			$emailTo = ''.of_get_option('contact_email').'';
			$subject = 'Contact Form Submission From '.$name;
			$body = "Name: $name \n\nEmail: $email \n\nMessage: $comments \n\n $msg";
			$headers = 'From: '.get_bloginfo('name').' <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;

			if(mail($emailTo, $subject, $body, $headers)) $emailSent = true;

	}

}

get_header(); ?>


		<?php if ( is_home() ) { ?>
		<!-- begin homepage -->
		<section id="homepage" class="bg" data-stellar-background-ratio="0.5" style="background-color: <?php echo of_get_option('homepagebgcolor')  ?>; background-image: url('<?php echo of_get_option('homepagebg')  ?>')">

				<!-- begin .homesummary -->
				<div class="homesummary">
					<div class="homecontent">
						<h2><?php echo of_get_option('hometitle')  ?></h2>
						
						<div class="col-1 homesum">
							<p class="moodosummary"><?php echo of_get_option('homesummary')  ?></p>
							
							<a href="<?php echo of_get_option('lefthomebuttonurl')  ?>" title="<?php echo of_get_option('lefthomebuttontitle')  ?>" class="homebutton">
								<span class="appicon"><i class="fa fa-apple"></i></span> <span class="apptext"><?php _e('Available in AppStore','site5framework') ?><br><b><?php echo of_get_option('lefthomebuttontitle')  ?></b></span>
							</a>
							
							<a href="<?php echo of_get_option('righthomebuttonurl')  ?>" title="<?php echo of_get_option('righthomebuttontitle')  ?>" class="homebutton">
								<span class="appicon"><i class="fa fa-android"></i></span> <span class="apptext"><?php _e('Available in PlayStore','site5framework') ?><br><b><?php echo of_get_option('righthomebuttontitle')  ?></b></span>
							</a>
						</div>
						
						<div class="col-1 homesumimg">
							<img src="<?php echo of_get_option('homepageimage')  ?>">
						</div>
						
						
					</div>
				</div>
				<!-- end .homesummary -->

		</section>
		<!-- end homepage -->
		<?php } ?>
		
		
		<?php if ( of_get_option('displayservice')=='1') {?>
		<!-- begin service -->
		<section id="services" class="bg" data-stellar-background-ratio="0.5" style="background-color: <?php echo of_get_option('servicebgcolor')  ?>;">

			<div class="container">

				<!-- begin .summary -->
				<div class="summary">
					<h2><?php echo of_get_option('servicetitle')  ?></h2>
				</div>
				<!-- end .summary -->

				<div id="service">
				
					<div class="serviceimg col-1">
						<img src="<?php echo of_get_option('serviceimg')  ?>">
					</div>

					<?php
					$the_query = new WP_Query( 'post_type=service' );
					while ( $the_query->have_posts() ) : $the_query->the_post();
					$s_icon = get_post_meta($post->ID,'spring_s_icon',true);
					$s_icon_color = get_post_meta($post->ID,'spring_s_icon_color',true);
					?>

					<div class="service col-1">
						<span class="serviceicon"><i class="<?php echo $s_icon ?>" style="color:<?php echo $s_icon_color ?>"></i></span>
						<span class="servicecontent"><h4><?php the_title()  ?></h4><?php the_excerpt(); ?></span>
					</div>

					<?php endwhile; wp_reset_postdata();?>

				</div>

			</div><!-- .container -->

		</section>
		<!-- end service -->
		<?php } ?>

		
		
		<?php if ( of_get_option('displaycta')=='1') {?>
		<!-- begin cta -->
		<section id="cta" class="bg" data-stellar-background-ratio="0.5" style="background-color: <?php echo of_get_option('ctabgcolor')  ?>; background-image: url('<?php echo of_get_option('ctabg')  ?>')">

			<div class="container">

						<div class="cta">
							
							<h2><?php echo of_get_option('ctatitle')  ?></h2>
							
							<?php if ( of_get_option('displayctabutton')=='1') {?>
							<a href="<?php echo of_get_option('lefthomebuttonurl')  ?>" title="<?php echo of_get_option('lefthomebuttontitle')  ?>" class="homebutton">
								<span class="appicon"><i class="fa fa-apple"></i></span> <span class="apptext"><?php _e('Available in AppStore','site5framework') ?><br><b><?php echo of_get_option('lefthomebuttontitle')  ?></b></span>
							</a>
							
							<a href="<?php echo of_get_option('righthomebuttonurl')  ?>" title="<?php echo of_get_option('righthomebuttontitle')  ?>" class="homebutton">
								<span class="appicon"><i class="fa fa-android"></i></span> <span class="apptext"><?php _e('Available in PlayStore','site5framework') ?><br><b><?php echo of_get_option('righthomebuttontitle')  ?></b></span>
							</a>
							<?php } ?>
							
						</div>

			</div><!-- .container -->

		</section>
		<!-- end cta -->
		<?php } ?>


		<?php if ( of_get_option('displaytestimonial')=='1') {?>
		<!-- begin testimonial -->
		<section id="testimonial" class="bg" data-stellar-background-ratio="0.5" style="background-color: <?php echo of_get_option('teambgcolor')  ?>; background-image: url('<?php echo of_get_option('teambg')  ?>')">
		
				<script>
					jQuery(document).ready(function($) {
					  var owl = $("#owl-demo");
					  owl.owlCarousel({
						  items : 2, //10 items above 1000px browser width
						  itemsDesktop : [1000,2], //5 items between 1000px and 901px
						  itemsDesktopSmall : [900,1], // betweem 900px and 601px
						  itemsTablet: [600,1], //2 items between 600 and 0
						  itemsMobile : true, // itemsMobile disabled - inherit from itemsTablet option
					  });
					});
				</script>

				<!-- begin .summary -->
				<div class="summary">
					<h2><?php echo of_get_option('testimonialtitle')  ?></h2>
				</div>
				<!-- end .summary -->
				
				

				<div id="owl-demo" class="owl-carousel owl-theme">

						<?php
						$the_query = new WP_Query( 'post_type=testimonial&posts_per_page=4 ');
						while ( $the_query->have_posts() ) : $the_query->the_post();
						$t_owner = get_post_meta($post->ID,'spring_t_ownertitle',true);
						$t_story = get_post_meta($post->ID,'spring_t_story',true);
						?>

						<div class="item">
							<?php
							$thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'team-item-small','team-item-small' );
							$large = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'large', false);
							if(has_post_thumbnail()): echo '<img src="'.$thumbnail[0].'" alt="'.get_the_title().'"/>'; else: ?><img src="<?php bloginfo('template_url'); ?>/images/t_sample.png" alt="team info" />

							<?php endif; ?>
							
							<p><?php echo $t_story ?></p>
							
							<div class="twrap">
								<span class="ttitle"><?php the_title()  ?></span>  - <span class="towner"><?php echo $t_owner ?></span> 
							</div>
						</div>

					<?php endwhile; wp_reset_postdata();?>

				</div>

		</section>
		<!-- end testimonial -->
		<?php } ?>



		<?php if ( of_get_option('displaycontact')=='1') {?>
		<!-- begin contact -->
		<section id="contact" class="bg" data-stellar-background-ratio="0.5" style="background-color: <?php echo of_get_option('contactbgcolor')  ?>; background-image: url('<?php echo of_get_option('contactbg')  ?>')">
		
				<!-- begin .summary -->
				<div class="summary">

					<h2><?php echo of_get_option('contacttitle') ?></h2>

				</div>
				<!-- end .summary -->
				
				<?php if(of_get_option('contact_map')!=''){?>
					<div id="contact-map">
						<?php echo of_get_option('contact_map') ?>
					</div>
				<?php }?>


			<div class="container">

				<div class="row">

					<div class="twelve.columns column contactinfo">
						<span><i class="fa fa-map-marker"></i> <?php echo of_get_option('contact_address')  ?></span>
						<span><i class="fa fa-phone"></i> <?php echo of_get_option('contact_phone')  ?></span>
						<span><i class="fa fa-envelope"></i> <?php echo of_get_option('contact_email')  ?></span>
					</div>

					<div class="twelve.columns column">
					
						<p class="error" <?php if($hasError != '') echo 'style="display:block;"'; ?>><?php _e('There was an error submitting the form.', 'site5framework'); ?></p>

						<p class="thanks"><?php _e('<strong>Thanks!</strong> Your email was successfully sent. We should be in touch soon.', 'site5framework'); ?></p>

						<form id="contactForm" method="POST">

							<div class="one-half column">
							
								<input type="text" id="nameinput" name="contactName" value="<?php if(isset($_POST['contactName'])) echo $_POST['contactName'];?>" class="requiredField" placeholder="<?php _e("Full name", "site5framework"); ?>"/>
								<span class="error" <?php if($nameError != '') echo 'style="display:block;"'; ?>><?php _e("You forgot to enter your name.", "site5framework");?></span>
							</div>


							<div class="one-half column">
							<input type="text" id="emailinput" name="email" value="<?php if(isset($_POST['email']))  echo $_POST['email'];?>" class="requiredField email" placeholder="<?php _e("Email address", "site5framework"); ?>"/>
							<span class="error" <?php if($emailError != '') echo 'style="display:block;"'; ?>><?php _e("You forgot to enter your email address.", "site5framework");?></span>
							</div>


							<textarea cols="20" rows="7" id="commentinput" name="comments" class="requiredField" placeholder="<?php _e("Your message", "site5framework"); ?>"><?php if(isset($_POST['comments'])) { if(function_exists('stripslashes')) { echo stripslashes($_POST['comments']); } else { echo $_POST['comments']; } } ?></textarea>
							<span class="error" <?php if($commentError != '') echo 'style="display:block;"'; ?>><?php _e("You forgot to enter your comments.", "site5framework");?></span>

						<br />
						<input type="hidden" name="submitted" id="submitted" value="true" />
						<button type="submit" id="submitbutton" class="submitbutton"><?php _e('SEND', 'site5framework'); ?></button>

						</form>
					</div>

				</div>
				<!-- end .content -->


			</div><!-- .container -->

		</section>
		<!-- end contact -->
		<?php } ?>


<?php get_footer(); ?>