jQuery.noConflict(); // jQueryの $ 参照を無効


/*サイドバーアイコンをスライドさせる------------------------------------------------------------*/
var s_bar = function () {
	var $ = jQuery;
	$('#entries_navi').show();


/*----------------------------------------------------------------------------------------------*/

	// アイコンを作って突っ込む人 引数は列番号
	function fn_makeIconHtml(arg_os_icons){
		var s_html = '<div class="entries_area">';

		// 6 個分アイコンを作成する
		for(var i=0,l=arg_os_icons.length; i<l; ++i){
			s_html += '<div class="entries_box clearfix">';
			if(!arg_os_icons[i]['p']){
				s_html += '<img title="free" alt="free" src="http://www.elegant-apps.com/images/clear.gif" class="free" />';
			}
			s_html += '<a class="icons" href="' + arg_os_icons[i]['l'] + '"><img src="http://www.elegant-apps.com/images/clear.gif" class="entries_icon" title="' + arg_os_icons[i]['t'] + '" style="background-image:url(http://www.elegant-apps.com/apps/images/' + arg_os_icons[i]['c'] + '_icon_s.png); _background-image:none; _filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=http://www.elegant-apps.com/apps/images/' + arg_os_icons[i]['c'] + '_icon_s.png);" /></a><div class="entries_text"><h3><a href="' + arg_os_icons[i]['l'] + '">' + arg_os_icons[i]['t'] + '</a></h3><p>' + arg_os_icons[i]['e'] + '</p></div></div>';
		}
		s_html += '</div>';
		
		$('#entries_body').append(s_html);
	}

/*----------------------------------------------------------------------------------------------*/

	// スライドさせる 引数は、 'next' or 'prev'
	function fn_slide(arg_s_course) {
		if (arg_s_course === "next") {
			$('#entries_body>.entries_area:first').css('left', '0').animate({left:-264}, 'fast',
				function(){
					$(this).remove();
				}
			);
			$('#entries_body>.entries_area:last').css('left', '264px').animate({left:0}, 'fast');
		}
		else if (arg_s_course === "prev"){
			$('#entries_body>.entries_area:first').css('left', '0').animate({left:264}, 'fast',
				function(){
					$(this).remove();
				}
			);
			$('#entries_body>.entries_area:last').css('left', '-264px').animate({left:0}, 'fast');
		}
	}

/*----------------------------------------------------------------------------------------------*/

	// ボタン管理 引数は、今の列番号と、最大列番号
	function fn_btn(args_n_now, args_n_max) {
		if(args_n_now === 0){
			$('#prev').removeClass('on');
			$('#next').addClass('on');
		}
		else if(args_n_now === (args_n_max-1)){
			$('#prev').addClass('on');
			$('#next').removeClass('on');
		}
		else{
			$('#prev').addClass('on');
			$('#next').addClass('on');
		}
	}
	
/*----------------------------------------------------------------------------------------------*/




	// 「次へ進める」「前へ戻る」の全体管理をする人（クラス）
	// 以下の関数でしか使用しない変数は分かりやすいようここで定義
	var n_line = 0;
	var n_maxline = 0;
	var os_json;
	function fn_exeSlideMain(event) {

		// .entries_area が 2 以上あれば処理を止める
		if( $('#entries_body > .entries_area').length >= 2 ){
			return;
		}

		// どのボタンクリックしてきたのかを知る
		{
			if(event.target.id === "next"){
				n_line++;
			}
			else if(event.target.id === "prev"){
				n_line--;
			}
			else{
				// ここに来ただと？そんなばかな。だから処理を止める
				return;
			}
		}

		

		// div を作ってアイコンを作成する
		// 作成するアイコンの配列だけを渡してあげる
		{
			var os_icons = new Array();
			
			for(var i=0,l=6,n=n_line*6; i<l; ++i,++n){
				if(!os_json[n]) break;	// アイコンがないときは抜ける
				os_icons.push(os_json[n]);
			}
			
			fn_makeIconHtml(os_icons);
		}
		
		// スライドさせる 引数は、 'next' or 'prev'
		fn_slide(event.target.id);
		
		// ボタン管理 引数は、今の列番号と、最大列番号
		fn_btn(n_line, n_maxline);
	}

/*----------------------------------------------------------------------------------------------*/


	//アイコンの入れ替え
	function fn_changeIcon(num){
		n_line = Math.floor( num / 6 );	// 表示されるアイコンの列を計算し、小数を切り捨てる

		var os_icons = new Array();

		for(var i=0,l=6,n=n_line*6; i<l; ++i,++n){
			if(!os_json[n]) break;	// アイコンがないときは抜ける
			os_icons.push(os_json[n]);
		}
		
		fn_makeIconHtml(os_icons);
		fn_btn(n_line,n_maxline);
	}

/*----------------------------------------------------------------------------------------------*/

	//アイコンが最大で何列あるか計算
	function fn_maxLine(n){
		n_maxline = Math.floor( n / 6 );	// 何列あるかを計算し、少数を切り捨てる
		if( n % 6 > 0 ){	// 余りがあるときは、もう一列あるとする
			n_maxline++;
		}
	}

/*----------------------------------------------------------------------------------------------*/


	//表示している URL を取得してTOPページなら実行
	var s_jsonPath = 'http://www.elegant-apps.com/js/fenrirSearchDB.json';
	var strSearch = location.href+"";
	var max_entry;

	
	if( strSearch.match(/^http:\/\/[^\/]*\/($|[\?\#]|index\.html)/) !== null){

		$('#entries_area_1').show();
		// 【軽量化のための特別な処理】 １回だけ実行する one
		$('#next[class="on"]').one("click", function(){

			$.getJSON(s_jsonPath, function (data) {
				if (data.length) {
					os_json = data;
					max_entry = data.length;

					fn_maxLine(max_entry);
					
					
					// 次へボタンをクリックしたときの動きをイベント定義し、さらにそれを実行させる
					$('#next[class="on"]').live('click',function(e){fn_exeSlideMain(e);}).trigger('click');
					
					// 前へボタンもここで定義する（必要な時に初めてイベント定義をするようにしよう）
					$('#prev[class="on"]').live('click',function(e){fn_exeSlideMain(e);});

				}
			});

		});

	}else{

		$.getJSON(s_jsonPath, function (data) {
			if (data.length) {
				os_json = data;

				//json_num = 0		:MTにデータが入っていない場合最新6件を表示
				//json_num = 0～5	:最新6件の記事
				//json_num = 6以上	:最新6件より過去の記事
				var json_num = 0;

				//記事最大数
				max_entry = data.length;

				for(var i=0,l=data.length;i<l;i++){

					//MTに記事データが入っているか
					if(os_json[i].l === strSearch){

						//先頭から何番目の記事データか
						json_num = i;
						break;
					}
				}

				fn_maxLine(max_entry);
				$("#entries_area_1").remove();
				fn_changeIcon(json_num);



				// 次へボタンをクリックしたときの動きをイベント定義する
				$('#next[class="on"]').live('click',function(e){fn_exeSlideMain(e);});
				
				// 前へボタンもここで定義する（必要な時に初めてイベント定義をするようにしよう）
				$('#prev[class="on"]').live('click',function(e){fn_exeSlideMain(e);});

			}
		});


	}

};






/*-mail ポップアップウィンドウ用-----------------------------------------------------------------*/

var Mail;
function MailStart(){
	//var Mail = {};
	var GLOBALMAILTIMER;
	var $ = jQuery;

	var Mail = {
		overlayClose: function(id,rel) {
			try {
				var marginT = parseInt( $('#'+rel).css('top').replace(/px/,'') );
				$('#'+rel)
				.slideUp(500,function() {
					$('#'+id).fadeOut('fast',function() {
						$('body').children().remove('#'+id);
						$('body').children().remove('#'+rel);
					});
				});
			}
			catch(e) {
			}
			document.onkeyup = document.onkeypress = document.onkeydown = '';
			$('select').show();
			if ( GLOBALMAILTIMER )
				clearInterval(GLOBALMAILTIMER);
		},

		overlayShow: function(id,rel) {
			$('select').hide();
			try {
				var w = $('#'+rel).width();
				var h = $('#'+rel).height();
				var marginL = parseInt( ($(window).width() - w) / 2);
				var marginT = parseInt( ($(window).height() - h) / 2);
				if ( marginL <= 0 ) { marginL = 20; }
				if ( marginT <= 0 ) { marginT = 20; }
				marginL += $(window).scrollLeft();
				marginT += $(window).scrollTop();

				$('#'+id).fadeIn('fast', function() {
					$('#'+rel).css({
						'position': 'absolute',
						'top': marginT + 'px',
						'left': marginL + 'px',
						'color': '#fff',
						'z-index': '10000'
					})
					.slideDown(500);
				});

				// close event
				$('#'+id).click(function() {
					Mail.overlayClose(id,rel);
				});
				$('#pageback').click(function() {
					Mail.overlayClose(id,rel);
				});
				document.onkeyup = document.onkeypress = document.onkeydown = function(e) {
					var keycode;
					if ( e == null ) // ie
						keycode = event.keyCode;
					else
						keycode = e.which;
					if ( keycode == 27 ) // esc
						Mail.overlayClose(id,rel);
					else
						$('#mail').focus();
				};
			}
			catch(e) {
			}
		},

		overlayCreate: function(id) {
			var bgW = ( $('body').width() > $('#container').width() ) ? $('body').width() : $('#container').width();
			var bgH = ( $('body').height() > $('#container').height() ) ? $('body').height() : $('#container').height();

			$('body').append(
				$('<div id="'+id+'"></div>')
				.css({
					'position':'absolute','top':'0px','left':'0px', 'z-index':'9999',
					'width': bgW,
					'height': bgH,
					'background-color':'#000000','opacity':'0.7'
				})
				.hide()
			);
		},

		changeLabelImg: function(){
			if(document.getElementById('label').className == "normal"){
				document.getElementById('label').className = "click";
				$('#label1').attr('checked','true');
			}else{
				document.getElementById('label').className = "normal";
				$('#label1').attr('checked','false');
				var expire = new Date();
				expire.setTime(expire.getYear() - 1);
				document.cookie = '_eapUserMailToiPhone=; path=/; expires='+expire.toGMTString();
			}
			return false;
		},

		addHostname: function(host) {
			if ( host != 'i.softbank.jp' && host != 'me.com' )
				return false;

			var mailaddress = $('#mail').val();
			if ( mailaddress && mailaddress.match(/@/) ) {
				mailaddress = mailaddress.replace(/\@.*$/, '@' + host);
			}
			else if (mailaddress && mailaddress == 'メールアドレス' ) {
				return false;
			}
			else {
				mailaddress += '@' + host;
			}
			$('#mail').val(mailaddress);

			return false;
		},

		send2Callback: function(data) {
			var html = eval('('+data+')');
			var overlayId = '_fOverlay';
			var innerId = '_fMailDiv';
			$('body').append($('<div id="'+innerId+'"></div>').append(html.content).hide());
			$('#MailArea').append(
			$('<a href="#" id="pageback" title="閉じる">閉じる</a>').click($.proxy(function() {
				this.overlayClose(overlayId,innerId);return false;},this))
			);

			this.overlayCreate(overlayId);
			this.overlayShow(overlayId, innerId);
		},
		send2iPhone: function(eid) {
			try {
				$.post('http://www.elegant-apps.com/eapps-sys/eappsmail.cgi' , {'eid':eid,'type':'ajax'}, $.proxy(this.send2Callback,this));
			}
			catch(e) {
			}
			return false;
		},

		send2Callback_send: function(data) {
			var html = eval('('+data+')');
			$('#_fMailDiv').html(html.content);
			$('#MailArea').append(
				$('<a href="#" id="pageback" title="閉じる">閉じる</a>').click($.proxy(function() {
					this.overlayClose('_fOverlay','_fMailDiv');return false;
				},this))
			);

			GLOBALMAILTIMER = setInterval( $.proxy(function() {
				if ( html.stat == 'success' )
					this.overlayClose('_fOverlay','_fMailDiv');return false;},this),5000);
		},

		send2iPhone_send: function (eid, sess) {
			try {
				$.post('http://www.elegant-apps.com/eapps-sys/eappsmail.cgi', 
						{
							'eid':eid,
							'key':sess,
							'type':'ajax',
							'__mode':'send',
							'mailaddress':$('#mail').val(),
							'saveaddress':$('#label1').attr('checked')
						},$.proxy(this.send2Callback_send,this));
			}
			catch(e) {
			}
			return false;
		}
	};
	window.Mail = Mail;
}

MailStart();



(function(){

	var $ = jQuery;

	////////////////////////
	//google analytics	  //
	////////////////////////

	var _ga;
	jQuery(function($){
		$.getScript("http://www.google-analytics.com/ga.js", function(){
			try{
				var pT = _gat._getTracker("UA-2005247-8");
				pT._trackPageview();
			}catch(e){}
		});
		window._ga = function ga(q){
			try{
				_gat._getTracker("UA-2005247-8")._trackPageview(q);
			}catch(e){}
		}
		
		// initItems();   // fenrir_search_db.js
		initGallery(); // fenrir_gallery.js
	});





	////////////////////////////////
	//fenrir_gallery.js		 	  //
	//ポップアップギャラリー用	  //
	////////////////////////////////

	function _initGalleria() {
		jQuery(function($) {
			// galleria
			$('ul.gallery').galleria({
				history: false,
				clickNext : true,
				onImage: function(image,caption,thumb) {
	//				if(! ($.browser.mozilla && navigator.appVersion.indexOf("Win")!=-1) ) // FF/Win fades large images terribly slow
	//					image.css('display','none').fadeIn(1000);
					image.attr('title','Next image >>');
					if ( image.attr('width') > image.attr('height') ) { // change margin
						$('img.replaced').css({'margin-left':'14px','margin-top':'80px'});
					}
					thumb.parent('li').addClass('active');
	//				thumb.parent('li').parent('ul').children('li').children('img').fadeTo('fast',0.3);
	//				thumb.fadeTo('fast',1);
					thumb.parent('li').parent('ul').children('li').children('img').css({'opacity':0.3});
					thumb.css({'opacity':1});
				},
				onThumb : function(thumb) {
					var _li = thumb.parents('li');
					var _fadeTo = _li.is('.active') ? '1' : '0.3';
					thumb.css({display:'none',opacity:_fadeTo}).fadeIn(1500);
					thumb.css({opacity:_fadeTo});
					thumb.hover(
	//					function() { thumb.fadeTo('fast',1); },
	//					function() { _li.not('.active').children('img').fadeTo('fast',0.3); }
						function() {
							thumb.css({ 'opacity':1 });
							thumb.parent('li').css({'cursor':'normal'});
							thumb.parent('li').not('.active').css({
								'background-image':'url(http://www.elegant-apps.com/images/model/select.png)',
								'background-color':'#403e3c',
								'cursor':'pointer'
							});
						},
						function() {
							_li.not('.active').children('img').css({'opacity':0.3});
							_li.css({ 'background-image':'', 'background-color':'' });
						}
					);
				}
			});
		});
	}

	function _initGalleryArea() {
		jQuery(function($) {
			// galleriaArea
			var anchors = $('#content').find('a');
			for ( var i = 0; i < anchors.length; i++ ) {
				var anchor = anchors[i];
				var href = anchor.getAttribute('href');
				if ( href && href.match(/jpg$|gif$|png$/) ) {
					anchor.setAttribute('rel', href);
					$(anchor).click(function() {
						egalleryShow(this.href);
						return false;
					});
				}
			}
		});
	}

	function _createOverlay() {
		// backGround
		var bgWidth = ( $('body').width() > $('#container').width() ) ? $('body').width() : $('#container').width();
		var bgHeight = ( $('body').height() > $('#container').height() ) ? $('body').height() : $('#container').height();
		$('body').append(
			$('<div id="galleryOverlay"></div>')
			.css({
				'position':'absolute','top':'0px','left':'0px', 'z-index':'9999',
				'width': bgWidth,
				'height': bgHeight,
				'background-color':'#000000','opacity':'0.7'
			})
			.hide()
		);
		$('#galleryOverlay').click(function() { egalleryClose(); });
	}

	function _createGallery(rel) {
		// galleriaArea
	//	$('#galleriaArea').append( $('<a title="close" id="TB_closeWindowButton" href="#">閉じる</a>').click(function() { egalleryClose(); return false;} ));
		$('#galleriaArea').append( $('<div id="galleria_header">&nbsp;</div>') );
		$('#galleriaArea').append( $('<div id="ul"></div>').append ( $('<ul></ul>').addClass('gallery').addClass('clearfix') ) );
		$('#galleriaArea').append( $('<div id="galleria_footer">&nbsp;</div>') );
		$('#galleriaArea').append( $('<a title="close" id="TB_closeWindowButton" href="#">閉じる</a>').click(function() { egalleryClose(); return false;} ));

		var anchors = $('#content').find('a');
		var deposB = []; // big thumbnail
		var deposS = []; // small thumbnail
		for ( var i = 0; i < anchors.length; i++ ) {
			var anchor = anchors[i];
			var href = anchor.getAttribute('href');
			if ( href.match(/jpg$|gif$|png$/) ) {
				var w = 0;
				var s = '';
				var imgs =$(anchor).children('img');
				for ( var j = 0; j < imgs.length; j ++ ) {
					if ( $(imgs[j]).attr('class') != 'plus' ) {
						w = parseInt( $(imgs[j]).width() );
						s = href.replace(/l\.png$/, 's.png');
	//					s = $(imgs[j]).attr('src');
						break;
					}
				}
	//			var w = parseInt( $(anchor).children('img').width() );
	//			var s = $(anchor).children('img').attr('src');
				if ( s == '' ) { s = href; }
				if ( w > 30 )
					deposB.push({'href':href,'thumb':s});
				else
					deposS.push({'href':href,'thumb':s});

	//			if ( href == rel )
	//				$('#galleriaArea ul.gallery').append( $('<li class="active"></li>').append( $('<img class="noscale" src="'+href+'" title="" width="30" height="30" />') ) );
	//			else
	//				$('#galleriaArea ul.gallery').append( $('<li></li>').append( $('<img class="noscale" src="'+href+'" title="" width="30" height="30" />') ) );

			}
		}
		var depos = deposB.concat(deposS);
		for ( var i = 0; i < depos.length; i++ ) {
			var href = depos[i];
			if ( href.href == rel ) {
				$('#galleriaArea ul.gallery').append(
					$('<li class="active"></li>').append(
						$('<a href="'+href.href+'"></a>').append(
							$('<img class="noscale" src="'+href.thumb+'" title="" width="30" height="30" />') 
						)
					) 
				);
			}
			else {
				$('#galleriaArea ul.gallery').append(
					$('<li></li>').append(
						$('<a href="'+href.href+'"></a>').append(
							$('<img class="noscale" src="'+href.thumb+'" title="" width="30" height="30" />') 
						)
					) 
				);
			}
		}
	}

	function egalleryShow(rel) {
		// create overlay
		_createOverlay();

		// galleria
		_createGallery(rel);
		_initGalleria();

		var w = $('#galleriaArea').width() || 508;
		var h = $('#galleriaArea').height() || 554;

		var marginL = parseInt(( $(window).width() - w ) / 2);
		var marginT = parseInt(( $(window).height() - h ) / 2);

		if ( marginL <= 0 ) { marginL = 20; }
		if ( marginT <= 0 ) { marginT = 20; }
		marginL += $(window).scrollLeft();
		marginT += $(window).scrollTop();

		// show
		$('select').hide();
		$('#galleryOverlay').fadeIn('fast',function() {
			$('#galleriaArea').css({
				'position':'absolute',
				'top': parseInt(marginT + ( h / 2 ))+'px',
				'left':marginL + 'px',
				'width': w + 'px',
				'height': '0px',
				'z-index':'10000'
			})
			.animate({
				'height': h + 'px',
				'top': marginT + 'px'
			})
			.show();
			if ( $.browser.opera && $('img.replaced').width() > $('img.replaced').height() ) {
				$('img.replaced').css({'margin-left':'14px','margin-top':'80px'});
			}
		});
		document.onkeydown = function(e) {
			var keycode;
			if ( e == null ) // ie
				keycode = event.keyCode;
			else
				keycode = e.which;
			if ( keycode == 27 ) // esc
				egalleryClose();
		};
		document.onkeyup = function(e) {
			var keycode;
			if ( e == null ) // ie
				keycode = event.keyCode;
			else
				keycode = e.which;
			if ( keycode == 27 ) // esc
				egalleryClose();
		};
		document.onkeypress = function(e) {
			var keycode;
			if ( e == null ) // ie
				keycode = event.keyCode;
			else
				keycode = e.which;
			if ( keycode == 27 ) // esc
				egalleryClose();
		};

		return false;
	}

	function egalleryClose() {
		try {
			var marginT = parseInt( $('#galleriaArea').css('top').replace(/px/,'') );
	//		var h = $('#galleriaArea').height() || 554;
	//		var marginT = parseInt(( $(window).height() - h ) / 2);
	//		if ( marginT <= 0 ) { marginT = 20; }
	//		marginT += $(window).scrollTop();

			$('#galleriaArea')
			.animate({
				'height': '0px',
				'top': parseInt( marginT + $('#galleriaArea').height() / 2 )+'px'
			}, 500, function () {
				$('#galleriaArea').hide();
				$('#galleryOverlay').fadeOut('fast',function() {
					$('#galleriaArea').children().remove();
					$('body').children().remove('#galleryOverlay');
				});
			});
	//		.hide();

		}
		catch(e) {
		}
		document.onkeydown = '';
		document.onkeyup = '';
		document.onkeypress = '';
		$('select').show();
		return false;
	}


	function initGallery() {
		_initGalleryArea();
	}















	//////////////////////////////////////
	//  jquery.galleria.f.js			//
	//  モーダルウィンドウ用ライブラリ  //
	//////////////////////////////////////

	/**
	 * Galleria (http://monc.se/kitchen)
	 *
	 * Galleria is a javascript image gallery written in jQuery. 
	 * It loads the images one by one from an unordered list and displays thumbnails when each image is loaded. 
	 * It will create thumbnails for you if you choose so, scaled or unscaled, 
	 * centered and cropped inside a fixed thumbnail box defined by CSS.
	 * 
	 * The core of Galleria lies in it's smart preloading behaviour, snappiness and the fresh absence 
	 * of obtrusive design elements. Use it as a foundation for your custom styled image gallery.
	 *
	 * MAJOR CHANGES v.FROM 0.9
	 * Galleria now features a useful history extension, enabling back button and bookmarking for each image.
	 * The main image is no longer stored inside each list item, instead it is placed inside a container
	 * onImage and onThumb functions lets you customize the behaviours of the images on the site
	 *
	 * Tested in Safari 3, Firefox 2, MSIE 6, MSIE 7, Opera 9
	 * 
	 * Version 1.0
	 * Februari 21, 2008
	 *
	 * Copyright (c) 2008 David Hellsing (http://monc.se)
	 * Licensed under the GPL licenses.
	 * http://www.gnu.org/licenses/gpl.txt
	 **/

	;(function($){

	var $$;


	/**
	 * 
	 * @desc Convert images from a simple html <ul> into a thumbnail gallery
	 * @author David Hellsing
	 * @version 1.0
	 *
	 * @name Galleria
	 * @type jQuery
	 *
	 * @cat plugins/Media
	 * 
	 * @example $('ul.gallery').galleria({options});
	 * @desc Create a a gallery from an unordered list of images with thumbnails
	 * @options
	 *   insert:   (selector string) by default, Galleria will create a container div before your ul that holds the image.
	 *			 You can, however, specify a selector where the image will be placed instead (f.ex '#main_img')
	 *   history:  Boolean for setting the history object in action with enabled back button, bookmarking etc.
	 *   onImage:  (function) a function that gets fired when the image is displayed and brings the jQuery image object.
	 *			 You can use it to add click functionality and effects.
	 *			 f.ex onImage(image) { image.css('display','none').fadeIn(); } will fadeIn each image that is displayed
	 *   onThumb:  (function) a function that gets fired when the thumbnail is displayed and brings the jQuery thumb object.
	 *			 Works the same as onImage except it targets the thumbnail after it's loaded.
	 *
	**/

	$$ = $.fn.galleria = function($options) {
		
		// check for basic CSS support
		if (!$$.hasCSS()) { return false; }
		
		// init the modified history object
	//	$.historyInit($$.onPageLoad);
		
		// set default options
		var $defaults = {
			insert	  : '.galleria_container',
			history	 : true,
			clickNext   : true,
			onImage	 : function(image,caption,thumb) {},
			onThumb	 : function(thumb) {}
		};
		

		// extend the options
		var $opts = $.extend($defaults, $options);
		
		// bring the options to the galleria object
		for (var i in $opts) {
			$.galleria[i]  = $opts[i];
		}
		
		// if no insert selector, create a new division and insert it before the ul
		var _insert = ( $($opts.insert).is($opts.insert) ) ? 
			$($opts.insert) : 
			jQuery(document.createElement('div')).insertBefore(this);
			
		// create a wrapping div for the image
		var _div = $(document.createElement('div')).addClass('galleria_wrapper');
		
		// create a caption span
		var _span = $(document.createElement('span')).addClass('caption');
		
		// inject the wrapper in in the insert selector
		_insert.addClass('galleria_container').append(_div).append(_span);
		
		//-------------
		
		return this.each(function(){
			
			// add the Galleria class
			$(this).addClass('galleria');
			
			// loop through list
			$(this).children('li').each(function(i) {
				
				// bring the scope
				var _container = $(this);
								
				// build element specific options
				var _o = $.meta ? $.extend({}, $opts, _container.data()) : $opts;
				
				// remove the clickNext if image is only child
				_o.clickNext = $(this).is(':only-child') ? false : _o.clickNext;
				
				// try to fetch an anchor
				var _a = $(this).find('a').is('a') ? $(this).find('a') : false;
				
				// reference the original image as a variable and hide it
				var _img = $(this).children('img').css('display','none');
				
				// extract the original source
				var _src = _a ? _a.attr('href') : _img.attr('src');
				
				// find a title
				var _title = _a ? _a.attr('title') : _img.attr('title');
				
				// create loader image			
				var _loader = new Image();
				
				// check url and activate container if match
				if (_o.history && (window.location.hash && window.location.hash.replace(/\#/,'') == _src)) {
					_container.siblings('.active').removeClass('active');
					_container.addClass('active');
				}
			
				// begin loader
				$(_loader).load(function () {
					
					// try to bring the alt
					$(this).attr('alt',_img.attr('alt'));
					
					//-----------------------------------------------------------------
					// the image is loaded, let's create the thumbnail
					
					var _thumb = _a ? 
						_a.find('img').addClass('thumb noscale').css('display','none') :
						_img.clone(true).addClass('thumb').css('display','none');
					
					if (_a) { _a.replaceWith(_thumb); }
					
					if (!_thumb.hasClass('noscale')) { // scaled tumbnails!
						var w = Math.ceil( _img.width() / _img.height() * _container.height() );
						var h = Math.ceil( _img.height() / _img.width() * _container.width() );
						if (w < h) {
							_thumb.css({ height: 'auto', width: _container.width(), marginTop: -(h-_container.height())/2 });
						} else {
							_thumb.css({ width: 'auto', height: _container.height(), marginLeft: -(w-_container.width())/2 });
						}
					} else { // Center thumbnails.
						// a tiny timer fixed the width/height
						window.setTimeout(function() {
							_thumb.css({
								marginLeft: -( _thumb.width() - _container.width() )/2, 
								marginTop:  -( _thumb.height() - _container.height() )/2
							});
						}, 1);
					}
					
					// add the rel attribute
					_thumb.attr('rel',_src);
					
					// add the title attribute
					_thumb.attr('title',_title);
					
					// add the click functionality to the _thumb
					_thumb.click(function() {
						$.galleria.activate(_src);
					});
					
					// hover classes for IE6
					_thumb.hover(
						function() { $(this).addClass('hover'); },
						function() { $(this).removeClass('hover'); }
					);
					_container.hover(
						function() { _container.addClass('hover'); },
						function() { _container.removeClass('hover'); }
					);

					// prepend the thumbnail in the container
					_container.prepend(_thumb);
					
					// show the thumbnail
					_thumb.css('display','block');
					
					// call the onThumb function
					_o.onThumb(jQuery(_thumb));
					
					// check active class and activate image if match
					if (_container.hasClass('active')) {
						$.galleria.activate(_src);
						//_span.text(_title);
					}
					
					//-----------------------------------------------------------------
					
					// finally delete the original image
					_img.remove();
					
				}).error(function () {
					
					// Error handling
					_container.html('<span class="error" style="color:red">Error loading image: '+_src+'</span>');
				
				}).attr('src', _src);
			});
		});
	};

	/**
	 *
	 * @name NextSelector
	 *
	 * @desc Returns the sibling sibling, or the first one
	 *
	**/

	$$.nextSelector = function(selector) {
		return $(selector).is(':last-child') ?
			   $(selector).siblings(':first-child') :
			   $(selector).next();
			   
	};

	/**
	 *
	 * @name previousSelector
	 *
	 * @desc Returns the previous sibling, or the last one
	 *
	**/

	$$.previousSelector = function(selector) {
		return $(selector).is(':first-child') ?
			   $(selector).siblings(':last-child') :
			   $(selector).prev();
			   
	};

	/**
	 *
	 * @name hasCSS
	 *
	 * @desc Checks for CSS support and returns a boolean value
	 *
	**/

	$$.hasCSS = function()  {
		$('body').append(
			$(document.createElement('div')).attr('id','css_test')
			.css({ width:'1px', height:'1px', display:'none' })
		);
		var _v = ($('#css_test').width() != 1) ? false : true;
		$('#css_test').remove();
		return _v;
	};

	/**
	 *
	 * @name onPageLoad
	 *
	 * @desc The function that displays the image and alters the active classes
	 *
	 * Note: This function gets called when:
	 * 1. after calling $.historyInit();
	 * 2. after calling $.historyLoad();
	 * 3. after pushing "Go Back" button of a browser
	 *
	**/

	$$.onPageLoad = function(_src) {	
		
		// get the wrapper
		var _wrapper = $('.galleria_wrapper');
		
		// get the thumb
	//	var _thumb = $('.galleria img[@rel="'+_src+'"]');
		var _thumb = $('.galleria img[rel="'+_src+'"]');
		
		if (_src) {
			
			// new hash location
			if ($.galleria.history) {
				window.location = window.location.href.replace(/\#.*/,'') + '#' + _src;
			}
			
			// alter the active classes
			_thumb.parents('li').siblings('.active').removeClass('active');
			_thumb.parents('li').addClass('active');
		
			// define a new image
			var _img   = $(new Image()).attr('src',_src).addClass('replaced');

			// empty the wrapper and insert the new image
			_wrapper.empty().append(_img);

			// insert the caption
			_wrapper.siblings('.caption').text(_thumb.attr('title'));
			
			// fire the onImage function to customize the loaded image's features
			$.galleria.onImage(_img,_wrapper.siblings('.caption'),_thumb);
			
			// add clickable image helper
			if($.galleria.clickNext) {
				_img.css('cursor','pointer').click(function() { $.galleria.next(); })
			}
			
		} else {
			
			// clean up the container if none are active
			_wrapper.siblings().andSelf().empty();
			
			// remove active classes
			$('.galleria li.active').removeClass('active');
		}

		// place the source in the galleria.current variable
		$.galleria.current = _src;
		
	}

	/**
	 *
	 * @name jQuery.galleria
	 *
	 * @desc The global galleria object holds four constant variables and four public methods:
	 *	   $.galleria.history = a boolean for setting the history object in action with named URLs
	 *	   $.galleria.current = is the current source that's being viewed.
	 *	   $.galleria.clickNext = boolean helper for adding a clickable image that leads to the next one in line
	 *	   $.galleria.next() = displays the next image in line, returns to first image after the last.
	 *	   $.galleria.prev() = displays the previous image in line, returns to last image after the first.
	 *	   $.galleria.activate(_src) = displays an image from _src in the galleria container.
	 *	   $.galleria.onImage(image,caption) = gets fired when the image is displayed.
	 *
	**/

	$.extend({galleria : {
		current : '',
		onImage : function(){},
		activate : function(_src) { 
			if ($.galleria.history) {
				$.historyLoad(_src);
			} else {
				$$.onPageLoad(_src);
			}
		},
		next : function() {
	//		var _next = $($$.nextSelector($('.galleria img[@rel="'+$.galleria.current+'"]').parents('li'))).find('img').attr('rel');
			var _next = $($$.nextSelector($('.galleria img[rel="'+$.galleria.current+'"]').parents('li'))).find('img').attr('rel');
			$.galleria.activate(_next);
		},
		prev : function() {
	//		var _prev = $($$.previousSelector($('.galleria img[@rel="'+$.galleria.current+'"]').parents('li'))).find('img').attr('rel');
			var _prev = $($$.previousSelector($('.galleria img[rel="'+$.galleria.current+'"]').parents('li'))).find('img').attr('rel');
			$.galleria.activate(_prev);
		}
	}
	});

	})(jQuery);


	/**
	 *
	 * Packed history extension for jQuery
	 * Credits to http://www.mikage.to/
	 *
	**/


	//jQuery.extend({historyCurrentHash:undefined,historyCallback:undefined,historyInit:function(callback){jQuery.historyCallback=callback;var current_hash=location.hash;jQuery.historyCurrentHash=current_hash;if(jQuery.browser.msie){if(jQuery.historyCurrentHash==''){jQuery.historyCurrentHash='#'}$("body").prepend('<iframe id="jQuery_history" style="display: none;"></iframe>');var ihistory=$("#jQuery_history")[0];var iframe=ihistory.contentWindow.document;iframe.open();iframe.close();iframe.location.hash=current_hash}else if($.browser.safari){jQuery.historyBackStack=[];jQuery.historyBackStack.length=history.length;jQuery.historyForwardStack=[];jQuery.isFirst=true}jQuery.historyCallback(current_hash.replace(/^#/,''));setInterval(jQuery.historyCheck,100)},historyAddHistory:function(hash){jQuery.historyBackStack.push(hash);jQuery.historyForwardStack.length=0;this.isFirst=true},historyCheck:function(){if(jQuery.browser.msie){var ihistory=$("#jQuery_history")[0];var iframe=ihistory.contentDocument||ihistory.contentWindow.document;var current_hash=iframe.location.hash;if(current_hash!=jQuery.historyCurrentHash){location.hash=current_hash;jQuery.historyCurrentHash=current_hash;jQuery.historyCallback(current_hash.replace(/^#/,''))}}else if($.browser.safari){if(!jQuery.dontCheck){var historyDelta=history.length-jQuery.historyBackStack.length;if(historyDelta){jQuery.isFirst=false;if(historyDelta<0){for(var i=0;i<Math.abs(historyDelta);i++)jQuery.historyForwardStack.unshift(jQuery.historyBackStack.pop())}else{for(var i=0;i<historyDelta;i++)jQuery.historyBackStack.push(jQuery.historyForwardStack.shift())}var cachedHash=jQuery.historyBackStack[jQuery.historyBackStack.length-1];if(cachedHash!=undefined){jQuery.historyCurrentHash=location.hash;jQuery.historyCallback(cachedHash)}}else if(jQuery.historyBackStack[jQuery.historyBackStack.length-1]==undefined&&!jQuery.isFirst){if(document.URL.indexOf('#')>=0){jQuery.historyCallback(document.URL.split('#')[1])}else{var current_hash=location.hash;jQuery.historyCallback('')}jQuery.isFirst=true}}}else{var current_hash=location.hash;if(current_hash!=jQuery.historyCurrentHash){jQuery.historyCurrentHash=current_hash;jQuery.historyCallback(current_hash.replace(/^#/,''))}}},historyLoad:function(hash){var newhash;if(jQuery.browser.safari){newhash=hash}else{newhash='#'+hash;location.hash=newhash}jQuery.historyCurrentHash=newhash;if(jQuery.browser.msie){var ihistory=$("#jQuery_history")[0];var iframe=ihistory.contentWindow.document;iframe.open();iframe.close();iframe.location.hash=newhash;jQuery.historyCallback(hash)}else if(jQuery.browser.safari){jQuery.dontCheck=true;this.historyAddHistory(hash);var fn=function(){jQuery.dontCheck=false};window.setTimeout(fn,200);jQuery.historyCallback(hash);location.hash=newhash}else{jQuery.historyCallback(hash)}}});


})();





////////////////////////////
//fenrir_sbm.js			  //
//delicious の情報取得	  //
////////////////////////////

function reqDelicious(u) {
	var $ = jQuery;
	var delPath = "http://feeds.delicious.com/v2/json/urlinfo/blogbadge?url="+u;
	$.get(delPath,function(data){
		if ( data[0] && data[0].total_posts ) {
			var c = data[0].total_posts;
		}
		if(c){
			$('#delicious_count').css({'background':'#5592E9','padding':'0 4px','color':'#ffffff','font-size':'70%'})
								 .append(c);
		}
	},"jsonp");
}



//////////////////////////////
//  about.js				//
//  Aabout,manage 切り替え  //
//////////////////////////////

function aboutload() {
	document.getElementById("about").style.display = "block";
	document.getElementById("manage").style.display = "none";
		document.getElementById("about_button").style.backgroundImage = "url(images/about/aboutbutton_on.png)";
		document.getElementById("manage_button").style.backgroundImage = "url(images/about/managebutton_off.png)";
}

function manageload() {
	document.getElementById("about").style.display = "none";
	document.getElementById("manage").style.display = "block";
		document.getElementById("about_button").style.backgroundImage = "url(images/about/aboutbutton_off.png)";
		document.getElementById("manage_button").style.backgroundImage = "url(images/about/managebutton_on.png)";
}

function about(){
		document.getElementById("about").style.display = "block";
		document.getElementById("manage").style.display = "none";
		document.getElementById("about_button").style.backgroundImage = "url(images/about/aboutbutton_on.png)";
		document.getElementById("manage_button").style.backgroundImage = "url(images/about/managebutton_off.png)";
}

function manage(){
		document.getElementById("about").style.display = "none";
		document.getElementById("manage").style.display = "block";
		document.getElementById("about_button").style.backgroundImage = "url(images/about/aboutbutton_off.png)";
		document.getElementById("manage_button").style.backgroundImage = "url(images/about/managebutton_on.png)";
}


function a_hover(){
	if(document.getElementById("about").style.display == "none"){
		document.getElementById("about_button").style.backgroundImage = "url(images/about/aboutbutton_hover.png)";
	}
}

function m_hover(){
	if(document.getElementById("manage").style.display == "none"){
		document.getElementById("manage_button").style.backgroundImage = "url(images/about/managebutton_hover.png)";
	}
}

function a_out(){
	if(document.getElementById("about").style.display == "none"){
		document.getElementById("about_button").style.backgroundImage = "url(images/about/aboutbutton_off.png)";
	}
}

function m_out(){
	if(document.getElementById("manage").style.display == "none"){
		document.getElementById("manage_button").style.backgroundImage = "url(images/about/managebutton_off.png)";
	}
}




