<?php
class Main_model extends CI_Model{
	
 	function main_model(){
  		//parent::CI_model();
			
 	}


function get_home_slider() {

$query = $this->db->query("SELECT * FROM images WHERE type = 'project'", FALSE);	

	print'<div id="myCarousel" class="carousel slide">
		  <div class="carousel-inner" style="height:500px;">';
				
	$i=0;
	foreach($query->result() as $row){

		
	if($i==0) { $active = 'class="active item"'; } else { $active = 'class="item"'; }
		print '<div '.$active.'>
				<img src="'.base_url('/').'assets/images/'.$row->img_file.'" style="width:100%;">
			   </div>';
	$i++;	
	}

	print '</div>
			  <a class="carousel-control left" href="#myCarousel" data-slide="prev">&lsaquo;</a>
			  <a class="carousel-control right" href="#myCarousel" data-slide="next">&rsaquo;</a>
		   </div>';


}


	function get_num_proj_imgs($slug) {

		$getid = $this->db->where('slug', $slug);
		$getid = $this->db->select('project_id');
		$getid = $this->db->get('projects');
		$idrow = $getid->row();	
	
		$galget = $this->db->where('project_id', $idrow->project_id);		
		$galget = $this->db->select('type');
		$galget = $this->db->get('sidebars');
		$galid = $galget->row();
		if ($galget->num_rows() > 0){
		$id = substr($galid->type, (strpos($galid->type,'_')+ 1) , strlen($galid->type) );
		} else { $id = 0; }
		$query = $this->db->where('gal_id', $id);
		$query = $this->db->get('images');
		
		return $query->num_rows();		
		
	}


	function get_content($pid) {

		$query = $this->db->where('page_id', $pid);
		$query = $this->db->select('page_id, heading, body');
		$query = $this->db->get('pages');
		
		$cont = $query->row();	
		return '<h4>'.$cont->heading.'</h4>
			<div class="row-fluid" id="inner-content-div" style="padding-right:20px;">			
			'.$cont->body.'		
			</div>';

		
	}



	function get_cta_images($gid, $title, $slug) {
		
		$gal_id = str_replace("gallery_", "", $gid);

		$query = $this->db->query("SELECT * FROM images WHERE gal_id = '$gal_id' LIMIT 2", FALSE);
		
		print '<div class="row-fluid" style="margin-bottom:20px;">';
		
		if($query->result()){
			
			foreach($query->result() as $row){
			
			print '<a href="'.base_url('/').'index.php/project/'.$slug.'"><img src="'.base_url('/').'assets/images/'.$row->img_file.'" class="img-polaroid" style="width:100px"></a>';
				
			}
		}
		
		print '</div>
		<a href="'.base_url('/').'index.php/project/'.$slug.'">'.$title.'</a>&nbsp;';
		
	}


   function get_cta_sale($pid) {
	
	$sale = $this->db->where('project_id', $pid);
	$sale = $this->db->select('title, slug');
	$sale = $this->db->get('projects');
	$info = $sale->row();
	$title = $info->title;
	$slug = $info->slug;
	//$link = base_url('/').'index.php/project/'.$info->slug;      

	$gal = $this->db->where('project_id', $pid);
	$gal = $this->db->select('type');
	$gal = $this->db->get('sidebars');
	$gal_id = $gal->row();
	$gid = $gal_id->type;


	return $this->get_cta_images($gid, $title, $slug);
	   
   }

	//+++++++++++++++++++++++++++
	//GET CALL TO ACTION
	//++++++++++++++++++++++++++
	function get_cta($tid, $slug) {	
		
		$p_type_a = str_replace("s", "", $slug);
		$p_type = $p_type_a.'_id';
				
		$getid = $this->db->where($p_type, $tid);
		$getid = $this->db->get($slug);
		$info = $getid->row();
		$link = base_url('/').'index.php/'.$p_type_a.'/'.$info->slug;
		
		switch($info->type) {
			case 1:
			$i_type = '<span style="font-weight:bold; color:#F60;">Current Project: </span>';
			
			break;
			case 2:
			$i_type = '<span style="font-weight:bold; color:#F60;">Project For Sale: </span>';
			break;			
		}
		
		print '<li style="list-style:none">'.$i_type.'<a href="'.$link.'">'.$info->title.'</a></li><hr />';
		
	}


	//+++++++++++++++++++++++++++
	//GET CALL TO ACTION LIST
	//++++++++++++++++++++++++++
	
	function get_cta_list() {
				
		$query = $this->db->query("SELECT * FROM (`cta`)", FALSE);
		if($query->result()){
			foreach($query->result() as $row){
				
				
				
				if($row->project_id != '0') { $tid = $row->project_id; $slug = 'projects'; }
				if($row->post_id != '0') { $tid = $row->post_id; $slug = 'posts'; }
				if($row->page_id != '0') { $tid = $row->page_id; $slug = 'pages'; }
				
				print $this->get_cta($tid, $slug);
				
			}
		}
	}


	
	//+++++++++++++++++++++++++++
	//GET PROJECTS
	//++++++++++++++++++++++++++
	
	function get_projects_feature($fid) {
		
		$query = $this->db->where('type_id', $fid);
		$query = $this->db->where('type', 'project');
		$query = $this->db->select('img_file');
		$query = $this->db->get('images');
		
		$feature = $query->row();
		
		if ($query->num_rows() > 0){ 
				
		return '<img src="'.site_url("/").'assets/images/'.$feature->img_file.'" class="img-polaroid" style="width:200px">';
		
		} else {
		
		return  "";	
			
		}
		
	}
	
	//+++++++++++++++++++++++++++
	//GET PROJECTS
	//++++++++++++++++++++++++++
	
	function get_projects($tid) {
		
		$query = $this->db->where('status', 'live');
		$query = $this->db->where('type', $tid);	
		$query = $this->db->get('projects');
		if($query->result()){
			foreach($query->result() as $row3){
				
				print '<div style="float:left; margin-right:20px; margin-bottom:20px; text-align:center; color:#666; font-size:12px; background:#efefef;"><a href="'.site_url("/").'project/'.$row3->slug.'">';
				
				print $this->get_projects_feature($row3->project_id);
				
				print '</a><br><a href="'.site_url("/").'project/'.$row3->slug.'">'.$row3->title.'</a></div>';
				
			}
		}			
		
		
	}		
	
	
		
	
	//+++++++++++++++++++++++++++
	//GET PROJECT
	//++++++++++++++++++++++++++
	function get_project($slug){
			
		$getid = $this->db->where('slug', $slug);
		$getid = $this->db->get('projects');
		return $getid->row_array();
		
		//print '<h2>'.$info->title.'</h2>';	

		
	}
	
	//+++++++++++++++++++++++++++
	//GET PROJECT CONTENT
	//++++++++++++++++++++++++++
	function get_project_content($slug){
			
		$getid = $this->db->where('slug', $slug);
		$getid = $this->db->get('projects');
		$info = $getid->row();

		print '<div class="span7" style="padding-left:20px; padding-right:20px;">';
		
		print $this->get_project_images($slug);						
								
		print '</div>
		
		<div class="span3" id="inner-content-div" style="padding-right:30px;">
		
		<h4>'.$info->title.'</h4>
		
		'.$info->body.'		
									
		</div>		
		
	</div>';
	
	}
	
	//+++++++++++++++++++++++++++
	//GET PROJECT DOCUMENTS
	//++++++++++++++++++++++++++
	function get_project_documents($slug){
		
		$getid2 = $this->db->where('slug', $slug);
		$getid2 = $this->db->select('project_id');
		$getid2 = $this->db->get('projects');
		$idrow2 = $getid2->row();	
	

				
			$query2 = $this->db->where('project_id', $idrow2->project_id);
			$query2 = $this->db->get('project_documents');
			if($query2->result()){
				foreach($query2->result() as $row){
				
				$filename = base_url('/').'assets/documents/'.$row->doc_file;	
				
				$fsize = get_file_info($filename, 'size');
					
				print '<img src="'.base_url('/').'graphics/pdf_icon.png" width="20px"> <a href="'.base_url('/').'/assets/documents/'.$row->doc_file.'" target="_blank">'.$row->title.'</a>'.$fsize;	
					
				}
				
			}
			
	}	
	
	//+++++++++++++++++++++++++++
	//GET PROJECT IMAGES
	//++++++++++++++++++++++++++
	function get_project_images($slug){
		
		$getid = $this->db->where('slug', $slug);
		$getft = $this->db->select('project_id');
		$getid = $this->db->get('projects');
		$idrow = $getid->row();	
	
		$galget = $this->db->where('project_id', $idrow->project_id);		
		$galget = $this->db->select('type');
		$galget = $this->db->get('sidebars');
		$galid = $galget->row();
		
		if($galget->row()) {
		
			$id = substr($galid->type, (strpos($galid->type,'_')+ 1) , strlen($galid->type) );
			
				
			$query = $this->db->where('gal_id', $id);
			$query = $this->db->get('images');

			
			
			if($query->result()){ $i=1;

			print '<div id="myCarousel" class="carousel slide">
			  	   <div class="carousel-inner" style="height:300px;">';
			
				foreach($query->result() as $row){
				
				if($i == 1) { $active = 'class="active item"'; } else { $active = 'class="item"'; }
				
				print '<div '.$active.'><img src="'.base_url('/').'assets/images/'.$row->img_file.'"></div>';	
					
				$i++;}
				
			print '</div>
			  <a class="carousel-control left" href="#myCarousel" data-slide="prev">&lsaquo;</a>
			  <a class="carousel-control right" href="#myCarousel" data-slide="next">&rsaquo;</a>
			</div>
			<hr>
			<div class="row-fluid" style="margin-top:5px">	
			<div class="scroll-pane ui-widget ui-widget-header ui-corner-all">
 			<div class="scroll-content">		
			';	
			$p=0;
			foreach($query->result() as $row2){
			
				print '<a href="#" data-target="#myCarousel" data-slide-to="'.$p.'"><img src="'.base_url('/').'assets/images/'.$row2->img_file.'"  class="img-thumbnail" style="padding:5px; width:112px"></a>';	
				
			$p++;}
			
			print '
			
			</div>
			<div class="scroll-bar-wrap ui-widget-content ui-corner-bottom">
			<div class="scroll-bar"></div>
			</div>
			</div>			
			</div>';
			
		
			}
		}
	}
	
	//+++++++++++++++++++++++++++
	//GET PROJECT POP IMAGES
	//++++++++++++++++++++++++++
	function getPopImage($pid, $gid){
			
	
		$query = $this->db->where('gal_id', $gid);	
		$query = $this->db->get('images');

		print'<div id="myCarousel2" class="carousel slide">
		  <div class="carousel-inner">';
		  

			foreach($query->result() as $row){
			
			if($row->img_id==$pid) { 
			
				$active = 'class="item active"'; 
				
			} else { 
			
				$active = 'class="item"'; 
				
			}
					
				print '
				<div '.$active.'>
				<img src="'.base_url('/').'assets/images/'.$row->img_file.'" width="800px">
				</div>';

			}
			
		print '</div>
		  <a class="carousel-control left" href="#myCarousel2" data-slide="prev">&lsaquo;</a>
  		  <a class="carousel-control right" href="#myCarousel2" data-slide="next">&rsaquo;</a>
		</div>';

		
					
	}	
	
	
	
			

	//+++++++++++++++++++++++++++
	//GET PROJECT FEATURE
	//++++++++++++++++++++++++++
	function get_project_feature($slug){
			
		$getid = $this->db->where('slug', $slug);
		$getft = $this->db->select('project_id');
		$getid = $this->db->get('projects');
		$idrow = $getid->row();

		$getft = $this->db->where('type_id', $idrow->project_id);
		$getft = $this->db->where('type', 'project');
		$getft = $this->db->select('img_file');
		$getft = $this->db->get('images');
		
		$ftimg = $getft->row();	
		
		if($getft->row()) {
		return '<img src="'.base_url('/').'assets/images/'.$ftimg->img_file.'" width="100%" style="position:fixed" />';	
		} else {
		return '<img src="'.base_url('/').'graphics/projects.jpg" width="100%" style="position:fixed" />';	
		}
	}
		
	
	//+++++++++++++++++++++++++++
	//GET PAGE
	//++++++++++++++++++++++++++
	function get_page($slug){
			
		$test = $this->db->where('slug', $slug);
		$test = $this->db->get('pages');
		return $test->row_array();	

	}
	
	public function sub_pages_tabs($pid)
	{
		$query = $this->db->order_by('page_sequence', 'ASC');
		$query = $this->db->select('page_id, title');
		$query = $this->db->where('page_parent', $pid);
		$query = $this->db->get('pages');
		if($query->result()){
			$i=1;
			foreach($query->result() as $row){
				print '<li data-target="#myCarousel" data-slide-to="'.$i.'"><a href="#'.$row->page_id.'" data-toggle="tab">'.$row->title.'</a></li>';
				$i++;
			}
		}
	}
	
	public function sub_pages_content($pid)
	{
		$query = $this->db->where('page_parent', $pid);
		$query = $this->db->get('pages');
		if($query->result()){
			foreach($query->result() as $row2){
				print '<div class="tab-pane" id="'.$row2->page_id.'">'.'<h2>'.$row2->heading.'</h2>'.$row2->body.'</div>';
			}
		}
	}	
		
	//+++++++++++++++++++++++++++
	//GET POST
	//++++++++++++++++++++++++++
	function get_post($slug){
			
		$test = $this->db->where('slug', $slug);
		$test = $this->db->get('posts');
		return $test->row_array();	

	}
	
	
	
	//+++++++++++++++++++++++++++
	//Quick News
	//++++++++++++++++++++++++++
	function quick_news(){	

			$query = $this->db->where('status', 'live');
			$query = $this->db->order_by('datetime', 'DESC');
			$query = $this->db->limit(3);
			$query = $this->db->get('posts');
			
			foreach($query->result() as $row){
			
				echo '<strong style="color:#f60;">'.$row->title.'</strong><br>'.date('d F Y', strtotime($row->datetime)).'<br>'.$row->body.'<hr>';
				
			}
			
				echo '<a href="'.base_url('/').'index.php/main/news">view all >></a>';
			
			
	
	}
	
	
	//+++++++++++++++++++++++++++
	//GET POST
	//++++++++++++++++++++++++++
	function get_posts($query){
		
		if($query == ''){
				
			$test = $this->db->where('status', 'live');
			$test = $this->db->order_by('datetime', 'DESC');
			$test = $this->db->get('posts');
			
		}else{
			
			$test = $this->db->query($query, FALSE);
			
		}
		if($test->result()){
			
			foreach($test->result() as $row){
				
				    $texthtml = $row->body;
    			  	preg_match('/images.+\.(jpeg|jpg|gif)/', $texthtml, $image);
					
					if(isset($image[0])) {
					
					$get_image = '<img src="'.site_url('/').'assets/'.$image[0].'" width="100px" class="img-polaroid pull-left" style="margin-right:20px;">';
						
					} else {
					
					$get_image = '';
						
					}
					
					  /*<img src="'.base_url('/').'img/timbthumb.php?src='.$avatar['image'].'&q=100&w=40&h=40'.'" class="img-polaroid" style="float:left;margin:0px 5px 5px 0px"/>*/
					echo '<div class="blog_post">
							 <div class="arrow"></div>'.$get_image.'
						     <div >
								
								
								<h4><a href="'.site_url('/').'news/'.$row->slug.'/" style="color:#f50">'.
							$row->title .'</a></h4><small style="font-size:12px;color:#FF6600">'.date('d M Y',strtotime($row->datetime)).'</small><br>
							 <div>'.$row->body.'

							 
							</div>
							</div><hr />
							</div>
							';
				
				
			}
			
		}

	}
		
	//+++++++++++++++++++++++++++
	//GET POST
	//++++++++++++++++++++++++++
	function get_home_posts(){
			
		$test = $this->db->where('status', 'live');
		$test = $this->db->order_by('datetime', 'DESC');
		$test = $this->db->limit('2');
		$test = $this->db->get('posts');
		
		if($test->result()){
			echo '<h3>News</h3>';
			foreach($test->result() as $row){

					  /*<img src="'.base_url('/').'img/timbthumb.php?src='.$avatar['image'].'&q=100&w=40&h=40'.'" class="img-polaroid" style="float:left;margin:0px 5px 5px 0px"/>*/
					echo '<div class="comment">
						     <div class="well well-small">
								<div class="arrow"></div>
								<h5 class="commentbox-title"><font style="font-size:16px">'.
							  substr($row->title, 0,19) .'</font><small class="pull-right" style="font-size:12px;">'.date('d M Y',strtotime($row->datetime)).'</small></h5>
							 <div class="popover-content">'.substr(strip_tags($row->body),0,160).'
							 <div class="clearfix" style="height:10px;"></div>
							 <a href="'.site_url('/').'news/'.$row->slug.'/" class="btn btn-mini pull-right">Read more</a>
							 <div class="clearfix" style="height:20px;"></div>
							</div>
							</div>
							</div>
							';
				
				
			}
			
		}

	}
	
	//+++++++++++++++++++++++++++
	//GET COMMENT FORM
	//++++++++++++++++++++++++++
	function get_comments_form($comments, $post_id){
		
		   if(isset($comments) & $comments == 'no'){
					
			
			}elseif(isset($comments) & $comments == 'private'){
				
				$this->show_private_comment_form($post_id);
				
			}elseif(isset($comments) & $comments == 'allow'){
				
				$this->show_comment_form($post_id);
				
			}
			
	}
	//++++++++++++++++++++++++++++++++++++++++++++++++++++++
	//SHOW REGISTERED COMMENT FORM
	//++++++++++++++++++++++++++++++++++++++++++++++++++++++		

	function show_private_comment_form($post_id){

		$button_txt1 = "<img src='".base_url("/")."img/load.gif' /> Submitting...";
		$button_txt2 = "<i class='icon-comment'></i> Submit Comment";
		if($this->session->userdata('user_id')){

			echo '<h4>Leave a comment</h4>
				   <form id="commentfrm" name="commentfrm" method="post" action="'.site_url('/').'main/submit_comment/">
					   <input type="hidden" value="'.$post_id.'" name="post_id" />
					   <input type="hidden" value="'.$this->session->userdata('user_id').'" name="user_id" />
					   <textarea rows="3"  class="redactor span6" name="body"></textarea>
					   <br />
					   <button type="submit" id="commentbut" class="btn pull-right"><i class="icon-comment"></i> Submit Comment</button>
				   </form>
				   <div class="clearfix" style="height:20px;"></div>
				   <div id="comment_msg"></div>
				   
				   <script type="text/javascript">
					$("#commentbut").bind("click" , function(e) {
							e.preventDefault();
							var frm = $("#commentfrm");
							$("#commentbut").html("'.$button_txt1.'");
							$.ajax({
								type: "post",
								url: "'. site_url("/").'main/submit_comment/" ,
								data: frm.serialize(),
								success: function (data) {
									 $("#comment_msg").html(data);
									 $("#commentbut").html("'.$button_txt2.'");
								}
							});	
					});
					
					function load_comments(){
						
						$.ajax({
								type: "get",
								url: "'. site_url("/").'main/load_comments/'.$post_id.'" ,
								success: function (data) {
									 $("#comment_id").html(data);
								}
							});	
						
					}
				   </script>';
		
		}else{
			
			echo 'Please Login or Register';
			
		}
		
		
    }
	
	//++++++++++++++++++++++++++++++++++++++++++++++++++++++
	//SHOW REGISTERED COMMENT FORM
	//++++++++++++++++++++++++++++++++++++++++++++++++++++++		

	function show_comment_form($post_id){

		$button_txt1 = "<img src='".base_url("/")."img/load.gif' /> Submitting...";
		$button_txt2 = "<i class='icon-comment'></i> Submit Comment";
		if($this->session->userdata('user_id')){

			echo '<h4>Leave a comment</h4>
				   <form id="commentfrm" name="commentfrm" method="post" action="'.site_url('/').'main/submit_comment/">
					   <input type="hidden" value="'.$post_id.'" name="post_id" />
					   <input type="hidden" value="'.$this->session->userdata('name').'" placeholder="Your Name" name="name" />
					   <input type="hidden" class="span3" value="'.$this->session->userdata('email').'" placeholder="Your Email" name="email" />
					   <textarea rows="3"  class="redactor span6" name="body"></textarea>
					   <br />
					   <button type="submit" id="commentbut" class="btn pull-right"><i class="icon-comment"></i> Submit Comment</button>
				   </form>
				   <div class="clearfix" style="height:20px;"></div>
				   <div id="comment_msg"></div>
				   
				   <script type="text/javascript">
					$("#commentbut").bind("click" , function(e) {
							e.preventDefault();
							var frm = $("#commentfrm");
							$("#commentbut").html("'.$button_txt1.'");
							$.ajax({
								type: "post",
								url: "'. site_url("/").'main/submit_comment/" ,
								data: frm.serialize(),
								success: function (data) {
									 $("#comment_msg").html(data);
									 $("#commentbut").html("'.$button_txt2.'");
								}
							});	
					});
					function load_comments(){
						
						$.ajax({
								type: "get",
								url: "'. site_url("/").'main/load_comments/'.$post_id.'" ,
								success: function (data) {
									 $("#comment_id").html(data);
								}
							});	
						
					}	
				   </script>';
		
		}else{
			
			echo '<h4>Leave a comment</h4>
				   <form class="well" id="commentfrm" name="commentfrm" method="post" action="'.site_url('/').'main/submit_comment/">
					   <input type="hidden" value="'.$post_id.'" name="post_id" />
					   <input type="text" class="span6 pull-right" value="" placeholder="Your Name" name="name" />
					   <input type="text" class="span6" value="" placeholder="Your Email" name="email" />
					   <textarea rows="3"  class="redactor span12" name="body"></textarea>
					   <br />
					   <button type="submit" id="commentbut" class="btn btn-inverse pull-right"><i class="icon-comment icon-white"></i> Submit Comment</button>
					   <div id="comment_msg"></div>
				   <div class="clearfix" style="height:20px;"></div>
				   </form>
				   <div id="comment_msg"></div>
				   
				   <script type="text/javascript">
					$("#commentbut").bind("click" , function(e) {
							e.preventDefault();
							var frm = $("#commentfrm");
							$("#commentbut").html("'.$button_txt1.'");
							$.ajax({
								type: "post",
								url: "'. site_url("/").'main/submit_comment/" ,
								data: frm.serialize(),
								success: function (data) {
									 $("#comment_msg").html(data);
									 $("#commentbut").html("'.$button_txt2.'");
								}
							});	
					});
					function load_comments(){
						
						$.ajax({
								type: "get",
								url: "'. site_url("/").'main/load_comments/'.$post_id.'" ,
								success: function (data) {
									 $("#comment_id").html(data);
								}
							});	
						
					}	
				   </script>';
			
		}
		
		
    }
	
	//+++++++++++++++++++++++++++
	//GET COMMENTS
	//++++++++++++++++++++++++++
	function get_comments($post_id){

		//GET COMMENTS
		$test = $this->db->where('cont_id', $post_id);
		$test = $this->db->where('status', 'live');
		$test = $this->db->get('comments');
		
		if($test->result()){
			echo '<h4>All comments</h4>';	
			foreach($test->result() as $row){
				
					  
					  /*<img src="'.base_url('/').'img/timbthumb.php?src='.$avatar['image'].'&q=100&w=40&h=40'.'" class="img-polaroid" style="float:left;margin:0px 5px 5px 0px"/>*/
					echo '<div class="comment">
						     <div class="commentbox right">
								<div class="arrow"></div>
								<h3 class="commentbox-title">'.
							$row->name .'</h3>
							 <div class="popover-content">'.$row->body.'
							<small style="color:#CCC">'.date('M d',strtotime($row->datetime)).'</small></div>
							</div>
							</div>
							<br />';
				
			}
			
		}else{
			
		}

	}
	//+++++++++++++++++++++++++++
	//LOAD COMMENTS
	//++++++++++++++++++++++++++
	function load_comments($post_id){

		//GET COMMENTS
		$test = $this->db->where('cont_id', $post_id);
		$test = $this->db->get('comments');
		return $test->row_array();	

	}
		
	//+++++++++++++++++++++++++++
	//GET NAVIGATION
	//++++++++++++++++++++++++++
	function get_navigation(){
			
		$test = $this->db->where('status', 'live');
		$test = $this->db->where('page_parent', '0');
		$test = $this->db->order_by('title', 'ASC');
		$pages = $this->db->get('pages');
		
		if($pages->result()){
			
			foreach($pages->result() as $page_row){
				
				$active = '';
				if($this->uri->segment('2') == $page_row->slug){
					
					$active = 'active';
				}
				
				echo '<li  class="'.$active.'"><a href="'.site_url('/').'page/'.$page_row->slug.'/">'.$page_row->title.'</a></li>';	
				
			}
			$test = $this->db->where('status', 'live');

			
		}else{
			
				
		}

	}
	
	//+++++++++++++++++++++++++++
	//GET SUB NAVIGATION PAGES
	//++++++++++++++++++++++++++
	function get_navigation_pages(){
			
		$test = $this->db->where('status', 'live');
		$test = $this->db->order_by('page_id', 'ASC');
		$pages = $this->db->get('pages');
		
		if($pages->result()){
			
			foreach($pages->result() as $page_row){
				
				$active = '';
				if($this->uri->segment('1') == $page_row->slug){
					
					$active = ' class="active"';
				}
				
				echo '<li '.$active.'><a href="'.site_url('/').'page/'.$page_row->slug.'/">'.$page_row->title.'</a></li>';	
				
			}
			
			
		}else{
			
				
		}

	}
	//+++++++++++++++++++++++++++
	//GET SUB NAVIGATION PAGES
	//++++++++++++++++++++++++++
	function get_navigation_posts(){
			
		$test = $this->db->where('status', 'live');
		$pages = $this->db->get('posts');
		
		if($pages->result()){
			
			foreach($pages->result() as $page_row){
				
				$active = '';
				if($this->uri->segment('1') == $page_row->slug){
					
					$active = ' class="active"';
				}
				
				echo '<li '.$active.'><a href="'.site_url('/').'news/'.$page_row->slug.'/">'.$page_row->title.'</a></li>';	
				
			}
			
			
		}else{
			
				
		}

	}
	//+++++++++++++++++++++++++++
	//GET SUB NAVIGATION CATEGORIES
	//++++++++++++++++++++++++++
	function get_navigation_categories(){
			
		//$test = $this->db->where('status', 'live');
		$pages = $this->db->get('categories');
		
		if($pages->result()){
			
			foreach($pages->result() as $page_row){
				
				$active = '';
				if($this->uri->segment('1') == $page_row->cat_name){
					
					$active = ' class="active"';
				}
				
				echo '<li '.$active.'><a href="'.site_url('/').'main/category/'.$page_row->cat_id.'/'.$this->clean_url_str($page_row->cat_name).'/">'.$page_row->cat_name.'</a></li>';	
				
			}
			
			
		}else{
			
				
		}

	}
	
	//+++++++++++++++++++++++++++
	//GET GALLERY SPECIFIC IMAGEs
	//++++++++++++++++++++++++++
	public function get_sidebar_content($content)
	{

			
		  if( substr($content, 0, strpos($content,'_')) == 'page'){
			  
			  $page_id =  substr($content, (strpos($content,'_') + 1), strlen($content));
			  $query = $this->db->where('page_id', $page_id);
			  $query = $this->db->get('sidebars');
			  
			  if($query->result()){
				  
				  foreach($query->result() as $row){
					  
					  $this->load_sidebar_content($row);
				  }
			  }else{
				 
				// echo '<div class="alert">
				 		//No Sidebar Added</div>'; 
				
			  }

			  
		  }elseif(substr($content, 0, strpos($content,'_')) == 'post'){
			  
			  $post_id =  substr($content, (strpos($content,'_') + 1), strlen($content));
			  $query = $this->db->where('post_id', $post_id);
			  $query = $this->db->get('sidebars');
			  
			  if($query->result()){
				  
				  foreach($query->result() as $row){
					  
					  $this->load_sidebar_content($row);
				  }
			  }else{
				 
				// echo '<div class="alert">
				 		//No Sidebar Added</div>'; 
				 
			  }
			  
		  }else{
			  
			
		  }
					
		//echo $content . '     -  ' .substr($content, 0, strpos($content,'_')) . '    -   ' .substr($content, (strpos($content,'_') + 1), strlen($content));
			 
	
		
	}
	//+++++++++++++++++++++++++++
	//LOAD SIDEBAR CONTENTS
	//++++++++++++++++++++++++++		 
	 
	function load_sidebar_content($row){
		
		$type = substr($row->type, 0, strpos($row->type,'_'));
		$id = substr($row->type, (strpos($row->type,'_')+ 1) , strlen($row->type) );
		
		if($type == 'gallery'){
			
			//echo $id;
		
			$this->load_gallery_images($id);

			
		}elseif($type == 'contact'){
			
			echo 'Gallery';
		}else{
			
			echo $row->type;
		}
		
	}
	
	//+++++++++++++++++++++++++++
	//load gallery images
	//++++++++++++++++++++++++++
	
	function load_gallery_images($gal_id)
	{
		  $x = 0;
 		  $effect = 'slide';
		  $query = $this->db->where('type', 'gal_img');
		  $query = $this->db->where('gal_id', $gal_id);
		  $query = $this->db->get('images');
		  if($query->result()){
				
				echo '<div id="carousel'.$gal_id.'" class="carousel carousel_mini '.$effect.'">
							 
						<!-- Carousel items -->
						<div class="carousel-inner">';
				
				foreach($query->result() as $row){
					$active = '';
					if($x == 0){
					
						$active = 'active';
						
					}
					echo '<div class="item '.$active.'">
								  <img src="'.base_url('/').'assets/images/'.$row->img_file.'" alt="" > 
						 </div>';
					$x ++;
				}
			
			
			   echo '
			   		</div>
				     <!-- Carousel nav -->
					  <a class="carousel-control left" href="#carousel'.$gal_id.'" data-slide="prev">&lsaquo;</a>
					  <a class="carousel-control right" href="#carousel'.$gal_id.'" data-slide="next">&rsaquo;</a>
				</div>
				<script type="text/javascript">
				$(document).ready(function(){
					$("#carousel'.$gal_id.'").carousel();
				});
				</script>
				';
			
		 }else{
			 
			 echo ' No images added';
			
		 }

  
		
	}
	


	//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++	
	//CLEAN BUSINESS URL SLUG
	//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++		 	
	
		//setlocale(LC_ALL, 'en_US.UTF8');
		function clean_url_str($str, $replace=array(), $delimiter='-') {
			if( !empty($replace) ) {
				$str = str_replace((array)$replace, ' ', $str);
			}
		
			$clean = iconv('UTF-8', 'ASCII//TRANSLIT', $str);
			$clean = preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $clean);
			$clean = strtolower(trim($clean, '-'));
			$clean = preg_replace("/[\/_|+ -]+/", $delimiter, $clean);
		
			return $clean;
		}
		



}
?>