// Weblog Page Script
// Sakura Style (http://ffxi.sakura.tv/)
// Version 20100206

// Load Sidebar Via Ajax
function loadSidebar(){
	var ajaxContent = new Ajax.Request('/blog/sidebar_1', {
		method:'get',
		onSuccess:function(ls1){
			$('blog_sidebar').innerHTML += ls1.responseText;
		},
		onComplete:function(ls1){
			var ajaxContent = new Ajax.Request('/blog/sidebar_2', {
				method:'get',
				parameters:''+new Date().getTime(),
				onSuccess:function(ls2){
					$('blog_sidebar').innerHTML += ls2.responseText;
				},
				onComplete:function(ls2){
					var ajaxContent = new Ajax.Request('/blog/sidebar_3', {
						method:'get',
						parameters:''+new Date().getTime(),
						onSuccess:function(ls3){
							$('blog_sidebar').innerHTML += ls3.responseText;
						},
						onComplete:function(ls3){
							var ajaxContent = new Ajax.Request('/blog/sidebar_4', {
								method:'get',
								onSuccess:function(ls4){
									$('blog_sidebar').innerHTML += ls4.responseText;
								},
								onComplete:function(ls4){
									$('blog_friends').innerHTML = $('bp_prepare').childNodes[1].innerHTML;
									$('blog_friends').innerHTML += $('bp_prepare').childNodes[3].innerHTML;
									Element.remove($('bp_prepare'));
								},
								onException:function(ls4){
								}
							});	
						}
					});	
				}
			});	
		}
	});	
}


// Write Calendar
function calendar() {
	$('blog_calendar').innerHTML =
		'<object data="http://ffxi.sakura.tv/files/w_calendar300.swf?xmlURL=http://ffxi.sakura.tv/blog/xml/&kc=2&fC=525252&eC=ff7db7&tC=7064de&tp=1&mf=2&link=2&tg=1" type="application/x-shockwave-flash" width="650" height="22" id="w_calendar300">'
		+'<param name="allowScriptAccess" value="always" />'
		+'<param name="movie" value="http://ffxi.sakura.tv/files/w_calendar300.swf?xmlURL=http://ffxi.sakura.tv/blog/xml/&kc=2&fC=525252&eC=ff7db7&tC=7064de&tp=1&mf=2&link=2&tg=1" />'
		+'<param name="quality" value="high" /><param name="wmode" value="transparent" />'
		+'</object>';
}


// Write Prof-Video
function pv() {
	var n3 = Math.floor(Math.random()*3) + 1;
	var pv = new Array();
	pv[0] = '';
	pv[1] = 'prof_blm';
	pv[2] = 'prof_rng';
	pv[3] = 'prof_war';
	var pvh = '/files/';
	var pvf = '.swf';
	var pvd = pvh + pv[n3] + pvf;
	
	if(pv[n3] && $('prof_video')) {
		$('prof_video').innerHTML = '<object data="'+pvd+'" type="application/x-shockwave-flash" width="150" height="120">'
			+'<param name="allowScriptAccess" value="sameDomain" />'
			+'<param name="movie" value="'+pvd+'" />'
			+'<param name="quality" value="high" />'
			+'<param name="wmode" value="transparent">'
			+'</object>';
	}
}


// Write Twitter
function twitter() {
	if($('twitter')) {
		$('twitter').innerHTML = '<object data="http://twitter.com/flash/twitter_badge.swf" type="application/x-shockwave-flash" width="176" height="176" id="twitter_widget">'
			+'<param name="movie" value="http://twitter.com/flash/twitter_badge.swf" />'
			+'<param name="flashvars" value="color1=3381759&type=user&id=122035165" />'
			+'<param name="quality" value="high" />'
			+'<param name="AllowScriptAccess" value="always" />'
			+'<param name="wmode" value="transparent" />'
			+'</object>'
			+'<div style="text-align:right"><a href="http://twitter.com/Sakura_Style" onclick="return o(this)">Twitterでフォロー</a></div>';
	}
}


// Side Menu Open/Closer
function smoc(targetMenu) {
	if ($(targetMenu).style.display == 'none') {
		$(targetMenu).style.display = 'block';
	} else {
		$(targetMenu).style.display = 'none';
	}
}


// Menu List Open/Closer
function mloc(targetMenu) {
	if ($(targetMenu).style.display == 'block') {
		$(targetMenu).style.display = 'none';
	} else {
		$(targetMenu).style.display = 'block';
	}
}


// View More Feeds
function feedsMore() {
	if($('feeds_more')) {
		$('view_more_feeds').style.display = 'none';
		$('feeds_more').style.display ='block';
	}
}


// Blog Entry Open+aas/Closer
function wo(entryId) {
	var stgt = $('as'+entryId).src;
	if (stgt.indexOf('pg') == -1) {
		var pa = "http://ffxi.sakura.tv/ssaa/dsw.cgi";
		var pg = $('id'+entryId).innerHTML;
		var p = "n";
		var cnt = "";
		var a="&&";
		var pf=navigator.platform;
		var lng=navigator.language;
		var swh=screen.width+"x"+screen.height;
		var cd=screen.colorDepth;
		var pd=screen.pixelDepth;
		var rf=document.referrer;
		var aassrc = pa+"?xx="+new Date().getSeconds()+a+"pg="+pg+a+"p="+p+a+"md=j"+a
		+"cnt="+cnt+a+"pf="+pf+a+ "lng="+lng+a+"swh="+swh+a+"cd="+cd+a+"pd="+pd+a+"rf="+rf;
		$('as'+entryId).src = aassrc;
	}
	$('em'+entryId).style.display = 'block';
	$('eo'+entryId).style.display = 'none';
	$('ec'+entryId).style.display = 'block';
	autoScroll('em'+entryId);
	return false;
}

function wc(entryId) {
	$('em'+entryId).style.display = 'none';
	$('eo'+entryId).style.display = 'block';
	$('ec'+entryId).style.display = 'none';
	setTimeout(function(){autoScroll('an'+entryId,false)},250);
	return false;
}


// Blog Comment Open/Closer
function coc(entryId) {
	if ($('bc'+entryId).style.display == 'block') {
		$('bc'+entryId).style.display = 'none';
	} else if ($('tb'+entryId).style.display == 'block') {
		$('tb'+entryId).style.display = 'none';
		$('bc'+entryId).style.display = 'block';
	} else {
		$('bc'+entryId).style.display = 'block';
	}
	return false;
}


// Blog Trackback Open/Closer
function toc(entryId) {
	if ($('tb'+entryId).style.display == 'block') {
		$('tb'+entryId).style.display = 'none';
	} else if ($('bc'+entryId).style.display == 'block') {
		$('bc'+entryId).style.display = 'none';
		$('tb'+entryId).style.display = 'block';
	} else {
		$('tb'+entryId).style.display = 'block';
	}
	return false;
}


// Focus Comment Form
function cff(form) {
	form.style.borderColor = '#282E37'; 
}


// Blur Comment Form
function cfb(form) {
	form.style.borderColor = '#77748F';
}


// On Comment Submit
ocsFlag = true;
function commentSubmit(form) {
	if(form.text.value == '') {
		if(ocsFlag == true) {
			mTarget = form.getElementsByTagName('span')[0];
			mTarget.style.color = 'red';
			mTarget.innerHTML = 'メッセージがありません！';
			ocsFlag = false;
			setTimeout(function(){mTarget.innerHTML = '';ocsFlag = true;},3000);
		}
		return false;
	} else {
		disMultiClickable(form);
		escSymb(form);
		if(form.bakecookie.checked) {
			rememberMe(form);
		}
		return true;
	}
}

// Multi-click blocker
function disMultiClickable(form) {
	form.post.disabled = true;
	msgTgt = form.getElementsByTagName('span')[0];
	msgTgt.style.color = '#525252';
	msgTgt.innerHTML = '〆(・ω・。)))カキコミ中';
	msgIndicate = setInterval(function(){msgTgt.innerHTML = '.' + msgTgt.innerHTML;},1000);
	failMsg = setTimeout(function(){clearInterval(msgIndicate);setTimeout(function(){msgTgt.innerHTML = '投稿に失敗した可能性があります。';},1000);},30000);
}


// Escape Symbols on comentform
function escSymb(target) {
	innerForm =	target.text.value;
	innerForm = innerForm.replace(/</g,'&lt;');
	innerForm = innerForm.replace(/>/g,'&gt;');
	target.text.value = innerForm;
}


// Set to Clipboard Data
function copyCb(entryId) {
	var copyData = $('tu'+entryId).value;
	clipboardData.setData("Text", copyData)
}


// Open New Window for Edit
function editEntry(entryId) {
	if(!isNaN(entryId)) {
		window.open('/mt/mt.cgi?__mode=view&_type=entry&id='+entryId+'&blog_id=6');
	}
}


// Write Veoh Video on HS
var fKey = /Macintosh/.test(ua) ? 'command' : 'Ctrl';
function writeVideo(veohID,height) {
	var width = '540';
	if(!height) var height = '374';
	var objSrc = 'http://www.veoh.com/videodetails2.swf?player=videodetailsembedded&type=v&permalinkId='+veohID+'&id=anonymous';
	var code = '<script type="text/javascript">';
	code += 'var '+veohID+' = new SWFObject("'+objSrc+'", "embed'+veohID+'", "'+width+'", "'+height+'", "8", "#FFFFFF");';
	code += veohID+'.addParam("wmode", "transparent");';
	code += veohID+'.addParam("allowFullScreen", true);';
	code += veohID+'.addParam("pluginspage", "http://www.macromedia.com/go/getflashplayer");';
	code += '</script>';
	code += '<div style="text-align:center">';
	code += '<a id="'+veohID+'" class="highslide" href="http://www.veoh.com/videos/'+veohID+'" onclick="return ocVB(this,'+veohID+',\'Veoh\')"><img src="/files/veoh_player.jpg" width="180" height="146" alt="" /></a>';
	code += '</div>';
	document.write(code);
	
	if(!/MSIE 6/.test(ua)){
		$(veohID).onmouseover = function(e) {
			$('motip').innerHTML = 'クリック： 動画を開く(推奨)<br />Shift＋クリック： Veohで見る<br />'+fKey+'＋クリック： 使い方を見る';
			$('motip').style.fontWeight = 'bold';	
			$('motip').style.display = 'block';	
		};
		$(veohID).onmousemove = function(e) {
			$('motip').style.left = getMousePos(e).x + 10 + 'px';
			$('motip').style.top = getMousePos(e).y - 50 + 'px';
		};
		$(veohID).onmouseout = function(e) {
			$('motip').style.display = 'none';
			$('motip').style.fontWeight = 'normal';
		};
	} else {
		$(veohID).childNodes.item(0).alt = 'クリックで動画を開く・右クリックから対象を開いてVeohで見る';
	}
}



// Write zoome Video on HS
function writeZVideo(dID,zID) {
	var vName = 'zoome' + dID;
	var code = '<script type="text/javascript">';
	code += 'var '+vName+' = new SWFObject("http://zoome.jp/sakurastyle/zpdia/p/'+dID+'/'+zID+'", "embed'+dID+'-'+zID+'", "540", "430", "9", "#FFFFFF");';
	code += vName+'.addParam("wmode", "transparent");';
	code += vName+'.addParam("allowFullScreen", true);';
	code += vName+'.addParam("allowscriptaccess","always");';
	code += vName+'.addParam("pluginspage", "http://www.macromedia.com/go/getflashplayer");';
	code += '</script>';
	code += '<div style="text-align:center">';
	code += '<a id="'+vName+'" href="http://zoome.jp/sakurastyle/diary/'+dID+'/" onclick="return ocVB(this,'+vName+',\'zoome\')" class="highslide"><img src="/files/zoome.jpg" width="180" height="146" alt="" /></a>';
	code += '</div>';
	document.write(code);

	if(!/MSIE 6/.test(ua)){
		$(vName).onmouseover = function(e){
			$('motip').innerHTML = 'クリック： 動画を開く<br />Shift＋クリック： zoomeで見る(推奨)<br />'+fKey+'＋クリック： 使い方を見る';
			$('motip').style.fontWeight = 'bold';	
			$('motip').style.display = 'block';	
		};
		$(vName).onmousemove = function(e){
			$('motip').style.left = getMousePos(e).x + 10 + 'px';
			$('motip').style.top = getMousePos(e).y - 50 + 'px';
		};
		$(vName).onmouseout = function(e){
			$('motip').style.display = 'none';
			$('motip').style.fontWeight = 'normal';
		};
	} else {
		$(vName).childNodes.item(0).alt = 'クリックでリンクを開く';
	}
}


// Write eyeVio Video on HS
function writeEVideo(eid,thumnail) {
	var vid = 'ev' + eid;
	var code = '<script type="text/javascript">';
	code += 'var '+vid+' = new SWFObject("http://eyevio.jp/fla/emp_embed_solo.swf", "embed'+eid+'", "540", "340", "8", "#FFFFFF");';
	code += vid+'.addParam("wmode", "transparent");';
	code += vid+'.addParam("pluginspage", "http://www.macromedia.com/go/getflashplayer");';
	code += vid+'.addParam("allowscriptaccess", "always");';
	code += vid+'.addParam("quality", "high");';
	code += vid+'.addParam("devicefont", "true");';
	code += vid+'.addParam("flashvars", "plain=true&amp;movieId='+eid+'&amp;width=540&amp;height=340&amp;thumUrl=http://eyevio.jp/_images'+thumnail+'.jpg&amp;movie='+eid+'&amp;hostName=http://eyevio.jp&amp;onCompleteDisplayPath=http://eyevio.jp/fla/OnCompleteDisplay.swf?hdlink=http://eyevio.jp/ent/HD");';
	code += '</script>';
	code += '<div style="text-align:center">';
	code += '<a id="'+vid+'" class="highslide" href="http://eyevio.jp/movie/'+eid+'" onclick="return ocVB(this,'+vid+',\'eyeVio\')"><img src="/files/eyevio.jpg" width="180" height="146" alt="" /></a>';
	code += '</div>';
	document.write(code);

	if(!/MSIE 6/.test(ua)){
		$(vid).onmouseover = function(e){
			$('motip').innerHTML = 'クリック： 動画を開く<br />Shift＋クリック： eyeVioで見る(HDサイズ・推奨)<br />'+fKey+'＋クリック： 使い方を見る';
			$('motip').style.fontWeight = 'bold';
			$('motip').style.display = 'block';	
		};
		$(vid).onmousemove = function(e){
			$('motip').style.left = getMousePos(e).x + 10 + 'px';
			$('motip').style.top = getMousePos(e).y - 50 + 'px';
		};
		$(vid).onmouseout = function(e){
			$('motip').style.display = 'none';
			$('motip').style.fontWeight = 'normal';
		};
	} else {
		$(vid).childNodes.item(0).alt = 'クリックで動画を開く(SD)・右クリックから対象を開いてeyeVioで見る(HD)';
	}
}

function ocVB(obj,swf,type) {
	if (window.event.shiftKey) {
		o(obj)
	} else if ((window.event.ctrlKey || window.event.metaKey) && type) {
		window.open('/blog/2009/11/29/123941.php?s='+type)
	} else {
		hs.htmlExpand(obj,{swfObject:swf})
	}
	return false;
}



// Copyright (c) 1996-1997 Athenia Associates.
// http://www.webreference.com/js/
// License is granted if and only if this entire
// copyright notice is included. By Tomer Shiran.
function setCookie (name, value, expires, path, domain, secure) {
    var curCookie = name + "=" + escape(value) + (expires ? "; expires=" + expires : "") +
        (path ? "; path=" + path : "") + (domain ? "; domain=" + domain : "") + (secure ? "secure" : "");
    document.cookie = curCookie;
}

function getCookie (name) {
    var prefix = name + '=';
    var c = document.cookie;
    var nullstring = '';
    var cookieStartIndex = c.indexOf(prefix);
    if (cookieStartIndex == -1)
        return nullstring;
    var cookieEndIndex = c.indexOf(";", cookieStartIndex + prefix.length);
    if (cookieEndIndex == -1)
        cookieEndIndex = c.length;
    return unescape(c.substring(cookieStartIndex + prefix.length, cookieEndIndex));
}

function deleteCookie (name, path, domain) {
    if (getCookie(name))
        document.cookie = name + "=" + ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
}

function fixDate (date) {
    var base = new Date(0);
    var skew = base.getTime();
    if (skew > 0)
        date.setTime(date.getTime() - skew);
}

function rememberMe (f) {
    var now = new Date();
    fixDate(now);
    now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
    now = now.toGMTString();
    if (f.author != undefined)
       setCookie('mtcmtauth', f.author.value, now, '/', '', '');
    if (f.email != undefined)
       setCookie('mtcmtmail', f.email.value, now, '/', '', '');
    if (f.url != undefined)
       setCookie('mtcmthome', f.url.value, now, '/', '', '');
}

function forgetMe (f) {
    deleteCookie('mtcmtmail', '/', '');
    deleteCookie('mtcmthome', '/', '');
    deleteCookie('mtcmtauth', '/', '');
}

var mtcmtmail;
var mtcmtauth;
var mtcmthome;

function setCookieData() {
	for (f=0;f<document.forms.length;f++) {	
		if (document.forms[f]) {
			if (document.forms[f].email != undefined) {
				mtcmtmail = getCookie("mtcmtmail");
				document.forms[f].email.value = mtcmtmail;
			}
			if (document.forms[f].author != undefined) {
				mtcmtauth = getCookie("mtcmtauth");
				document.forms[f].author.value = mtcmtauth;
			}
			if (document.forms[f].url != undefined) {
				mtcmthome = getCookie("mtcmthome");
				if (mtcmthome.indexOf('http') != -1) {
					document.forms[f].url.value = mtcmthome;
				} else {
					document.forms[f].url.value = 'http://';
				}
			}
		}
	}
}


// Copyright (c) 2008 HEX68 (http://hmlab.info/minor/)
// WebClap Script (edited by Sakura Style)
var clapURL = "http://ffxi.sakura.tv/clap/";
function countClap(cpageurl, cpagename, entryId) {
	param = "pageurl=" + cpageurl + "&pagename=" + encodeURIComponent(cpagename) + "&cache=" + (new Date()).getTime();
	//pic = $('clap'+entryId);
	new Ajax.Request(clapURL, {
			method:'get',
			parameters:param+"&mode=gj" + "&gj_message=",
			onSuccess:function(e) {
				$('clap'+entryId).src = clapURL + "?pageurl=" + cpageurl + "&pagename=" + cpagename + "&button=1&mode=button&cache=" + new Date().getTime();	
				$('cmt'+entryId).innerHTML = "&nbsp;ありがとうございます(´∇｀)良ければコメントもどうぞ！";
				$('clap'+entryId).style.cursor = "default";
				$('clap'+entryId).onclick= "";
			},
			onException:function(e) {
			}
		}
	);
}
