function fnToggle(){
	var ob_td = document.getElementById('film');
	ob_td.style.backgroundColor='#fff';
}
//var gx_vodloader;
function loadPlayer(i_https, gs_vod_server, gs_fn, gs_skin_path, gi_video_w, gi_video_h, fileLink, params, movieType){
	$("#NACLIPS_PLAYER").remove();
	gx_vodloader = new cx_ncsloader('html5');
	//gx_vodloader = new cx_ncsloader('auto','auto');

	//var i_ret = gx_vodloader.burnPlayer('id_player',gi_video_w,parseInt(gi_video_w*9/16),'NACLIPS_PLAYER',document);
	var i_ret = gx_vodloader.burnPlayer('film',gi_video_w,gi_video_h,'NACLIPS_PLAYER',document);
	if     (i_ret == 0) alert('abnormal layer options');
	else if(i_ret  < 0) alert('burning player failed.');
	else{
		//add Params ///////////////////////////////////////
		gx_vodloader.addParam("BaseLayerID"  ,gx_vodloader.getLayerId());
		gx_vodloader.addParam("FileName"     ,gs_vod_server+gs_fn);
		gx_vodloader.addParam("SubParam"     ,params);
		//console.log("1. " + gs_vod_server + gs_fn);
		//console.log("2. " + gs_skin_path);
		//console.log("3. " + gi_video_w);
		//console.log("4. " + gi_video_h);

		gx_vodloader.addParam("title_url"    ,fileLink);

		//gx_vodloader.addParam("image_subpath" ,gs_thumb_path);//+"/demo");
		//gx_vodloader.addParam("title_url"    ,"http://192.168.7.104/first_fly/nstreamer/image/water_title.jpg");
		//gx_vodloader.addParam("ShowControls" , 0);

		gx_vodloader.addParam("AutoStart"    ,0); //처음 시작시 자동 플레이 extender mode일때는 무효화됨.
		//gx_vodloader.addParam("IsRepeatPlay" ,1); //모든 목록재생이 완료 되면 처음목록 부터 다시 재생
		//gx_vodloader.addParam('autoNext'     ,1); //자동으로 다음 동영상 재생
		//gx_vodloader.addParam("IsTitleSnap"  ,0);
		gx_vodloader.addParam("IsTitleSnap"  ,1);

		//gx_vodloader.addParam("Mute",1);

		//gx_vodloader.addParam("CurPosition",10);
		//gx_vodloader.addParam("EndPos",20);

		//HTML5 Player Only ///////////////////////////////
		gx_vodloader.addParam('skin_path'      , gs_skin_path);
		gx_vodloader.addParam('fire_status_ex'  , true);
		gx_vodloader.addParam('fire_subtitle_ex', true);
		//gx_vodloader.addParam('show_title'      , true);
		//gx_vodloader.addParam('fire_error_ex'   , true);
		gx_vodloader.addParam('show_title'      , true);
		//gx_vodloader.addParam('fire_error_ex'   , true);

		gx_vodloader.addParam('enable_vod_ssl'  , i_https==1?true:false); //https protocol ///////////////////////////////////////////////////////////

		//gx_vodloader.addMultiBpsMenu('1080P');
		//gx_vodloader.addMultiBpsMenu('720P');
		//gx_vodloader.setMultiBpsIdx(0);

		//gx_vodloader.addParam('is_load_thumbnails'  , true);
		//gx_vodloader.addParam('is_load_frame_index' , true);
		gx_vodloader.addParam('is_load_thumbnails' , false);
		gx_vodloader.addParam('is_load_frame_index' , false);

		// gx_vodloader.showCtrlIcon("play"       , false);
		// gx_vodloader.showCtrlIcon("multibps"   , false);
		// gx_vodloader.showCtrlIcon("repeat"     , true);
		// gx_vodloader.showCtrlIcon("speed"      , false);
		/*if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
			gx_vodloader.showCtrlIcon("full"       , false);
		}*/

		//gx_vodloader.showCtrlIcon("volume"     , false);
		// gx_vodloader.showCtrlIcon("jamak"      , false);
		// gx_vodloader.showCtrlThumbs(false);
		// gx_vodloader.showPlayer(false);

		//gx_vodloader.setWatermark('/first_fly/html5/image/player_wrap.png','http://nexpoly.co.kr', 4);
		//gx_vodloader.setWatermark('/first_fly/image/wmark.png','http://nexpoly.co.kr', 5);
		//gx_vodloader.setWatermarkOption('size','100%');
		//gx_vodloader.setWatermarkOption('margin',4,4);

		//gx_vodloader.setInitPos(17);

		//gx_vodloader.setTrimming(40,80);
		//gx_vodloader.setTrimmingOption('reset_on_next',true);

		//gx_vodloader.setBackgroundMessage("음악을 재생중 입니다.","잠시 멈춤");

		//gx_vodloader.addSubtitle('/sect01/track_samp.srt', 'English');
		//gx_vodloader.addSubtitle('/sect01/seeking.a.friend.for.the.end.of.the.world.2012.srt', 'English');


		//gx_vodloader.setSubtitleDisablingLabel("무자막");
		//gx_vodloader.addSubtitle('/sect01/demo_k.srt', '한국어');
		//gx_vodloader.addSubtitle('/sect01/demo_e.srt', 'English');
		//gx_vodloader.setSubtitleFontSizeRatio(16);
		if(movieType == 'M') {
			if($("#subtitle").length > 0 && $("#subtitle").find("span").length > 0) {
				gx_vodloader.setSubtitlePaddingBottom(50);
				gx_vodloader.setSubtitleDisablingLabel("무자막");
				$("#subtitle").find("span").each(function(){
					var subtitle_file = gs_fn.substr(0,6) + $(this).data('file') + '.srt';
					var subtitle_name = $(this).text();
					gx_vodloader.addSubtitle(subtitle_file, subtitle_name);
				});
			}
		}
		

		//gx_vodloader.setBackgroundAudio(gs_vod_server+'/audio_files/1c39d0273197d813bab88e560769ea85.m4a', 0);
		//gx_vodloader.setBackgroundAudioOption('repeat' , true);
		//gx_vodloader.setBackgroundAudioOption('sync_video', true);

		//gx_vodloader.x_player.s_info_url ='http://www.mizzim.com';
		//gx_vodloader.x_player.b_disable_info = true;

		//gx_vodloader.setPacketRate(0);
		//gx_vodloader.setBuffering(i_presec, i_check_interval); / i_presec초 분량의 패킷이 준비 되지 않으면 버퍼링(버퍼링 패킷 분량은 서버의 초기버퍼링 초시간), i_check_interval간격으로 체크
		//gx_vodloader.setBuffering(60,0); //

		//gx_vodloader.setFuidSrcIdx(0);
		var chk = false;
		var i_rtn = gx_vodloader.loadPlayer();
		if(i_rtn == 1){
			if(gx_vodloader.curr_player == 'html5'){
				//naclips player : extra status change event for HTML5 /////////////////////////////////////////
				document.addEventListener("naclips_status_change", function(evt){
					// evt.detail.layer_id, evt.detail.status, evt.detail.option
					//console.log("evt.detail.status : " + evt.detail.status);
					if(evt.detail.status == 'play'){ // emulate Media Open Event ///////////////////////////////
						// i_https, gs_vod_server, gs_fn, gs_skin_path, gi_video_w, gi_video_h, fileLink, params, movieType
						var s_media_src = gx_vodloader.s_media_src;
						var s_serv_param = gx_vodloader.s_serv_param;
						//var params = s_serv_param.split('|');
						//var ip = params[0];
						//if(ip == '218.39.199.97') {
						if(!chk) {
							console.log('chk - 1');
							$.ajax({
								url: "/indie/naclicpsCheck.do",
								type: "get",
								data: { "src" : s_media_src, "param" : s_serv_param },
								async: false,
								success: function(data){
									//console.log(data);
									if(parseInt(data.result) < 1) {
										//gx_vodloader.pause();
										gx_vodloader.unload();
										if(data.result == '0') {
											alert('영상 정보가 존재하지 않습니다.');
										} else if(data.result == '-1') {
											alert('먼저 로그인 하세요.');
											location.href = '/indie/login.do';
										} else if(data.result == '-2') {
											alert('회원ID가 일치하지 않습니다.');
										} else if(data.result == '-3') {
											alert('영화 정보가 존재하지 않습니다.');
										} else if(data.result == '-4') {
											alert('회원 정보가 존재하지 않습니다.');
										} else if(data.result == '-5') {
											alert('비공개 상태인 컨텐츠입니다.');
										} else if(data.result == '-6') {
											alert('정보수정 페이지에서 본인인증 후 확인할 수 있는 컨텐츠입니다.');
										} else if(data.result == '-7') {
											alert('연령제한이 있는 컨텐츠입니다.');
										} else {
											alert('플레이어를 실행할 수 없습니다.');
										}
										//location.reload();
										location.replace(location.href);
									}
								},
								error: function(){
									//alert("error");
								}
							});
						}
						chk = true;
						//}
						//console.log(gx_vodloader);
						//console.log(gx_vodloader.is_mobile() + " : " + gx_vodloader.is_android() + " : " + gx_vodloader.is_ios() + " : " + gx_vodloader.is_ipad() + " : " + gx_vodloader.is_ipod_phone() + " : " + gx_vodloader.is_windows());
						//console.log(gx_vodloader);
						/*$.getJSON("/common/checkOverseasIp.do", function(e){
							var yn = e.yn;
							var ip = e.ip;
							console.log('ip : ' + ip);
							console.log('yn : ' + yn);
							if(yn == 'Y') {
								if(gx_vodloader != null && gx_vodloader != undefined) gx_vodloader.pause();
								if($("body").data('yn') == undefined) {
									alert('해외 IP인 경우 플레이어를 실행할 수 없습니다.');
									$("body").data('yn', yn);
								}
							}
						});*/
					}
					//if(evt.detail.status == 'ended'){
						// 플레이 종료
					//	;//window.setTimeout(function(){gx_vodloader.play();},500);
					//}

					//if(evt.detail.status == 'accelerate') alert('accelerate : ' + evt.detail.option);
					/*
					////////////////////////////////////////////////
					if(evt.detail.status == 'loadedmetadata'){ // emulate Media Open Event ///////////////////////////////
						try{
							if(xvnt_OpenStatusChange) xvnt_OpenStatusChange(2,evt.detail.layer_id); //opened
						}catch(e){};
					}
					else if(evt.detail.status == 'change_media'){

					}
					else if(evt.detail.status == 'play_next'){
						gx_vodloader.setBackgroundAudioOption('origin_volume', 0);
					}
					*/
					//if(evt.detail.status.substr(0,4) == 'bga_') alert(evt.detail.status);
				//else if(evt.detail.status == 'change_bandwidth')
					////////////////////////////////////////////////
				}, false);

				//naclips player : extra subtitle change event for HTML5 /////////////////////////////////////////
				// document.addEventListener("naclips_subtitle_change", function(evt){
				// 	////////////////////////////////////////////////
				// 	if(evt.detail.layer_id == gx_vodloader.getLayerId()){
				// 		//var ob_spn = document.getElementById('ex_jamak');
				// 		//if(ob_spn){
				// 		//	var s_text = evt.detail.text.replace(/\<br\>/g, " ").replace(/(<([^>]+)>)/ig,"");
				// 		//	ob_spn.innerHTML = evt.detail.start +" &raquo; "+ evt.detail.end + ' : '+s_text;
				// 		//}
				// 	}
				// 	////////////////////////////////////////////////
				// }, false);

				//naclips player : error event /////////////////////////////////////////////////
				document.addEventListener("naclips_error", function(e){
					//alert("error > "+e.detail.code+" : "+e.detail.message);
				}, false);

				//naclips player : error event /////////////////////////////////////////////////
				document.addEventListener("naclips_watermark_click", function(e){
					alert("watermark > "+e.detail.text);
				}, false);

				gi_video_w = $(".movie_view_screen").width();
				gi_video_h = $(".movie_view_screen").height();
				gx_vodloader.resize(gi_video_w,gi_video_h);
			}
		}
		else if(i_rtn == -2) alert('VOD-Query Interface Failed!!');
		else if(i_rtn ==  0) alert('Load Player Failed!!');
	}
}
function xvnt_EndInitEx(layer_id){ gx_vodloader.initVdoSpace(); } // important
$(document).ready(function(){
	$(".movie_view_screen").on("resize", function() {
		/* works when this plugin is added */
		console.log('resize !!');
		gx_vodloader.resize($(".movie_view_screen").width(),$(".movie_view_screen").height());
		//gx_vodloader.resize(document.getElementById("film").getBoundingClientRect().width,document.getElementById("film").getBoundingClientRect().height);
	});
});


function view(year ,name , movieExt , file , val , seq, params, movieType){
	$.getJSON("/common/getIp.do", function(g){
		var ip = g.ip;
		var yn = g.yn;
		console.log('g - ip : ' + ip);
		console.log('g - yn : ' + yn);
		if(yn == null) {
			console.log('yn is null');
			$.ajax({
				"url": "https://api.ip.pe.kr/json/",
				"method": "GET"
			}).done(function (data) {
				console.log("ip: "+data.ip);
				console.log("country_code: "+data.country_code);
				$.getJSON("/common/saveIp.do?ip="+data.ip+"&code="+data.country_code, function(s){
					ip = s.ip;
					yn = s.yn;
					console.log('s - ip : ' + ip);
					console.log('s - yn : ' + yn);
					if(yn == 'N') {
						call_player(year ,name , movieExt , file , val , seq, ip+'|'+params, movieType);
					} else {
						alert('해외 IP인 경우 플레이어를 실행할 수 없습니다.');
					}
				});
			}).fail(function(){
				call_player(year ,name , movieExt , file , val , seq, ip+'|'+params, movieType);
			});
		} else if(yn == 'N'){
			call_player(year ,name , movieExt , file , val , seq, ip+'|'+params, movieType);
		} else {
			alert('해외 IP인 경우 플레이어를 실행할 수 없습니다.');
		}
	});
}

function call_player(year ,name , movieExt , file , val , seq, params, movieType)
{
	var c = "https://indieground.kr/";
	var fileLink = c + "/movieImgFolder/poster-login.jpg";
	if(val == false) fileLink = c + "/movieImgFolder/poster-login.jpg";
	else fileLink = c + "/" + file;
	/*
	// 와우자 플레이어
	$('#film_youtube').hide();
	$("#film_youtube").empty();
	$('#film').show();
	WowzaPlayer.create("film", {
		"license": "PLAY1-cB7xR-4m4yB-hW6b9-6AH48-DNxR6",
	//		"sourceURL":"http://115.68.202.205:1935/"+year+"/"+movieExt+":"+name+"."+movieExt+"/playlist.m3u8",
			"sourceURL":"https://movie.indieground.kr:443/"+year+"/"+movieExt+":"+name+"."+movieExt+"/playlist.m3u8",
			"autoPlay": false,
		"loop": false,
			"mute": false,
			"volume": 75, // 0 ~ 100
		"posterFrameURL": fileLink,
		"uiShowPlaybackControls": val
		});
	*/

	// 나클립스 플레이어
	$("#film").empty();
	var gs_fn = "/"+year+"/"+name+"."+movieExt;
	var i_https = 1;
	if(i_https==1){
		var gs_vod_server = "assp://movie.indieground.kr";
	}else{
		var gs_vod_server = "assp://115.68.202.205"
	}
	var gs_skin_path  = "/naclips/skin/neon_blue";
	var gi_video_w = $(".movie_view_screen").width();
	var gi_video_h = $(".movie_view_screen").height();
	loadPlayer(i_https, gs_vod_server, gs_fn, gs_skin_path, gi_video_w, gi_video_h, fileLink, params, movieType);
}

function initLayerPosition(){
	var width = 400;
	var height = 500;
	var borderWidth = 5;

	// 위에서 선언한 값들을 실제 element에 넣는다.
	element_layer.style.width = width + 'px';
	element_layer.style.height = height + 'px';
	element_layer.style.border = borderWidth + 'px solid';

	element_layer.style.left = (((window.innerWidth || document.documentElement.clientWidth) - width)/2 - borderWidth) + 'px';
	element_layer.style.top = (((window.innerHeight || document.documentElement.clientHeight) - height)/2 - borderWidth) + 'px';
}

function fncLayerClose(){
	$("#filmMakerLayer").hide();
}

function nullcheck(val){
	if(val == null)	return "";
	else if(val == "undefined") return "";
	else if(val == undefined) return "";
	else  return val;
}

var ddd ="";
function viewComp(code){
	$.ajax({
		type : "get",
		url  : "https://kobis.or.kr/kobisopenapi/webservice/rest/company/searchCompanyInfo.json?key=3792ad590415185202dce2b5a388afb5&companyCd="+ code,
		data : "",
		dataType: "json",
		success : function(data) {
			$("#filmMakerLayer").empty();
			var d = data['companyInfoResult'];
			var a = d['companyInfo'];

			var html = "";
			html += "<div class=\"popCon movie_production_crew library_view_box\"style=\"max-width:600px;\">";
			html += "<button type=\"button\" class=\"btn-pop-close\" onClick=\"fncLayerClose();\">닫기</button>";
			html += "<h2>배급사 정보</h2>";
			html += "<div class=\"boxCon\">";
			html += "<table style='width:100%; border-radius:15px 0;'>";
			html += "<tr><th>코드</th><td>" + a['companyCd'] + "</td></tr>";
			html += "<tr><th>회사명</th><td>" + a['companyNm'] + "</td></tr>";
			html += "<tr><th>회사명(영어)</th><td>" + nullcheck(a['companyNmEn']) + "</td></tr>";
			html += "<tr><th>대표자</th><td>" + a['ceoNm'] + "</td></tr>";
			var hh = "";
			var h1 = "";
			for(var i = 0; i < a['parts'].length; i++){
				h1 = a['parts'][i];
				hh += h1['companyPartNm'] + ",";
			}

			html += "<tr><th>분류</th><td>" + hh.slice(0,-1) + "</td></tr>";
			html += "</table>";
			html += "</div>	";
			html += "</div>";
			$("#filmMakerLayer").append(html);

			$("#filmMakerLayer").show();
		}
	});
}

function isMobile()
{
	var agent = navigator.userAgent.toLowerCase();
	if (/mobi|Android|android|webos|iphone|ipad|ipod|blackberry|iemobile|opera mini/i.test(agent)) {
		return 'Y';
	}
	return 'N';
}

function getDevice()
{
	var agent = navigator.userAgent.toLowerCase();
	if (/Android/i.test(agent)) return 'Android';
	else if(/webos/i.test(agent)) return 'WebOS';
	else if(/iphone/i.test(agent)) return 'iPhone';
	else if(/ipad/i.test(agent)) return 'iPad';
	else if(/ipod/i.test(agent)) return 'iPod';
	else if(/blackberry/i.test(agent)) return 'BlackBerry';
	else if(/iemobile/i.test(agent)) return 'IEMobile';
	else if(/opera mini/i.test(agent)) return 'Opera Mini';
	else return 'Other';
}

function getBrowser()
{
	var agent = navigator.userAgent.toLowerCase();
	if(/trident/i.test(agent)) return 'MS IE';
	else if(/edge/i.test(agent)) return 'MS Edge';
	else if(/edg/i.test(agent)) return 'Edge (chromium based)';
	else if(/whale/i.test(agent)) return 'Whale';
	else if(/chrome/i.test(agent)) return 'Chrome';
	else if(/opr/i.test(agent) || /opera/i.test(agent)) return 'Opera';
	else if(/firefox/i.test(agent)) return 'Mozilla Firefox';
	else if(/safari/i.test(agent)) return 'Safari';
	else return 'Other';
}