/**
 * @version  1.00
 * @updated  2010/04/01
 */



(function ($) { $(function () {
	var index = {
		init: function() {
			var def = 1;
			index.imgchange(def);
			index.control();
			index.timer();
			index.info();
		},

		
		/* ================= mainvisual ================= */
		
		
		control: function () {
			$('ul#control li a').click(function () {
				var key = $(this).parent().attr('id').replace('ctl-','');
				
				$('ul#control li.on').attr('class','');
				$(this).parent().attr('class','on');
				$('ul#control').attr('class','ctl-num-' + key);
				
				index.imgchange(key);
				$('ul#control').stopTime();
				index.timer();
				
				return false;
			});
		},
		
		
		
		imgchange: function (key) {
			$('ul#main-imgs li.mv-current').fadeOut();
			$('ul#main-imgs li.mv-current').attr('class','');
			
			$('ul#main-imgs li#mv-' + key).fadeIn('slow');
			$('ul#main-imgs li#mv-' + key).attr('class','mv-current');
			
		},
		
		
		
		timer: function () {
		
			var ctl_length = $('ul#control li').size();

			$('ul#control').everyTime(5000, function() {
				var ctl_id = $('ul#control li.on').attr('id').replace('ctl-','');
				var key    = (ctl_id == ctl_length) ? 1 : parseFloat(ctl_id) + 1;
				
				$('ul#control li.on').attr('class','');
				$('ul#control li#ctl-' + key).attr('class','on');
				$('ul#control').attr('class','ctl-num-' + key);
				
				index.imgchange(key);
			});
		
		},
		
		
		/* ================= news ================= */
	
		
		info : 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'
			}
			
			$.ajax({
				url: '/info/?feed=rss2',
				success: function (r) {
					var html = [];
					
					$(r).find('item').each(function (i) {
						if (i < 4) {
							var date_elm = $(this).find('pubDate').text().split(' ');
							var date     = date_elm[3].replace('20','') + '.' + DICT[date_elm[2]] + '.' + date_elm[1];
							switch ($(this).find('category').text()){
								case 'キャンペーン': var icon = '<img width="90" height="27" alt="" src="/shared/img/info/icon_campaign.gif">'; break;
								case 'メディア'   : var icon = '<img width="90" height="27" alt="" src="/shared/img/info/icon_media.gif">'; break;
								default         : var icon = '<img width="90" height="27" alt="" src="/shared/img/info/icon_other.gif">';
							}

							html.push('<li>' + icon + '<span class="date">' + date + '</span><a class="title" href="' + $(this).find('link').text() + '">' + $(this).find('title').text() + '</a></li>');
						}
					});
					
					index.show(html);
				}
			});
		},
		
		
		
		show: function(html) {
			$('ul#info').html(html.join(''));
			$('p.loader').animate(
				{ height: $('ul#info').height() + 0 }, 'slow'
			).fadeOut('normal', function () {
				$('ul#info').show();
			});
		
		}	
	}

	index.init();
	
})})($);
