﻿$(function() {
	//ツール部分のアニメーション
	$('#trigger_nav_open').click(function() {
		$('#tool .container').slideToggle('fast');
		$(this).find('a').toggleClass('opened');
		$('#content object').toggleClass('hidden');
	});
	
	$('.hover_ops').hoverOpacity({speed:120});//ホバー要素に透過設定
	$('#nav2head').scrollFollow({container:'content'});//ヘッダーへのアンカーリンクをスクロールに追従
	
	//twitter@anywhere
	var tw;
	twttr.anywhere(onAnywhereLoad);
	
	$('a[href], area[href]').click(function () {//外部リンクを自動的に_blankへ
		if ($(this).attr('href') != "#") {
			if (this.hostname !== window.location.hostname) {
				window.open($(this).attr('href'));
			} else {
				location.href = $(this).attr('href');
			}
			return false;
		}
	});
});

//twitter@Anywhere
function onAnywhereLoad(twitter){
	tw = twitter;
	
	//twitter signin
	/*tw('#btn_tw_signin').connectButton({
		authComplete: function(signedInUser){
			
		}
	});*/
	
	tw("#btn_follow_twitter").followButton('pelepop');
	tw('.text').hovercards();
	tw('.author .twitter span').hovercards({linkify: false});
}

//Twitter読み込み
function twitterCallback(tw) {
	var statusHTML = [];
	for (var i=0; i<tw.length; i++){
		var username = tw[i].user.screen_name;
		var img = tw[i].user.profile_image_url;
		var status = tw[i].text.replace(/((https?|s?ftp|ssh)\:\/\/[^"\s\<\>]*[^.,;'">\:\s\<\>\)\]\!])/g, function(url) {
			return '<a href="'+url+'">'+url+'</a>';
		}).replace(/\B@([_a-z0-9]+)/ig, function(reply) {
			return  reply.charAt(0)+'<a href="http://twitter.com/'+reply.substring(1)+'">'+reply.substring(1)+'</a>';
		});
		statusHTML.push('<li><p class="data"><img src="'+img+'" width="16" height="16" /> <a href="http://twitter.com/'+username+'/statuses/'+tw[i].id_str+'">'+username+'</a></p><p class="status">'+status+'</p></li>');
	}
	$('#widget_twitter ul').html(statusHTML.join(''));
}
