<?if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true)die();
function formatFileSize($bytes) 
{
	if (!is_numeric($bytes) || !$bytes) {
		return '';
	}
	if ($bytes >= 1000000000) {
		return round($bytes / 1000000000,2).' '.GetMessage("GB");
	}
	if ($bytes >= 1000000) {
		return round($bytes / 1000000,2).' '.GetMessage("MB");
	}
	return round($bytes / 1000,2). ' '.GetMessage("KB");
}
function human_plural_form($number, $titles)
{
    $cases = array (2, 0, 1, 1, 1, 2);
    return $number." ".$titles[ ($number%100 >4 && $number%100< 20)? 2 : $cases[min($number%10, 5)] ];
}
?>
<div class="ots">
		<?if(is_array($arResult["PREVIEW_PICTURE"]) || is_array($arResult["DETAIL_PICTURE"])):?>
			
				<?if(is_array($arResult["PREVIEW_PICTURE"]) && is_array($arResult["DETAIL_PICTURE"])):?>
					<?echo CFile::Show2Images($arResult["PREVIEW_PICTURE"]['ID'], $arResult["DETAIL_PICTURE"]['ID'], 225, 138, "hspace='0' align='left' vspace='0' border='0' title='".$arResult["NAME"]."'", true);?>
				<?elseif(is_array($arResult["DETAIL_PICTURE"])):?>
					<?echo CFile::ShowImage($arResult['DETAIL_PICTURE']['ID'], 225, 138, "border=0 align=left", "", false);?>	
				<?elseif(is_array($arResult["PREVIEW_PICTURE"])):?>
					<?echo CFile::ShowImage($arResult['PREVIEW_PICTURE']['ID'], 225, 138, "border=0 align=left", "", false);?>
				<?endif?>
				<?if(count($arResult["MORE_PHOTO"])>0):?>
					<br /><a href="#more_photo"><?=GetMessage("CATALOG_MORE_PHOTO")?></a>
				<?endif;?>
			
		<?endif;?>
		<div class="files-download" style="padding-right:0px;">
			<div style="padding-left:20px;">
				<?if($arResult["DETAIL_TEXT"]):?>
					<br /><?=$arResult["DETAIL_TEXT"]?><br />
				<?elseif($arResult["PREVIEW_TEXT"]):?>
					<br /><?=$arResult["PREVIEW_TEXT"]?><br />
				<?endif;?>
			</div>
		</div>
	<div class="clear"></div>
</div>
		<br />
		<?foreach($arResult["DISPLAY_PROPERTIES"] as $pid=>$arProperty):
			if($pid!="FILE"):?>
				<small>
				<?=$arProperty["NAME"]?>:&nbsp;
				<?if(is_array($arProperty["DISPLAY_VALUE"])):?>
					<?=implode("&nbsp;/&nbsp;", $arProperty["DISPLAY_VALUE"]);?>
				<?else:?>
					<?=$arProperty["DISPLAY_VALUE"];?>
				<?endif?>
				</small><br />
			<?endif;
		endforeach;?>
		<?if (!empty($arResult["DISPLAY_PROPERTIES"]['FILE']["DISPLAY_VALUE"])):?>
			<div class="files-download">
				<?if(is_array($arResult["DISPLAY_PROPERTIES"]['FILE']["DISPLAY_VALUE"])) {
					$arFiles = $arResult["DISPLAY_PROPERTIES"]['FILE']["DISPLAY_VALUE"];
					$arFilesData = $arResult["DISPLAY_PROPERTIES"]['FILE']['FILE_VALUE'];
				}
				else {
					$arFiles = array('file');
					$arFilesData = array($arResult["DISPLAY_PROPERTIES"]['FILE']['FILE_VALUE']);
				}
				foreach($arFiles as $key=>$value):	
					if(!$arFilesData[$key]['DESCRIPTION'])
						$arFilesData[$key]['DESCRIPTION']=$arFilesData[$key]['ORIGINAL_NAME'];
					$ext=substr($arFilesData[$key]['SRC'], strrpos($arFilesData[$key]['SRC'], '.') + 1);
					if (file_exists($_SERVER['DOCUMENT_ROOT'].'/bitrix/redirect.php'))
						$fileLink = 'href="/bitrix/redirect.php?goto='.$arFilesData[$key]['SRC'].'&event1=file&event3='.$arFilesData[$key]['FILE_NAME'].'&event2=download"';
					else
						$fileLink = 'target="blank" href="'.$arFilesData[$key]['SRC'].'"';
					?>
					<div>
						<a class="<?=$ext?>" <?=$fileLink?> title="<?=GetMessage("DOWNLOAD")?> <?=$arFilesData[$key]['DESCRIPTION']?>">
							<span><?=GetMessage("DOWNLOAD")?> "<?=$arFilesData[$key]['DESCRIPTION']?>"</span>
							<i> 
								(<?=formatFileSize($arFilesData[$key]['FILE_SIZE'])?>, <?=$ext?>)
								<?if (CModule::IncludeModule("statistic")):
									$rs = CStatEvent::GetList(
										 ($by = "s_id"), 
											($order = "desc"), 
										 array(
												'EVENT1'=>"file",
												"EVENT1_EXACT_MATCH"=>"Y",
												'EVENT2'=>"download",
												"EVENT2_EXACT_MATCH"=>"Y",
												"EVENT3"=>$arFilesData[$key]['FILE_NAME'],
												"EVENT3_EXACT_MATCH"=>"Y"),
										 $is_filtered
										);
									echo GetMessage("DOWNLOAD_COUNT").human_plural_form($rs->SelectedRowsCount(), array(GetMessage("RAZ"),GetMessage("RAZA"),GetMessage("RAZ")));
								endif?>	
							</i>
						</a>
					</div>
				<?endforeach;?>
			</div>
		<?endif?>
	<?if(count($arResult["LINKED_ELEMENTS"])>0):?>
		<br /><b><?=$arResult["LINKED_ELEMENTS"][0]["IBLOCK_NAME"]?>:</b>
		<ul>
	<?foreach($arResult["LINKED_ELEMENTS"] as $arResult):?>
		<li><a href="<?=$arResult["DETAIL_PAGE_URL"]?>"><?=$arResult["NAME"]?></a></li>
	<?endforeach;?>
		</ul>
	<?endif?>
	<?
	// additional photos
	$LINE_ELEMENT_COUNT = 2; // number of elements in a row
	if(count($arResult["MORE_PHOTO"])>0):?>
		<a name="more_photo"></a>
		<?foreach($arResult["MORE_PHOTO"] as $PHOTO):?>
			<img border="0" src="<?=$PHOTO["SRC"]?>" width="<?=$PHOTO["WIDTH"]?>" height="<?=$PHOTO["HEIGHT"]?>" alt="<?=$arResult["NAME"]?>" title="<?=$arResult["NAME"]?>" /><br />
		<?endforeach?>
	<?endif?>
	<?if(is_array($arResult["SECTION"])):?>
		<br />
		<noindex>
			<a href="<?=$arResult["SECTION"]["SECTION_PAGE_URL"]?>" rel="nofollow"><?=GetMessage("CATALOG_BACK")?> "<?=$arResult['SECTION']['NAME']?>"</a>
		</noindex>
	<?endif?>