(function(){
	$.fn.extend({
		contentSelector: function(){
			var contents = [];
			$(this).each(function(){
				var h = $(this).attr('href'), tid = h.substr(h.indexOf('#'));
				contents.push(tid);
				$(tid).hide();
				$(this).click(function(){
					$.each(contents, function(i, cid){
						$(cid).hide();
					});
					$(tid).show();
					return false;
				})
			});
			$(contents[0]).show();
		}
	});
	jQuery(function(){
		var extlink = location.hostname.match(/^en\./) ?
			'<a href="http://jci-academy2010-tsukuba.com/" id="ext-link">日本語サイトはこちら</a>' :
			'<a href="http://en.jci-academy2010-tsukuba.com/" id="ext-link">english site</a>';
		$('#header').append(extlink);
		if (!$('body').is('.editable-mode')) {
			if ($('.main-content').children().is('#volunteers')) {
				$('#navi-section a').contentSelector();
			}
			if ($('.main-content').children().is('#contact,#volunteers')) {
				$('form').ajaxForm({
					dataType:'json',
					success:function(json){
						if (json.error) {
							alert(json.error);
						}
						if (json.ok) {
							alert('フォーム内容を正常に送信しました。');
						}
					}
				});
			}
		}
	});
})();
