/*------------------------------------------------------------
 * basic.js (jQuery.js) Version 0.7
/*------------------------------------------------------------*/

$(function (){
	initRollOver();
	iniExLink();
	iniCloseBox();
	iniColorBox();
	iniColorBoxLink();
});



/* 1: img.btn, input.btnにロールオーバー効果を付けます。
==============================================================*/

function initRollOver(){
    $("img.btn, input.btn").mouseover(
		function (){ initMouseOver($(this));}
	).mouseout(
		function (){initMouseOut($(this));}
	);
}

function initMouseOver(obj){
	obj.not("[src*='_on.']").attr("src", obj.attr("src").replace(/^(.+)(\.[a-z]+)$/, "$1_on$2"));
}

function initMouseOut(obj){
	obj.attr("src", obj.attr("src").replace(/^(.+)_on(\.[a-z]+)$/, "$1$2"));
}


/* 2: 外部リンクを別窓で開きます。
==============================================================*/

function iniExLink(){
	$("a.ex-link").click(function(){
		window.open(this.href, "new");
		return false;
	});
}





/* 3: .close-boxを開閉させます。
==============================================================*/

function iniCloseBox(){
	var closeBox = $(".close-box");
	var triggerBar = $("dt, h3", closeBox);
	var box, flag;

	$("dd, table.table-form", closeBox).css("display", "none");
	$(triggerBar).not("#config-master dt").css("margin-bottom", "15px");

	$(triggerBar).css({
		cursor: "pointer",
		color: "#009ce5"
	}).click(function(){
		if(this.tagName.toLowerCase() == "dt"){
			box = $("~dd", $(this));
			flag = "block";
		}else
		if(this.tagName.toLowerCase() == "h3"){
			box = $("~table.table-form", $(this));
			flag = "table";
		}

		if( $(box).is(":hidden") ){
			if( flag == "table" ){ box.css("display", "table"); }else{ box.css("display", "block"); }
		}else{
			box.css("display", "none");
		}
	});
}





/* 4: a.colorboxのリンクをcolorboxで開きます。
==============================================================*/

function iniColorBox() { 
	$(".colorbox").colorbox({width:"690px", height:"90%", iframe: true});
}


function iniColorBoxLink() {
	if($("body#popup a").length){
		$("body#popup p.rel-link a, body#popup p.ex-link a").click(function(){
			parent.location.href = $(this).attr("href");
		});
	}
}

