$(function(){

// ===addclass===
$("tr:even").addClass("even");
$("tr:odd").addClass("odd");

//===form label===
$("label:has(input)").each(function(){
	$(this).css({'display':'inline', 'margin-right':'5px', 'font-size':'100%'});
});

//===button===
$("input:submit").each(function(){
	$(this).css({'font-size':'90%','font-size':'80%','padding':'5px 15px','color':'#111'});
	$(this).button();
});
$("button, a.button, a.btn").each(function(){
	$(this).css({'font-size':'90%','padding':'1px 4px','color':'#111'});
	$(this).button();
});

//===buttonset===
$("div.buttonset ").each(function(){
	$(this).buttonset();
});

//===pause function===
$.fn.pause = function(duration) {
	$(this).animate({ dummy: 1 }, duration);
	return this;
};

//===message_brief===
$(".message_brief li").each(function(){
	$(this).addClass("ui-corner-all");
	$(this).fadeTo(0,0.8).pause(1000).fadeOut(1000);
});

//===growl===
$.fn.growl = function(message) {
	$('body').prepend('<ul class="message_brief"></ul>');
	$('.message_brief').prepend('<li>'+message+'</li>');
	$('.message_brief li').addClass("ui-corner-all");
	$('.message_brief').fadeTo(0,0.8).pause(1000).fadeOut(1000);
	return this;
};

//==floatimage margin==
$('#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'});
	}
});

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

//==== a.current img ====
$('a.current img').each(function(){
	var imgsrc = $(this).find('img').attr('src').replace('_df.gif','_ro.gif');
	$(this).find('img').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);
});

// ===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 = 'enlearge image (to back to press x)' + altx;
	$(this).find('img').attr('alt',altx);
	$(this).lightBox();
});

// ===kontiki_controllers===
var kmwheight = $('#kontiki_menus_wrapper').height();
$('#kontiki_menus_wrapper').next('div').css({'position':'relative','z-index':'5','padding-top':kmwheight});

// ===kontiki_required input error===
$('form').submit(function(){
	var ealert='';
	var noninput = '<span class="errormessage">※未入力です。</span>'
	$(':text,textarea').filter('.required').each(function(){
		//下記の条件に一致するラベルを検索したら広範囲に拾えるんじゃない？（今は未使用）
		var labelsearch = $(this).attr('name');


		//.requiredのラベル（アラートと条件クリア時に使用）
		var epoint = $(this).prev('label').html().replace(noninput,'');
		//エラー表記のリセット
		$(this).css({'background':'#fff'}).prev('label').html(epoint);
		//.requiredがfalse：なければ色変更と警告spanを追加（ある時は）
		if($(this).val()==''){
			if(! $(this).prev('label').children('span.errormessage').html()){
				$(this).prev('label').append(noninput);
			}
			$(this).css({'background':'#fff0f0'});
			//エラーアラート用（配列使った方がきれい？）
			ealert = ealert+'[ '+epoint+' ]\n';
		}
	});
	if($('span.errormessage').size() > 0){
		ealert=ealert+' が未入力です。';
		$('html,body').animate({ scrollTop: $('span.errormessage').offset().top-100 }, 'slow');
		alert(ealert);
		return false;
	}
});

//コナミコマンドで映画部へ
$(document).cheatCode({
	unbind : false,
	activated : function(){
		alert('時代工房の映画部へ');
		window.location = "http://club.jidaikobo.com/";
	}
});

});

