/*
 * yuga.js 0.2.0β - 優雅なWeb制作のためのJS
 *
 * Copyright (c) 2007 Kyosuke Nakamura (kyosuke.jp)
 * Licensed under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 * Since:     2006-10-30
 * Modified:  2007-03-20
 */
 

var yuga = {
	/* imageのプリローダー */
	preloader: {
		loadedImages: [],
		load: function (url){
			var img = this.loadedImages;
			var l = img.length;
			img[l] = new Image();
			img[l].src = url;
		}
	},
	uri: {
		absolutePath: function(path){
			var img = new Image();
			img.src = path;
			path = img.src;
			img.src = '#';
			return path;
		},
		anchorName: function (uri){
			return uri.split('#')[1];
		},
		isSelfLink: function(href){
			return (this.absolutePath(href) == location.href) ;
		}
	}
};
 
$(function(){
	
	//class="btn"はロールオーバーを設定（src属性を_r付きのものに差し替える）
	$('.btn').each(function(){
		this.originalSrc = $(this).attr('src');
		this.rolloverSrc = this.originalSrc.replace(/(\.gif|\.jpg|\.png)/, "_r$1");
		yuga.preloader.load(this.rolloverSrc);
	}).hover(function(){
		$(this).attr('src',this.rolloverSrc);
	},function(){
		$(this).attr('src',this.originalSrc);
	});
 
	//現在のページへのリンク
	$('a[@href]').each(function(){
		var href = this.getAttribute('href');
		if (yuga.uri.isSelfLink(href) && !yuga.uri.anchorName(href)) {
			$(this).addClass('current');
			//img要素が含まれていたら現在用画像（_r）に設定
			$(this).find('img').each(function(){
				//ロールオーバーが設定されていたら削除
				$(this).unbind('mouseover');
				$(this).unbind('mouseout');
				this.currentSrc = this.getAttribute('src').replace(/(\.gif|\.jpg|\.png)/, "_r$1");
				$(this).attr('src',this.currentSrc);
			});
		}
	});
 
});
