<?
$SES_MEMBER_ID          = $this->session->userdata('C_Member_Id');

$is_more = 'Y';
if($total_count <= $limit) {
	$is_more = 'N';
}

?>
<link rel="stylesheet" type="text/css" href="/css/web/imgcss.css"/>


	<div class="contents">
		<div class="s_wrap">
			<div id="search" style="border-bottom:0 !important; padding-bottom:0px !important">
				<div class="search_images">
					<div class="search_cate" style="margin:0 0 0 20px">
						이미지  <span class="search_num"><?=number_format($total_count)?>건</span>
					</div>
					<section class="image-grid"></section>
				</div>
			</div>
		</div>
	</div>



<script>


$(document).ready(function () {
	var more_yn = '<?=$is_more?>';
  	$(document).scroll(function() {
    	var maxHeight = $(document).height();
    	var currentScroll = $(window).scrollTop() + $(window).height();
    	if (maxHeight <= (currentScroll+100)) {
    		console.log(more_yn);
        	if(more_yn=="Y") {
            	get_img_list();
        	}
    	}
  	})
});


var img_list_page = 1;
function get_img_list() {

	console.log("get_img_list");
	var form_data = {
		"page"              : img_list_page,
		"search_keyword"    : "<?=$search_keyword?>"
	};
	$.ajax({
		url: '/web/search/image_list_more',
		async: false,
		type: 'POST',
		dataType: 'HTML',
		data: form_data,
		success: function (rtnHtml) {
			var arrHtml = rtnHtml.split("|||||");
			if(arrHtml[0].trim()=='0000') {
				more_yn = arrHtml[2];
				console.log(more_yn);
				if (arrHtml[1] != "") {
					$('.image-grid').append(arrHtml[1]);
					img_list_page++;
				}
			}
		},
		error: function (rtnHtml) {
			alert('데이터 로드에 실패했습니다.');
			return false;
		}
	});

}

get_img_list();

$(document).ready(function(){
	//get_img_list();


	$('.smalls').click(function(){
	  var tmp = $(this).parent()
		  if (tmp.attr('class') == 'imms') {
			  $('.imms').removeClass('act');
			  tmp.addClass('act');
		  }else{
			  tmp.removeClass('act');
		  }
	});
	$('.omm_a2').click(function(){
	  var tmp = $(this).parent().parent()
		  if (tmp.attr('class') == 'omgg_ul1') {
			  tmp.addClass('act');
		  }else{
			  tmp.removeClass('act');
		  }
	});
	$('.omm_c').click(function(){
	  	$('.omgg_ul1').removeClass('act');
	});

	/*
	$('.ommbtn.omm_next').click(function(){
		var tmp = $(this).parent()
		  if (tmp.attr('class') == 'image--expand') {
			 $('html, body').animate({scrollTop:$(this).offset().top}, 0);
		  }else{
			// $('html, body').animate({scrollTop:$(this).offset().top + 140}, 0);
		  }
	});
	*/
	
});

var $cell = $('.image__cell');
	
function thumb_img_click(t){
	var $thisCell = $(t).closest('.image__cell');
  	if ($thisCell.hasClass('is-collapsed')) {
    	$cell.not($thisCell).removeClass('is-expanded').addClass('is-collapsed');
    	$thisCell.removeClass('is-collapsed').addClass('is-expanded');
		$('html, body').animate({ scrollTop : $(t).offset().top}, 300);
  	} else {
    	$thisCell.removeClass('is-collapsed').addClass('is-expanded');
	}
}


function img_view_change(num){
	var $thisCell = $('#img_item'+num).closest('.image__cell');
  	if ($thisCell.hasClass('is-collapsed')) {
    	$cell.not($thisCell).removeClass('is-expanded').addClass('is-collapsed');
    	$thisCell.removeClass('is-collapsed').addClass('is-expanded');
		$('html, body').animate({ scrollTop : $('#img_item'+num).offset().top}, 0);
  	} else {
    	$thisCell.removeClass('is-expanded').addClass('is-collapsed');
	}
}

function img_view_close(t){
	var $thisCell = $(t).closest('.image__cell');
  	$thisCell.removeClass('is-expanded').addClass('is-collapsed');
}
	
	
$('.ommbtn.omm_next','.ommbtn.omm_pre').click(function() {
  var $thisCelle = $(this).closest('.image__cell');
 // var $this = $(this).closest('.omm_con');

  if ($thisCelle.hasClass('is-collapsed')) {
    $cell.not($thisCelle).removeClass('is-expanded').addClass('is-collapsed');
    $thisCelle.removeClass('is-collapsed').addClass('is-expanded');
	$('html, body').animate({ scrollTop : $(this).offset().top}, 300);
    //return true;

  } else {
    $thisCelle.removeClass('is-expanded').addClass('is-collapsed');
  }
});
</script>