/**
 * body 태그의 onload 이벤트에 들어갈 이벤트 핸들러
 */
function documentprocess_onload() {
	classprocess_ext();
	classprocess_imageframeclick();
	classprocess_imageframeclickdialog();
	classprocess_imageresizemobile();
}

/**
 * ext 클래스를 가진 a 태그에 대해 target을 blank 를 지정해줌. XHTML 1.1 을 위함
 * JQuery 용 스크립트
 */
function classprocess_ext() {
	$('a.ext').filter(function (index) {
		return this.target == "";
	}).attr('target', '_blank');
/*
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i = 0; i < anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") && anchor.getAttribute("class") == "ext") {
			anchor.target = "_blank";
		}
	}
*/
}

/**
 * imageframeclick 클래스를 가진 img 태그에 대해 클릭시 새 창으로 해당 이미지를 보여주는 스크립트를 넣어줌.
 * JQuery 용 스크립트
 */
function classprocess_imageframeclick() {
	$('img.imageframeclick').filter(function (index) {
		return this.title.length == 0;
	}).attr('title', '클릭하시면 큰 이미지를 보실 수 있습니다.')

	$('img.imageframeclick').click(function(){ window.open(this.src); return false;});
}


/**
 * imageframeclickdialog 클래스를 가진 img 태그에 대해 클릭시 click_imageframeclickdialog() 를 호출.
 * JQuery 용 스크립트
 */
function classprocess_imageframeclickdialog() {
	$('img.imageframeclickdialog').filter(function (index) {
		return this.title.length == 0;
	}).attr('title', '클릭하시면 대화창에서 큰 이미지를 보실 수 있습니다.')

	$('img.imageframeclickdialog').click(function(){
		click_imageframeclickdialog(this);
		return false;
	});
}

/**
 * m.solanara.net 으로 접속한 경우 imageresizemobile 클래스를 가진 img 태그에 대해 이미지 크기를 줄이고, 클릭시 새 창으로 해당 이미지를 보여주는 스크립트를 넣어줌.
 * JQuery 용 스크립트
 */
function classprocess_imageresizemobile() {
	if (window.location.hostname.indexOf("m.solanara.net") >= 0) {
		$('img.imageresizemobile').filter(function (index) {
			return this.title.length == 0;
		}).attr({
			title: "클릭하시면 큰 이미지를 보실 수 있습니다.",
			width: "100"
		});

		$('img.imageresizemobile').click(function(){ window.open(this.src); return false;});
	}
}

/**
 * url로 winname 이름을 가진 width, height 크기의 새창을 띄움. 사이즈 조절 불가.
 */
function openwin3(url, winname, width, height) {
	wleft = (window.screen.width - width) / 2;
	wtop = (window.screen.height - height) / 2;
	wi = window.open(url, winname, "width=" + width + ",height=" + height + ",top=" + wtop + ",left=" + wleft + ",directories=no,fullscreen=no,location=no,menubar=no,resizable=no,scrollbars=no,status=no,titlebar=no,toolbar=no");
	if (wi == null) {
		alert("팝업창이 허용되어있지 않아 팝업창을 열 수 없습니다. 팝업을 허용하신 후 다시 시도해 주십시오.");
	} else {
		wi.focus();
	}
}

/**
 * SNS로 현재 페이지의 URL과 제목을 스크랩. 현재는 트위터와 페이스북, 미투데이만 지원.
 */
function open_sns(snsid) {
	if (snsid == "twitter") {
		// http://dev.twitter.com/pages/tweet_button
		openwin3("http://twitter.com/share?text=" + encodeURIComponent(document.title) + "&via=" + encodeURIComponent("Solanara") + "&url=" + encodeURIComponent(location.href), "solanara_twitter", 640, 400);
	} else if (snsid == "facebook") {
		// http://developers.facebook.com/docs/share
		openwin3("http://www.facebook.com/sharer.php?u=" + encodeURIComponent(location.href) + "&t=" + encodeURIComponent(document.title), "solanara_facebook", 900, 500);
	} else if (snsid == "me2day") {
		// http://dev.naver.com/openapi/apis/me2day/newpostlink_api
		// http://me2day.net/plugins/post/new?new_post[body]=%22body+here%22:http://me2day.net&new_post[tags]=tag1+tag2
		window.open("http://me2day.net/plugins/post/new?new_post[body]=%22" + encodeURIComponent(document.title) + "%22:" + encodeURIComponent(location.href) + "&new_post[tags]=" + encodeURIComponent("솔라나라"), "solanara_me2day", "");
	}
}

