﻿$(function(){
fontSizeInit();
imgRoll();

	//dont right click
	$("#noRightClick").bind("contextmenu",function(event){
	return false;
	});
	$("body#noCopy").bind("copy",function(event){
	return false;
	});

});

/*---------------
font size change
----------------*/
//css dir path
dirPath = "http://www.seikyoonline.jp/common/css/";

//cookie name
fsize = $.cookie('fsize');

function fontSizeInit(){
	if(fsize != null) {
		$("#fontSizeControl").attr({href:dirPath + "font_" + $.cookie('fsize') + ".css"});
		dispSizeBtn(fsize);
	}else{
		dispSizeBtn("null");
	}
}

//change font size
function fontSize(size){
	cssPath = dirPath + "font_" + size + ".css";
	$('#fontSizeControl').attr({href:cssPath});
	$.cookie('fsize',size,{expires:30,path:'/'});
	dispSizeBtn(size);
}

//display size button
function dispSizeBtn(size){
	html = "";

	html += '<dl>';
	html += '<dt>文字サイズ</dt>';

	if(size == "l"){
	html += '<dd><a href="javascript:fontSize(\'s\');"><img src="http://www.seikyoonline.jp/common/images/header_btn_font_s_ovoff.gif" width="31" height="23" alt="小" /></a></dd>';
	html += '<dd><a href="javascript:fontSize(\'m\');"><img src="http://www.seikyoonline.jp/common/images/header_btn_font_m_ovoff.gif" width="30" height="23" alt="中" /></a></dd>';
	html += '<dd><img src="http://www.seikyoonline.jp/common/images/header_btn_font_l_ovon.gif" width="31" height="23" alt="大" /></dd>';
	}
	if(size == "m"){
	html += '<dd><a href="javascript:fontSize(\'s\');"><img src="http://www.seikyoonline.jp/common/images/header_btn_font_s_ovoff.gif" width="31" height="23" alt="小" /></a></dd>';
	html += '<dd><img src="http://www.seikyoonline.jp/common/images/header_btn_font_m_ovon.gif" width="30" height="23" alt="中" /></dd>';
	html += '<dd><a href="javascript:fontSize(\'l\');"><img src="http://www.seikyoonline.jp/common/images/header_btn_font_l_ovoff.gif" width="31" height="23" alt="大" /></a></dd>';
	}
	if(size == "s"){
	html += '<dd><img src="http://www.seikyoonline.jp/common/images/header_btn_font_s_ovon.gif" width="31" height="23" alt="小" /></dd>';
	html += '<dd><a href="javascript:fontSize(\'m\');"><img src="http://www.seikyoonline.jp/common/images/header_btn_font_m_ovoff.gif" width="30" height="23" alt="中" /></a></dd>';
	html += '<dd><a href="javascript:fontSize(\'l\');"><img src="http://www.seikyoonline.jp/common/images/header_btn_font_l_ovoff.gif" width="31" height="23" alt="大" /></a></dd>';
	}
	if(size == "null"){
	html += '<dd><a href="javascript:fontSize(\'s\');"><img src="http://www.seikyoonline.jp/common/images/header_btn_font_s_ovoff.gif" width="31" height="23" alt="小" /></a></dd>';
	html += '<dd><img src="http://www.seikyoonline.jp/common/images/header_btn_font_m_ovon.gif" width="30" height="23" alt="中" /></dd>';
	html += '<dd><a href="javascript:fontSize(\'l\');"><img src="http://www.seikyoonline.jp/common/images/header_btn_font_l_ovoff.gif" width="31" height="23" alt="大" /></a></dd>';
	}

	html += '</dl>';

	$('#headerFontBtn').html(html);
	imgRoll();
}


/*---------------
image rollover
----------------*/
function imgRoll(){
	var outImgName = "_ovoff";
	var overImgName = "_ovon";
	var preload = new Array();

	if(document.getElementsByTagName){
		var imgTagData = document.getElementsByTagName("img");
		var reOverImg = new RegExp(outImgName + "+(\.[a-z]+)$");
		var reOutImg = new RegExp(overImgName + "+(\.[a-z]+)$");

		for(var i=0; i<imgTagData.length; i++){
			if(imgTagData[i].getAttribute("src").match(reOverImg)){
				preload[i] = new Image();
				preload[i].src = imgTagData[i].getAttribute("src").replace(reOverImg, overImgName + "$1");
	
				imgTagData[i].onmouseover = function() {
					this.setAttribute("src", this.getAttribute("src").replace(reOverImg, overImgName + "$1"));
				}
	
				imgTagData[i].onmouseout = function() {
					this.setAttribute("src", this.getAttribute("src").replace(reOutImg, outImgName + "$1"));
				}
			}
		}
	}
	
	if(document.getElementsByTagName){
		var inputTagData = document.getElementsByTagName("input");
		var reOverImg = new RegExp(outImgName + "+(\.[a-z]+)$");
		var reOutImg = new RegExp(overImgName + "+(\.[a-z]+)$");
	
		for(var i=0; i<inputTagData.length; i++){
			if(inputTagData[i].src && inputTagData[i].getAttribute("src").match(reOverImg)){
				preload[i] = new Image();
				preload[i].src = inputTagData[i].getAttribute("src").replace(reOverImg, overImgName + "$1");
	
				inputTagData[i].onmouseover = function() {
					this.setAttribute("src", this.getAttribute("src").replace(reOverImg, overImgName + "$1"));
				}
	
				inputTagData[i].onmouseout = function() {
					this.setAttribute("src", this.getAttribute("src").replace(reOutImg, outImgName + "$1"));
				}
			}
		}
	}
}

/*---------------
light box
----------------*/
$(function() {
	if(document.getElementById("morePhoto")){
		$('#morePhoto a').lightBox();
	}
});

/*---------------
popup window
----------------*/
$(function() {
	//new Window
	$("a.openNewWin").click(function(){
		var url = $(this).attr("href");
		window.open(url,'',''); return false;
	});
	//パターンＡ（790）：今日の紙面/本誌特集記事
	$("a.openPop790").click(function(){
		var url = $(this).attr("href");
		window.open(url,"popup","width=790,height=660"); return false;
	});
	//パターンＢ（540）：音声再生ツール
	$("a.openPop540").click(function(){
		var url = $(this).attr("href");
		window.open(url,"popup","width=540,height=252,resizable=no"); return false;
	});
	//パターンＣ（748）：お問い合わせフォーム
	$("a.openPop748").click(function(){
		var url = $(this).attr("href");
		window.open(url,"popup","width=748,height=800,scrollbars=yes"); return false;
	});
	//パターンＣ（790）：環境報告
	$("a.openPop790b").click(function(){
		var url = $(this).attr("href");
		window.open(url,"popup","width=790,height=800,scrollbars=yes"); return false;
	});
	//パターンＤ（570）：携帯サイト
	$("a.openPop570").click(function(){
		var url = $(this).attr("href");
		window.open(url,"popup","width=570,height=380"); return false;
	});
	//パターンE（650）：プリント
	$("a.openPop650").click(function(){
		var url = $(this).attr("href");
		window.open(url,"popup","width=665,scrollbars=yes"); return false;
	});
});
