/*==================================================================
//
//  font_x.cssの切り替え
//
==================================================================*/
var rootPath = '/';
//==============================
//cookieのfsizeを取得
fsize = $.cookie('fsize');
//fsizeがnullじゃなかったら、#fontSize（css）のhref属性を置き換え
if(fsize != null) {
	$(function(){
		$("#fontSize").attr({href:rootPath + $.cookie('fsize')});
	});
}
//==============================
function fontSize(size){
	cssName = "css/" + size + ".css";
	cssPath = rootPath + cssName;
	//
	$('#fontSize').attr({href:cssPath});
	//fsizeにcssPathをセットして、30日間保存
	$.cookie('fsize',cssName,{expires:30,path:'/'});
}
//==============================
/*
function cookieControl(){
	lang=document.form1.language.value;
	size=document.form1.font_size.value;
	timer=document.form1.exp_date.value;
	//
	cssName="shared/css/"+size+".css";
	cssPath=currentPath+cssName;
	//
	//fsizeにcssPathをセットして、timer日間保存
	$.cookie('fsize',cssName,{expires:timer,path:'/'});
	//languageにlangをセットして、timer日間保存
	$.cookie('language',lang,{expires:timer,path:'/'});
	//
	$('#fontSize').attr({href:cssPath});
	window.opener.location.reload();
}
*/
//==============================
/*
function cookieReset(lang,size,timer){
	cssName="css/" + size + ".css";
	cssPath = rootPath + cssName;
	//
	//fsizeにcssPathをセットして、timer日間保存
	$.cookie('fsize',cssName,{expires:timer,path:'/'});
	//fsizeにcssPathをセットして、timer日間保存
	$.cookie('language',lang,{expires:timer,path:'/'});
	//
	$('#fontSize').attr({href:cssPath});
	window.opener.location.reload();
}
*/

/*==================================================================
//
//  LIKN
//
==================================================================*/
function clickLink(URL, target){
	if(URL != "" ){
		if(target == "top"){
			top.location.href = URL;
		}else if(target == "blank"){
			window.open(URL, "");
		}else if(target != ""){
			eval("parent.' + target + '.location.href = URL");
		}else{
			location.href = URL;
		}
	}
}

/*==================================================================
//
//  ロールオーバー
//
==================================================================*/
function initClickableArea()
{
	//画像のロールオーバー
	var obj = $(".rollover a img, img.rollover");
	$.each(obj, function() {
		changeBt($(this), $(this));
	});
	//==============================
	//画像の透過
	$(".img_over a img").hover (
		function ()
		{
			$(this).fadeTo(100, 0.7);
		},
		function ()
		{
			$(this).fadeTo(100, 0.999999);
		}
	);
	//==============================
	//テキスト要素のみ
	$(".clickable_area").find("[onclick*='clickLink']").addClass("clickable");
	//
	var obj = $(".clickable_area .clickable");
	$.each(obj, function(){
		var _target = $(this).hover(
			function ()
			{
				$(this).addClass("over");
			},
			function ()
			{
				$(this).removeClass("over");
			}
		);
		//画像のボタンがある場合
		if (_target.find("div").is(".rolloverBt"))
		{
			changeBt(_target.find("a img"), _target);
		}
	});
	//==============================
	//画像を含む時
	$(".clickable_areaContainImg").find("[onclick*='clickLink']").addClass("clickableContainImg");
	//
	var obj = $(".clickable_areaContainImg .clickableContainImg");
	$.each(obj, function(){
		var _target = $(this).append("<span class='imgCover'></span>");
		//
		var imgCover = _target.find(".imgCover").css({
			width: _target.outerWidth(),
			height: _target.outerHeight(),
			background: "url('../images/common/spacer.gif')",
			display: "block",
			position: "absolute",
			top: "0px",
			left: "0px",
			zIndex: "100",
			cursor: "pointer"
		});
		//
		imgCover.hover(
			function ()
			{
				$(this).parent().find("img.mainImg").fadeTo(100, 0.7);
				//
				$(this).parent(".backNumberTopic").find(".backNumberTopicCapBg").animate({
					height: "40px",
					top: "117px"
				}, 100);
				//
				$(this).parent(".backNumberTopic").find("h4").animate({
					top: "117px"
				}, 100);
			},
			function ()
			{
				$(this).parent().find("img.mainImg").fadeTo(100, 0.999999);
				//
				$(this).parent(".backNumberTopic").find(".backNumberTopicCapBg").animate({
					height: "35px",
					top: "122px"
				}, 100);
				//
				$(this).parent(".backNumberTopic").find("h4").animate({
					top: "122px"
				}, 100);
			}
		);
		//
		//画像のボタンがある場合
		if (_target.find("div").is(".rolloverBt"))
		{
			changeBt(_target.find("a img"), _target.find(".imgCover"));
		}
	});
	//
	function changeBt(target, clickableArea)
	{
		var image_cache = new Object();
		//
		target.not("[src*='_on.']").each(function(i) {
			var _this = this; 
			var imgsrc = _this.src;
			var dot = _this.src.lastIndexOf('.');
			var imgsrc_on = _this.src.substr(0, dot) + '_on' + _this.src.substr(dot, 4);
			image_cache[_this.src] = new Image();
			image_cache[_this.src].src = imgsrc_on;
			//
			clickableArea.hover(
				function() { _this.src = imgsrc_on; },
				function() { _this.src = imgsrc; }
			);
		});
	};
}
//
$(document).ready(initClickableArea);

/*==================================================================
//
//  時計
//
==================================================================*/
var Clock = {
	
	init: function(){
		this.start();
	},
	
	display: function()
	{
		var _d = new Date();
		var Y = _d.getFullYear();
		var M = _d.getMonth() + 1;
		var D = _d.getDate();
		var h = _d.getHours();
		var m = _d.getMinutes();
		var s = _d.getSeconds();
		var t = "JP :: " + Y + "." + Clock.trim(M) + "." + Clock.trim(D) + " " + Clock.trim(h) + ":" + Clock.trim(m);
		
		$("#clock").html("<p>" + t + "</p>");
	},
	
	trim: function(num){
		num += 100;
		num = String(num).substr(1, 2)
		return num;
	},
	
	start: function(){
		var timer = setInterval(this.display, 1000);
	}
};
//
$(document).ready(function(){
	Clock.init();
});
/*==================================================================
//
//  タブ
//
==================================================================*/
jQuery.fn.extend({
	
	simpleTab: function( _header, _body){
		
		this.obj = { _oList:[], _h:_header, _b:_body }
		var _this = this;
		
		this.each(function(index, domEle)
		{
			_this.obj._oList.push(jQuery(this));
			var tabBody = jQuery(this).find(_body);
			
			//クラスが current でないものを閉じる
			var currentTabClass = "";
			currentTabClass = getTabClass(jQuery(this).find(_header + "[class*='current']").attr("class"));
			jQuery(this).find(_body).hide();
			jQuery(this).find(_body + "[class*=" + currentTabClass +"]").show();
			//console.log(currentTabClass)
			//
			//タブのz-index入れ替え
			_this.obj._t = jQuery(this).find(_header + "[class*=" + currentTabClass +"]");
			setDepth();
			//
			jQuery(this).find(_header)
				.click(function(){tabAction(jQuery(this), tabBody);})
				.mouseover(function(){jQuery(this).addClass("over")})
				.mouseout(function(){jQuery(this).removeClass("over")})
		});
	
		function tabAction(_t, _tBody)
		{
			_this.obj._t = _t;
			_t.addClass("current");
			_t.siblings(_this.obj._h).removeClass("current");
			var currentTabClass = getTabClass(_t.attr("class"));
			if(currentTabClass != "line")
			{
				_tBody.filter("[class!=" + currentTabClass + "]").hide();
				_tBody.filter("[class*=" + currentTabClass + "]").show();
			}
			setDepth();
		};
		
		function getTabClass( _classNames )
		{
			_classNames = _classNames.replace("current", "");
			_classNames = _classNames.replace("over", "");
			_classNames = _classNames.replace("tabTitle", "");
			_classNames = _classNames.replace("pingFix", "");
			_classNames = jQuery.trim(_classNames);
			return _classNames;
		}
		
		function setDepth()
		{
			_this.obj._t.siblings(_this.obj._h).each(function (index, domEle){
				jQuery(this).css("z-index", 10-index);
			});
			_this.obj._t.css("z-index", 50);
		}
	}
})

jQuery(document).ready(function(){
	jQuery(".tab").simpleTab("li", "div.tabBody");
	jQuery("#sidePanel .layerTab").simpleTab("li.tabTitle", "div");
	jQuery("#sidePanel .layerTab2").simpleTab("li.tabTitle", "div.tabBody");
});
/*==================================================================
//
//  ランキング
//
==================================================================*/
jQuery(document).ready(function(){
	jQuery("#sideRankingPanel ol").each(function(index, domEle)
	{
		jQuery(this).find("li").each(function(index, domEle)
		{
			jQuery(this).addClass("num" + Number(index + 1));
		});
	});
});
/*==================================================================
//
//  アーカイブ縞
//
==================================================================*/
jQuery(document).ready(function(){
	jQuery("#sideArchivePanel ul li:odd").addClass("odd")
});
/*==================================================================
//
//  エントリーキャプション幅
//
==================================================================*/
jQuery(document).ready(function(){
	var loc = jQuery(".image_w img");
	if( loc[0] ) jQuery(".image_w .cap").width( loc.width() )
});
/*==================================================================
//
//  エントリー画像のフレーム
//
==================================================================*/
function initImgFrame()
{
	if ($(".entryDetail").find("[class='entryImageNoCap']").hasClass("entryImageNoCap"))
	{
		$(".entryImageNoCap").wrapInner("<span class='imgFrame'></span>");
		//
		$(".entryImageNoCap .imgFrame").css({
			display: "block",
			width: $(".entryImageNoCap img").width(),
			height: $(".entryImageNoCap img").height(),
			margin: "0px auto",
			padding: "5px",
			border: "1px solid #CCCCCC"
		});
	}
}
//
$(document).ready(initImgFrame);


/*==================================================================
//
//  実績紹介のapple風スライドショー
//
==================================================================*/
function initShowCase()
{
	if ($(".showcase").length)
	{
		$(function() {
			$(".showcase").jCarouselLite({
				btnNext: ".showcase_prev",
				btnPrev: ".showcase_next"
			});
		});
	}
}
//
$(document).ready(initShowCase);


/*==================================================================
//
//  トップの画像切り替え
//
==================================================================*/
function initSlideShow()
{
	if ($("#s3slider").length)
	{
		$('#s3slider').s3Slider({ 
			timeOut: 6000 
		});
	}
}
//
$(document).ready(initSlideShow);

/*==================================================================
//
//  角丸
//
==================================================================*/
function initCorner()
{
	if ($(".corner").length)
	{
		$('.corner').corner("5px");
	}
}
//
$(document).ready(initCorner);


