//--- ↓jQueryの初期化（prototype.jsとの衝突回避）↓ ---//
//	jQuery.noConflict();
//	var j$ = jQuery;
//--- ↑jQueryの初期化（prototype.jsとの衝突回避）↑ ---//

// Easingにquartオプションを追加
$.easing.quart = function (x, t, b, c, d){
	return -c * ((t=t/d-1)*t*t*t - 1) + b;
};


//--- 初期化 ---//
$(document).ready(function($){
	SyntaxHighlighter.all(); 	//ソースコードを有効

	// <a href="#***">の場合、スクロール処理を追加  
	$('a[href*=#]').click(function(){
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname){
			var $target = $(this.hash);
			$target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
			if ($target.length){
				if($.browser.msie && ($.browser.version < 7.0)){	//IE6とsafariの時
					var targetOffset = $target.offset().top;
					if(targetOffset < 0){ targetOffset = 0; }
					$('body').animate({ scrollTop: targetOffset }, 1500, 'quart');
				}else{
					var targetOffset = $target.offset().top - 120;
					if(targetOffset < 0){ targetOffset = 0; }
					if(($('html,body').height()) < targetOffset){ targetOffset = $('html,body').height()+50; }
					$('html,body').animate({ scrollTop: targetOffset }, 1500, 'quart');
				}
				return false;
			}
		}
	});
	
	/* counterの角丸化 */
	$('.rounded').corners();
	
	/* tooltipの実行 */
	readyWikipediaTip();
	
	$.tooltip.defaults = $.extend($.tooltip.defaults, {
		delay			: 1,
		showURL		: false,
		showBody	: " - ",
		//left		: -100,
    track			: true
	});

	$('.ttip').tooltip({extraClass: 'darktip'});

	/*
	 * 各々のページでページ読込完了時に実行したいことがある場合は
	 　pageReady関数を各々のページで作成し、その中に記述してください
	*/
	pageReady();
});

function pageReady(){
}

//--- WikipediaAPIと連動したToolTip ---//
function readyWikipediaTip(){
	$('.wktip').hover(function(){
		target = this;
		url = "http://wikipedia.simpleapi.net/api?callback=?";

		title = $(target).attr("word");
		title != undefined ? keyword = title : keyword = $(target).text();
		
		data = {
			keyword:keyword,
			output:'json'
		}
			
		$.getJSON(url, data, function(data){
			if(data == null){
				/**/
			}else{
				$(target).css("cursor","pointer")
				         .attr("title", data[0].body)
				         .tooltip({extraClass: 'darktip'});
			}
		});
	});
}

//--- メールの起動 ---//
function popUpMail() {
	name = 'miew';
	domain = "miew-world.net";
	this.location.href = "mailto:" + name + "@" + domain; 
}

//--- 管理ページへ移動 ---//
function redirectManager() {
	linkdir = 'MANAGER';
	this.location.href = "http://miew-world.net/" + linkdir + "/";
}

// jqueryオブジェクトの中身をダンプする関数
// FireFox専用　IEでは構文エラーでスクリプト自体が止まります
/*
function jquery_dump($obj){
	var dumphtml = [];
	if($.browser.msie){
		for(var i = 0; i < $obj.length; i++){
			dumphtml.push('[' + i + '] ');
			dumphtml.push($obj[i].outerHTML.replace(/^[\r\n\t]+/, ''));
			dumphtml.push("\n");
		}
	}else{
		for(var i = 0; i < $obj.length; i++){
			dumphtml.push('[' + i + '] '
				+ '<' + $obj[i].nodeName.toLowerCase());
			for(var j = 0; j < $obj[i].attributes.length; j++){
				dumphtml.push(' ' + $obj[i].attributes[j].nodeName + '="' 
					+ $obj[i].attributes[j].nodeValue + '"');
			}
			dumphtml.push('>' + $obj[i].innerHTML);
			dumphtml.push('<\/' + $obj[i].nodeName.toLowerCase() + '>');
			dumphtml.push("\n");
		}
	}
	alert(dumphtml.join(''));
}
*/


