
/*-------------------
	スライドショー
---------------------*/
(function($){
	$.fn.slideView = function() {
		var self = $(this);
		var imgList = self.find("li");
		var imgNum = imgList.length;
		var slide = function(time){
			var num = 0;
			setInterval(function(){
				imgList.filter(":eq("+num+")").fadeOut(400,function(){
					num++;
					num = num%imgNum;
					imgList.filter(":eq("+num+")").fadeIn(400);
				});
			},time);
		};
		return this.each(function() {
			imgList.filter(":not(:eq(0))").hide();
			if(imgList>1){
				slide(9000);
			}
		});
	};
})(jQuery);

/*------------------------
	twetterのスクロールバー
-------------------------*/

(function($){
	$.fn.scrollBar = function() {
		var self = $(this);
		var inner = self.find("ul");
		var barWrap = self.find("#scrollbar");
		var bar = self.find(".bar");
		var sectionH = self.height();
		var totalH = self.find("#tweetList").height() +50;
		var ratio = totalH / sectionH;

		function scroll(a){
			bar.css({top:a});
			inner.css({top:-a*ratio+12});
		}

		return this.each(function() {
			bar.height(sectionH/ratio);
			var maxTop = 260 - bar.height() - 2;

			//クリック
			barWrap.mousedown(function(e){
				var a = scrollAmount(e.pageY - 1023);
				scroll(a);

				//ドラッグ
				$(document).mousemove(function(e){
					//console.log("mousemove")
					var a = scrollAmount(e.pageY - 1023);
					scroll(a);
					return false;
				})
				$(document).one("mouseup",function(e){
					//console.log("mouseup");
					$(document).unbind("mousemove");
				})
				return false;
			})
			//マウスホイール
			self.mousewheel(function(e,delta){
				event.preventDefault();
				//console.log(delta);
				var a = scrollAmount(bar.position().top - delta);
				scroll(a);
			})

			//スクロール量を返す
			function scrollAmount(tarTop){
				var a = ( tarTop < 2 ) ? 2 : tarTop;
				a = ( a > maxTop ) ? maxTop : a;
				return a;
			}

		});
	};
})(jQuery);

/*-------------------
	セレクトして他が薄くなる
---------------------*/
(function($){
	$.fn.overOther = function() {
		var self = $(this);
		var listItem = self.find("li");

		return this.each(function() {
			listItem.hover(function(){
				//console.log("e");
				listItem.not(this).stop(true).animate({
					opacity:0.3
				},300);
				//$(this).hide();
			},function(){
				//console.log("o");
				listItem.not(this).stop(true).animate({
					opacity:1
				},300);
				//$(this).show();
			})
		});
	};
})(jQuery);


/*-------------------
	セレクトしたら一瞬光る
---------------------*/
(function($){
	$.fn.blinkSelect = function() {
		var self = $(this);


		return this.each(function() {
			self.mouseover(function(){
				$(this).stop(true).animate({
					opacity:0.8
				},60,function(){
					self.animate({
						opacity:1
					},220);
				});
			});

		});
	};
})(jQuery);


(function($){
	$.fn.selectLnk = function() {
		var self = $(this);
		var links = self.find("a");
		var url = document.URL;
		var tarStr = regExUrl(url);

		function regExUrl(tarUrl){
			return tarUrl.match(".*/(.+?)$")[1].replace("/","");
		}

		return this.each(function() {
			//console.log(tarStr);
			links.each(function(i){
				var href = $(this).attr("href");

				var hrefStr = ( href == "/" || href == "./" )? href : regExUrl(href);
				//console.log(tarStr);
				if(hrefStr == tarStr){
					$(this).addClass("selected");
				}
			})

		});
	};
})(jQuery);


$(function(){

	var init = function(){
		//$("#topImage").slideView();
		$("#tweetListWrap").scrollBar();
		$("#projectList li").blinkSelect();
		//$(".idxMenu").selectLnk();
	}

	init();

})
