
//--------------------------------------------------------------------------------
// SpecialThanks to Kyosuke Nakamura (^o^)/ 
//--------------------------------------------------------------------------------

/*
 * Thanks to Kyosuke Nakamura
 *
 * 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
 */


var yuga = {
	preloader: {
		loadedImages: [],
		load: function (url){
			var img = this.loadedImages;
			var l = img.length;
			img[l] = new Image();
			img[l].src = url;
		}
	},
	uri: {
		dirName: function(uri){
			var ary = uri.split('/');
			ary.pop();
			return ary.join('/');
		},
		path: function (uri){
			return uri.split('#')[0];
		},
		anchorName: function (uri){
			return uri.split('#')[1];
		},
		isSelfLink: function(href){
			return ((this.path(href) == this.path(location.href)) || (this.path(href) == this.dirName(location.href)+'/'));
		}
	}
};

$(function(){
	
	//リンク画像はロールオーバーを設定
	$('a img.rov').each(function(){
		this.originalSrc = $(this).src();
		this.rolloverSrc = this.originalSrc.replace(/(\.gif|\.jpg|\.png)/, "_rov$1");
		yuga.preloader.load(this.rolloverSrc);
	}).hover(function(){
		$(this).src(this.rolloverSrc);
	},function(){
		$(this).src(this.originalSrc);
	});

	//現在のページへのリンク
	$('#nav a').each(function(){
		if (yuga.uri.isSelfLink($(this).href()) && !yuga.uri.anchorName($(this).href())) {
			$(this).addClass('current');
			//img要素が含まれていたら現在用画像に設定
			$(this).find('img').each(function(){
				//ロールオーバーが設定されていたら削除
				$(this).unbind('mouseover');
				$(this).unbind('mouseout');
				this.currentSrc = this.getAttribute('src').replace(/(\.gif|\.jpg|\.png)/, "_cur$1");
				$(this).src(this.currentSrc);
			});
		}
	});
		//現在のページへのリンク
	$('#localnav a').each(function(){
		if (yuga.uri.isSelfLink($(this).href()) && !yuga.uri.anchorName($(this).href())) {
			$(this).addClass('current');
			//img要素が含まれていたら現在用画像に設定
			$(this).find('img').each(function(){
				//ロールオーバーが設定されていたら削除
				$(this).unbind('mouseover');
				$(this).unbind('mouseout');
				this.currentSrc = this.getAttribute('src').replace(/(\.gif|\.jpg|\.png)/, "_cur$1");
				$(this).src(this.currentSrc);
			});
		}
	});

	//外部リンクは別ウインドウを設定
	$('a[@href^="http://"].external').click(function(){
		window.open(this.href, '_blank');
		return false;
	}).addClass('externalLink');
	
	//ページ内リンクはするするアニメーション
	$('a[@href^="#wrap"]').click(function(){
		var href = yuga.uri.anchorName($(this).href());
		$('#'+href).ScrollTo(500,'easeout');
		return false;
	});

	//画像へ直リンクするとthickboxで表示
	$('a[@href$=".jpg"]').add('a[@href$=".gif"]').add('a[@href$=".png"]').click(function(){
		var t = this.title || this.name || null;
		var g = this.rel || false;
		TB_show(t,this.href,g);
		this.blur();
		return false;
	});
	//ポップアップウィンドウ
	$('a[@href^=""].popup').click(function(){
	window.open(this.href, "_blank","status=yes,scrollbars=yes,resizable=yes,left=0,top=0");
    return false;
	});
	
});



//--------------------------------------------------------------------------------
// SpecialThanks to Kelvin Luck (^o^)/ 
//--------------------------------------------------------------------------------

/*
* Styleswitch stylesheet switcher built on jQuery
* Under an Attribution, Share Alike License
* By Kelvin Luck ( http://www.kelvinluck.com/ )
*/

$(document).ready(function() {
	$('.styleswitch').click(function()
	{
		switchStylestyle(this.getAttribute("id"));
		return false;
	});
	var c = readCookie('style');
	if (c) switchStylestyle(c);
});

function switchStylestyle(styleName)
{
	$('link[@rel*=style][@title]').each(function(i) 
	{
		this.disabled = true;
		if (this.getAttribute('title') == styleName) this.disabled = false;
	});
	createCookie('style', styleName, 365);
}

// cookie functions http://www.quirksmode.org/js/cookies.html
function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function eraseCookie(name)
{
	createCookie(name,"",-1);
}



//--------------------------------------------------------------------------------
// Script by T.takahashi THANKS (^o^)/ 
//--------------------------------------------------------------------------------

function Flash( swf , width , height )
{
	var htm = ""
						htm+="		<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000'"
						htm+="      codebase='http://download.macromedia.com/pub/shockwave/"
						htm+="		cabs/flash/swflash.cab'"
						htm+="      width   = " + width
						htm+="      height  = " + height + ">"
						htm+="		<param  name    = movie value=" + swf + ">"
						htm+="		<param  name    = quality value=high>"
						htm+="		<embed  src     = " + swf + " "
						htm+="      quality = high  "
						htm+="      width   = "+ width
						htm+="      height  = " + height
						htm+="      type    = 'application/x-shockwave-flash' "
						htm+="      pluginspage='http://www.macromedia.com/go/getflashplayer'>"
						htm+="		</embed>"
						htm+="		</object>" 
  document.write(htm)
}