$(function(){

	/*$(".bestPerGrade").each(function(){
		var act   = $(this).attr("act");
		var grade = $(this).attr("grade");
		$.post("search/do_exe.php","tm="+tm+"&act="+act+"&grade="+grade+"&msearch="+msearch,function(rs){
			$(".bestPerGrade[grade='"+grade+"']").html(rs);
		});
	});*/

	if(_uid!=''){

		$.post("search/do_exe.php","tm="+tm+"&act=lastMV&msearch="+msearch,function(rs){
			if(rs=='') $(".lastMV").parent().hide();
			else $(".lastMV").html(rs);
		});

		$.post("search/do_exe.php","tm="+tm+"&act=lastIncorrect&msearch="+msearch,function(rs){
			if(rs=='') $(".lastIncorrect").parent().hide();
			else $(".lastIncorrect").html(rs);
		});

		$.post("search/do_exe.php","tm="+tm+"&act=lastBookmark&msearch="+msearch,function(rs){
			if(rs=='') $(".lastBookmark").parent().hide();
			else $(".lastBookmark").html(rs);
		});

	}

	$.post("search/do_exe.php","tm="+tm+"&act=three&msearch="+msearch,function(rs){
		if(rs=='') $(".three").parent().hide();
		else $(".three").html(rs);
	});

	$.post("search/do_exe.php","tm="+tm+"&act=top5week&msearch="+msearch,function(rs){
		if(rs=='') $(".top5week").parent().hide();
		else $(".top5week").html(rs);
	});

	$.post("search/do_exe.php","tm="+tm+"&act=top5month&msearch="+msearch,function(rs){
		if(rs=='') $(".top5month").parent().hide();
		else $(".top5month").html(rs);
	});

	if(msearch!=''){
		$.post("search/do_exe.php","tm="+tm+"&act=relConcept&msearch="+msearch,function(rs){
			if(rs=='') $(".relConcept").parent().hide();
			else $(".relConcept").html(rs);
		});
		$.post("search/do_exe.php","tm="+tm+"&act=relType&msearch="+msearch,function(rs){
			if(rs=='') $(".relType").parent().hide();
			else $(".relType").html(rs);
		});
		$.post("search/do_exe.php","tm="+tm+"&act=totalsearch&msearch="+msearch+"&sType="+sType,function(rs){
			if(rs=='') $(".totalsearch").parent().hide();
			else $(".totalsearch").html(rs);
		});

	}

});

//<![CDATA[
var sp = StarPlayerApp;
sp.license = "2C614836-7CA3-4155-8818-24618F35E79B";
//sp.license = "72C6BF6C-CDDA-4C72-BF4D-C6BE6B3CD0E1";
sp.version = "1.0.0";
sp.android_version = "1.0.0";
sp.ios_version = "1.0.0";
sp.pmp = "false";
var app = function(info_url) {
	sp.executeApp(info_url);
}
//]]>

$(function(){
	$(document).on("click",".eimark",function(){
		if(_uid==''){alert("로그인 후 영상을 볼 수 있습니다.");return false;}
		var sign = $(this).attr('sign');
		var list = $(this).attr('list');
		var uid  = $(this).attr('pid');
		var lid  = $(this).attr('lid');
		var itn  = $(this).attr('itn');

		// if(isMobile()&&!v5){
		// 	mvstart(0,sign,list,lid,uid);
		// }else{
			var title = $(this).closest("li").find(".tit").text();
			if(title) $("#hometitle").html(title);
			else $("#hometitle").html("검색학습 학습영상");
			homemov_open("/starplayer/cm_player.php?start=auto&list="+list+"&sign="+sign+"&lid="+lid+"&pid="+uid+'&itn='+itn);	//window.open("http://mssabu.net/starplayer/cm_player.php?list="+list+"&sign="+sign+"&lid="+lid+"&pid="+uid,"reading_movie","width=730,height=480,scrollbars=0");
		// }
	});
});

function mvstart(sims,sign,list,lid,uid){
		app('http://mssabu.net/starplayer/mobile/cm_streaming.php?sign='+sign+'&list='+list+'&lid='+lid+"&pid="+uid);
		return false;
}

function isMobile(){
	var UserAgent = navigator.userAgent;

	if (UserAgent.match(/iPhone|iPad|iPod|Mackintosh|Android|Windows CE|BlackBerry|Symbian|Windows Phone|webOS|Opera Mini|Opera Mobi|POLARIS|IEMobile|lgtelecom|nokia|SonyEricsson|x11;/i) != null || UserAgent.match(/LG|SAMSUNG|Samsung/) != null)
	{
		return true;
	}else{
		return false;
	}
}

function base64_encode(str) {
	return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, function(match, p1) {
		return String.fromCharCode('0x' + p1);
	}));
}

function base64_decode(str) {
	return decodeURIComponent(Array.prototype.map.call(atob(str), function(c) {
		return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
	}).join(''));
}

function urlencode(str) {
	str = (str + '').toString();
    return encodeURIComponent(str)
        .replace(/!/g, '%21')
        .replace(/'/g, '%27')
        .replace(/\(/g, '%28')
        .replace(/\)/g, '%29')
        .replace(/\*/g, '%2A')
        .replace(/%20/g, '+');
	/*str = escape(str);
	str = str.replace('+', '%2B');
	str = str.replace('%20', '+');
	str = str.replace('*', '%2A');
	str = str.replace('/', '%2F');
	str = str.replace('@', '%40');
	return str;*/
}

function urldecode(str) {
	str = str.replace('+', ' ');
	str = unescape(str);
	return str;
}
