//smartrollover
function smartRollover() {
	if(document.getElementsByTagName) {
		var images = document.getElementsByTagName("img");
		for(var i=0; i < images.length; i++) {
			if(images[i].getAttribute("src").match("_n.")){
				images[i].onmouseover = function() {
					this.setAttribute("src", this.getAttribute("src").replace("_n.", "_o."));
				}
				images[i].onmouseout = function() {
					this.setAttribute("src", this.getAttribute("src").replace("_o.", "_n."));
				}
			}
		}
	}
}

if(window.addEventListener) {
	window.addEventListener("load", smartRollover, false);
} else if(window.attachEvent) {
	window.attachEvent("onload", smartRollover);
}

//external
function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external")
		anchor.target = "_blank";
	}
}
if(window.addEventListener) {
	window.addEventListener("load", externalLinks, false);
} else if(window.attachEvent) {
	window.attachEvent("onload", externalLinks);
}

//smoothscroll
jQuery.easing.quart = function (x, t, b, c, d) {
	return -c * ((t=t/d-1)*t*t*t - 1) + b;
};

$(function(){
	jQuery('a[href*=#]').click(function() {
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
			var $target = jQuery(this.hash);
			$target = $target.length && $target || jQuery('[name=' + this.hash.slice(1) +']');
			if ($target.length) {
				var targetOffset = $target.offset().top;
				jQuery('html,body').animate({ scrollTop: targetOffset }, 600, 'quart');
				return false;
			}
		}
	});
});


//リンクにフタ
this.tooltip = function(){	
	xOffset = 10;
	yOffset = 20;
	$("a.tooltip").hover(function(e){
		this.t = this.title;
		this.title = "";
		$(this).css('cursor','default');
		$("body").append("<p id='tooltip'>"+ this.t +"</p>");
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");
	},
	function(){
		this.title = this.t;
		$("#tooltip").remove();
	});	
	$("a.tooltip").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});
};

$(function(){
	//リンクにフタを実行
	tooltip();
	//新着の角丸
	//var cornerBlock = $('section#whatsNewBlock dl');
	//$(cornerBlock).corner('tl cc:#CC0000 10px');
	//$(cornerBlock).corner('tr cc:transparent 10px');
	//$(cornerBlock).corner('bl cc:transparent 10px');
	//$(cornerBlock).corner('br cc:transparent 10px');
	//過去リンクBOXの制御
	$('#bnrA,#archivesNav').mouseover(function(){
		$('#archivesNav').css('display','block');
	}).mouseout(function(){
		$('#archivesNav').css('display','none');
	})
	$('#archivesNav li').click(function(){
		$('#archivesNav').css('display','none');
	});
	//リンクの枠消し
	$('p.sponsor a,.mainSponsor,a.tooltip,header a').focus(function(){
		this.blur();
	})
	//メルマガ登録ポップアップ
	$(".popWin").click(function(){
		var WO=window.open(this.href,'magazine','status=1,scrollbars=1,width=500,height=300,top=40,left=40');
		WO.focus();
		return false;
	});
	//問い合わせフォームポップアップ
	$(".popConcactJp").click(function(){
		var WO=window.open(this.href,'contact','status=yes,scrollbars=yes,width=620,height=620,top=20,left=20');
		WO.focus();
		return false;
	});
	
	//プログラムページの外部HTML読み込み
	$("#program #updateTxt").load("update.html");
	//プログラムページのブロック高さ調整
	//プログラムページのCSS調整
	$('#program div.circuitBlock dt:first-child').css('border-top','none');
	$('#program div.circuitBlock dd:last-child').css('border-bottom','none');
	$('dl.timeSche dd:last-child').css('margin-bottom','0');
	$('dl.timeSche dd:last-child').css('padding-bottom','0');
})

//------------------------------
//link to mailer
//
function applyClubtokyojazz(){
	var address = '';
	address += 'clubtokyojazz';
	address += '@';
	address += 'nhk-ep.co.jp';
	window.location.href = 'mailto:'+address;
}

