<?if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true)die();?>
<?if($arParams["DISPLAY_TOP_PAGER"]):?>
	<?=$arResult["NAV_STRING"]?><br />
<?endif;?>
<?
	$field=$_GET["by"];
	$ord=$_GET["order"];
?>

<?
//$arnew=null;
//?clear_cache=Y
$c=0;
foreach($arResult["ITEMS"] as $cell=>$arElement)
{
$c=$c+1;
$arnew[$c]["num"]=$c;
$arnew[$c]["NAME"]=$arElement["NAME"];
$arnew[$c]["DETAIL_PAGE_URL"]=$arElement["DETAIL_PAGE_URL"];
$arnew[$c]["ADD_URL"]=$arElement["ADD_URL"];
$arnew[$c]["PREVIEW_PICTURE"]=$arElement["PREVIEW_PICTURE"];
$arnew[$c]["DETAIL_PICTURE"]=$arElement["DETAIL_PICTURE"];
foreach($arElement["PRICES"] as $code=>$arPrice){
	if($arPrice["CAN_ACCESS"]){
		if($arPrice["DISCOUNT_VALUE"] < $arPrice["VALUE"]){
			$prp=$arPrice["PRINT_DISCOUNT_VALUE"];
			$prv=$arPrice["DISCOUNT_VALUE"];
		} else
		{
			$prp=$arPrice["PRINT_DISCOUNT_VALUE"];
			$prv=$arPrice["DISCOUNT_VALUE"];
		}
	}
}
$arnew[$c]["PRICE_PRINT"]=$prp;
$arnew[$c]["PRICE_Value"]=$prv;
}
if (!function_exists(cmp_price_asc))
{
	function cmp_price_asc($a, $b)
	{	
		if ($a["PRICE_Value"] == $b["PRICE_Value"]) {
		return 0;
	}
		return ($a["PRICE_Value"] < $b["PRICE_Value"]) ? -1 : 1;
	}
	
	function cmp_price_desc($a, $b)
	{	
		if ($a["PRICE_Value"] == $b["PRICE_Value"]) {
		return 0;
	}
		return ($a["PRICE_Value"] > $b["PRICE_Value"]) ? -1 : 1;
	}
	
	function cmp_name_asc($a, $b)
	{	
		if ($a["NAME"] == $b["NAME"]) {
		return 0;
	}
		return ($a["NAME"] < $b["NAME"]) ? -1 : 1;
	}
	
	function cmp_name_desc($a, $b)
	{	
		if ($a["NAME"] == $b["NAME"]) {
		return 0;
	}
		return ($a["NAME"] > $b["NAME"]) ? -1 : 1;
	}
	if (isset($field) and isset($ord))
	{
	$ord_str="cmp_".$field."_".$ord;
	uasort($arnew, $ord_str);
	}
}
?>
<?foreach($arnew as $key => $arElement):		
		$this->AddEditAction($arElement['ID'], $arElement['EDIT_LINK'], CIBlock::GetArrayByID($arParams["IBLOCK_ID"], "ELEMENT_EDIT"));
		$this->AddDeleteAction($arElement['ID'], $arElement['DELETE_LINK'], CIBlock::GetArrayByID($arParams["IBLOCK_ID"], "ELEMENT_DELETE"), array("CONFIRM" => GetMessage('CT_BCS_ELEMENT_DELETE_CONFIRM')));
		?>
		<div class="productInner<?if($key==$c):?> last<?endif?>">
			<?if(is_array($arElement["PREVIEW_PICTURE"])):?>
				<?echo CFile::ShowImage($arElement['PREVIEW_PICTURE']['ID'], 225, 138, "border=0 align=left", "", false);?>							
			<?elseif(is_array($arElement["DETAIL_PICTURE"])):?>
				<?echo CFile::ShowImage($arElement['DETAIL_PICTURE']['ID'], 225, 138, "border=0 align=left", "", false);?>					
			<?endif?>			
			<div class="ots" id="<?=$this->GetEditAreaId($arElement['ID']);?>">
				<div class="price">
					<p><?=$arElement["NAME"]?></p>				
					<p class="bold"><?echo GetMessage("CATALOG_PRICE")?><span class="orange"><?=$arElement["PRICE_PRINT"]?></span></p>
					<div class="buttons">
						<a href="<?echo $arElement["ADD_URL"]?>" rel="nofollow"><?echo GetMessage("CATALOG_ADD")?></a>
					</div>
				</div>
				<div class="clear"></div>	
			</div>
			<p class="small_p"><span class="orange">»</span> <a class="orange" href="<?=$arElement["DETAIL_PAGE_URL"]?>"><?echo GetMessage("MORE_INFO")?></a></p>
			<div class="clear"></div>	
		</div>
<?endforeach?>

<?if($arParams["DISPLAY_BOTTOM_PAGER"]):?>
	<br /><?=$arResult["NAV_STRING"]?>
<?endif;?>
