/******************************
	いくくるウェブ基本JS（下記のことが出来ます）
	・外部リンクに外部アイコンをつける
	・スムーズスクロール
	・ロールオーバー
	・半透明のロールオーバー
	・現在のカテゴリ選択
	・スタイルキャッチャー（文字サイズ、背景色）
	・余計なフォントタグの除去
******************************/


/**********
	blank
**********/
$(document).ready(function() {
	$('#contents .pageLink a[href*=http]').each(function() {
		var href = $(this).attr("href");
		
		var regs = [];
		regs.push( new RegExp("^http://www.city.izumiotsu.lg.jp", "i") );
		regs.push( new RegExp("^http://www.city.izumiotsu.osaka.jp", "i") );
		
		//_blank
		var myDomain = false;
		
		for(var i=0; i < regs.length; i++) {
			if(  href.match(regs[i])  ) {
				myDomain = true;
				break;
			}
		}

		if(myDomain) {
			$(this).attr("target", "_self");
		}
		else {
			$(this).attr("target", "_blank");
			$(this).prepend('<img src="http://www.city.izumiotsu.lg.jp/material/template/img_page/icon_blank.gif" width="18" height="15" alt="外部サイトへ" />&nbsp;');
		}
	});
});







/**********
	smoothScroll
**********/
$(document).ready(function() {
	$.fn.smoothScroll = function(config) {
		var target = this;
		
		config = jQuery.extend({
				hoge: "Default value 1",
				hoge2: "Default value 2"
			},config);

		target.each(function(){
			var href = $(this).attr("href");
			
			
			if(href=='#') {
				$(this).click(function() {
					return false;
				});
				return true;
			}
			
			var hrefAry = href.match(/^([^#]*)#([^#]+)$/,function(whole,$1){ return $1 });
			
			if(hrefAry) {
				var j = $( "#" + hrefAry[2] );
				if(j.size() > 0) {
					
					jQuery.data($(this).get(0), "pos", j.offset().top);
					
					$(this).click(function() {
						
						$('html,body').animate({scrollTop: jQuery.data($(this).get(0), "pos")}, 400);
						return false;
					});
				}
			}
		});
	};
});

$(document).ready(function() {
	$('a[href*=#]').filter(function(){
		return !$(this).parent().parent().parent().is(".cNavTabBox");
	}).smoothScroll();
});


/**********
	rollover
**********/
$(document).ready(function(){
	$("img[src*='_off.']").each(function(){
		
		$("<img>").attr("src", $(this).attr("src").replace("_off.", "_on."));
	
		$(this).hover(function () {
			$(this).attr("src", $(this).attr("src").replace("_off.", "_on."));
		},function () {
			$(this).attr("src", $(this).attr("src").replace("_on.", "_off."));
		});
	});
});






/**********
	rollover2
**********/
$(document).ready(function(){
	$("img.JSroll").hover(function(){
		$(this).fadeTo(100, 0.7); // マウスオーバーで透明度を60%にする
	},function(){
		$(this).fadeTo(100, 1.0); // マウスアウトで透明度を100%に戻す
	});
});




/**********
	category
**********/
$(document).ready(function(){
	var reqUrl = location.pathname;
	var reqFstCat = reqUrl.split('/')[1];

	$("#headerNav > li > a").each(function(idx){
		var lnkUrl = $(this).attr("href");
		var fstCat = lnkUrl.split('/')[1];
		if(reqFstCat == fstCat) {
			var jImg = $($(this).find("img").get(0));
			jImg.attr("src", jImg.attr("src").replace(/_off(\.gif|\.jpg)/,"_on"+'$1') );
		}
	});
   
});





/**********
	style
**********/
jQuery.jStyle = function(opt){
	opt = opt || {};

	var self = {};
	self.path = opt.path;
	self.id = opt.id;


	self.setPath = function(name) {
		$('#' + this.id ).attr({href:this.path + name + '.css'});//this.=self.
		
	};


	self.Set = function(name) {
		this.setPath(name);
		$.cookie(this.id, name, {path:'/'});
	};
	
	if($.cookie(self.id)) {
		self.setPath($.cookie(self.id));
	}
	
	return self;
};
var js_s;
var js_c;
$(document).ready(function() {
	function rollOver() {
		//イベント削除
		$('.jStyle').find("img").unbind();
		
		$(".jStyle img[src*='_off.']").each(function(){
			
			$("<img>").attr("src", $(this).attr("src").replace("_off.", "_on."));
		
			$(this).hover(function () {
				$(this).attr("src", $(this).attr("src").replace("_off.", "_on."));
			},function () {
				$(this).attr("src", $(this).attr("src").replace("_on.", "_off."));
			});
		});
	}
	
	
	$('.jStyle').attr("href", "#");
	
	$('.jStyle').click(function(){
		return false;
	});







	
	
	
	js_s = $.jStyle({ path:'/material/template/css/', id:'styleSize' });
	js_c = $.jStyle({ path:'/material/template/css/', id:'styleColor' });
	
});






/**********
	space
**********/
$(document).ready(function(){
	/*連続でファイルダウンロード一覧があった場合、スペースを短くする*/
	var pageLinkFlg = false;
	$("#contents > *").each(function(idx){
		if( $(this).hasClass('pageLink') ) {
			// 前回のクラスが「pageLink」だったら
			if(pageLinkFlg) {
				$(this).addClass("top10");
			}
			pageLinkFlg = true;
		}
		else {
			pageLinkFlg = false;
		}
	});
});

$(document).ready(function(){
	/*pで囲まれていないテキストがあったら囲む*/
	$("div.wys").filter(function(){
		if( $($(this).find("p")).size() > 0 ) {
			return false;
		}
		if( $($(this).find("ul")).size() > 0 ) {
			return false;
		}
		if( $($(this).find("table")).size() > 0 ) {
			return false;
		}
		if( $($(this).find("div")).size() > 0 ) {
			return false;
		}
		
		return true;
	}).wrapInner("<p />");
});

/*先頭の要素はmargin-topをとる*/
$(document).ready(function(){
	$(".JSspace").each(function(idx){
		$(this).find("> *").each(function(idx2){
			if(idx2 == 0) {
				var tag = this.tagName;
				
				if(    tag.match(/^p$/i) || tag.match(/^ul$/i) || tag.match(/^div$/i) || tag.match(/^table$/i)   ) {
					$(this).addClass("top0");
				}
				return false;
			}
	    });
	});
});





/**********
	font
**********/
$(document).ready(function() {
	$("p[style]").removeAttr("style");
	$("span[style]").removeAttr("style");
	$("font[size]").removeAttr("size");
	$("font[face]").removeAttr("face");
	$("font[color]").removeAttr("color");
});




/**********
	横並び画像
**********/
$(document).ready(function() {
	$(".c2lMod").each(function() {
		var L = $(this).find(".L");
		var R = $(this).find(".R");
		
		var LImg = L.find("img");
		var RImg = R.find("img");
		
		L.width(LImg.width());
		R.width(RImg.width());
	});
});



/**********
	ページトップがめり込んでしまう対策
**********/
$(document).ready(function() {
	if($("#container").height() == $("#sideNav").height()) {
		$("#container").css("paddingBottom", 40);
	}
});



