<?php get_header(); ?> 
<?php
$args=array(
    'post_type' => 'page',
    'order' => 'ASC',
    'orderby' => 'menu_order',
    'posts_per_page' => '-1'
  );
$main_query = new WP_Query($args); 
$page_number=0;
/*if( have_posts() ) : */
    while ($main_query->have_posts()) : $main_query->the_post();

    global $post;

    $post_name = $post->post_name;
    
    $title = $post->post_title;
    
    $post_id = get_the_ID();
    
    $content = get_the_content();
    
    $show_page_in_menu =  get_post_meta($post_id , 'show_page_in_menu' , true);    
    
    $pageTemplate=  get_post_meta($post_id , 'page_template' , true);
    
    $shortDesc = get_post_meta($post_id , 'short_desc' , true);

	 $page_number++;
	 $first_class='';
	 if($page_number == 1) {
	 		$first_class=' firstPage';
	 }

	 if ($show_page_in_menu == 'Yes')
	 {	
    
    if ($pageTemplate == 'Home')
    { 
    ?> 	
		
		<div id="<?php echo $post_name; ?>" class="sectionWrapper <?php echo $first_class; ?>" ><!-- start section -->
		<?php 
		 if($page_number == 1) {	
					topHeaderDisplay();
					echo '<div class="clearfix"></div>';
			}
		?>
		
		<?php menu($page_number); ?>	
		<div class="clearfix"></div>
	
				<!-- slider -->
				<?php

				 if ( function_exists( 'get_option_tree' ) ) {
						if  (get_option_tree( 'display_home_page_slider') == 'Yes' ){
    		    		  if (get_option_tree( 'nivo_slider')) {
    		    				$slides = get_option_tree( 'nivo_slider', $option_tree, false, true, -1 );
								$img_num = 1;
    		    				if(!empty($slides)){ ?>
								<div id="slides">
									<div class="slides_container">
								<?php
								foreach( $slides as $slide ) {
									echo '<div class="slide">';
									echo '<a href="'.$slide['link'].'"><img src="'.$slide['image'].'" title="" alt="" /></a>';
									if (($slide['title'] != '')||($slide['description'] != '')) {
										echo '<div class="caption">';
										echo '<div class="text1">'.$slide['title'].'</div>';
										echo '<div class="text2">'.$slide['description'].'</div>';
										echo '</div>';
									}
									echo '</div>';
									$img_num++;
								}
								echo '</div></div>';
					} }}}
					
					?>	
					
				
				<!-- quote -->
				<?php
				$home_page_quote_title=''; 
				$home_page_quote_content=''; 
				
				if ( function_exists( 'get_option_tree') ){
					if( get_option_tree( 'home_page_quote_title') ) {
						$home_page_quote_title = get_option_tree( 'home_page_quote_title' );
						
					}
					if( get_option_tree( 'home_page_quote_content') ) {
						$home_page_quote_content = get_option_tree( 'home_page_quote_content' );
						
					}
				
					if( get_option_tree( 'display_home_page_quote') == 'Yes' ) {
						echo '<div class="quote">';
						echo '<h1>'.$home_page_quote_title.'</h1>';
						echo '<p>'.$home_page_quote_content.'</p>';
						echo '</div>';
					}
				}
				?>		

				<?php if ( function_exists( 'get_option_tree' ) ) {
						if  (get_option_tree( 'display_home_page_circle_columns') == 'Yes' ){
    		    		  if (get_option_tree( 'circle_columns')) {
    		    				$columns = get_option_tree( 'circle_columns', $option_tree, false, true, -1 );
    		    				$col_num = 0;
    		    				if(!empty($columns)){ ?>
									<div id="circles"><!-- start circles -->
									<ul id="sti-menu" class="sti-menu">
									
								<?php
								foreach( $columns as $columns ) {
									echo '<li data-hovercolor="#e4e3e3">';
									echo '<a href="'.$columns['link'].'">';
									echo '<h2 data-type="mText" class="sti-item">'.$columns['title'].'</h2>';
								   echo '<p data-type="sText" class="sti-item">'.$columns['description'].'</p>';
								   echo '<span data-type="icon" class="sti-icon sti-icon-circle1 sti-item" style="background-image:url('.$columns['image'].');"></span>';
								   echo '</a></li>';				
								}
								echo '</ul></div>';
					} }}}
					
					?>	

			</div><!-- end section -->
			<div class="clearfix"></div>
			<div class="h250"></div>
		<?php 
		}		//end if home
		else 
		
	if ($pageTemplate == 'Portfolio')
      { 
      ?> 
      	
			<div id="<?php echo $post_name; ?>" class="sectionWrapper <?php echo $first_class; ?> mh500"><!-- start section -->
			<?php 
			 if($page_number == 1) {	
					topHeaderDisplay();
					echo '<div class="clearfix"></div>';
			}
			?>
			<?php menu($page_number); ?>	
			<?php 
			echo '<div class="page-title">';
			echo '<h2 class="titleH2">'.$title.'</h2>';
			if (!empty($shortDesc)) {
				echo 	'<span class="shortDesc11">}</span><p class="shortDesc12">'.$shortDesc.'</p>';
			}		
			echo '</div>';
			
			?>
		   	<div id="eden">
		   	</div>
		   <div id="vsi">
		   <?php
		   
			echo '<div id="portfolio-content" data-name="portfolio-content">';
			
			echo '<div id="portfolio-filter">';
			echo '<div class="line-filter"></div>';
			echo '<ul id="filterOptions">';
			echo '<li class="active"><a href="#" data-name="all" class="all">All</a></li>';
			$terms = get_terms("portfolio_categories");
				 $count = count($terms);
				 if ( $count > 0 ){ 
				 	
				     foreach ( $terms as $term ) {
						 echo '<li class="dot"><span></span></li><li ><a href="#" data-name="'.$term->slug.'" class="'.$term->slug.'">'.$term->name.'</a></li>';
				        
				     }
			}
			echo '</ul><div class="clearfix"></div><div class="line-filter"></div></div><div class="clearfix"></div>';
			
			
						$args = array('post_type'=> 'portfolio', 'posts_per_page' => -1, 'order'=> 'DESC', 'orderby' => 'post_date'  );
						$posts = get_posts($args);
						$idd=0;
						if($posts) {									
							
								echo '<ul id="thumbs" class="portfolio-circles"  class="mb450">';
								$itemCount = 0;
								foreach($posts as $post)
								{
										$termlist="";
										$itemClass='';
										setup_postdata($post); 		
										$idd++;	
													
										$terms =  get_the_terms( $post->ID, 'portfolio_categories' );
				                  $term_list = '';
				                  if( is_array($terms) ) {
				                        foreach( $terms as $term ) {
				                            $term_list .= $term->slug;
				                            $term_list .= ' ';
				                        }
				                  }
								$itemCount++;
								if(($itemCount % 5) == 0) {
									$itemClass='class="last"';
								}
								else {
									$itemClass='';
								}
								
							
							$link=get_permalink();
							
								?>			
						
							<li 
							<?php  echo  $itemClass ?> data-id="id-<?php echo $idd; ?>"  data-type="<?php echo $term_list; ?>" >
								<?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); 	?>
								
								<a onclick="return showPortfolioItem('<?php  echo $link; ?>', '<?php echo $post_name; ?>');" href="#" class="view"><div class="circle-p1 <?php echo $term_list; ?> all"><img src="<?php echo get_template_directory_uri(); ?>/images/lines-hover-circle-portfolio.png" alt="" /></div></a>
								
								<a  onclick="return showPortfolioItem('<?php  echo $link; ?>', '<?php echo $post_name; ?>');" href="#" class="view"><div class="circle-p <?php echo $term_list; ?> all" style="background-image: url(<?php echo get_template_directory_uri(); ?>/scripts/timthumb.php?src=<?php echo get_image_path($image[0]); ?>&amp;h=160&amp;w=160&amp;zc=1);">&nbsp;</div></a>	
								<a  onclick="return showPortfolioItem('<?php  echo $link; ?>', '<?php echo $post_name; ?>');" href="#" class="view"><p class="w160"><?php the_title(); ?></p></a>
								
							</li>
						
								
					
								<?php 
								 } //end foreach
								echo '</ul>';
							} //end if($posts)
			?>
							</div>	<!--end portfolio content -->	
					 </div>		
			</div><!-- end PORTFOLIO section -->
			<div class="clearfix"></div>
			<div class="h260"></div>		
<?php	
		}
		else 
		if ($pageTemplate == 'Contact')
      { 
      
			$input_one_title = 'Name: '; 
			$input_two_title = 'Email Address: '; 
			$textarea_title = 'Message: '; 
			$input_one_prevalue = 'John Doe'; 
			$input_two_prevalue = 'john.doe@domain.com'; 
			$textarea_prevalue = 'We will appreciate your critics and your good words..'; 
			$required_message_indicator = ' indicates a required field'; 
			$send_success = 'Thank you!<br /> Your email has been delivered. We will contact you ASAP.  <br /><br /><img src="http://trendis.si/wp-themes/amazing-studio/wp-content/uploads/2012/02/logo.png" alt="" />'; 
			$send_unsuccess = 'Error submitting the form'; 
			$required_message = 'This is a required field.'; 
			$invalid_email_message = 'Sorry! You have entered an invalid E-mail.'; 
			$button_text = 'Send!';
			
			if ( function_exists( 'get_option_tree') ){
				if( get_option_tree( 'input_one_title') ) {
					$input_one_title = get_option_tree( 'input_one_title' );
					
				}
				if( get_option_tree( 'input_two_title') ) {
					$input_two_title = get_option_tree( 'input_two_title' );
					
				}
				if( get_option_tree( 'textarea_title') ) {
					$textarea_title = get_option_tree( 'textarea_title' );
					
				}
				if( get_option_tree( 'input_one_prevalue') ) {
					$input_one_prevalue = get_option_tree( 'input_one_prevalue' );
					
				}
				if( get_option_tree( 'input_two_prevalue') ) {
					$input_two_prevalue = get_option_tree( 'input_two_prevalue' );
					
				}
				if( get_option_tree( 'textarea_prevalue') ) {
					$textarea_prevalue = get_option_tree( 'textarea_prevalue' );
					
				}
				if( get_option_tree( 'required_message_indicator') ) {
					$required_message_indicator = get_option_tree( 'required_message_indicator' );
					
				}
				if( get_option_tree( 'send_success') ) {
					$send_success = get_option_tree( 'send_success' );
					
				}
				if( get_option_tree( 'send_unsuccess') ) {
					$send_unsuccess = get_option_tree( 'send_unsuccess' );
					
				}
				if( get_option_tree( 'required_message') ) {
					$required_message = get_option_tree( 'required_message' );
					
				}
				if( get_option_tree( 'invalid_email_message') ) {
					$invalid_email_message = get_option_tree( 'invalid_email_message' );
					
				}
				if( get_option_tree( 'button_text') ) {
					$button_text = get_option_tree( 'button_text' );
					
				}
			}      
   ?>        
			<div id="<?php echo $post_name; ?>" class="sectionWrapper <?php echo $first_class; ?>" ><!-- start section -->
			<?php 
			 if($page_number == 1) {	
						topHeaderDisplay();
						echo '<div class="clearfix"></div>';
				}
			?>
			<?php menu($page_number); ?>	 
			<?php 
			echo '<div class="page-title">';
			echo '<h2 class="titleH2">'.$title.'</h2>';
			if (!empty($shortDesc)) {
				echo 	'<span class="shortDesc11">}</span><p class="shortDesc12">'.$shortDesc.'</p>';
			}		
			echo '</div>';	?>	
			<div id="map_canvas" class="mapStyleClass"></div>
			
			<div id="contact-form" class="clearfix fl">
			<?php
				$contact_title='Fill out our contact form below to get in touch with us!'; 
				if ( function_exists( 'get_option_tree') ){
					if( get_option_tree( 'contact_title') ) {
						$contact_title = get_option_tree( 'contact_title' );
						
					}
				}
			?>
			<h3><?php echo $contact_title; ?></h3>
			
			<?php if(isset($emailSent) && $emailSent == true) { ?>
                <p class="info">Your email was sent. Huzzah!</p>
            <?php } else { ?>
					<?php if(isset($hasError) || isset($captchaError) ) { ?>
                        <p class="alert"><?php echo $send_unsuccess; ?></p>
                    <?php } ?>
			<?php } ?>
			
					<?php
					$nameError='';
					$emailError='';
					$commentError='';
					?>
					
					<form id="contact-form1" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">						
						<div class="fl mr30 mb20">
							<label for="contactName"><?php echo $input_one_title; ?><span class="required">*</span></label>
							<input type="text" name="contactName" id="contactName" value="<?php if(isset($_POST['contactName'])) echo $_POST['contactName'];?>" class="txt requiredField" placeholder="<?php echo $input_one_prevalue; ?>" />
							<?php if($nameError != '') { ?>
								<br /><p class="error"><?php echo $nameError;?></p> 
							<?php } ?>
						</div>
						
						
                        <div class="fl mb20">
							<label for="email"><?php echo $input_two_title; ?><span class="required">*</span></label>
							<input type="text" name="email" id="email" value="<?php if(isset($_POST['email']))  echo $_POST['email'];?>" class="txt requiredField email" placeholder="<?php echo $input_two_prevalue; ?>" />
							<?php if($emailError != '') { ?>
								<br /><p class="error"><?php echo $emailError;?></p>
							<?php } ?>
						</div>
						
						<div class="fl">
							<label for="commentsText"><?php echo $textarea_title; ?><span class="required">*</span></label>
							<textarea name="comments" id="commentsText" class="txtarea requiredField" placeholder="<?php echo $textarea_prevalue; ?>"><?php if(isset($_POST['comments'])) { if(function_exists('stripslashes')) { echo stripslashes($_POST['comments']); } else { echo $_POST['comments']; } } ?></textarea>
								<?php if($commentError != '') { ?>
									<br /><p class="error"><?php echo $commentError;?></p> 
								<?php } ?>
						</div>
						
						<input type="submit" value="<?php echo $button_text; ?>" id="submit-button" name="submit"  />
						<input type="hidden" name="submitted" id="submitted" value="true" />
						<p id="req-field-desc"><span class="required">*</span> <?php echo $required_message_indicator; ?></p>    
					</form>							
				</div>
				<?php 
				$messageAfterSend='';
				if ( function_exists( 'get_option_tree') ) {			
					if( get_option_tree( 'message_send') ) {
							$messageAfterSend = get_option_tree( 'message_send' );					
					}	
				}
				?>
				<script type="text/javascript">
	<!--//--><![CDATA[//><!--
	jQuery(document).ready(function($) {
		jQuery('form#contact-form1').submit(function() {
			jQuery('form#contact-form1 .error').remove();
			var hasError = false;
			jQuery('.requiredField').each(function() {
				if($.trim(jQuery(this).val()) == '') {
					var labelText = $(this).prev('label').text();
					jQuery(this).parent().append('<p class="error"><?php echo $required_message; ?></p>');
					jQuery(this).addClass('inputError');
					hasError = true;
				} else if(jQuery(this).hasClass('email')) {
					var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
					if(!emailReg.test($.trim(jQuery(this).val()))) {
						var labelText = jQuery(this).prev('label').text();
						jQuery(this).parent().append('<p class="error"><?php echo $invalid_email_message; ?></p>');
						jQuery(this).addClass('inputError');
						hasError = true;
					}
				}
			});
			if(!hasError) {
				var formInput = jQuery(this).serialize();
				$.post(jQuery(this).attr('action'),formInput, function(data){
					jQuery('form#contact-form1').slideUp("fast", function() {				   
						jQuery(this).before('<p class="tick"><?php echo $send_success; ?></p>');
					});
				});
			}			
			return false;	
		});
	});
	//-->!]]>
</script>
				<div class="contact-col-300 last fl">
				<?php
					$right_col_title='Who we are..'; 
					if ( function_exists( 'get_option_tree') ){
						if( get_option_tree( 'right_col_title') ) {
							$right_col_title = get_option_tree( 'right_col_title' );
							
						}
					}
				?>
					<h3><?php echo $right_col_title; ?></h3>
					<p class="contact-paragraph">
						<?php
						if ( function_exists( 'get_option_tree') ) {
							if( get_option_tree( 'contact_info') ) {
								$contact_info = get_option_tree( 'contact_info' );	
								echo $contact_info;					
							}
						}
						?>
						<?php 
						if ( function_exists( 'get_option_tree') ) {
							if( get_option_tree( 'contact_page_email') ) {
							$contact_page_email = get_option_tree( 'contact_page_email' );
							?>
							<strong>E:</strong> <a href="mailto:<?php echo $contact_page_email; ?>"><?php echo $contact_page_email; ?></a><br /><br />						

							<?php			
							}	
						}
							?>
							</p>
					<p class="contact-paragraph-call">
					<?php
						if ( function_exists( 'get_option_tree') ) {
							if( get_option_tree( 'call_info') ) {
								$call_info = get_option_tree( 'call_info' );	
								echo $call_info;					
							}
						}
						?>
					</p>
				</div>
			</div><!-- end CONTACT page -->
			<div class="h400"></div>
		
			<?php
      }      
      else 
		if ($pageTemplate == 'Blog')
      { 
      ?>
		   <div id="<?php echo $post_name; ?>" class="sectionWrapper <?php echo $first_class; ?> mh500"><!-- start section -->
			<?php 
			 if($page_number == 1) {	
					topHeaderDisplay();
					echo '<div class="clearfix"></div>';
			}
			?>
			<?php menu($page_number); ?>	
			<?php 
			echo '<div class="page-title">';
			echo '<h2 class="titleH2">'.$title.'</h2>';
			if (!empty($shortDesc)) {
				echo 	'<span class="shortDesc11">}</span><p class="shortDesc12">'.$shortDesc.'</p>';
			}			
			echo '</div>';
			
			$args = array('post_type'=> 'post', 'posts_per_page' => -1, 'order'=> 'DESC', 'orderby' => 'post_date'  );
						$posts = get_posts($args);
						$idd=0;
						if($posts) {									
								$itemCount = 0;
								echo '<div class="blog-template">';
								foreach($posts as $post)
								{
										$termlist="";
										setup_postdata($post); 		
										$idd++;	
										$publish=true;
										$postType = get_post_meta($post->ID, 'post_type_selected' , true); 
										if($postType == 'News'){$publish=false;}
													
										$terms =  get_the_category($post->ID);
				                  $term_list = '';
				                
				                  if( is_array($terms) ) {
				                        foreach( $terms as $term ) {
				                        	// if($term->cat_name == 'News'){$publish=false;}
				                            $term_list .= $term->cat_name;
				                            $term_list .= ' ';
				                        }
				                  }
				                  if($publish==true)
				                  {
												$itemCount++;
												if(($itemCount % 2) == 0) {
													$itemClass=' last';
												}
												else {
													$itemClass='';
												}
												
												echo '<div class="post fl '.$itemClass.'">';
												echo '<div class="post-date">';
												echo '<p>'. get_the_time('d').' <span>'. get_the_time('M').'</span></p>';
												echo '</div>';
												echo '<div class="post-title">';
												get_permalink();
											
												?>
											
												<h3><a  href="<?php the_permalink(); ?>"  title=""><?php the_title(); ?></a></h3>
												<?php
												echo '</div>';
												echo '<div class="post-image">';
												$image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); 
												?>					
												<a  href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><img src="<?php echo get_template_directory_uri(); ?>/scripts/timthumb.php?src=<?php echo $image[0]; ?>&amp;h=181&amp;w=465&amp;zc=1" alt="" /></a>
												<?php
												echo '</div></div>';
										}		
								}
								echo '</div>';
						}
								?>
				<div class="clearfix"></div>
		</div><!-- end BLOG page -->      
      <?php
      }
      else 
      if ($pageTemplate == 'News')
      { 
      ?>
      	
		   <div id="<?php echo $post_name; ?>" class="sectionWrapper <?php echo $first_class; ?>" ><!-- start section -->
		   <?php 
		 	if($page_number == 1) {	
					topHeaderDisplay();
					echo '<div class="clearfix"></div>';
			}
			?>
			<?php menu($page_number); ?>	
			<?php 
			echo '<div class="page-title">';
			echo '<h2 class="titleH2">'.$title.'</h2>';
			if (!empty($shortDesc)) {
				echo 	'<span class="shortDesc11">}</span><p class="shortDesc12">'.$shortDesc.'</p>';
			}		
			echo '</div>';
			
			$args = array('post_type'=> 'post', 'posts_per_page' => -1, 'order'=> 'DESC', 'orderby' => 'post_date'  );
						$posts = get_posts($args);
						$idd=0;
						if($posts) {									
								$itemCount = 0;
								$itemClass='';
								echo "<div class='news'>";
								foreach($posts as $post)
								{
										$termlist="";
										setup_postdata($post); 		
										$idd++;	
										$publish=false;
										$postType = get_post_meta($post->ID, 'post_type_selected' , true); 
										if($postType == 'News'){$publish=true;}
													
										$terms =  get_the_category($post->ID);
				                  $term_list = '';
				                
				                  if( is_array($terms) ) {
				                        foreach( $terms as $term ) {
				                       // 	 if($term->cat_name == 'News'){$publish=true;}
				                            $term_list .= $term->cat_name;
				                            $term_list .= ' ';
				                        }
				                  }
				                  if($publish==true)
				                  {
												$itemCount++;
												//if ($itemClass== ' last') { echo '<div class="clearfix"></div><div class="line"></div>';}
												if(($itemCount % 3) == 0) {
													$itemClass=' last';
												}
												else {
													$itemClass='';
												}			
												echo '<div class="col-300 fl '.$itemClass.'">';
												echo '<div class="news-date fl">';
												echo '<p>'. get_the_time('d').' <span>'. get_the_time('M').'</span></p>';
												echo '</div>';
												echo '<div class="news-content fl">';
												echo '<h3>'.get_the_title().'</h3>';
												$content = get_post($post->ID)->post_content;
												/*f (strlen($content) > 103)
												{
													$content = substr($content,0,100).'...';
												}
												*/
												echo '<p>'.$content.'</p>';
												echo '</div></div>';
												
										}		
								}
								echo '</div>';
						}
								?>
				<div class="clearfix"></div>
		</div><!-- end BLOG page -->      
      <?php
      }
      else
		{ 
			
			echo '<div id="'. $post_name.'" class="sectionWrapper '. $first_class .'" >';
			if($page_number == 1) {	
					topHeaderDisplay();
					echo '<div class="clearfix"></div>';
			}		
			menu($page_number);
			echo '<div class="page-title">';
			echo '<h2 class="titleH2">'.$title.'</h2>';
			if (!empty($shortDesc)) {
				echo 	'<span class="shortDesc11">}</span><p class="shortDesc12">'.$shortDesc.'</p>';
			}		
			echo '</div>';
			the_content();
			echo '</div>';		
		}
		?>
		<?php
	}
    endwhile;
 /*   endif; */
?>

<?php get_footer(); ?>
