<?php

/**

* @version		1.1

* @package		DJ Classifieds

* @subpackage	DJ Classifieds Component

* @copyright	Copyright (C) 2010 Blue Constant Media LTD, All rights reserved.

* @license		http://www.gnu.org/licenses GNU/GPL

* @autor url    http://design-joomla.eu

* @autor email  contact@design-joomla.eu

* @Developer    Lukasz Ciastek - lukasz.ciastek@design-joomla.eu

* 

* 

* DJ Classifieds is free software: you can redistribute it and/or modify

* it under the terms of the GNU General Public License as published by

* the Free Software Foundation, either version 3 of the License, or

* (at your option) any later version.

*

* DJ Classifieds is distributed in the hope that it will be useful,

* but WITHOUT ANY WARRANTY; without even the implied warranty of

* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

* GNU General Public License for more details.

*

* You should have received a copy of the GNU General Public License

* along with DJ Classifieds. If not, see <http://www.gnu.org/licenses/>.

* 

*/

defined ('_JEXEC') or die('Restricted access');

require_once(dirname(__FILE__).DS.'helper.php');



$main_id= JRequest::getVar('cid','0','int');

$par =& $mainframe->getParams('com_djclassifieds');

$limit	= JRequest::getVar('limit', $par->get('limit_djitem_show'), '', 'int');

$limitstart	= JRequest::getVar('limitstart', 0, '', 'int');

$order = JRequest::getVar('order', 'name', '', 'string');

$lista_count_items = 0;



$Itemid = JRequest::getVar('Itemid', 0, 'int');

$menus	= &JSite::getMenu();

foreach($menus->_items as $m){

	if($m->link == 'index.php?option=com_djclassifieds&view=show&cid=0'){

		$Itemid=$m->id;

		break;

	}

}



?>

<div id="dj-classifieds" class="clearfix">

	<?php $modules_breadcrumb = &JModuleHelper::getModules('dj_breadcrumb');

			if(count($modules_breadcrumb)>0){

				echo '<div class="dj_breadcrumb clearfix">';

				foreach (array_keys($modules_breadcrumb) as $m){

					echo JModuleHelper::renderModule($modules_breadcrumb[$m]);

				}

				echo'</div>';		

			}

			?>

	<table class="dj-category" width="100%">

	<tr><th colspan="3">

		<?php

		if($this->main_name == ""){

			echo JText::_('Categories');

		}else{

			echo $this->main_name;	

		}

		?> 

	</th></tr>

	<tr class="row0">

	<?php

	$all_cat = Array();

	$ii=0;

	$row=0;

	foreach($this->cat_list as $c){

		if($c->parent_id==$main_id){

			$_list = new TreeHelper();

			$lists = $_list->getList($c->id,$this->cat_list);

	

			if(count($lists)>1){

				if($ii%3==0 && $ii!=0){

					$row==0 ? $row=1 : $row=0;

					echo '</tr><tr class="row'.$row.'"><td class="cat" >';	

				}else{

					echo '<td class="cat" >';

				}

				

				foreach($lists as $l){

					$all_cat[]=$l;

				}

				$count_items=$this->model->getCountCategories($lists);

				$lista_count_items = $lista_count_items + $count_items;

				echo '<div class="title">';

				if($c->icon_url){

					echo '<img src="'.JURI::base().'/components/com_djclassifieds/images/'.$c->icon_url.'.ths.jpg"  />';

				}

				echo '<a href="index.php?option=com_djclassifieds&view=show&layout=blog&cid='.$c->id.'&Itemid='.$Itemid.'">';

				if($this->par->get('show_adsn_cat')){

					echo $c->name.'<span>('.$count_items.')</span></a></div>';	

				}else{

					echo $c->name.'</a></div>';	

				}	

				echo '<div class="cat_desc">'.$c->description.'</div>';

				echo '</td>';

			}else{

				if($ii%3==0 && $ii!=0){

					$row==0 ? $row=1 : $row=0;

					echo '</tr><tr class="row'.$row.'"><td class="cat" >';				

				}else{

					echo '<td class="cat" >';

				}

				$all_cat[] = $lists[0];

				$count_items=$this->model->getCountCategories($lists);

				$lista_count_items = $lista_count_items + $count_items;	

				echo '<div class="title">';			

				if($c->icon_url){

					echo '<img src="'.JURI::base().'/components/com_djclassifieds/images/'.$c->icon_url.'.ths.jpg"  />';

				}

				echo '<a href="index.php?option=com_djclassifieds&view=showlist&layout=blog&cid='.$c->id.'&Itemid='.$Itemid.'">';

				if($this->par->get('show_adsn_cat')){

					echo $c->name.'<span>('.$count_items.')</span></a></div>';	

				}else{

					echo $c->name.'</a></div>';	

				}	

				echo '<div class="cat_desc">'.$c->description.'</div>';

				echo '</td>';			

			}		

		$ii++;	

		}

	}

	

	if($ii%3==1){

		echo '<td class="cat" ></td><td class="cat" ></td>';

	}

	if($ii%3==2){

		echo '<td class="cat" ></td>';

	}

	

	

	

	if($main_id=='0'){

		$items = $this->model->getAllElements();

		if(JRequest::getVar('search','0','string')!='0'){

			$lista_count_items = $this->model->getCountAllElements();

		}

	}else{

		$all_cat[]=$main_id;

		$items = $this->model->getElements($all_cat);

		$lista_count_items = $this->model->getCountCategories($all_cat);

	}

?>

</tr><tr class="last"><td colspan="3"></td></tr></table>

		<?php $modules = &JModuleHelper::getModules('banner_items');

			if(count($modules)>0){

				echo '<div class="banner_items clearfix">';

				$i=1;

				foreach (array_keys($modules) as $m){

					echo '<div class="banner'.$i++.'">';

					echo JModuleHelper::renderModule($modules[$m]);

					echo '</div>';

				}

				echo'</div>';		

			}

			?>

<?php 

$sw = JRequest::getVar('search', '', '', 'string');

if($sw){?>

<div class="searchword">

	<?php echo JText::_('Results for').' : <span>'.$sw.'</span>'; ?>

</div>

<?php } ?>

<div class="items"><div class="djcf_items_blog">

<?php	

	$r=TRUE;

	?>

	

	<?php

	if($this->par->get('showitem_jump',0)){

		$anch = '#dj-classifieds';

	}else{

		$anch='';

	}

	$img_w = $par->get("middleth_width")+15;

	$col_n = 100 / $par->get('blog_columns_number') - 0.1;

	$ii=0;

	foreach($items as $i){

		

		$cn= $ii%$par->get('blog_columns_number');

		$ii++;

		if($i->special==1){$row=' special';}else{$row='';}

		echo '<div class="item_box'.$row.' clearfix" style="width:'.$col_n.'%;"><div class="item_box_bg'.$cn.'"><div class="item_box_in"><div class="item_box_in2">';

		echo '<div class="title"><a href="index.php?option=com_djclassifieds&view=showitem&cid='.$i->cat_id.'&id='.$i->id.'&Itemid='.$Itemid.$anch.'" >'.$i->name.'</a></div>';

		echo '<table class="blog_det" cellpadding="0" cellspacing="0" ><tr>';

		if($i->image_url!=''){

			echo '<td><div class="item_img" style="width:'.$img_w.'px">';

			$images=explode(';',$i->image_url);	

			echo '<a href="index.php?option=com_djclassifieds&view=showitem&cid='.$i->cat_id.'&id='.$i->id.'&Itemid='.$Itemid.$anch.'">';					

			echo '<img src="'.JURI::base().'/components/com_djclassifieds/images/'.$images[0].'.thm.jpg"  />';

			echo '</a>';

			echo '</div></td>';

		}

		

		echo '<td><div class="item_box_right"><div class="name">';		

		

		echo '</div>';

		echo '<div class="description"><span class="label_title">'.JText::_('Description').'</span>'.$i->intro_desc.'</div>';

		echo '<div class="cat_name"><span class="label_title">'.JText::_('Category').'</span>'.$i->c_name.'</div>';

		echo '<div class="date_start"><span class="label_title">'.JText::_('Added').'</span>'.$i->date_start.'</div>';

		echo '<div class="see_details_box"><a class="see_details" href="index.php?option=com_djclassifieds&view=showitem&cid='.$i->cat_id.'&id='.$i->id.'&Itemid='.$Itemid.$anch.'" >'.JText::_('See details').'</a></div>';	

		echo '</div>';

		echo '</td></tr></table></div></div></div></div>';

	}

	?>	

	<?php

		echo '<br style="clear:both"/>';

		echo '<div class="pag" colspan="6" >';	     

			$pagination = new JPagination($lista_count_items, $limitstart, $limit);

			echo $pagination->getPagesLinks(); 

		echo '</div>';

	?>

	</div>



</div>	

</div>

<script type="text/javascript">

	function DJCatMatchModules(className){

	var maxHeight = 0;

	if ($$(className)) {

		var divs = $$(className);

		divs.each(function(element){

			maxHeight = Math.max(maxHeight, parseInt(element.getStyle('height')));

		});

		

		divs.setStyle('height', maxHeight);

	}

}



window.addEvent('load', function(){

	DJCatMatchModules('.item_box_in2');

});



</script>