// JavaScript Document

jQuery(function() {
	// 画像ロールオーバー（ロールオーバーアクション以外の画像には末尾に「_off」をつけないように）
	var rollin = function() {
		var $img = jQuery(this);
		$img.attr('src', $img.attr('src').replace('_off.', '_ov.'));
	},
	rollout = function() {
		var $img = jQuery(this);
		$img.attr('src', $img.attr('src').replace('_ov.', '_off.'));
	}
	jQuery('img:[src*="_off."]').each(function() {
		var $this = jQuery(this);
		$this.mouseover(rollin).mouseout(rollout);
	});

	// 画像のないimgタグを削除
	jQuery('img[src=""]').hide();

	// ショップ検索時の右サイドメニュー
	jQuery(".acc > li > a").each(function(index){
		var $this = jQuery(this);

//		if(index > 0) $this.next().hide();
		$this.siblings().hide();

		$this.click(function(){
			var params = {height:"toggle", opacity:"toggle"};
			var $this = jQuery(this);

			$this
			.children('img').unbind('mouseover, mouseout').end()
			.siblings().animate(params, 'normal', 'swing', function() {
				if (jQuery(this).is(':hidden')) {
					$this.children('img').mouseover(rollin).mouseout(rollout)
					.trigger('mouseout');
				}
				
			}).parent().siblings()
			.find('ul:visible').animate(params).siblings('a').children('img')
			.mouseover(rollin).mouseout(rollout).trigger('mouseout');

			return false;
		});
	});

	var menu_select = function() {
		var url = jQuery.url();
		var directory_a = url.attr('directory').split('/');
		var selector = "home";

		// 22: ニュース
		// 43: スナップ
		if (directory_a[1] == 'category' || directory_a[1] == 'apinews') {
			selector = 'apirenews';
		} else if (directory_a[1] == 'date' && url.param('cat') == 22) { 
			selector = 'apirenews';
		} else if (directory_a[1] != '') {
			selector = directory_a[1];
		}

		var $ro = jQuery('img.rollOver.'+selector);

		if ($ro.size() > 0) {
			$ro.attr('src', $ro.attr('src').replace('_off.', '_ov.')).unbind('mouseover, mouseout');
		}
	}
	menu_select();

	if (typeof _initialize == "function") {
		_initialize();
	}
});

