/*
 * yuga.js 0.1.0
 * Copyright (c) 2006 Kyosuke Nakamura (kyosuke.jp)
 * Licensed under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 * Since:     2006-10-30
 * Modified:  2006-11-15
 */

/* Last Added: 2007-02-26 */


//Utility
var absPath,sharePath = '/shared',isIE='\v'=='v',isIE6=(navigator.userAgent.indexOf("MSIE 6")>=0)?true:false,isWebKit = navigator.userAgent.match(/WebKit/),isLinkAry = location.pathname.split('/').slice(1),jcommon={preloader:{loadedImages:[],load:function(a){var b=this.loadedImages,c=b.length;b[c]=new Image;b[c].src=a}},URIExp:new RegExp("^[https]*[^a-z]*"+document.domain),URI:function(a){this.absolutePath=a.replace(jcommon.URIExp,"").replace(/^[^a-z]*/,"").replace(/index.*$/,"").replace(/\/$/,"");this.len=isLinkAry.length;for(this.isSelfLink=false;this.len--&&!this.isSelfLink;)this.isSelfLink=this.isSelfLink||this.absolutePath==isLinkAry[this.len]},addLinkAry:function(){for(var a=0,b=isLinkAry.length;a<
b;)isLinkAry.push(isLinkAry.slice(0,++a).join("/").replace(/^\//,"").replace(/index.*$/,""))}};jcommon.addLinkAry();switch(true){case location.host.split('.')[1]===('apkisndov'+40*50).replace(/[p-z]/g,''):absPath = '/'+(location.pathname.split('/')[1]);var isBeta = true;break;case location.protocol==='file:':absPath = (isIE?'':'/')+('IYK:M/HOtMdoNcRs/X').replace(/[I-X]/g,'')+(location.pathname.split('/')[3])+'/www/\u4f5c\u696d\u7528';var isBeta = true;break; default:absPath = '';break;}



/*!
 * liScroll 1.0
 * Examples and documentation at: 
 * http://www.gcmingati.net/wordpress/wp-content/lab/jquery/newsticker/jq-liscroll/scrollanimate.html
 * 2007-2010 Gian Carlo Mingati
 * Version: 1.0.2 (30-MARCH-2009)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 * Requires:
 * jQuery v1.2.x or later
 * 
 */


jQuery.fn.liScroll=function(settings){settings=jQuery.extend({travelocity:0.07},settings);return this.each(function(){var $strip=jQuery(this);$strip.addClass("newsticker")
var stripWidth=0;var $mask=$strip.wrap("<div class='mask'></div>");var $tickercontainer=$strip.parent().wrap("<div class='tickercontainer'></div>");var containerWidth=$strip.parent().parent().width();$strip.find("li").each(function(i){stripWidth+=jQuery(this,i).outerWidth(true);});$strip.width(stripWidth);var totalTravel=stripWidth+containerWidth;var defTiming=totalTravel/settings.travelocity;function scrollnews(spazio,tempo){$strip.animate({left:'-='+spazio},tempo,"linear",function(){$strip.css("left",containerWidth);scrollnews(totalTravel,defTiming);});}
scrollnews(totalTravel,defTiming);$strip.hover(function(){jQuery(this).stop();},function(){var offset=jQuery(this).offset();var residualSpace=offset.left+stripWidth;var residualTime=residualSpace/settings.travelocity;scrollnews(residualSpace,residualTime);});});};



//ロールオーバー
$.fn.addRollOver=function(add){$(this).filter('img').each(function(){$(this).runRollOver(add,$(this));}).end().not('img').each(function(){$(this).runRollOver(add,$(this).find('img'));});};
$.fn.runRollOver=function(add,target){$(this).each(function(num){this.originalSrc=String(target.attr('src'));this.rolloverSrc=this.originalSrc.replace(/(\.gif|\.jpg|\.png)/,add+"$1");}).hover(function(){target.attr('src',this.rolloverSrc);},function(){target.attr('src',this.originalSrc);});};
//現在のページへのリンク
$.fn.addCurrentImages=function(add){$(this).each(function(){var href=new jcommon.URI($(this).attr('href'));if(href.isSelfLink){$(this).addClass('current');$(this).unbind('mouseenter');$(this).unbind('mouseleave');$(this).find('img').each(function(){$(this).unbind('mouseenter');$(this).unbind('mouseleave');this.currentSrc=this.getAttribute('src').replace(/(\.gif|\.jpg|\.png)/,add+"$1");$(this).attr('src',this.currentSrc)});}});};	
//ページ全体にリンク
$.fn.groupLink=function(){$(this).css({cursor:'pointer'}).hover(function(){$(this).addClass('hover')},function(){$(this).removeClass('hover')}).click(function(){location.href=$(this).find('a:last').attr('href');return false})}


$(function(){
	
	
//-----------------------------------------------------------------
// Twitter


	if($('#twit').length){
		//$j('#twit input').val('ごめんなさい、現在込み合っています…');
		var tweeturl="http://twitter.com/status/user_timeline/iiiesawada.json?count=5&callback=?";
		$.getJSON(tweeturl, function(data){
			var twitTxt ="";
			// JSONデータ読み込み
			$.each(data, function(i, item){
														
			// URLにテキストがある場合はリンク設置
			//txt = item.text;
			
			var tmpURL ="";
			
			//リンクテキストを削除 urlに保存
			 var txt =  item.text.replace(/((https?|s?ftp|ssh)\:\/\/[^"\s\<\>]*[^.,;'">\:\s\<\>\)\]\!])/g, function(url) {
				tmpURL = url;
				return '';
			}).replace(/\B@([_a-z0-9]+)/ig, function(reply) {
				return  reply.charAt(0)+'<a href="http://twitter.com/'+reply.substring(1)+'">'+reply.substring(1)+'</a>';
			});
			
			//リンクがあれば追加
			if(tmpURL != ""){
				txt = '<a href="'+ tmpURL + '" target="_top">' + txt + '</a>';
			}
			
			// 日時データを要素分解
			var created_at = item['created_at'].split(" ");
			// 投稿日時変換 "Mon Dec 01 14:24:26 +0000 2008" -> "Dec 01, 2008 14:24:26"
			var post_date  = created_at[1] + " "
										 + created_at[2] + ", "
										 + created_at[5] + " "
										 + created_at[3];
			// 日時データ処理
			var date = new Date(post_date);     // 日付文字列 -> オブジェクト変換
			date.setHours(date.getHours() + 9); // UTC -> JST (+9時間)
			var year  = date.getFullYear();     // 年取得
			var mon  = date.getMonth() + 1;     // 月取得
			var day  = date.getDate();          // 日取得
			twitTxt += ("<li>"+txt+"（"+ year + "/"+ mon + "/"+ day + "）</li>");
//				var txt = item.text.replace(/(https?:\/\/[-a-z0-9._~:\/?#@!$&\'()*+,;=%]+)/ig,'<a href="$1">$1</a>').replace(/@+([_A-Za-z0-9-]+)/ig,'<a href="http://twitter.com/$1">@$1</a>').replace(+([_A-Za-z0-9-]+)/ig,'<a href="http://search.twitter.com/search?q=$1">#$1</a>');
			//	$j('#twit input').after().attr('value',txt);
			});

			if(twitTxt != ""){
				$('#twit input').replaceWith('<div id="teleshizuTweet"><ul id="teleshizuTweetUl">' + twitTxt + '</ul></div>');
				$('#twit #teleshizuTweet #teleshizuTweetUl').liScroll({travelocity: 0.04});
			}else{
			}
		});
	}
	//ロールオーバー
	$('a img.btn,a.btn,#globalNav li a').addRollOver('_on');

	//現在のページへのリンク
	$('#globalNav li a').addCurrentImages('_cr');	

	//外部リンクは別ウインドウを設定
	$('a[href^="http://"]:not([href^="http://www.iiie-sawada.jp/"],[href^="http://iiie-sawada.jp/"])').click(function(){
		window.open(this.href, '_blank');
		return false;
	}).addClass('externalLink');

	//別ウィンドウを設定
	$('a[href$=".pdf"],a[href$=".asx"]').click(function(){
		window.open(this.href, '_blank');
		return false;
	});

	

});
