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

$start_tab = ($opt['start_tab'] > 0) ? $opt['start_tab'] : 0;

if($type == "tab") { 

	$opt['tab_skin'] = $opt['tab_skin'] ? $opt['tab_skin'] : 'basic';

	if(file_exists(THEMA_PATH.'/latest/tab/'.$opt['tab_skin'].'/latest.tab.php')) {
		$latest_tab_path = THEMA_PATH.'/latest/tab/'.$opt['tab_skin'];
		$latest_tab_url = THEMA_URL.'/latest/tab/'.$opt['tab_skin'];
	} else {
		$latest_tab_path = AMINA_PATH.'/misc/latest/tab/'.$opt['tab_skin'];
		$latest_tab_url = AMINA_URL.'/misc/latest/tab/'.$opt['tab_skin'];
	}

	if(!file_exists($latest_tab_path.'/latest.tab.php')) {
		echo '<p>'.$opt['head_skin'].' 최근글 탭스킨 필요</p>';
	} else {
		include($latest_tab_path.'/latest.tab.php');
	}
} else if($type == "list") { 
	$page_file = THEMA_PATH.'/html/'.$page_name.'.php';

	if(!file_exists($page_file)) {
		echo '<p>테마내 /html/'.$page_name.'.php 파일 필요</p>';
	} else {	
?>
	<div id="main_Content1_<?php echo $main_id; ?>">
		<?php 
			$tab_id = $tab[0]['tab_id']; //첫번째 탭 출력
			include($page_file); 
		?>
	</div>

	<div id="main_Content2_<?php echo $main_id; ?>" style="display:none;">
		<iframe name="<?php echo $main_id; ?>frame" id="<?php echo $main_id; ?>frame" width="100%" height="0" frameborder="0" scrolling="no"></iframe>
	</div>

	<script>
		<?php if($opt['tab_type'] == 'img') { ?>
			function mainTab_<?php echo $main_id; ?>(n,on,url) {

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

				$("#Main"+ n +"_<?php echo $main_id; ?>").attr('src', on);

				if(n == 1) {
					$("#main_Content1_<?php echo $main_id; ?>").show();
					$("#main_Content2_<?php echo $main_id; ?>").hide();
				} else {
					$("#main_Content1_<?php echo $main_id; ?>").hide();
					$("#main_Content2_<?php echo $main_id; ?>").show();

					frames.<?php echo $main_id; ?>frame.location.href = url;
				}
	        }
			<?php if($start_tab > 0) { ?>
				mainTab_<?php echo $main_id; ?>('<?php echo $tab[$start_tab]['num']; ?>','<?php echo $tab[$start_tab]['title']; ?>','<?php echo $tab[$start_tab]['href']; ?>');
			<?php } ?>
		<?php } else { ?>
			function mainTab_<?php echo $main_id; ?>(n,url) {

				var i;
				for (i = 1; i <= <?php echo $tab_cnt; ?>; i++)	{
					$("#Main"+ i +"_<?php echo $main_id; ?>").removeClass("on");
				}

				$("#Main"+ n +"_<?php echo $main_id; ?>").addClass("on");

				if(n == 1) {
					$("#main_Content1_<?php echo $main_id; ?>").show();
					$("#main_Content2_<?php echo $main_id; ?>").hide();
				} else {
					$("#main_Content1_<?php echo $main_id; ?>").hide();
					$("#main_Content2_<?php echo $main_id; ?>").show();

					frames.<?php echo $main_id; ?>frame.location.href = url;
				}
	        }
			<?php if($start_tab > 0) { ?>
				mainTab_<?php echo $main_id; ?>('<?php echo $tab[$start_tab]['num']; ?>','<?php echo $tab[$start_tab]['href']; ?>');
			<?php } ?>
		<?php } ?>
	</script>
	<?php } ?>
<?php } ?>