<?php
if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가

// add_stylesheet('css 구문', 출력순서); 숫자가 작을 수록 먼저 출력됨
add_stylesheet('<link rel="stylesheet" href="'.G5_SHOP_CSS_URL.'/style.css">', 0);
?>

<!-- 상품진열 10 시작 { -->
<?php
for ($i=1; $row=sql_fetch_array($result); $i++) {
    if ($this->list_mod >= 2) { // 1줄 이미지 : 2개 이상
        if ($i%$this->list_mod == 0) $sct_last = ' sct_last'; // 줄 마지막
        else if ($i%$this->list_mod == 1) $sct_last = ' sct_clear'; // 줄 첫번째
        else $sct_last = '';
    } else { // 1줄 이미지 : 1개
        $sct_last = ' sct_clear';
    }

    if ($i == 1) {
        if ($this->css) {
            echo "<ul class=\"{$this->css}\">\n";
        } else {
            echo "<ul class=\"sct sct_10\">\n";
        }
    }

    echo "<li class=\"sct_li{$sct_last}\" style=\"width:{$this->img_width}px\">\n";

    if ($this->href) {
        echo "<div class=\"sct_img\"><a href=\"{$this->href}{$row['it_id']}\" class=\"sct_a\">\n";
    }

    if ($this->view_it_img) {
        //echo get_it_image($row['it_id'], $this->img_width, $this->img_height, '', '', stripslashes($row['it_name']))."\n";
		//get it imag 변경
		echo get_it_image_over($row['it_id'], $this->img_width, $this->img_height, '', '', stripslashes($row['it_name']))."\n";
    }

    if ($this->href) {
        echo "</a></div>\n";
    }

    if ($this->view_it_icon) {
        echo "<div class=\"sct_icon\">".item_icon($row)."</div>\n";
    }

    if ($this->view_it_id) {
        echo "<div class=\"sct_id\">&lt;".stripslashes($row['it_id'])."&gt;</div>\n";
    }

    if ($this->href) {
        echo "<div class=\"sct_txt\"><a href=\"{$this->href}{$row['it_id']}\" class=\"sct_a\">\n";
    }

    if ($this->view_it_name) {
        echo stripslashes($row['it_name'])."\n";
    }

    if ($this->href) {
        echo "</a></div>\n";
    }

    if ($this->view_it_basic && $row['it_basic']) {
        echo "<div class=\"sct_basic\">".stripslashes($row['it_basic'])."</div>\n";
    }

    if ($this->view_it_cust_price || $this->view_it_price) {

        echo "<div class=\"sct_cost\">\n";

        if ($this->view_it_cust_price && $row['it_cust_price']) {
            echo "<strike>".display_price($row['it_cust_price'])."</strike>\n";
        }

        if ($this->view_it_price) {
            echo display_price(get_price($row), $row['it_tel_inq'])."\n";
        }

        echo "</div>\n";

    }

    if ($this->view_sns) {
        $sns_top = $this->img_height + 10;
        $sns_url  = G5_SHOP_URL.'/item.php?it_id='.$row['it_id'];
        $sns_title = get_text($row['it_name']).' | '.get_text($config['cf_title']);
        echo "<div class=\"sct_sns\" style=\"top:{$sns_top}px\">";
        echo get_sns_share_link('facebook', $sns_url, $sns_title, G5_SHOP_SKIN_URL.'/img/sns_fb_s.png');
        echo get_sns_share_link('twitter', $sns_url, $sns_title, G5_SHOP_SKIN_URL.'/img/sns_twt_s.png');
        echo get_sns_share_link('googleplus', $sns_url, $sns_title, G5_SHOP_SKIN_URL.'/img/sns_goo_s.png');
        echo "</div>\n";
    }

    echo "</li>\n";
}

if ($i > 1) echo "</ul>\n";

if($i == 1) echo "<p class=\"sct_noitem\">등록된 상품이 없습니다.</p>\n";
?>


<!-- 제품 이미지 마우스 오버 처리  -->
<script type="text/javascript">
<!--
	jQuery(document).ready(function(){
	/*fade */
	jQuery(".image_change").on("mouseenter",function(){
		var src = jQuery(this).attr("data-val2"); 
		jQuery(this).fadeOut('fast' , function(){jQuery(this).attr("src", src)}); 
		jQuery(this).fadeIn('fast'); 
		
	});
	jQuery(".image_change").on("mouseleave",function(){
		var src = jQuery(this).attr("data-val1");	
		jQuery(this).fadeOut('fast' , function(){jQuery(this).attr("src", src)});
		jQuery(this).fadeIn('fast'); 
	});
	
	/*바로 변경 주석 을 제거하시고 위의 fade 를 주석처리하세요 */
	/*
	jQuery(".image_change").on("mouseenter",function(){
		jQuery(this).attr("src", jQuery(this).attr("data-val2"));
		
	});
	jQuery(".image_change").on("mouseleave",function(){
		jQuery(this).attr("src", jQuery(this).attr("data-val1"));
	});
	*/
}); 

//-->
</script>
<!-- 제품 이미지 마우스 오버 처리 완료  -->

<!-- } 상품진열 10 끝 -->

<?php 
// 상품 이미지를 얻는다 get_it_image : shop.lib 에 get_it_image 변경
function get_it_image_over($it_id, $width, $height=0, $anchor=false, $img_id='', $img_alt='', $is_crop=false)
{
    global $g5;

    if(!$it_id || !$width)
        return '';

    $sql = " select it_id, it_img1, it_img2, it_img3, it_img4, it_img5, it_img6, it_img7, it_img8, it_img9, it_img10 from {$g5['g5_shop_item_table']} where it_id = '$it_id' ";
    $row = sql_fetch($sql);

    if(!$row['it_id'])
        return '';

    $img_array=array();
    $k=0;
    for($i=1;$i<=10; $i++) {
        $file = G5_DATA_PATH.'/item/'.$row['it_img'.$i];
        if(is_file($file) && $row['it_img'.$i]) {
            $size = @getimagesize($file);
            if($size[2] < 1 || $size[2] > 3)
                continue;
		
            $img_array[$k][filename] = basename($file);
            $img_array[$k][filepath] = dirname($file);
            $img_array[$k][img_width] = $size[0];
            $img_array[$k][img_height] = $size[1];
			$k++;
			if($k>1){
				break;
			}
		}
    }
	$counter=$k;
	if($counter)
	{
		for($i=0;$i<$counter;$i++)
		{
			$filename=$img_array[$i][filename];
			$filepath=$img_array[$i][filepath];
			$img_width=$img_array[$i][img_width];
			$img_height=$img_array[$i][img_height];

			if($img_width && !$height) {
				$height = round(($width * $img_height) / $img_width);
			}

			//thumbnail($filename, $source_path, $target_path, $thumb_width, $thumb_height, $is_create, $is_crop=false, $crop_mode='center', $is_sharpen=true, $um_value='80/0.5/3')
			$thumb = thumbnail($filename, $filepath, $filepath, $width, $height, false, $is_crop, 'center', false, $um_value='80/0.5/3');
	
			if(!$i){
				$file_url = str_replace(G5_PATH, G5_URL, $filepath.'/'.$thumb);
				$img .= '<img src="'.$file_url.'" width="'.$width.'" height="'.$height.'" alt="'.$img_alt.'" data-val1="'.$file_url.'"';
			}
			else{
				$file_url = str_replace(G5_PATH, G5_URL, $filepath.'/'.$thumb);
				$img .= ' data-val2="'.$file_url.'" class="image_change" ';
			}
		}
		if($img_id){
			$img .= ' id="'.$img_id.'"';
		}
		$img .= '>';		
	}
	else
	{	
		$img = '<img src="'.G5_SHOP_URL.'/img/no_image.gif" width="'.$width.'"  ';
		if($height){
			$img .= ' height="'.$height.'"';
			$img .= ' alt="'.$img_alt.'"';
		}
		if($img_id)
			$img .= ' id="'.$img_id.'"';
		$img .= '>';
	}
	if($anchor){
		$img = '<a href="'.G5_SHOP_URL.'/item.php?it_id='.$it_id.'">'.$img.'</a>';
	}
    return $img;
}


?>