<?php
if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가

//latest_amina 함수가 아닐 경우 옵션값을 다시 불러온다.
if(!$latest_amina) {
	$tab = array();
	$opt = array();
	$opt = amina_query($options);
	$tab[0]['title'] = $board['bo_subject'];
	$tab[0]['href'] = G4_BBS_URL.'/board.php?bo_table='.$bo_table;
}

$opt['head_skin'] = $opt['head_skin'] ? $opt['head_skin'] : 'basic';
$opt['list_skin'] = $opt['list_skin'] ? $opt['list_skin'] : 'basic';

$latest_head_path = G4_SKIN_PATH.'/latest/'.$skin_dir.'/head/'.$opt['head_skin'];
$latest_head_url = G4_SKIN_URL.'/latest/'.$skin_dir.'/head/'.$opt['head_skin'];
$latest_list_path = G4_SKIN_PATH.'/latest/'.$skin_dir.'/list/'.$opt['list_skin'];
$latest_list_url = G4_SKIN_URL.'/latest/'.$skin_dir.'/list/'.$opt['list_skin'];

$opt['list_wrap'] = ($opt['list_wrap'] && !$opt['tab']) ? ' class="'.$opt['list_wrap'].'"' : '';
$opt['head'] = ($opt['head'] && !$opt['tab']) ? ' '.$opt['head'] : '';
$opt['tab_id'] = $opt['tab_id'] ? $opt['tab_id'] : $tab_id; //탭타켓
$opt['href_target'] = $opt['target'] ? ' target="'.$opt['target'].'"' : ''; //링크타켓
$opt['start_tab'] = ($opt['start_tab'] > 0) ? $opt['start_tab'] : 0; //탭시작번호
$opt['tab_cnt'] = count($tab); //탭갯수

if($opt['head_skin'] != "none") {
	if(!file_exists($latest_head_path.'/latest.head.php')) {
		echo '<p>'.$opt['head_skin'].' 최근글 헤드스킨 필요</p>';
	} else {
		include_once($latest_head_path.'/load.style.php'); 
		include($latest_head_path.'/latest.head.php'); 
	}
}

if(!file_exists($latest_list_path.'/latest.list.php')) {
	echo '<p>'.$opt['list_skin'].' 최근글 목록스킨 필요</p>';
} else {

//출력하기
if($opt['list_wrap']) echo '<div'.$opt['list_wrap'].'>';

if($opt['tab_cnt'] > 1) {
	echo '<div id="latest_content1_'.$opt['tab_id'].'">';
	include($latest_list_path.'/latest.list.php');
	echo '</div>'."\n";
	echo '<div id="latest_content2_'.$opt['tab_id'].'" style="display:none;">';
	echo '<div id="latest_'.$opt['tab_id'].'"></div>';
	echo '</div>'."\n";
?>
	<script>
		function latest_load_<?php echo $opt['tab_id']; ?>(url) {
			$.get(url, function (data) {
			    $("#latest_<?php echo $opt['tab_id']; ?>").html(data);
	        });
        }

		<?php if($opt['head_skin'] == 'img') { ?>
			function TabClk_<?php echo $opt['tab_id']; ?>(n,on,url) {

				<?php for ($i=0; $i < $opt['tab_cnt']; $i++) { ?>
					$("#Tab<?php echo $i.'_'.$opt['tab_id']; ?>").attr('src', '<?php echo $tab[$i]['title_off']; ?>');
				<?php } ?>

				$("#Tab"+ n +"_<?php echo $opt['tab_id']; ?>").attr('src', on);

				if(n == 0) {
					$("#latest_content1_<?php echo $opt['tab_id']; ?>").show();
					$("#latest_content2_<?php echo $opt['tab_id']; ?>").hide();
				} else {
					$("#latest_content1_<?php echo $opt['tab_id']; ?>").hide();
					$("#latest_content2_<?php echo $opt['tab_id']; ?>").show();

					latest_load_<?php echo $opt['tab_id']; ?>(url);
				}
	        }
			<?php if($opt['start_tab'] > 0) { ?>
				TabClk_<?php echo $opt['tab_id']; ?>('<?php echo $tab[$opt['start_tab']]['num']; ?>','<?php echo $tab[$opt['start_tab']]['title']; ?>','<?php echo $tab[$opt['start_tab']]['query']; ?>');
			<?php } ?>
		<?php } else { ?>
			function TabClk_<?php echo $opt['tab_id']; ?>(n,url) {

				var i;
				for (i = 0; i < <?php echo $opt['tab_cnt']; ?>; i++)	{
					$("#Tab"+ i +"_<?php echo $opt['tab_id']; ?>").removeClass("on");
				}

				$("#Tab"+ n +"_<?php echo $opt['tab_id']; ?>").addClass("on");

				if(n == 0) {
					$("#latest_content1_<?php echo $opt['tab_id']; ?>").show();
					$("#latest_content2_<?php echo $opt['tab_id']; ?>").hide();
				} else {
					$("#latest_content1_<?php echo $opt['tab_id']; ?>").hide();
					$("#latest_content2_<?php echo $opt['tab_id']; ?>").show();

					latest_load_<?php echo $opt['tab_id']; ?>(url);
				}
	        }
			<?php if($opt['start_tab'] > 0) { ?>
				TabClk_<?php echo $opt['tab_id']; ?>('<?php echo $tab[$opt['start_tab']]['num']; ?>','<?php echo $tab[$opt['start_tab']]['query']; ?>');
			<?php } ?>
		<?php } ?>
	</script>

<?php 
	} else {	
		include($latest_list_path.'/latest.list.php'); 
	} 

if($opt['list_wrap']) echo '</div>'."\n";

} 
?>