$(function(){
	// ===addclass===
	$("tr:even").addClass("even");
	$("tr:odd").addClass("odd");
	$("form :submit").addClass("button");

	// ===jquery4contentslist===
	$('.jquery4contentslist h1').after('<ul id="jquery4contentslist"></ul>');
	$('.pico_container h2').each(function(){
		var txt = $(this).html();
		var number = 't'+($('.pico_container h2').index(this)+1);
		$(this).append('<a name="'+number+'" id="'+number+'"></a>');
		$('ul#jquery4contentslist').append('<li><a href="#'+number+'">'+txt+'</a></li>');
	});

	// ===Mainmenu===
	$('#sitemenu li a.mainitem').each(function(){
		var menuid = $(this).attr('id');
		var alt = $(this).text();
		$(this).empty();
		if($(this).attr('class')=='on'){
			$('<img src="/public_html/themes/main/images/sitemenu/'+menuid+'_ro.gif" alt="'+alt+'" />').prependTo(this);
		}else{
			$('<img src="/public_html/themes/main/images/sitemenu/'+menuid+'_df.gif" alt="'+alt+'" />').prependTo(this);
		}
		});

	$('#sitemenu li a').hover(function(){
		var imgsrc = $(this).find('img').attr('src').replace('_df.gif','_ro.gif');
		$(this).find('img').attr('src',imgsrc);
		},function(){
		if($(this).attr('class')=='on'){
		}else{
		var imgsrc = $(this).find('img').attr('src').replace('_ro.gif','_df.gif');
		$(this).find('img').attr('src',imgsrc);
		}
	});

	//==floatimage margin for FCKeditor==
	$('#CenterWrapper img').each(function(){
	if($(this).attr('align')=='left'){
		$(this).css({'margin':'0 10px 10px 0','float':'left'});
		$(this).removeAttr('align');
	}else if($(this).attr('align')=='right'){
		$(this).css({'margin':'0 0 10px 10px','float':'right'});
		$(this).removeAttr('align');
	}else if($(this).attr('align')=='center'){
		$(this).css({'margin':'0 10px 10px 10px'});
	}
	});

	//==== rollover4text ====
	$('a.rollover4text').each(function() {
		var alt = $(this).html();
		$(this).empty();
		var class_arr = $(this).attr('class').split(' ');
		var filename4rollover = class_arr[1].replace(/__/g,'/');
		$('<img src="'+filename4rollover+'_df.gif" alt="'+alt+'" />').prependTo(this);
	});

	//==== a.rollover img ====
	$('a.rollover img').hover(function(){
		var imgsrc = $(this).attr('src').replace('_df.gif','_ro.gif');
		$(this).attr('src',imgsrc);
		},function(){
		var imgsrc = $(this).attr('src').replace('_ro.gif','_df.gif');
		$(this).attr('src',imgsrc);
	});

	//==== a.current img ====
	$('a.current img').each(function(){
		var imgsrc = $(this).attr('src').replace('_df.gif','_ro.gif');
		$(this).attr('src',imgsrc);
	});

	//==== input.rollover ====
	$('input.rollover').hover(function(){
		var imgsrc = $(this).attr('src').replace('_df.gif','_ro.gif');
		$(this).attr('src',imgsrc);
		},function(){
		var imgsrc = $(this).attr('src').replace('_ro.gif','_df.gif');
		$(this).attr('src',imgsrc);
	});

	//====add markers====
	currenturl = location.href;
	if (currenturl.search(/system/i) != -1) {
		$(".cite").prepend("<img src='../view/style/images/general_marker.gif' alt=''> ");
		$(".cite_left").prepend("<img src='../view/style/images/general_marker.gif' alt=''> ");
		$("#toppage #backtotop").prepend("<img src='../view/style/images/toppage_backtotop.gif' alt=''> ");
	} else {
		$(".cite").prepend("<img src='./view/style/images/general_marker.gif' alt=''> ");
		$(".cite_left").prepend("<img src='./view/style/images/general_marker.gif' alt=''> ");
		$("#toppage #backtotop").prepend("<img src='./view/style/images/toppage_backtotop.gif' alt=''> ");
	}



	// ===captionblock===
	$('img.fcr').each(function(){
		var captxt = $(this).attr('alt').replace('[/url]','</a>').replace(']','">').replace('[url=','<a class="noicon" href="');
		var capwidth = $(this).attr('width');
		capwidth=capwidth+10;
//		$(this).wrap('<span style="width:'+capwidth+'px;font-size:90%;float:right;margin:0 0 10px 10px;text-align:center;dispay:block;">');
		$(this).wrap('<div style="width:'+capwidth+'px;font-size:90%;float:right;margin:0 0 10px 10px;text-align:center;">');
		$(this).attr('alt','').after('<br />'+captxt);
	});

	$('img.fcl').each(function(){
		var captxt = $(this).attr('alt').replace('[/url]','</a>').replace(']','">').replace('[url=','<a class="noicon" href="');
		var capwidth = $(this).attr('width');
		capwidth=capwidth+10;
//		$(this).wrap('<span style="width:'+capwidth+'px;font-size:90%;float:left;margin:0 10px 10px 0;text-align:center;dispay:block;">');
		$(this).wrap('<div style="width:'+capwidth+'px;font-size:90%;float:left;margin:0 10px 10px 0;text-align:center;">');
		$(this).attr('alt','').after('<br />'+captxt);
	});


	$('img.fcc').each(function(){
		var captxt = $(this).attr('alt').replace('[/url]','</a>').replace(']','">').replace('[url=','<a class="noicon" href="');
//		$(this).wrap('<span style="text-align:center;font-size:90%;margin:0 10px 10px 0;clear:both;dispay:block;">');
		$(this).wrap('<div style="text-align:center;font-size:90%;margin:0 10px 10px 0;clear:both;">');
		$(this).attr('alt','').after('<br />'+captxt);
	});

	// ===lightbox===
	$('a.lb').each(function(){
		var capwidth = $(this).find('img').attr('width');
		capwidth=capwidth+10;
		var altx = $(this).find('img').attr('alt');
		var altx = '画像拡大表示' + altx;
		$(this).find('img').attr('alt',altx);
		$(this).lightBox();
	});

	// ===fn.disableDoubleSubmit===
	// http://www.alink.co.jp/tech/wiki/index.php?jQuery%2F%E3%82%B5%E3%83%B3%E3%83%97%E3%83%AB%E3%82%B3%E3%83%BC%E3%83%89%2Fsubmit%EF%BC%88%E9%80%81%E4%BF%A1%EF%BC%89%E3%83%9C%E3%82%BF%E3%83%B3%E3%81%AE2%E5%BA%A6%E6%8A%BC%E3%81%97%E3%82%92%E7%A6%81%E6%AD%A2%E3%81%99%E3%82%8B
	(function() {
		$.fn.disableDoubleSubmit = function(timeout) {
			if(!timeout || timeout < 1) {
				timeout = 3000; // 3sec.
			}
			$(this).bind("submit",function() {
				var submit_buttons = $(":submit",this);
				submit_buttons.attr("disabled", true);
				setTimeout(function(){
					submit_buttons.attr("disabled", false);
				},timeout);
			});
			return this;
		}
	})(jQuery);
	$('form').disableDoubleSubmit(); //for all forms

});

