/**
 * @version  1.00
 * @updated  2008/09/26
 */



function createFlash (swf, w, h, bgcolor) {
	var bgcolor     = (typeof(bgcolor) != 'undefined') ? bgcolor : '#ffffff';
	var flash       = [];
	
	flash.push('<object width="' + w + '" height="' + h + '"');
	flash.push(!!(window.attachEvent && !window.opera) ? ' type="application/x-shockwave-flash">' : '>');
	flash.push('<param name="movie"   value="' + swf     + '" />');
	flash.push('<param name="bgcolor" value="' + bgcolor + '" />');
	flash.push('<param name="quality" value="high" />');
	flash.push('<param name="scale"   value="noscale" />');
	flash.push('<param name="salign"  value="lt" />');
	flash.push('<embed src="' + swf     + '"');
	flash.push(' width="'  + w + '"');
	flash.push(' height="' + h + '"');
	flash.push(' bgcolor="'   + bgcolor + '"');
	flash.push(' quality="high"');
	flash.push(' scale="noscale"');
	flash.push(' salign="lt"');
	flash.push(' type="application/x-shockwave-flash">');
	flash.push('</embed>');
	flash.push('</object>');
	
	return flash.join('');
}



function getFlashPlayerVersion() {
	var vsn = '';
	var check = checkPlugin('application/x-shockwave-flash', 'ShockwaveFlash.ShockwaveFlash');
	
	if (check) {
		if( navigator.plugins && navigator.mimeTypes.length ) {     // not IE
			var tmp = (navigator.plugins["Shockwave Flash"]) ? navigator.plugins["Shockwave Flash"].description.match(/([0-9])/) : 'noFlash' ;
			
			if (tmp == 'noFlash') {
				vsn = false;
			} else {
				vsn = (tmp[0] == 1) ? 10 + parseFloat(tmp[1]) :tmp[0];
			}
		}
		else {    // IE
			var tmp = new ActiveXObject("ShockwaveFlash.ShockwaveFlash").GetVariable
			("$version").match(/([0-9])/);
			vsn = (tmp[0] == 1) ? 10 + parseFloat(tmp[1]) :tmp[0];
		}
	}
	else {
		vsn = false;
	}
	return vsn;
}



function checkPlugin(mimeType, comNames){
	comNames = [].concat(comNames);
	if(navigator.userAgent.indexOf('MSIE')==-1){
		return !!navigator.mimeTypes[mimeType];
	}
	for(var i=comNames.length-1 ; comNames[i] ; i-- ){
		try{
			new ActiveXObject(comNames[i]);
			return true;
		}catch(e){
	}
}
  return false;
}



$(function(){
	var vsn = getFlashPlayerVersion();

	if (vsn >= 9) {
		$('#mainvisual').append(createFlash('index/mainvisual.swf', 700, 280, '#ffffff'));
	}
	else {
		$('#mainvisual').html('<img src="index/mainvisual.jpg" alt="" width="700" height="280" />');
	}
});



$(function(){
	DICT = {'Jan' : '01',
		'Feb'     : '02',
		'Mar'     : '03',
		'Apr'     : '04',
		'May'     : '05',
		'Jun'     : '06',
		'Jul'     : '07',
		'Aug'     : '08',
		'Sep'     : '09',
		'Oct'     : '10',
		'Nov'     : '11',
		'Dec'     : '12'
	}
	
	var flag = $('div#news div.important div.in').html();
	
	if (flag == 'none') {
	
		info(0);
		
	} else {
	
		$('div#news div.title').html(
			'<ul class="tab" id="clickable">' + '\n' +
			'<li class="tab-important" id="tab-on"><a href="#">重要なお知らせ</a></li>' + '\n' +
			'<li class="tab-info"><a href="#">新着情報</a></li>' + '\n' +
			'</ul>' + '\n' +
			'<h2><img src="/index/news_important_title.gif" alt="重要なお知らせ" width="700" height="26"/></h2>' + '\n'
		);
		
		$('div.loader').animate(
			{ height: $('#news div.important').height() }, 'slow'
		).fadeOut('normal', function () {
			$('#news div.important').show();
		});
		
		info(1);
		
	}
	
	
	$('ul.tab a').click(function () {
		
		if ($('ul.tab').attr('id') == 'clickable' && $(this).parent().attr('id') != 'tab-on') {
			$('ul.tab').attr('id','unclickable');
			
			var elm = $(this).parent().attr('class');
			var on  = elm.replace('tab-','');
			var off = (on == 'important') ? 'info' : 'important';
			
			$('div#news div.title h2').html('<img src="/index/news_' + on + '_title.gif" alt="' + ((on == 'info') ? '新着情報':'重要なお知らせ') + '" width="700" height="26"/></a>');
						
			$('ul.tab li').each(function () {
				$(this).attr('id','');
			});
			$(this).parent().attr('id','tab-on');
			
			$('div.loader').height($('div.' + off).height());
			$('div.loader').show();
			$('div.' + off).hide();
	
			$('div.loader').animate(
				{ height: $('div.' + on).height() }, 'slow'
			).fadeOut('normal', function () {
				$('div.' + on).css({'display':'block'});
				$('ul.tab').attr('id','clickable');
			});	
		}
				
		return false;
	});
	
	
	function info (flag) {
		$.ajax({
			url: '/info/?feed=rss2',
			success: function (r) {
				var html = [];
				
				html.push('<ul>');
				$(r).find('item').each(function (i) {
					if (i < 3) {
						var date_elm = $(this).find('pubDate').text().split(' ');
						var date     = date_elm[3].replace('20','') + '.' + DICT[date_elm[2]] + '.' + date_elm[1];
						html.push('<li><a href="' + $(this).find('link').text() + '"><span>' + date + '</span>' + $(this).find('title').text() +'</a></li>');
					}
				});
				html.push('</ul>');
							
				$('#news div.info').html(html.join(''));
				
				if (flag == 0) {
					default_info();
				}

			}
		});
	}
	
	
	function default_info (html) {
		$('div#news div.title').html('<h2><a href="/info/"><img src="/index/news_info_title.gif" alt="新着情報" width="700" height="26"/></a></h2>');
			
		$('.loader').animate(
			{ height: $('#news div.info').height() }, 'slow'
		).fadeOut('normal', function () {
			
			$('#news div.info').show();
		});		
	}
	
});



