$(function(){
	// 画像ロールオーバー
	var chImage = {
		imageLinkLocation: new Array(),
		chasheImage: new Array(),
		init: function() {
			$('input.linkImage, .linkImage a > img, a.linkImage > img').each(function(imageIndex){
				chImage.imageLinkLocation[imageIndex] = $(this).attr('src');
				chImage.chasheImage[imageIndex] = new Image();
				chImage.chasheImage[imageIndex].src = chImage.imageLinkLocation[imageIndex].replace(new RegExp('(_on)?(\.gif|\.jpg|\.png)$'), "_on$2");
				$(this).hover(function(){
					$(this).attr('src',chImage.chasheImage[imageIndex].src);
				}, function(){
					$(this).attr('src',chImage.imageLinkLocation[imageIndex]);
				});
			});
		}
	};
	chImage.init();

	// 情報リスト
	$('#mainContents .informationList .information:odd').css('backgroundColor','#f1f1f1');
	// 新着情報リスト
	$('#mainContents .newsList .news:odd').css('backgroundColor','#f1f1f1');
	// ショップ情報リスト
	$('#mainContents .shopList .shop:odd').css('backgroundColor','#f1f1f1');
	// フロアマップ エレベーション
	$('#mainContents table.elevation tbody tr:even th').css({'backgroundColor':'#b8b8b8','borderBottomColor':'#adadad'});
	$('#mainContents table.elevation tbody tr:even td').css('backgroundColor','#f7f6f0');
	// お問合せフォーム
	$('#mainContents .inner form tr:odd th, #mainContents .inner form tr:odd td, #mainContents .inner .complete tr:odd th, #mainContents .inner .complete tr:odd td').css('backgroundColor','#f7f6f0');

	// ヘッダー
	$('#header a.shopList,#header a.netShop').hover(function(){
		$(this).next().show();
	});
	$('#header div.shopList > a,#header div.netShop > a').click(function(){
		$(this).parent().hide();
	});
	$('#header div.shopList,#header div.netShop').hover(function(){},function(){
		$(this).hide();
	});
	$('#header div.search').hover(function(){
		$(this).addClass('hover');
	},function(){
		$(this).removeClass('hover');
	});
	
	// ローカルメニュー（新着・催物）
	var localMenuSpeed = 200;
	$('#subContents .localMenu ul ul:visible').each(function(){
		$(this).parent().addClass('open');
	});
	$('#subContents .localMenu > ul > li > a').click(function(){
		var toggleObj = $(this).next();
		if($(this).parent().hasClass('open')) {
			$(this).parent().removeClass('open');
			toggleObj.slideUp(localMenuSpeed);
		} else {
			$(this).parent().addClass('open');
			toggleObj.slideDown(localMenuSpeed);
		}
	});

	// ローカルメニュー（店舗）
	if($.cookie('openTab')) {
		$('#subContents ul.tab').removeClass('floor category jAlpha').addClass($.cookie('openTab'));
		$('#subContents .section').hide();
		$('#subContents .section.'+$.cookie('openTab')).show();
	}
	$('#subContents ul.tab li a').each(function(index){
		$(this).click(function(){
			if($(this).parents('ul.tab').hasClass($(this).parent().attr('class'))){
				return;
			} else {
				if(location.pathname.split('/')[1] != '') {
					$.cookie('openTab',$(this).parent().attr('class'),{path:'/'+location.pathname.split('/')[1]+'/'});
				}
				$(this).parents('ul.tab').removeClass('floor category jAlpha');
				$(this).parents('ul.tab').addClass($(this).parent().attr('class'));
				$('#subContents .section').hide();
				$('#subContents .section').eq(index).show();
			}
		});
	});

	// ソーシャルボタン
	$('.socialButton .tweet').socialbutton('twitter', {
	    button: 'none',
	    lang: 'ja'
	});
	$('.socialButton .facebook').socialbutton('facebook_like', {
	    button: 'button_count',
	    width: 69,
	    height: 20,
	    action: 'like',
	    locale: 'ja_JP',
	    font: 'arial',
	    colorscheme: 'light'
	});
	$('.socialButton .google').socialbutton('google_plusone', {
	    button: 'medium',
	    lang: 'ja',
	    parsetags: 'onload',
	    count: false
	});
	
	
	// メインバナー
	var banner = {
		timer: false,
		speed: 4000,
		fade: 200,
		obj: $('#mainContents .mainBanner'),
		bannerLength: $('#mainContents .mainBanner ul.banner li').length,
		current: 0,
		pager: $('<li><a href="javascript:void(0)">●</a></li>'),
		init: function(){
			$('.textBase', this.obj).css('opacity',0.5);
			$('ul.pager', this.obj).empty();
			if($('ul.banner li',this.obj).length > 1) {
				$('ul.banner li',this.obj).each(function(index){
					var appendObj = banner.pager.clone();
					// pager
					$('a', appendObj).hover(function(){
						banner.viewChange(index);
					}).attr('href',$('ul.banner li a',banner.obj).eq(index).attr('href'));
					if(index == 0) {
						appendObj.addClass('current');
					} else {
						$(this).hide();
						$('ul.bannerText li',banner.obj).eq(index).hide();
					}
					$('ul.bannerText li',banner.obj).eq(index).click(function(){
						location.href = $('ul.banner li a',banner.obj).eq(index).attr('href');
					});
					$('ul.pager', this.obj).append(appendObj);
				});
	
				$('ul.banner li a,ul.bannerText li,ul.pager li a',this.obj).hover(function(){
					clearTimeout(banner.timer);
					$(this).css('textDecoration','underline');
				},function(){
					banner.timer = setTimeout(banner.fadeChange,banner.speed);
					$(this).css('textDecoration','none');
				});
	
				banner.timer = setTimeout(banner.fadeChange,banner.speed);
			}
		},
		viewChange: function(num) {
			$('ul.banner li',this.obj).hide().eq(num).show();
			$('ul.bannerText li',this.obj).hide().eq(num).show();
			//$('ul.pager li', this.obj).removeClass('current').eq(num).addClass('current');
			$('ul.pager li.current', this.obj).removeClass('current');
			$('ul.pager li', this.obj).eq(num).addClass('current');
			this.current = num;
		},
		fadeChange: function(){
			var currentView = $('ul.banner li:visible',banner.obj);
			var nextView;
			
			banner.current++;
			if(banner.current >= banner.bannerLength) {
				banner.current = 0;
			}
			nextView = $('ul.banner li',banner.obj).eq(banner.current);
			currentView.fadeOut(banner.fade);
			nextView.fadeIn(banner.fade,function(){
				$('ul.bannerText li',banner.obj).hide().eq(banner.current).show();
				//$('ul.pager li', banner.obj).removeClass('current').eq(banner.current).addClass('current');
				$('ul.pager li.current', banner.obj).removeClass('current');
				$('ul.pager li', banner.obj).eq(banner.current).addClass('current');
				banner.timer = setTimeout(banner.fadeChange,banner.speed);
			});
		}
	};
	banner.init();
		
	// サービスガイド
	var service = {
		speed: 500,
		target: $('body.service #mainContents .inner .section'),
		init: function(){
			$('h3 a', this.target).click(function(){
				var linkObj = $(this);
				$(this).parent().next().slideToggle(service.speed,function(){
					if(linkObj.hasClass('open')){
						linkObj.removeClass('open');
					} else {
						linkObj.addClass('open');
					}
				})
			});
			$('.serviceTitle', this.target).click(function(){
				$(this).next().slideToggle(service.speed);
			});
		}
	};
	service.init();
});

// ショップ詳細ランキング
var ranking = {
	current: 1,
	page: 0,
	speed: 500,
	view: false,
	viewNum: 4,
	target: false,
	itemWidth: false,
	navi: false,
	init: function(){
		this.view = $('#mainContents .ranking .rankList').width();
		this.target = $('#mainContents .ranking ul');
		this.itemWidth = $('#mainContents .ranking li').outerWidth({margin: true});
		this.navi = $('#mainContents .ranking .rankList .pager');
		
		if($('#mainContents .ranking li').length <= this.viewNum) {
			$('.next',this.navi).hide();
			this.page = 1;
		}
		this.page = Math.ceil($('#mainContents .ranking li').length/this.viewNum);
		$('.next',this.navi).click(function(){
			if(ranking.page > ranking.current) {
				ranking.current++;
				ranking.target.animate({marginLeft: -((ranking.current-1)*ranking.view)},ranking.speed,'swing',function(){
					if(ranking.page <= ranking.current) {
						$('.next',ranking.navi).hide();
					}
					$('.prev',ranking.navi).show();
				});
			}
		});
		$('.prev',this.navi).click(function(){
			if(1 < ranking.current) {
				ranking.current--;
				ranking.target.animate({marginLeft: -((ranking.current-1)*ranking.view)},ranking.speed,'swing',function(){
					if(1 >= ranking.current) {
						$('.prev',ranking.navi).hide();
					}
					$('.next',ranking.navi).show();
				});
			}
		});
	}
};


// jquery.cookie


/*jslint browser: true */ /*global jQuery: true */

/**
 * jQuery Cookie plugin
 *
 * Copyright (c) 2010 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */

// TODO JsDoc

/**
 * Create a cookie with the given key and value and other optional parameters.
 *
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Set the value of a cookie.
 * @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
 * @desc Create a cookie with all available options.
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Create a session cookie.
 * @example $.cookie('the_cookie', null);
 * @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain
 *       used when the cookie was set.
 *
 * @param String key The key of the cookie.
 * @param String value The value of the cookie.
 * @param Object options An object literal containing key/value pairs to provide optional cookie attributes.
 * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
 *                             If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
 *                             If set to null or omitted, the cookie will be a session cookie and will not be retained
 *                             when the the browser exits.
 * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
 * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
 * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
 *                        require a secure protocol (like HTTPS).
 * @type undefined
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */

/**
 * Get the value of a cookie with the given key.
 *
 * @example $.cookie('the_cookie');
 * @desc Get the value of a cookie.
 *
 * @param String key The key of the cookie.
 * @return The value of the cookie.
 * @type String
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */
jQuery.cookie = function (key, value, options) {
    
    // key and at least value given, set cookie...
    if (arguments.length > 1 && String(value) !== "[object Object]") {
        options = jQuery.extend({}, options);

        if (value === null || value === undefined) {
            options.expires = -1;
        }

        if (typeof options.expires === 'number') {
            var days = options.expires, t = options.expires = new Date();
            t.setDate(t.getDate() + days);
        }
        
        value = String(value);
        
        return (document.cookie = [
            encodeURIComponent(key), '=',
            options.raw ? value : encodeURIComponent(value),
            options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
            options.path ? '; path=' + options.path : '',
            options.domain ? '; domain=' + options.domain : '',
            options.secure ? '; secure' : ''
        ].join(''));
    }

    // key and possibly options given, get cookie...
    options = value || {};
    var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent;
    return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
};
