// °Ë»ö

$(function(){
	$("#inp_sea").click(function(){
		var _val = $(this).val();
		if(_val == "Å°¿öµå³ª ÀÌ¹ÌÁö ¹øÈ£¸¦ ÀÔ·ÂÇØ ÁÖ¼¼¿ä."){ $(this).val(''); }
	});

	//$("#inp_sea").keyup(function(event){ if(event.keyCode == 13){ fn_sea(); } });
	$(".bt_sea").click(function(){ fn_sea(); });
});

function fn_sea(){ // °Ë»ö Ã³¸®
	var chk = document.getElementsByName('check[]');
	var _get = '';
	if($("#inp_sea").val() == 'Å°¿öµå³ª ÀÌ¹ÌÁö ¹øÈ£¸¦ ÀÔ·ÂÇØ ÁÖ¼¼¿ä.' || $("#inp_sea").val() == ''){ alert('°Ë»ö¾î¸¦ ÀÔ·ÂÇØÁÖ¼¼¿ä'); $("#inp_sea").val('').focus(); return; }
	$.ajax({
		type : "GET",
		url : "/photo/__urlkwd.php",
		data : "k="+$("#inp_sea").val(),
		success:function(msg){
			if($("#gty").val() == 'cd'){ top.location.href = "/photo/list_request_cd.php?action=search&search="+$.trim(msg); return; }
			if($("#gty").val() == 'motion'){ top.location.href = "/motion/list_request.php?action=search&search="+$.trim(msg); return; }
			if($("#gty").val() != '') _get += "&gty="+$("#gty").val();
			if($("#nD").val() != '') _get += "&nD="+$("#nD").val();

			if($("#nD").val() == '2'){
				top.location.href = "/illust/?search="+$.trim(msg)+_get;
			}else if($("#nD").val() == '3'){
				top.location.href = "/art/?search="+$.trim(msg)+_get;
			}else{
				top.location.href = "/photo/?search="+$.trim(msg)+_get;
			}

		}
	});
}

function fn_gty(){
	var chk = document.getElementsByName('check[]');

	var _gty = '';

	if(chk[0].checked == true && chk[1].checked == false && chk[2].checked == false){ 
		_gty = '2';
	}else if(chk[0].checked == false && chk[1].checked == true && chk[2].checked == false){ 	
		_gty = '1';
	}else if(chk[0].checked == false && chk[1].checked == false && chk[2].checked == true){ 	
		_gty = '3';
	}

	var url = "./?search="+$("#__search").val();
	if(_gty != '') url += "&gty="+_gty;
	if($("#_nD").val() != '') url += "&nD="+$("#_nD").val();
	if($("#_cate").val() != '') url += "&cate="+$("#_cate").val();

	if(_gty == 3){
		top.location.href = "/photo/list_request_cd.php?action=search&search="+$("#__search").val();
	}else{
		top.location.href = url;
	}
}


// Ä«Å×°í¸®

$(function(){

	$("body").delegate(".bt_cate", "click", function(){
		rel2 = $(this).attr('rel2');
		if(rel2 == ''){
			rel = $(this).attr('rel');
			len = (rel.length)/2;

			if(len > 1){
				if($(".cate_ic_"+rel).attr('rel2') == 'off'){
					$("#Bcate span").css("color", "#525252");
					$("#tree_"+rel+" span").css("color", "#f60");
					$(".cate_ic_"+rel).attr("src", "/icon/cate_minus.gif").attr('rel2','on');
				}else{
					$("#tree_"+rel+" span").css("color", "#525252");
					$(".cate_ic_"+rel).attr("src", "/icon/cate_plus.gif").attr('rel2','off');
					$("#Btree_"+rel).empty().remove();
					return;
				}
			}
		
			$.ajax({
				type : 'GET',
				url : './__cate.php',
				data : "tree="+rel,
				success:function(msg){
					if(len == 1){
						$("#Btab_tree").html($.trim(msg));
					}else{
						$("#tree_"+rel).after("<div id=\"Btree_"+rel+"\">"+$.trim(msg)+"</div>");
					}
				}
			});	
		}else{
			var url = "./?search="+rel2+"&cate="+$(this).attr('rel');
			if($("#_gty").val() != '') url += "&gty="+$("#_gty").val();
			if($("#_nD").val() != '') url += "&nD="+$("#_nD").val();
			top.location.href = url;
		}
	});

	$("body").delegate(".bt_cate", "mouseover", function(){ $(this).css("color", "#f60"); });
	$("body").delegate(".bt_cate", "mouseout", function(){ $(this).css("color", "#525252");	});

	$(".bt_tab_cate").mouseover(function(){ // Ä«Å×°í¸® TAB Ä«Å×°í¸®
		$("#Btab_vs").hide();
		$("#Btab_cate").show();
	});

	$(".bt_tab_vs").mouseover(function(){ // Ä«Å×°í¸® TAB ¾ÆÀÌµð¾î
		$("#Btab_cate").hide();
		$("#Btab_vs").show();
	});

	$("body").delegate(".bt_cate_ic", "click", function(){
		rel = $(this).attr('rel');
		len = (rel.length)/2;

		if(len > 1){
			if($(this).attr('rel2') == 'off'){
				$("#Bcate span").css("color", "#525252");
				$("#tree_"+rel+" span").css("color", "#f60");
				$(this).attr("src", "/icon/cate_minus.gif").attr('rel2','on');
			}else{
				$("#tree_"+rel+" span").css("color", "#525252");
				$(this).attr("src", "/icon/cate_plus.gif").attr('rel2','off');
				$("#Btree_"+rel).empty().remove();
				return;
			}
		}
	
		$.ajax({
			type : 'GET',
			url : './__cate.php',
			data : "tree="+rel,
			success:function(msg){
				if(len == 1){
					$("#Btab_tree").html($.trim(msg));
				}else{
					$("#tree_"+rel).after("<div id=\"Btree_"+rel+"\">"+$.trim(msg)+"</div>");
				}
			}
		});	
	});

});

function fn_cate(){
	$.ajax({
		type : 'GET',
		url : './__cate.php',
		data : "cate="+$("#_cate").val(),
		success:function(msg){
			$("#Bcate").html($.trim(msg));
			$("#_loading").val(1);
			$("#_pg").val(1); fn_list();
		}
	});
}
