$(function() {
	$(".overImage").each(function() {
		var name = $(this).parent().parent().attr('name');
		if (!name) name = '_';
		// alert(name + " " + $(this).attr('name'));
			if (name.indexOf($(this).attr('name')) == 0) {
				var targetName = $(this).attr('name');
				overImageView($(this),true);	
				$(this).removeClass("overImage");
			}
			if ($(this).attr('over') == "yes") {
				var targetName = $(this).attr('name');
				overImageView($(this),true);
			}
		});
	$(".overImage").mouseover(function() {
		overImageView($(this),true);
	}).mouseout(function() {
		if($(this).attr('over') != "yes")
		{
			overImageView($(this),false);
		}
	});
});

function overImageView(obj,view)
{
	if(obj.attr('src'))
	{
		var file = obj.attr('src').split('/');
		var filename = file[file.length - 1];
		var path = '';
		for (i = 0; i < file.length - 1; i++) 
		{
			path = (i == 0) ? path + file[i] : path + '/' + file[i];
		}
		if(view == true)
		{
			obj.attr('src',	path + '/' + filename.replace('_off', '_on'));
		}
		else
		{
			obj.attr('src',	path + '/' + filename.replace('_on', '_off'));
		}
	}
}

function viewContent(contentNum , page)
{
	if(!page) page = 0;
	
	popup(BASEURL + 'content/viewer/'+contentNum+'/'+page+'/',1012,706,'viewer');
}

function addWishlist(url)
{
	if(url)
	{
		$.getJSON(url, function(data) {
			if(data.script)
			{
				eval(data.script);
			}
			
			if(data.html)
			{
				$("#wishlist_box").html(data.html);
			}
		});
	}
}

function buyContent(url)
{
	if(url)
	{
		$.getJSON(url, function(data) {
			if(data.script)
			{
				eval(data.script);
			}
		});
	}
}

function viewVolume()
{
	if($(".volume_list").is(':visible') == true)
	{
		$(".volume_list").hide();
	}
	else
	{
		$(".volume_list").show("fast");
	}
	
}


//로그인 폼 체크

function Loginformcheck()
{
	var frm = document.loginForm;
	if(frm.userid.value==""){
		alert("아이디를 입력하세요");
		frm.userid.focus();
		return false;
	}
	if(frm.password.value==""){
		alert("비밀번호를 입력하세요");
		frm.password.focus();
		return false;
	}
	frm.submit();
	return;
}

//엔터 로그인 체크
/*
function EnterCheck()
{
	if(event.keyCode ==13) {
		var frm = document.loginForm;
		if(frm.userid.value==""){
			alert("아이디를 입력하세요");
			frm.userid.focus();
			return false;
		}
		if(frm.password.value==""){
			alert("비밀번호를 입력하세요");
			frm.password.focus();
			return false;
		}
		frm.submit();
		return;
	}
}
*/
//엔터 로그인 체크
$(function(){
	$("#input_id:password").keydown(function(evt){
		if (evt.keyCode==13)
		{
			var frm = document.loginForm;
			if(frm.userid.value==""){
				alert("아이디를 입력하세요");
				frm.userid.focus();
				return false;
			}
			if(frm.password.value==""){
				alert("비밀번호를 입력하세요");
				frm.password.focus();
				return false;
			}
			frm.submit();
			return;
		}
			
	});
});

$(function (){
	$(".review form a").unbind(); 
	$(".review form a").filter('[href=#]').click( 
		function()
		{ 
			var form = $(this).parent(); 
			var userid = form.find("[name=register_num]").val();
			
			if(userid)
			{
				if($.trim(form.find("[name=replay_msg]").val()) != '')
				{
					
					var options = { 
					       success     : responseJsonReply,
					       /*url         : "../include/control.php",*/
					       contentType : "application/x-www-form-urlencoded;charset=UTF-8",
					       type        : "post", /* get, post */
					       dataType    : "json" /* xml, html, script, json */
					   };					
					form.ajaxSubmit(options);	
				}
				else
				{
					form.find("[name=replay_msg]").focus();
					alert('내용을 입력하세요.');
				}
				
				form.find("[name=replay_msg]").val("");

			}
			else
			{
				alert('로그인 후 이용하실 수 있습니다.');
			}
			
			return false;
		}
	);
});

function responseJsonReply(json, status)
{
	if (status == 'success')
	{
		if(json.html)
		{
			$('.review_list').html(json.html);
		}
		if(json.script)
		{
			eval(json.script);
		}	
	}
	else
	{
		alert(status);
	}
	return false;
}

function commentControl(url,conf)
{
	if(conf == 'delete')
	{
		if(confirm('삭제 하시겠습니까?'))
		{
			$.getJSON(url,responseJsonReply);
		}
		
	}
	else
	{
		$.getJSON(url,responseJsonReply);
	}
}

//팝업
function popup(url,w,h,name)
{
	if(!name) name = '';
	var x = 225; 
	var y = 100;
	var value = 'width=' + w + ',height=' + h + ',status = no, scrollbars=no ,resizable=no,left=' + x + ',top=' + y;
	window.open(url,'',value);
}

//팝업아이디 패스워드
function id_search(url,w,h)
{
	popup(url,w,h);
}

//달력
$(function() 
{
// $.datepick.setDefaults({useThemeRoller: true});
 $('#start_date').datepick();
 $('#end_date').datepick();
 $('#inlineDatepicker').datepick({onSelect: showDate});
});

function showDate(date) {
 alert('The date chosen is ' + date);
}

//모아보기,찜한목록,책갈피,최근감상 목록

function form_check(formname,name)
{
	var choiceOjb = document.getElementsByName(name+"[]");
	var check_cnt = 0;
	
	for(var i=0;i<choiceOjb.length;i++){
		if (choiceOjb[i].checked == true) check_cnt++;
	}

	if (!check_cnt) {
		alert("삭제할 게시물을 선택해주세요");
		return false;
	}

	if(confirm("정말로 삭제 하시겠습니까?")){
		var form = eval("document."+formname);
		form.submit();
	}
	return;
}

function resize(x,y)
{ 
	x=eval(x);
	y=eval(y);
	
	x = x + 17;
	y = y + 67;
	
	if(screen.width < self.screenLeft  + x || screen.height < self.screenTop  + y)
	{
		//moveTo(screen.width - x,screen.height - y);
		moveTo(0,0);
	}
	
	if (navigator.appName.indexOf("Microsoft") != -1) 
	{
		if(navigator.appVersion.indexOf('MSIE 7.0') != -1)
		{
			//익스 7
			resizeTo(x,(y+25));
		}
		else
		{
			//익스 6
			resizeTo(x,y);
		}
	}else
	{
		if(navigator.appVersion.indexOf("Chrome") != -1) 
		{
			//Chrome
			resizeTo(x,(y));
		}else
			{
			//ff
			resizeTo(x,(y+30));
		}		
	
	}
	//alert(window.screenTop);
	//if (screen.width || screen.height)
	
 }
 
 function changeUrl(url)
 {
 	document.location.href = url;
 }
 
function viewWeekBest(url,category)
{
	if(url)
	{
		$.get(url, function(data) {
			$("#weekBestList").html(data);
		});
	}
	if(category)
	{
		overImageView($(".best_list").find("[name=best_000]"),false);
		$(".best_list").find("[name=best_000]").attr('over','');
		
		overImageView($(".best_list").find("[name=best_100]"),false);
		$(".best_list").find("[name=best_100]").attr('over','');
		
		overImageView($(".best_list").find("[name=best_101]"),false);
		$(".best_list").find("[name=best_101]").attr('over','');
		
		overImageView($(".best_list").find("[name=best_102]"),false);
		$(".best_list").find("[name=best_102]").attr('over','');
		
		overImageView($(".best_list").find("[name=best_"+category+"]"),true);
		$(".best_list").find("[name=best_"+category+"]").attr('over','yes');
	}
	else
	{
		overImageView($(".best_list").find("[name=best_000]"),true);
		$(".best_list").find("[name=best_000]").attr('over','yes');
	}
}
 
 //공유 박스 스크립트 
function viewShareBox()
{
	if($(".share_sub_box").is(':visible') == true)
	{
		overImageView($(".btn_share"),false);
		$(".share_sub_box").hide();
	}
	else
	{
		overImageView($(".btn_share"),true);
		$(".share_sub_box").show();
	}
}

//퍼가기 부분
function fbs_click(u,t) {window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','resizable=yes,toolbar=0,status=0,width=626,height=436');return false;}
function tweet_click(u,t) {window.open('https://twitter.com/share?url='+encodeURIComponent(u)+'&text='+encodeURIComponent(t),'sharer','resizable=yes,toolbar=0,status=0,width=626,height=436');return false;}
function yozm_click(u,t) {window.open('http://yozm.daum.net/home?m='+encodeURIComponent(t+' '+u));return false;}
function csp_click(u,t) {window.open('http://csp.cyworld.com/bi/bi_recommend_pop.php?url='+encodeURIComponent(u), 'recom_icon_pop', 'width=400,height=364,scrollbars=no,resizable=no');return false;}
function me2day_click(u,t,d,img)
{
	var bodyText = '';
	bodyText += encodeURIComponent('"'+t+'":'+img+' : ');
	bodyText += encodeURIComponent('"'+d+'":'+u) +encodeURIComponent(' '+u) ;
	window.open('http://me2day.net/plugins/post/new?new_post[body]='+bodyText+'&new_post[tags]='+encodeURIComponent('망가짱 mangazzang 넥스큐브 nexcube'));
	return false;
}

//베스트 리스트 마우스 셋
$(function(){
	viewWeekBest();
	$(".share_sub_box").hide();
});


//팝업 자동 리사이즈
function setWindowResize() {
 var thisX = parseInt(document.body.scrollWidth);
 var thisY = parseInt(document.body.scrollHeight);
 var maxThisX = screen.width - 50;
 var maxThisY = screen.height - 50;
 var marginY = 0;
// alert(thisX + "===" + thisY);
 //alert!("임시 브라우저 확인 : " + navigator.userAgent);
 // 브라우저별 높이 조절. (표준 창 하에서 조절해 주십시오.)
 if (navigator.userAgent.indexOf("MSIE 6") > 0) marginY = 45;        // IE 6.x
 else if(navigator.userAgent.indexOf("MSIE 7") > 0) marginY = 75;    // IE 7.x
 else if(navigator.userAgent.indexOf("MSIE 8") > 0) marginY = 75;    // IE 8.x
 else if(navigator.userAgent.indexOf("MSIE 9") > 0) marginY = 80;    // IE 9.x
 else if(navigator.userAgent.indexOf("Firefox") > 0) marginY = 50;   // FF
 else if(navigator.userAgent.indexOf("Opera") > 0) marginY = 30;     // Opera
 else if(navigator.userAgent.indexOf("Chrome") > 0) marginY = 70;     // Chrome
 else if(navigator.userAgent.indexOf("Netscape") > 0) marginY = -2;  // Netscape


 if (thisX > maxThisX) {
  thisX = maxThisX;
 }
 if (thisY > maxThisY - marginY) {
  thisX += 19;
  thisY = maxThisY - marginY;
 }
 window.resizeTo(thisX+10, thisY+marginY);

}

//--> 

