/*
 * requires:jQuery v1.4.2 later
 * name:settings.js
 * author:Manabu Kushimoto(kushimoto@n-di.co.jp)
 */
 
jQuery(function($){
					 
	//外部リンクブランク
	var pageURL=document.URL,siteURL=new String(pageURL).replace(/^([\D\d\.]+)\/\/([\D\d\.]+).jp\/([\D\d\.\/]+)?/,"$1//$2.jp");
	$.fn.targetBlank=function(){
		var $t=$(this),thisURL=$t.attr("href");
		$t.click(function(){
			window.open(thisURL,"_blank");
			return false;
		});
	}
	$("a[href^='http://'],a[href^='https://'],a.blank").not($("a[href^='"+siteURL+"']")).each(function(){$(this).targetBlank();});

	//擬似セレクタ - only first-child and last-child
	$.fn.ElementSelecter=function(){
		var $t=$(this),$children=$t.children();
		$children.each(function(i){
			var lastNum=new Number($children.length)-1;
			$children.eq(0).addClass("first-child");
			$children.eq(lastNum).addClass("last-child");
		});
	};
	$(".pageNav").each(function(){ $(this).ElementSelecter(); });

	//セレクタに正規表現を利用するプラグイン
	$.expr[':'].regex = function(elem, index, match) {
		var matchParams = match[3].split(','),
		validLabels = /^(data|css):/,
		attr = {
			method: matchParams[0].match(validLabels) ? 
			matchParams[0].split(':')[0] : 'attr',
			property: matchParams.shift().replace(validLabels,'')
		},
		regexFlags = 'ig',
		regex = new RegExp(matchParams.join('').replace(/^\s+|\s+$/g,''), regexFlags);
		return regex.test(jQuery(elem)[attr.method](attr.property));
	}

	//ページ内スクロール
	$.fn.pageScroll=function(){
		var $t=$(this);
		$t.click(function(){
			var Hash=$(this.hash),HashOffset=$(Hash).offset().top;
			$("html,body").animate({
				scrollTop: HashOffset
			},1000,"easeOutQuart");
			return false;
		});
	}
	$("a:regex(href,^#[a-z,A-Z])").pageScroll();
	
	/*
	$.fn.radioDisplay=function(){
		var $t=$(this),$radio=$("input:radio",$t),$checked=$("input:checked",$t),active="active",$nextElm=$t.next();
		$nextElm.hide();
		$checked.addClass(active);
		$radio.click(function(){
			switch($(this).attr("class")){
				case active:
					$(this).removeAttr("checked");
					$radio.removeClass(active);
					$nextElm.fadeOut();
					$("input",$nextElm).val("").removeAttr("checked");
				break;
				default:
					$radio.not(this).removeClass(active);
					$(this).addClass(active);
					$nextElm.fadeIn();
				break;
			}
		});
	};
	
	$(".radioDisplay").radioDisplay();
	*/

	$(".ready").each(function(){
		$(this).append("<canvas class='arrowCanvas' width='40' height='40' /><canvas class='arrowCanvas02' width='40' height='40' />");
		var arrowCanvas = $($(this).children("canvas.arrowCanvas")).get(0),
		arrowCanvas02 = $($(this).children("canvas.arrowCanvas02")).get(0);
		if( ! arrowCanvas || ! arrowCanvas.getContext ){
			return false;
		}else{
			var ctx = arrowCanvas.getContext("2d");
			ctx.beginPath();
			ctx.moveTo(0,20);
			ctx.lineTo(40,40);
			ctx.lineTo(20,0);
			ctx.closePath();
			ctx.strokeStyle="#cdcdcd";
			ctx.stroke();
			var ctx = arrowCanvas02.getContext("2d");
			ctx.beginPath();
			ctx.moveTo(0,19);
			ctx.lineTo(39,39);
			ctx.lineTo(19,0);
			ctx.closePath();
			ctx.fillStyle="#fff";
			ctx.fill();
		}
	});
});

