// Google Ajax Lib Selector
switch( document.body.getAttribute('id') ) {
	case 'reserve': google.load('jqueryui','1');break;
	default: break;
}

jQuery.noConflict();
jQuery(document).ready(function($) {

	// RESTPAGE CONFIG
	var rc = {
		uri: function(){ return ( location.href ).replace( /#.*$/g, '' ).replace( /(rcon)\.gnavi\.co\.jp/, 'r.gnavi.co.jp' ) },
		top: function(){ return ( $( 'link[rel=index]' ).attr( 'href' ) ).replace( /#.*$/g, '' ).replace( /(rcon)\.gnavi\.co\.jp/, 'r.gnavi.co.jp' ) },
		ref: function(){ return ( document.referrer ) },
		title: function(){ return $( 'title' ).html() },
		shopname: function(){ return $( 'meta[name=shopname]' ).attr( 'content' ) },
		id: function(){ return $( 'meta[name=shopid]' ).attr( 'content' ) },
		zip: function(){ return $( 'meta[name=zip]' ).attr( 'content' ) },
		area: function(){ return $( 'meta[name=area]' ).attr( 'content' ).split(':') },
		pref: function(){ return $( 'meta[name=pref]' ).attr( 'content' ) },
		gx: function(){ return $( 'meta[name=gx]' ).attr( 'content' ) },
		isie6: function(){
			return ( navigator.appName.toUpperCase().indexOf( 'EXPLORER' ) !== -1 && navigator.appVersion.toUpperCase().split( ';' )[1].charAt( 6 ) === '6' );
		},
		debug: function(){
			( location.host ).match( /([^\.]+)\.gnavi\.co\.jp$/ );
			return ( ( ( RegExp.$1 ).indexOf( 'test' ) !== -1 ) || ( $.query.get( 'mode' ) === 'debug' ) );
		},
		page: {
			id: function(){ return $( 'body' ).attr( 'id' ) },
			cl: function(){ return $( 'body' ).attr( 'class' ).split(' ') }
		},
		js: function(){
			var p = $( 'link[rel=index]' ).attr( 'href' ) + 'p.js?';
			return ( 'https:' === document.location.protocol ) ? p.replace( 'http:', 'https:' ) : p;
		},
		time: function(){ return Math.floor( ( new Date() ).getTime() / 1000 ) },
		gmemdispAPI: 'http://r.gnavi.co.jp/api/login/loginCheck.php',
		slide: {
			disable: false
		},
		pr: {
			disable: false,
			xhtml: '<a href="http://sp.gnavi.co.jp/kansougei/?sc_bid=sp_enkai_1" target="pr" class="pr">必見！宴会の予約は送別会・歓迎会特集で</a>'
		},
		map: {
			auth: function() { return $('body.auth').size() },
			authAPI: '/coupon/auth/',
			authFormat: /^[0-9]{10}$/,
			authConstCode: '9999999999',
			authPrintConstCode: function() { return $('#editing').size(); }
		},
		reserve: {
			periodHour: 23,
			periodMin: 30,
			maxDate: function(){
				var maxMonth = 6;
				var s = new Date(), d = new Date();
				d.setMonth( s.getMonth() + maxMonth );
				d.setDate( 1 );
				d = new Date( d - s );
				d = Math.floor( d / ( 24 * 60 * 60 * 1000 ) ) - 1;
				return d;
			},
			calMonth: 2
		},
		smartphone: {
			exist: function(){ var u=navigator.userAgent;return (/android/i.test(u)&&/mobile/i.test(u))||(!/ipad/i.test(u)&&/ip(hone|od)/i.test(u)); },
			cookieName: 'smartphone',
			cookieExpires: 90, // [days]
			cookieDomain: '.gnavi.co.jp',
			cookiePath: '/',
			cookieNamePC: 'smp_pcview'
		},
		history: {
			cookieMax: 15,
			cookieName: 'GHistory',
			cookieExpires: 90, // [days]
			cookieDomain: '.gnavi.co.jp',
			cookiePath: '/',
			cookieDlm: ',',
			cookieValDlm: ':'
		},
		print: {
			cookieMax: 15,
			cookieName: 'GPrint',
			cookieExpires: 90, // [days]
			cookieDomain: '.gnavi.co.jp',
			cookiePath: '/',
			cookieDlm: ',',
			cookieValDlm: ':'
		},
		edm: {
			query: 'sc_mid',
			valFormat: /^ed[0-9a-z_]*$/,
			cookieMax: 20,
			cookieName: 'Gedm',
			cookieExpires: 90, // [days]
			cookieDomain: '.gnavi.co.jp',
			cookiePath: '/',
			cookieDlm: ',',
			cookieValDlm: ':',
			popDisable: false,
			popXhtml: '<div id="redm"><a href="#" id="redmPop">気になるお店は「チョットぐ」</a><a href="#" id="redmX" title="閉じる">閉じる</a></div>'
		},
		extsearch: {
			cookieName: 'GExtSearch',
			cookieExpires: '',
			cookieDomain: '.gnavi.co.jp',
			cookiePath: '/',
			cookieDlm: ',',
			trimWords: ['ぐるなび','ぐるナビ','グルナビ','グルなび','gurunabi','Gurunavi','グルメナビ'],
			data: [
				{ eng: 'yahoo.co.jp', key: 'p', neg: [/site:/, /link:/, /inurl:/, /intitle:/, /[\s　]and[\s　]/ig, /[\s　]or[\s　]/ig, /[\s　]not[\s　]/ig] },
				{ eng: 'yahoo.com', key: 'p', neg: [/site:/, /link:/, /inurl:/, /intitle:/, /[\s　]and[\s　]/ig, /[\s　]or[\s　]/ig, /[\s　]not[\s　]/ig] },
				{ eng: 'google.co.jp', key: 'q', neg: [/site:[^+]+\s/, /cache:[^+]+\s/, /related:/, /[\s　]and[\s　]/ig, /[\s　]or[\s　]/ig] },
				{ eng: 'google.com', key: 'q', neg: [/site:[^+]+\s/, /cache:[^+]+\s/, /related:/, /[\s　]and[\s　]/ig, /[\s　]or[\s　]/ig] },
				{ eng: 'msn.co.jp', key: 'q', neg: [/[\s　]and[\s　]/ig, /[\s　]or[\s　]/ig] },
				{ eng: 'msn.com', key: 'q', neg: [/[\s　]and[\s　]/ig, /[\s　]or[\s　]/ig] },
				{ eng: 'bing.com', key: 'q', neg: [/[\s　]and[\s　]/ig, /[\s　]or[\s　]/ig] }
			]
		},
		colorbox: {
			iframe: { width: '650px', height: '600px', iframe: true },
			normal: { width: '650px', height: '600px' },
			obj: [
				'#chotto .gu a',
				'#topic .new a',
				'#infoTool #infoTool-send a',
				'#usefulTool #usefulTool-csend a',
				'.assist .assist-send a',
				'.assist .assist-myreg a',
				'.qr a',
				'#shoptoolQR a',
				'.sb-pg a'
			]
		},
		sb: {
			titlePrefix: 'ぐるなび - ',
			denyFormatID: /^i[0-9]{6}$/,
			scPrefix: 'sb',
			ht: 'http://b.hatena.ne.jp/add?mode=confirm&title=$t$&url=$u$',
			dl: 'http://del.icio.us/post?url=$u$&title=$t$',
			lv: 'http://clip.livedoor.com/redirect?link=$u$&title=$t$',
			bz: 'http://buzzurl.jp/entry/$u$',
			yh: 'http://bookmarks.yahoo.co.jp/action/bookmark?t=$t$&amp;u=$u$',
			gg: 'http://www.google.com/bookmarks/mark?op=edit&bkmk=$u$&title=$t$',
			ex: 'http://mylink.excite.co.jp/click/?url=$u$&title=$t$',
			tw: 'http://twitter.com/?status=$t$%20$u$%20%23gnavi',
			en: 'http://r.gnavi.co.jp/tool/evernote/?gid=',
			mx: 'http://mixi.jp/share.pl?k=27adcb8585292156253662544649a4e2acb970f1&u=$u$',
			gr: 'http://gree.jp/?act=write&mode=share&url=$u$',
			pg: 'http://r.gnavi.co.jp/tool/blogparts/?gid=',
			wl: 'http://profile.live.com/badge/?url=$u$&title=$t$',
			fb: 'http://www.facebook.com/plugins/like.php?layout=button_count&show_faces=false&width=100&action=like&colorscheme=light&href=$u$'
		},
		twitter: {
			disable: false,
			user: function(){ return $( '#tweetArea' ).attr( 'class' ).replace( 'user:', '' ); },
			api: {
				i: 'http://r.gnavi.co.jp/tool/twitter/?userid=$user$&shopid=$shop$&count=$count$&reply=$reply$',
				e: 'http://api.twitter.com/1/statuses/user_timeline.json?include_entities=true&include_rts=false&screen_name=$user$&count=$count$'
			},
			apiSel: 'e',
			count: 3,
			reply: 1, // 0:OFF 1:ON
			xhtml: {
				head: '<dl><dt><a href="http://twitter.com/$user.screen_name$/" target="tweet" class="userIcon"><img src="$user.profile_image_url$" /></a><span class="userName">$user.name$</span><span class="userScreename"><a href="http://twitter.com/$user.screen_name$/" target="tweet">$user.screen_name$</a></span><a href="http://www.twitter.com/$user.screen_name$/" target="tweet" class="userFollow"><img src="http://twitter-badges.s3.amazonaws.com/ja_follow_me-b.png" alt="gnavi_tweetをフォローしましょう" /></a></dt><dd class="txt">',
				body: '<p>$text$<span>$created_at$</span></p>',
				foot: '</dd><dd class="credit">※旬な情報(ツイート)の内容は、お店に直接お問い合わせ下さい。</dd></dl>'
			},
			key: ['user.screen_name','user.name','text','created_at','user.id','user.profile_image_url'],
			denyWord: /\150\164\164\160\072\057\057\167\167\167\056\150\157\164\160\145\160\160\145\162\056(\143\157\056)?\152\160\057.+/,
			errorCode: /^error$/
		},
		google: {
			marker: 'http://r.gnst.jp/c/r/marker_ns.png',
			shadow: 'http://r.gnst.jp/c/r/shadow.png',
			markerIcon: 'http://maps.gstatic.com/mapfiles/cb/man_arrow-0.png'
		},
		wakeari: {
			disable: false,
			uri: 'https://my.gnavi.co.jp/send_mail/wakeari/?id='
		},
		rw: {
			disable: false,
			xhtml: '<p id="rwBanner" title="JAPAN RESTAURANT WEEK 2012"><a href="http://www.jrw.jp/gnavi/%id%/" target="_blank">JAPAN RESTAURANT WEEK 2012</a></p>',
			uri: 'http://r.gnavi.co.jp/c/r/rw.js'
		}
	}
	rc.wakeari.uri += rc.id();
	if(rc.debug()){
		rc.wakeari.uri = rc.wakeari.uri.replace( 'https://', 'https://test-' );
		rc.gmemdispAPI = rc.gmemdispAPI.replace( 'http://', 'http://test-' );
	}

	// SiteCatalyst
	if ( rc.gx() ) {
		s.un = ( rc.debug() ) ? 'gnavidev' : 'gnavi2008homeglobal';
		s.channel = 'home';
		s.prop1 = ( rc.page.id() !== 'plan' ) ? 'r' : 'plan';
		s.prop2 = ( rc.page.id() !== 'plan' ) ? 'r' : 'plan';
		s.eVar2 = s.prop1;
		s.eVar3 = s.prop2;
		s.prop18 = rc.id().charAt( 0 ) == 'i' ? '30' : '80';
		s.prop19 = rc.id();
		s.eVar19 = s.prop19;
		s.pageName = location.pathname.replace( /\/index\.\w+/, '' );
		s.pageName = s.prop1 + ( s.pageName ? s.pageName : '' );
		if ( ( rc.page.id() !== 'reserve' ) && ( rc.page.id() !== 'plan' ) ) {
			s.pageName = s.pageName.replace( new RegExp( '/' + s.pageName.split( '/' )[1] ), '' );
		}
		s.prop14 = s.pageName;
		s.prop62 = s.pageName.replace(/\/$/,'');
		s.eVar62 = s.prop62;
		if ( rc.page.id() !== 'plan' ) {
			s.events = s.apl( s.events, 'event1', ',', 2 );
		}
		switch( rc.page.id() ) {
			case 'top':
				s.events = s.apl( s.events, 'event9', ',', 2 );
				break;
			case 'map':
				s.events = s.apl( s.events, 'event7', ',', 2 );
				// secret coupon
				$('body.coupon').each(function(){
					var p = [];
					p.push(s.pageName);
					p.push($(this).hasClass('secret')? 'secret' : 'unsecret');
					p.push($.cookie('GMemDisp')? 'login' : 'unlogin');
					if(p[1] === 'secret' && p[2] === 'login'){
						s.events = s.apl(s.events, 'event53', ',', 1);
					}
					s.prop57 = p[0]+p[1]+'/'+p[2];
					s.prop58 = s.prop57;
					s.eVar57 = s.prop57;
					s.eVar58 = s.prop58;
				});
				break;
			case 'reserve':
				if ( $.inArray( 'step1', rc.page.cl() ) !== -1 ) {
					s.events = s.apl( s.events, 'event5', ',', 2 );
				}
				if ( $.inArray( 'step5', rc.page.cl() ) !== -1 ) {
					s.events = s.apl( s.events, 'event6', ',', 2 );
					s.events = s.apl( s.events, 'event16', ',', 2 );
				}
				break;
			case 'plan':
				s.un = ( rc.debug() ) ? 'gnavidev' : 'gnavi2008planmain,gnavi2008homeglobal';
				s.channel = 'plan';
				s.prop3 = 'tool';
				s.prop4 = 'tool';
				/* Test & Target とくとくプランmbox用gif生成 2011-12 */
				if(typeof s.getQueryParam === 'function'){
					if(s.getQueryParam("sc_aid")){
						s.eVar21 = s.prop21 = s.getQueryParam("sc_aid");
					}
				}
				break;
			case 'movie':
				s.prop2 = 'gChannel';
				break;
			case 'ramen':
				s.un = ( rc.debug() ) ? 'gnavidev' : 'gnavi2008ramenmain,gnavi2008homeglobal';
				s.channel = 'ramen';
				s.prop1 = 'ramen';
				s.prop2 = 'ramen';
				s.eVar2 = s.prop2;
				s.events=s.apl(s.events,'event3',',',2);
				break;
			case 'menu':
				s.events = s.apl( s.events, 'event27,event28', ',', 2 );
				break;
			case 'yuino':
				s.events = s.apl( s.events, 'event29', ',', 2 );
				break;
			case 'channel':
				s.events = s.apl( s.events, 'event30', ',', 2 );
				break;
			case 'eco':
				s.events = s.apl( s.events, 'event32', ',', 2 );
				break;
			case 'chef':
				s.events = s.apl( s.events, 'event33', ',', 2 );
				break;
			default: break;
		}
		if(location.host=="rcon.gnavi.co.jp"){
			s.un = ( rc.debug() ) ? 'gnavidev' : 'gnavi2008adminmain';
			s.prop21 = s.prop19;
			s.eVar21 = s.prop21;
		}
		void(s.t());
	} else {
		if ( $( 'body#reserve.mail' ).size() ) {
			s.un = ( rc.debug() ) ? 'gnavidev' : 'gnavi2008homeglobal';
			s.pageName = location.pathname.replace( /\/index\.\w+/, '' );
			s.pageName = 'r' + ( s.pageName ? s.pageName : '' );
			s.channel = 'rest_reserve_mail';
			s.prop1 = 'rest_reserve_mail';
			s.prop2 = 'rest_reserve_mail';
			void(s.t());
		}
	}

	// COMMON
	$( '#footer #footerTopicpath, body#top #content #feature dl dd.urikey ul, body#plan #content .planSearch .sort ul' ).each(function(){
		$( this ).find( '> li:last' ).addClass( 'last' );
	});
	$( 'body#top #content #topic .desc dl, body#top #content #feature dl' ).each(function(){
		$( this ).find( '> dd:last' ).addClass( 'last' );
	});
	$( '[target="myreg"]' ).each(function(){
		$( this ).attr( 'href', $( this ).attr( 'href' ).replace( 'wMode=1', 'wMode=2' ) );
	});
	$( ':submit' ).hover(function(){
		$( this ).addClass( 'hover' );
	},function(){
		$( this ).removeClass( 'hover' );
	});
	$( 'input' ).each(function(){
		var obj = $( this );
		obj.addClass( obj.attr( 'type' ) );
	});
	$( '.pager ol' ).each(function(){
		var obj = $( this );
		var m = Math.ceil( ( obj.parents( '[id]:first' ).width() - obj.width() ) / 2 * 0.99 );
		obj.css( 'padding-left', m + 'px' );
	});
	$( '.toggle > a', '#footer' ).bind( 'click', function(){
		$( '+ ul', $( this ) ).toggle();
		return false;
	}).each( function(){
		var obj = $( this );
		var objLeft = obj.position().left + 'px';
		obj.next( 'ul' ).css( 'left', objLeft );
	});
	$( 'select' ).each(function(){
		$( 'option:even', this ).addClass( 'even' );
		$( 'option:odd', this ).addClass( 'odd' );
	});
	// pr
	$( '#headerLogo > a:first' ).each(function(){
		var obj = $( this );
		if ( !rc.pr.disable ) {
			obj.after( rc.pr.xhtml );
		}
	});
	// disable anchor for myself
	$( 'li', '.nav' ).bind({
		click:function(){
			if( $( this ).attr( 'class' ).indexOf( rc.page.id() ) !== -1 ) {
				return false;
			}
		}
	});
	// write cookie for EDM
	var edmQuery = $.query.get( rc.edm.query );
	if ( edmQuery && ( edmQuery ).match( rc.edm.valFormat ) ) {
		setEdmCookie( rc.id() );
		$('body#top').each(function(){
			// recommend edm
			dhuc = 0;
			$(rc.edm.popXhtml).appendTo('#header>.wrapper').each(function(){
				$(this).show().animate({
					top: '5px'
				},800);
			}).bind('click',function(){
				$.colorbox({
					href: $('#chotto .gu a').attr('href'),
					width: '650px',
					height: '600px',
					iframe: true
				});
				return false;
			}).hover(function(){
				$('#redmX').fadeIn('fast');
			},function(){
				$('#redmX').fadeOut('fast');
			}).find('#redmX').bind('click',function(){
				$('#redm').fadeOut();
				return false;
			});
		});
	}

	// EFFECT with colorbox
	$.map( rc.colorbox.obj, function( obj, idx ) {
		$( obj ).colorbox( rc.colorbox.iframe );
	});
	$( '.sb-en a' ).each(function(){
		$( this ).attr( 'href', rc.sb.en + rc.id() );
	}).colorbox({
		width: '400px',
		height: '300px',
		iframe: true
	});
	$( '.sb-pg a' ).each(function(){
		$( this ).attr( 'href', rc.sb.pg + rc.id() );
	}).colorbox({
		width: '650px',
		height: '600px',
		iframe: true
	});
	$( '#mr .vote > a' ).colorbox({
		width: '650px',
		height: '360px',
		iframe: true
	});

	// SOCIAL MEDIA
	$( '#shoptoolSB' ).each(function(){
		$( '[class^="sb-"] a', this ).bind({
			click:function(){
				if ( ( rc.id() ).match( rc.sb.denyFormatID ) && ( !rc.debug() ) ) {
					return false;
				}
				$( this ).closest( '[class^=sb-]' ).attr( 'class' ).match( /sb-([^ ]+)/ );
				var o = RegExp.$1;
				if( rc.sb[ o ] ) {
					s.linkTrackVars = 'prop5,events';
					s.prop5 = rc.sb.scPrefix + ':' + o + ':' + rc.id() + ':' + rc.gx() + ':' + rc.page.id();
					s.linkTrackEvents = s.events = 'event38';
					s.tl(this, 'o');
					s.prop5 = '';
					if ( o !== 'en' && o !== 'pg' ) {
						var j = ( ( rc.page.id() === 'top' || rc.page.id() === 'menu' || rc.page.id() === 'map' ) && o !== 'mx' && o !== 'gr' && o !== 'wl' );
						var u = ( j ) ? rc.uri() : rc.top();
						u = u.replace( '//test-', '//' );
						var t = ( j ) ? rc.title() : rc.sb.titlePrefix + rc.shopname();
						var a = ( o === 'bz' ) ? rc.sb[ o ].replace( /\$u\$/, u ) : rc.sb[ o ].replace( /\$u\$/, encodeURIComponent( u ) ).replace( /\$t\$/, encodeURIComponent( t ) );
						window.open( a, o );
						return false;
					} else {
						return true;
					}
				}
			}
		});
		// FACEBOOK ASYNC
		if ( rc.isie6() ) {
			$( '.sb-fb' ).hide();// IE6
		} else {
			$( '.sb-fb > iframe' ).attr( 'src', rc.sb[ 'fb' ].replace( /\$u\$/, encodeURIComponent( rc.top() ) ) );
		}
		// GOOGLE+1 
		$( '#shoptoolSB ul:first' ).append( '<li class="sb-gp" title="Google"><div class="g-plusone" data-size="medium" data-count="false"></div></li>' );
		window.___gcfg = {lang: 'ja'};
		$.getScript( 'https://apis.google.com/js/plusone.js' );
	});

	// EXT SEARCH ENGINE REFFERER
	if ( rc.ref() ) {
		setGSearchKeyword();
	}
	// SEARCH KEYWORD HIGHLIGHT
	$( '#gsearchKey' ).focus(function(){
		$( this ).addClass( 'focus' );
	}).blur(function(){
		$( this ).removeClass( 'focus' );
	}).each(function(){
		var keyword = $( this ).val();
		if ( keyword ) {
			$( this ).addClass( 'highlight' );
			var keywords = [];
			if ( keyword.indexOf(' ') !== -1 || keyword.indexOf('　') !== -1 ) {
				keywords = keyword.replace( /　/g, ' ' ).split( ' ' );
			} else {
				keywords.push( keyword );
			}
			$.map( keywords, function(obj,idx){
				$( '#container' ).highlight( obj );
			});
		}
	});
	function setGSearchKeyword () {
		var keyword   = '';
		for (var i = 0, imax = rc.extsearch.data.length; i < imax; i++) {
			if ( rc.extsearch.data[i] ) {
				if ( rc.ref().indexOf( rc.extsearch.data[i].eng ) !== -1) {
					var hash = getParam( rc.ref() );
					if (hash[ rc.extsearch.data[i].key ]) {
						keyword = hash[ rc.extsearch.data[i].key ];
						keyword = window[ 'Unescape' + GetEscapeCodeType(keyword) ](keyword);
						keyword = keyword.replace( /\+/g, ' ' );
						for (var j = 0, jmax = rc.extsearch.data[i].neg.length; j < jmax; j++) {
							keyword = keyword.replace( rc.extsearch.data[i].neg[j], ' ' );
						}
					}
					break;
				}
			}
		}
		$( '#gsearchKey' ).each(function(){
			var wd = keywordFilter( keyword );
			if( wd.indexOf( '%' ) == 0 && wd.split( '%' ).length > 1 ) wd = decodeURI( wd );
			$( this ).val( wd );
/*
			$( this ).val( keywordFilter( keyword ) );
*/
		});
	};
	function getParam (uri) {
		var param = [];
		var item  = [];
		var query = '';
		if ( uri.indexOf( '?', 0 ) > -1 ) {
			query = uri.split('?')[1];
		}
		var params = query.split('&');
		for ( var i = 0, imax = params.length; i < imax; i++ ) {
			var item = params[i].split('=');
			if ( item[0] !== '' ) {
				param[item[0]] = item[1];
			}
		}
		return param;
	}
	function keywordFilter(keyword) {
		var ret = keyword;
		for (var i = 0, imax = rc.extsearch.trimWords.length; i < imax; i++) {
			if ( rc.extsearch.trimWords[i] ) {
				ret = ret.replace( rc.extsearch.trimWords[i], '' ).replace( /[\s　]{2,}/, ' ' ).replace( /[\s　]$/, '' ).replace( /^[\s　]/, '' );
			}
		}
		return ret;
	};

	// COMMON
	$('#footer .mediasel').each(function(){
		if(rc.smartphone.exist()) {
			var $this = $(this).show();
			$('#header').prepend('<p class="mediasel" style="padding-top:20px;text-align:center;"><a href="'+$this.find('a').attr('href')+'"><img src="http://www.gnst.jp/img/go_smart.png" /></a></p>');
		}
	});
	$('.mediasel a').live('click', function(){
		// set smartphone cookie
		var sp = $.gncookie(rc.smartphone.cookieName) || {};
		delete sp.pc;
		$.gncookie(rc.smartphone.cookieName,sp,{
			expires:rc.smartphone.cookieExpires,
			domain:rc.smartphone.cookieDomain,
			path:rc.smartphone.cookiePath
		});
		$.cookie(rc.smartphone.cookieNamePC,null,{
			domain:rc.smartphone.cookieDomain,
			path:rc.smartphone.cookiePath
		});
		trackAjaxName( 'smart_button_shop' );
		return true;
	});

	// TOP
	$( 'body#top' ).each(function(){

		// slide show
		$( '#slide' ).each(function(){
			if ( !rc.slide.disable ) {
				slideShow();
			}
		});
		// wakeari coupon
		if((typeof couponW === 'object') && !rc.wakeari.disable){
			var c = couponW[0];
			var n = (new Date()).getTime();
			if(c.dstart<n && c.close>n){
				$('<dd class="wakeari"><a href="'+rc.wakeari.uri+'">時間限定！枚数限定！ワケあり「得・ぐ」クーポンをチェック！</a></dd>').prependTo('#topic .desc dl');
				$('.wakeari a').colorbox(rc.colorbox.iframe);
				$("#topic.noTopic").removeClass("noTopic");
			}
		}
		// menu ranking
		$('#mr').each(function(){
			var $ol = $('#mrSlide>ol');
			var $o = $ol.data({
				'now': 0,
				'max': Math.floor(($('li',$ol).size()-1)/3)
			});
			if($o.data('max')){
				$('#mrNext').addClass('enable');
			}
			$('#mrPrev,#mrNext',$(this)).show().click(function(){
				var $this = $(this);
				if($this.hasClass('enable')){
					var now = $o.data('now');
					var max = $o.data('max');
					var next = ($this.attr('id') === 'mrPrev') ? now-1 : now+1;
					if(next === 0){
						$('#mrPrev').removeClass('enable');
					}else if(max > 0){
						$('#mrPrev').addClass('enable');
					}
					if(next === max){
						$('#mrNext').removeClass('enable');
					}else if(max > 0){
						$('#mrNext').addClass('enable');
					}
					var x = next * -720;
					$o.animate({
						marginLeft: x + 'px'
					},400);
					$o.data('now', next );
				}
				return false;
			});
		});
		// set history cookie
		setHistoryCookie( rc.id(), rc.area()[0] );
		// twitter
		$( '#tweet' ).each(function(){
			if ( rc.twitter.disable ) {
				return false;
			}
			var api = rc.twitter.api[ rc.twitter.apiSel ];
			api = api.replace( /\$user\$/, rc.twitter.user() ).replace( /\$shop\$/, rc.id() ).replace( /\$count\$/, rc.twitter.count ).replace( /\$reply\$/, rc.twitter.reply ) + '&callback=?';
			$.getJSON( api, function( json ){
				var data;
				if ( rc.twitter.apiSel === 'i' ) {
					var err = false;
					$.each( json, function( key, val ) {
						if ( key.match( rc.twitter.errorCode ) ) {
							err = true;
							return false;
						} else {
							data = val;
						}
					});
					if ( err ) {
						return false;
					}
				} else {
					data = json;
				}
				var t = [];
				$.each( data, function( idx, obj ) {
					var x = rc.twitter.xhtml.head;
					var y = rc.twitter.xhtml.body;
					$.map( rc.twitter.key, function( o, i ) {
						d = o.split( '.' );
						d = ( d.length === 2 ) ? obj[ d[0] ][ d[1] ] : obj[ d[0] ];
						if ( o === 'created_at' ) {
							d = new Date( transDate( d.split( ' ' ) ) );
							d = formatDate( d );
						} else if ( o === 'text' ) {
							d = d.replace( rc.twitter.denyWord, '' );
						}
						var r = new RegExp( '\\$' + o + '\\$', 'g' );
						if ( ! t[0] ) {
							x = x.replace( r, d );
						}
						y = y.replace( r, d );
					});
					if ( ! t[0] ) {
						t.push( x );
					}
					t.push( y );
				});
				if ( t.length ) {
					t.push( rc.twitter.xhtml.foot );
					t = t.join( '\n' );
					$( '#tweetArea' ).html( t );
					$( '#tweet' ).show();
				}
				function transDate( a ) {
					delete a[4];
					var da = new Date( a.join( ' ' ) );
					return da.setHours( da.getHours() + 9 );
				}
			});
		});
		// restaurant week
		if( !rc.rw.disable ) {
			if( rc.debug() ) {
				rc.rw.uri = rc.rw.uri.replace( 'http://', 'http://test-' );
			}
			$.getScript( rc.rw.uri, function( str, status ) {
				if( typeof rwBan === 'undefined'  ) {
					eval( str );
				}
				if( typeof rwBan === 'object' ) {
					if( $.inArray( rc.id(), rwBan ) !== -1 ) {
						$( '#pr200' ).after( rc.rw.xhtml.replace( '%id%', rc.id() ) );
					}
				}
			});
			$( '#rwBanner a' ).live( 'click', function(){
				trackAjaxName( 'r:rw' + rc.id() );
			});
		}
	});

	// MENU
	$( 'body#menu' ).each(function(){
		var n = 0;
		$( 'li', '#menuList' ).each(function(){
			var o = $( this );
			if ( o.hasClass( 'item' ) ) {
				o.addClass( ( n % 2 ) ? 'odd' : 'even' ).removeClass( 's' );
				n++;
			} else {
				n = 0;
			}
		});
	});

	// PLAN
	$( 'body#plan' ).each(function(){
		$( '#planList', this ).each(function(){
			$( 'li.section:even', this ).addClass( 'even' );
			$( 'li.section:odd', this ).addClass( 'odd' );
		});
		$( '#cancel dd:last', this ).each(function(){
			$( this ).addClass( 'note' );
		});
	});

	// ECO
	$( 'body#eco' ).each(function(){
		$( '#match ul', this ).each(function(){
			heightFix( $( this ), 2 );
		});
	});


	// MAP
	$( 'body#map' ).each(function(){
		// wakeari coupon
		if((typeof couponW === 'object') && !rc.wakeari.disable){
			var c = couponW[0];
			function f(t){
				var x = {
					t: new Date(t),
					h: function(){ return (this.t).getHours() },
					m: function(){ return (this.t).getMinutes() }
				}
				return dig2(x.h())+':'+dig2(x.m());
			}
			function fmt(n){
				return (n<4)?n+24:n;
			}
			function dig2(n){
				return (n<10)?'0'+n:n;
			}
			var n = (new Date()).getTime();
			if(c.dstart<n && c.close>n){
				$('<div id="couponW"><dl><dt>'+c.title+'</dt><dd>利用可能時間：<span><var id="couponW-start">'+f(c.start)+'</var>～<var id="couponW-close">'+f(c.close)+'</var></span><a href="'+rc.wakeari.uri+'" id="couponW-btn">ケータイ・スマホに送る</a></dd></dl></div>').hide().insertAfter('#shopMap').fadeIn();
				$('#couponW-btn').colorbox(rc.colorbox.iframe);
			}
		}
		var nowPrint = 0;
		// only IE
		document.body.onbeforeprint = function(){
			if ( ! nowPrint ) {
				$( 'body' ).removeClass( 'coupon' );
				setPrintCookie( rc.id() );
				reqGet( 'print-map' );
			}
		}
		var obj = $( this );
		var printObj = $( '#authPrint, #usefulTool-print, #usefulTool-cprint, #mapTool-print', obj );
		printObj.addClass( 'on' ).bind({
			click:function(){
				nowPrint = 1;
				$( 'body' ).removeClass( 'onlyCoupon' );
				setPrintCookie( rc.id() );
				if ( $( this ).attr( 'id' ) === 'usefulTool-cprint' ) {
					$( 'body' ).addClass( 'onlyCoupon' ).filter( '.onlyCoupon' ).each(function(){
						authPrint('print-coupon');
					});
				} else {
					authPrint('print-map');
				}
				nowPrint = 0;
				return false;
			}
		});
		function authPrint(req) {
			if( rc.map.auth() ) {
				var authPrintCode = function(_apiData) {
					var authCode = _apiData.result;
					var authResult = _apiData.success;
					if ( ! authCode.match(rc.map.authFormat) || ! authResult ) {
						$('#authCode').hide();
						location.href = authCode;
					} else {
						$('#authCode').text(authCode);
						$('#authCode').removeClass('invalid').prepend('クーポンNo:');
						reqGet(req);
						print();
					}
				};
				if ( rc.map.authPrintConstCode() ) {
					var constApiData = { success: 1, result: rc.map.authConstCode };
					authPrintCode(constApiData);
				} else {
					$.ajax({
						url: rc.map.authAPI,
						type: 'GET',
						dataType: 'json',
						data: 'getCoupon='+rc.id(),
						success: function(_apiData){
							authPrintCode(_apiData);
						},
						error: function(_err, _textStatus){
						}
					});
				}
			} else {
				reqGet(req);
				print();
			}
		}
		// secret coupon
		$('#scoupon .logout').colorbox({
			width: '510px',
			height: '550px',
			iframe: true
		}).filter('[class*=type]').each(function(){
			var $this = $(this);
			$this.attr('href', $this.attr('href')+rc.uri());
		});
		if ($('#scoupon').size() == 1 && $('#scoupon .logout').size() == 0 &&  $('#infoTool-mreg').size() == 1) {
			$("#pr_edm.logout").removeClass("logout");
		}

		if ( GBrowserIsCompatible() ) {
			window.onunload=google.maps.Unload;
			if ( ( typeof mapRoute === 'undefined' ) || ( mapRoute === '' ) ) {
				$('#figureListData').html( '最寄り駅を検索できませんでした。' );
			} else {
				var figureListData = $( '#figureListData', obj );
				var routeXhtml = [];
				$.each( mapRoute, function( key, val ){
					routeXhtml.push( '<li><a href="#'+val['lat']+'_'+val['lng']+'" id="latlng-'+val['lat']+'_'+val['lng']+'">'+val['name']+'</a></li>' );
				});
				if ( routeXhtml.length ) {
					figureListData.html( '<ul>' + routeXhtml.join( '' ) + '</ul>' );
				} else {
					figureListData.html( '最寄り駅がありませんでした。' );
				}
			}
		}
		$( '#figureList', obj ).show();

		$( '<div id="figureLoad">地図を動かして周辺を確認する</div>' ).appendTo( $( '#figureView' ) );

		if ( !rc.smartphone.exist() ) {
			$( '#figureMap > img' ).click(function(){
				loadGmap();
				return false;
			}).css( 'cursor', 'pointer' ).attr( 'title', '地図を動かして周辺を確認する' );
		}

		$( '#figureLoad' ).live( 'click', function(){
			loadGmap();
		});

		$( '#figureListData a' ).live( 'click', function(){
			loadGmap( $( this ) );
		});

		$( '#figureSel li', obj ).filter( ':first' ).addClass( 'sel' ).end().bind({
			click:function(){
				var obj = $( this );
				obj.addClass( 'sel' ).siblings().removeClass( 'sel' );
				$( 'li', obj.parents( 'ul:first' ) ).each(function(){
					if ( $( this ).hasClass( 'sel' ) ){
						$( $( 'a', this ).attr( 'href' ) ).show();
					} else {
						$( $( 'a', this ).attr( 'href' ) ).hide();
					}
				});
				return false;
			}
		}).filter( ':not(:first)' ).each(function(){
			$( $( 'a', this ).attr( 'href' ) ).hide();
		});

		function loadGmap( obj ){
			if ( $( '#figureCanvas' ).children().size() !== 0 ) {
				return false;
			}
			s.linkTrackVars = 'eVar13,prop13';
			var sc_menu = 'gmap:' + rc.gx();
			s.prop13 = sc_menu;
			s.eVar13 = sc_menu;
			s.tl( this, 'o' ,sc_menu);
			$( '#figureLoad' ).hide();
			$( '#figureControl,#mapReset' ).show();
			$( '#figureCanvas' ).each(function(){
				var gdata = {};
				var c = $( this ).attr( 'class' ).split( ' ' );
				if ( c.length !== 5 ) {
					return false;
				}
				$.map( c, function( val, key ){
					var d = val.split( ':' );
					gdata[ d[0] ] = Number( d[1] );
				});
				var shopPoint = new GLatLng( gdata.lat, gdata.lng );
				var point = new GLatLng( gdata.latc, gdata.lngc );
				var zoom = gdata.zoom;
				var map = new GMap2( $( '#figureCanvas' )[0] );
				map.addControl( new GLargeMapControl() );
				map.addControl( new GScaleControl() );
				map.addControl( new GMapTypeControl() );
				map.setCenter( point, zoom );
				$( '#mapReset' ).bind({
					click:function(){
						directions.clear();
						map.closeInfoWindow();
						map.setCenter( point, zoom, G_NORMAL_MAP );
						return false;
					}
				});
				// ICON
				var icon = new GIcon();
				icon.image = rc.google.marker;
				icon.iconSize = new GSize(48,48);
				icon.iconAnchor = new GPoint(48/2,48-5);
				icon.shadow = rc.google.shadow;
				icon.shadowSize = new GSize(73,48);
				var marker = new GMarker( shopPoint, {icon: icon, zIndexProcess: function(){ return 1; }} );
				map.addOverlay( marker );
				// ROUTE
				var directions = new GDirections(map, $( '#figureListCache' )[0] );
				var option = {locale: 'ja_JP', travelMode: G_TRAVEL_MODE_WALKING, preserveViewport: false };
				var points = [];
				var displayRoute = false;
				$.fn.stationFunc = function(lat, lng, name) {
					directions.clear();
					var element = name+'<br /><br /><a href="#" id="figureStation" onclick="jQuery().routeFunc(); return false;">経路を表示しない</a>';
					map.openInfoWindowHtml(new GLatLng(lat, lng), element);
					points = [];
					points.push( new GLatLng( lat, lng ) );
					points.push( new GLatLng( gdata.lat, gdata.lng ) );
					directions.loadFromWaypoints( points, option );
					displayRoute = true;
				};
				$.fn.routeFunc = function() {
					if (displayRoute) {
						$('#figureStation').text('経路を表示する');
						directions.clear();
					} else {
						$('#figureStation').text('経路を表示しない');
						directions.loadFromWaypoints( points, option );
					}
					displayRoute = !displayRoute;
				};
				$( 'a', '#figureListData' ).live( 'click', function(){
					var o = $( this );
					var loc = ( o.attr( 'id' ).replace( 'latlng-', '' ) ).split( '_' );
					o.stationFunc( loc[0], loc[1], o.text() );
				});
				if ( obj ) {
					$( obj ).trigger( 'click' );
				}
				// STREET VIEW
				if ( swfEnable() ){
					$( '#figureStreetCanvas' ).html( '' );
				}
				var isStreetViewInitialized = false;
				var svOverlay, streetviewMarker, street;
				var panoramaOpt = {features: {userPhotos: false}};
				$( '#streetViewToggle' ).each(function(){
					street = new GStreetviewPanorama( $( '#figureStreetCanvas' )[0], panoramaOpt );
					street.setLocationAndPOV( shopPoint );
					GEvent.addListener( street, 'error', function( err ) { // 非対応エリアはコントロール非表示
						$( 'p', '#figureView' ).hide();
						$( '#streetViewToggle', '#figureView' ).addClass( 'hidden' );
					});
				}).bind({
					click:function(){
						if (!isStreetViewInitialized) {
							var streetviewMarkerIcon = new GIcon();
							streetviewMarkerIcon.image = rc.google.markerIcon;
							streetviewMarkerIcon.iconSize = new GSize(49,52);
							streetviewMarkerIcon.iconAnchor = new GPoint(25,35);
							streetviewMarker = new GMarker(point, {icon: streetviewMarkerIcon, draggable: true, zIndexProcess: function(){ return 2; }});
							GEvent.addListener(street, 'initialized', function(loc){ streetviewMarker.setLatLng(loc.latlng); });
							GEvent.addListener(streetviewMarker, 'dragend', function(loc){ street.setLocationAndPOV(loc) });
							svOverlay = new GStreetviewOverlay();
							isStreetViewInitialized = true;
						}
						if ( $( this ).hasClass( 'open' ) ) {
							$( '#figureStreetView, #streetViewUse' ).hide();
							map.removeOverlay(svOverlay);
							map.removeOverlay(streetviewMarker);
							$( this ).removeClass( 'open' );
						} else {
							$( '#figureStreetView, #streetViewUse' ).show();
							street.setLocationAndPOV( shopPoint );
							map.addOverlay(svOverlay);
							map.addOverlay(streetviewMarker);
							$( this ).addClass( 'open' );
						}
						return false;
					}
				});
				// GOOGLE MAP VISIBLE
				$( '#figureCanvas' ).addClass( 'on' );
			});
		}
		// MR FOR PRINT
		if ( ( typeof mrItem === 'undefined' ) || ( mrItem === '' ) ) {
			return false;
		}
		if(mrItem.length){
			var mrHtml = [];
			mrHtml.push('<img src="http://r.gnst.jp/c/r/print_mrbg.png" id="printBox" />');
			mrHtml.push('<div id="printMR">');
			$.map(mrItem,function(n,i){
				mrHtml.push('<img src="http://r.gnst.jp/c/r/mr'+(i+1)+'.png" /><p>'+n+'</p>');
			});
			mrHtml.push('</div>');
			mrHtml = mrHtml.join('');
			$('#figure').append(mrHtml);
		}else{
			$('#figure').append('<img src="http://r.gnst.jp/c/r/print_pr.png" id="printBox" />');
		}
	});

	// RAMEN

	$( 'body#ramen' ).each(function(){
		// set history cookie
		setHistoryCookie( rc.id(), rc.area()[0] );

		var obj = $( this );
		var printObj = $( '#usefulTool-print, #usefulTool-cprint, #mapTool-print', obj );
		printObj.addClass( 'on' ).bind({
			click:function(){
				$( 'body' ).removeClass( 'coupon' );
				setPrintCookie( rc.id() );
				if ( $( this ).attr( 'id' ) === 'usefulTool-cprint' ) {
					$( 'body' ).addClass( 'coupon' ).filter( '.coupon' ).each(function(){
						print();
					});
				} else {
					print();
				}
				return false;
			}
		});
		$( '.ramenitem .detail .chart table th', obj ).each( function(){
			var o  = $( this );
			o.addClass( 'honge' );
			o.html( '<div class="wrap" style="height:' + $( o ).height() + 'px;">' + o.html() + '<span class="illust">&nbsp;</span></div>' );
		})
	});

	// RESERVE
	$( 'body#reserve:not(.mail)' ).each(function(){
		$( 'table', this ).each(function(){
			$( 'tr:even', this ).addClass( 'even' );
			$( 'tr:odd', this ).addClass( 'odd' );
		});
		google.setOnLoadCallback(function() {
			if ( ( typeof reserveDisableDay === 'undefined' ) || ( reserveDisableDay === '' ) ) {
				return false;
			}

			$( '#toggleSupport' ).show().click(function(){
				$( '#dateSupport' ).toggle();
				return false;
			});

			var reserveOffset = Number( $( '#reserveOffset' ).text() );
			var d = new Date();
			if ( ( d.getHours() === rc.reserve.periodHour ) && ( d.getMinutes() >= rc.reserve.periodMin ) ) {
				reserveOffset++;
			}
			$.datepicker.regional['ja'] = {
				beforeShowDay: disableDays,
				closeText: '閉じる',
				prevText: '前月',
				nextText: '次月',
				currentText: '今日',
				monthNames: ['年 01月','年 02月','年 03月','年 04月','年 05月','年 06月','年 07月','年 08月','年 09月','年 10月','年 11月','年 12月'],
				monthNamesShort: ['1月','2月','3月','4月','5月','6月','7月','8月','9月','10月','11月','12月'],
				dayNames: ['日曜日','月曜日','火曜日','水曜日','木曜日','金曜日','土曜日'],
				dayNamesShort: ['日','月','火','水','木','金','土'],
				dayNamesMin: ['日','月','火','水','木','金','土'],
				isRTL: false,
				showMonthAfterYear: true,
				minDate: reserveOffset,
				maxDate: rc.reserve.maxDate(),
				numberOfMonths: rc.reserve.calMonth
			};
			$.datepicker.setDefaults($.datepicker.regional['ja']);

			$( '#dateCal' ).datepicker({
				onSelect: function(){
					var d = getYMD( $( this ).datepicker( 'getDate' ) );
					$( '#dateY' ).val( d.year );
					$( '#dateM' ).val( adjDigit( d.month ) );
					$( '#dateD' ).val( adjDigit( d.date ) );
					$( '#dateW' ).val( fitWday( d.wday ) );
					setCalNote( d.year, adjDigit( d.month ) );
				}
			}).each(function(){
				var d = {
					year: Number( $( '#dateY' ).val() ),
					month: Number( $( '#dateM' ).val() ),
					date: Number( $( '#dateD' ).val() )
				};
				if ( ( d.month === 0 || d.date === 0 ) ) {
					var n = new Date();
					n.setDate( n.getDate() + reserveOffset );
					m = n.getFullYear().toString() + '-' + ( n.getMonth()+1 ).toString() + "-" + n.getDate().toString();
					while ( $.inArray( m, reserveDisableDay ) !== -1 ) {
						n.setDate( n.getDate() + 1 );
						m = n.getFullYear().toString() + '-' + ( n.getMonth()+1 ).toString() + "-" + n.getDate().toString();
					}
					var d = getYMD( n );
					$( '#dateY' ).val( d.year );
					$( '#dateM' ).val( adjDigit( d.month ) );
					$( '#dateD' ).val( adjDigit( d.date ) );
					$( '#dateW' ).val( fitWday( d.wday ) );
				}
				setCal();
			});

			$( '#dateY, #dateM, #dateD' ).bind( 'change',function(){
				setCal();
			});

			function setCal() {
				var d = {
					year: Number( $( '#dateY' ).val() ),
					month: Number( $( '#dateM' ).val() ),
					date: Number( $( '#dateD' ).val() )
				};
				$( '#dateSupport .comment p' ).hide();
				if ( d.year && d.month ) {
					setCalNote( d.year, adjDigit( d.month ) );
					var h = getMday( d.year, d.month );
					$( '#dateD option' ).show().filter( ':gt(' + h + ')' ).hide();
					if ( d.date ) {
						if ( d.date > h ) {
							$( '#dateD' ).val( '01' );
							d.date = 1;
						}
						d = new Date( d.year, d.month - 1, d.date, 0, 0, 0 );
						$( '#dateW' ).val( fitWday( d.getDay() ) );
						$( '#dateCal' ).datepicker( 'setDate', d );
					}
				}
			}

			function setCalNote( yyyy, mm ) {
				if ( yyyy && mm ) {
					$( '#dateSupport .comment p' ).hide().filter( '.date' + yyyy + mm ).show();
				}
			}

			function fitWday( n ) {
				return ( n === 0 )? 7 : n;
			}

			function getYMD( t ) {
				var d = {
					year: t.getFullYear(),
					month: t.getMonth() + 1,
					date: t.getDate(),
					wday: t.getDay()
				}
				return d;
			}

			function disableDays( d ) {
				d = d.getFullYear().toString() + '-' + ( d.getMonth()+1 ).toString() + "-" + d.getDate().toString();
				if ( $.inArray( d, reserveDisableDay ) !== -1 ) {
					return [false, 'ng', '予約不可'];
				} else {
					return [true, '', ''];
				}
			}

			function getMday( y, m ){
				var l = [31,28,31,30,31,30,31,31,30,31,30,31];
				if ( ( ( y % 4 == 0 ) && ( y % 100 !== 0 ) ) || ( y % 400 === 0 ) ) {
					l[1] = 29;
				}
				return l[ m - 1 ];
			}
		});
	});

	// MOVIE
	$( 'body#movie' ).each(function(){
		$( '#movieareaContent', this ).each(function(){
			var obj = $( this );
			obj.prepend( '<div id="gnaviMoviePlayer"></div>' );
			var msrc = $( '> a', obj ).attr( 'href' ).split( 'youtube.com/watch?v=' ).join( 'youtube.com/v/' ) + '&hl=ja&fs=1&rel=0';
			var so = new SWFObject( msrc, 'movie', '480', '385', '8', '#ffffff' );
			so.addParam( 'wmode', 'transparent' );
			so.addParam( 'allowFullScreen', 'true' );
			so.addParam( 'allowScriptAccess', 'sameDomain' );
			so.write( 'gnaviMoviePlayer' );
			$( '> a', obj ).hide();
		});
	});

	function slideShow() {
		if( $( '#slideList > ul > li' ).length <= 1 ) {
			$( '#slideList ul li a' ).click( function(){ return false });
			return false;
		}
		var isie6 = navigator.appName.toUpperCase().indexOf( 'EXPLORER' ) !== -1 && navigator.appVersion.toUpperCase().split( ';' )[1].charAt( 6 ) === '6' ? true : false;
		var slset = {
			rep: 5000,
			longrep: 7000,
			length: $( '#slideList > ul > li' ).length,
			timer: null,
			now: 0,
			caption: $( '#slideCaption' )
		};
		function getleft(){ return (351 + (101 * (slset.now % 4))) - 3 + (isie6 ? 3 : 0 ); }
		function gettop(){ return 15 + 86 * ((slset.now <= 3) ? 0 : ((slset.now <= 7) ? 1 : 2)) - 3; }
		function changePhoto() {
			var targ = $( '#slideList > ul > li:eq(' + slset.now + ') a' );
			$( '#slideObj td img' ).attr( 'title', $( 'img', targ).attr( 'title' )  ).attr( 'alt', $( 'img', targ ).attr( 'alt' ) ).attr( 'src', targ.attr( 'href' ) ).clearQueue().fadeTo( 512, 1, function(){
				$( this ).removeAttr( 'style' );
			});
			slset.caption.text( $( 'img', targ ).attr( 'alt' ) );
		}
		function changeSlide() {
			if( $( '#cboxOverlay' ).css( 'display' ) === 'none' ) {
				slset.now = (slset.now < slset.length - 1) ? slset.now + 1 : 0;
				$( '#slideActive' ).animate( {left: getleft(), top: gettop()}, 512, function(){
					changePhoto();
					setTim( slset.rep );
				});
				$( '#slideObj td img' ).fadeTo( 512, '0' );
			} else {
				setTim( slset.rep );
			}
		}
		function setTim( num ) {
			slset.timer = setTimeout( changeSlide, num );
		}
		$( '<div />', { width:96, height:72,id:'slideActive'})
			.css({
				border: '3px solid #C00',
				position: 'absolute',
				left: getleft(),
				top: gettop()
			})
			.prependTo( '#slide #slideList' )
			.fadeTo( 0, 0 )
			.fadeTo( 256, 1 );
		$('#slideList ul li').hover( function(){
			if( $( '#slideActive' ).queue().length !== 0 ) $( '#slideActive' ).stop();
			clearTimeout( slset.timer );
			slset.now = $( this ).index();
			changePhoto();
			$( '#slideActive' ).animate( {left: getleft(), top: gettop()}, 0, function(){} );
		}, function(){
			setTim( slset.longrep );
		}).click( function(){
			return false;
		});
		setTim( slset.rep );
	}

	function getHistoryCookie() {
		if ( !$.cookie( rc.history.cookieName ) ) {
			return '';
		}
		return $.cookie( rc.history.cookieName ).split( rc.history.cookieDlm );
	}

	function setHistoryCookie( shopID, shopArea ) {
		if ( shopID && shopArea ) {
			shopArea = 'AREA' + shopArea;
		} else {
			return false;
		}
		var d = {};
		d.arr  = [];
		d.date = rc.time();
		d.arr.push( shopID + rc.history.cookieValDlm + shopArea + rc.history.cookieValDlm + d.date );
		var i = 1;
		$.map( getHistoryCookie(), function( obj, idx ) {
			if ( i < rc.history.cookieMax ) {
				objs = obj.split( rc.history.cookieValDlm );
				if ( objs[0] !== shopID ) {
					d.arr.push( obj );
					i++;
				}
			} else {
				return false;
			}
		});
		$.cookie( rc.history.cookieName, d.arr,{
			expires: rc.history.cookieExpires,
			path: rc.history.cookiePath,
			domain: rc.history.cookieDomain
		});
		return true;
	}

	function getPrintCookie() {
		if ( !$.cookie( rc.print.cookieName ) ) {
			return '';
		}
		return $.cookie( rc.print.cookieName ).split( rc.print.cookieDlm );
	}

	function setPrintCookie( shopID ) {
		if ( !shopID ) {
			return false;
		}
		var d = {};
		d.arr = [];
		d.date = rc.time();
		d.arr.push( shopID + rc.print.cookieValDlm + d.date );
		var i = 1;
		$.map( getPrintCookie(), function( obj, idx ) {
			if ( i < rc.print.cookieMax ) {
				objs = obj.split( rc.print.cookieValDlm );
				if ( objs[0] !== shopID ) {
					d.arr.push( obj );
					i++;
				}
			} else {
				return false;
			}
		});
		$.cookie( rc.print.cookieName, d.arr,{
			expires: rc.print.cookieExpires,
			path: rc.print.cookiePath,
			domain: rc.print.cookieDomain
		});
		return true;
	}

	function getEdmCookie() {
		if ( !$.cookie( rc.edm.cookieName ) ) {
			return '';
		}
		return $.cookie( rc.edm.cookieName ).split( rc.edm.cookieDlm );
	}

	function setEdmCookie( shopID ) {
		if ( !shopID ) {
			return false;
		}
		var d = {};
		d.arr = [];
		d.date = rc.time();
		d.arr.push( shopID + rc.edm.cookieValDlm + rc.edm.cookieValDlm + d.date );
		var i = 1;
		$.map( getEdmCookie(), function( obj, idx ) {
			if ( i < rc.edm.cookieMax ) {
				objs = obj.split( rc.edm.cookieValDlm );
				if ( objs[0] !== shopID ) {
					d.arr.push( obj );
					i++;
				}
			} else {
				return false;
			}
		});
		$.cookie( rc.edm.cookieName, d.arr,{
			expires: rc.edm.cookieExpires,
			path: rc.edm.cookiePath,
			domain: rc.edm.cookieDomain
		});
		return true;
	}

	function reqGet( q ) {
		var query = [
			'gx=' + rc.gx(),
			'id=' + rc.id(),
			't=' + rc.time(),
			'q=' + q
		];
		$.get( '/c/r/?' + query.join( '&' ) );
		s.events = s.apl( s.events, 'event8', ',', 2 );
		void(s.t());
	}

	function swfEnable() {
		if ( navigator.plugins['Shockwave Flash'] ) {
			return true;
		} try {
			new ActiveXObject( 'ShockwaveFlash.ShockwaveFlash' );
			return true;
		} catch (e) {
			return false;
		}
	};

	function heightFix( obj, size ) {
		$( obj ).each( function() {
			var o = [];
			$( '> *', this ).each( function( idx ) {
				var unit = Math.floor( idx / size );
				if ( ( idx % size ) === 0 ) {
					o[ unit ] = [];
				}
				o[ unit ].push( $( this ).height() );
			});
			$( '> *', this ).each( function( idx ) {
				var unit = Math.floor( idx / size );
				$( this ).height( Math.max.apply( null, o[ unit ] ) );
			});
		});
	}

	function formatDate( d ) {
		var m = ['日','月','火','水','木','金','土'];
		d = d.getFullYear() + '年' + adjDigit( d.getMonth() + 1 ) + '月' + adjDigit( d.getDate() ) + '日(' + m[ d.getDay() ]  + ') ' + adjDigit( d.getHours() ) + ':' + adjDigit( d.getMinutes() );
		return d;
	}

	function adjDigit( n ) {
		return ( Number( n ) < 10 ) ? '0' + n : n;
	}

	// GPOINT
	$( '#gpoint' ).each(function(){
		if ( gpointT[0] || gpointT[1] || gpointT[2] ) { // rest
			if ( gpointT[2] && gpointT[2].point ) {
					$( '#gpointT-regist' ).find( 'var' ).text( '+'+gpointT[2].point ).end().show();
			} else if ( gpointT[0] && gpointT[0].point ) {
					$( '#gpointT-regist' ).find( 'var' ).text( '+'+gpointT[0].point ).end().show();
			}
			if ( gpointT[1] && gpointT[1].point ) {
				$( '#gpointT-visit' ).find( 'var' ).text( '+'+gpointT[1].point ).end().show();
			}
			$( '#gpointT' ).show();
		};
	});

	// MYBOX
	$( '#myBox' ).each(function(){

		if($.cookie('GMemDisp')){
			$.cookie('GMemDisp',$.cookie('GMemDisp'),{domain:'.gnavi.co.jp',path:'/'});
			mybox();
		}else{
			if($.cookie('GMember')){
				$.get(rc.gmemdispAPI, function(){
					mybox();
				});
			}else{
				mybox();
			}
		}
		if($.cookie('GMember')){$.cookie('GMember',$.cookie('GMember'),{expires:730,domain:'.gnavi.co.jp',path:'/'});}

		function mybox() {
			if ( $.cookie( 'GMemDisp' ) ) {
				$( '#myBoxLogin' ).hide();
				var m = ( $.cookie( 'GMemDisp' ) ).split( '&' );
				m[3] = Number(m[3]);
				m[5] = Number(m[5]);
				//limitpoint undefined
				if ( m.length !== 7 ) {
					m[5] = 0;
				}
				// [0]:? [1]:medal [2]:account [3]:point [4]:user [5]:limitpoint [6]:point + limitpoint
				$( '#myBoxMsg > span' ).text( UnescapeEUCJP( m[4] ) );
				$( '#myBoxMsg' ).after( '<p id="myBoxOth">※本人でない場合は<a href="http://my.gnavi.co.jp/">こちら</a></p>' );
				$( '#myBoxPoint' ).after( '<p id="myBoxLimPoint">&#9492;&nbsp;期間限定：<var>' + m[5] + '</var>ポイント</p>' );
				$( '#myBoxPoint > var' ).text( m[3] + m[5] );
				if ( m[3] + m[5] >= 1000 ) {
					$( '#myBoxPoint' ).before( '<div id="campoint"><a href="https://my.gnavi.co.jp/point/gpoint/"><img src="http://my.gnavi.co.jp/lib/mybox/campoint_buttom.png" alt="今すぐ交換！ポイントご利用券" title="今すぐ交換！ポイントご利用券" /></a></div>' );
				}
				$( '#myBoxPoint, #myBoxLimPoint, #myBoxPhistory' ).show();
			} else {
				$( '#myBoxReg' ).show();
			}

			$( '#myBoxMsg > span' ).wrap( '<a href="' + $( '#myBoxGnavi' ).attr( 'href' ) +'"></a>' );
			$( '#myBoxGnavi' ).attr( 'title', '' );
			$( '#myBoxMsg' ).show();
			var l = encodeURIComponent( location.href );
			$( '#myBoxLogin' ).click(function(){
				location.href = $( this ).attr( 'href' ) + l;
				return false;
			});
			$( '#myBoxReg > a' ).click(function(){
				location.href = $( this ).attr( 'href' ) + '&rType=z&rUrl=' + l;
				return false;
			});
		}
	});

	// USERAREA
	var config = {
		general: {
			disable: false,
			shopInfoAPI: 'http://async.gnavi.co.jp/rinfo/restUserInformation.py',
			recommendAPI: 'http://rcm.gnavi.co.jp/restUserRecommendation.php',
			jsonKey: Array( 'shopStatus', 'shopID', 'shopURL', 'shopName', 'shopType', 'shopStation' ),
			imgExistStatus: Array( 30, 80 ),
			errorStatus: Array( 90, 99 ),
			cookieName: 'GUserarea',
			cookieExpire: '',
			obj: '#userarea',
			objFootXhtml: '<div id="uaFoot"></div>',
			unitObj: '.sideUnit',
			shopObj: '.shopUnit',
			mainObj: '.main',
			subObj: '.sub',
			delObj: '.del',
			loc: location.href,
			query: function(){ return ( ( location.href ).split( '?' ) )[1] }
		},
		shop: {
			nameLenMax: 20,
			imgPath: 'img/',
			imgTail: 's.png',
			noimgURI: 'http://r.gnst.jp/c/r/noimg.png',
			formatID: /^[a-z0-9]{4}[0-9]{3}$/
		},
		catalyst: {
			fixCode: 'uarea1',
			code: {
				compare: 'cm',
				history: 'hs',
				recommend: 'rc'
			},
			exist: function(){ return ( ( typeof s === 'object' ) && ( s.visitorNamespace === 'gurunavi' ) && ( typeof trackAjaxName === 'function' ) ) }
		},
		effect: {
			moveSpeed: 1000,
			fadeSpeed: 400,
			toggleSpeed: 400,
			moreObj: '.more',
			toggleObj: '.toggle',
			toggleClass: 'compact',
			toggleOpenTitle: '開く',
			toggleCloseTitle: '閉じる',
			targetObj: '.assist-compare',
			compareObj: 'li:last',
			compareOpacity: Array( 1, 0.5 ),
			compareBorderWidth: Array( 3, 1 ),
			compareOutlineObj: '.compareOutline',
			compareBalloonObj: '.compareBalloon',
			compareBalloonLoc: Array( 10, -40 ),
			compareOutlineXhtml: '<div class="compareOutline"></div>',
			compareBalloonXhtml: '<div class="compareBalloon"><span>&nbsp;</span></div>'
		},
		my: {
			obj: '#uaMy',
			nameObj: '#uaMyName',
			logObj: '#uaMyTitle dd a',
			logoutURI: 'http://my.gnavi.co.jp/logout.php?r=',
			nojsObj: '#uaMyTitle dd, #uaMyReg',
			regObj: '#uaMyReg dd a',
			cookieName: 'GMemDisp',
			objFootXhtml: '<div id="uaMyFoot"></div>'
		},
		compare: {
			uri: 'http://rd.gnavi.co.jp/compare/regist_shop.php?id_shop=',
			obj: '#uaCompare',
			query: 'compare',
			visibleMax: 5,
			displayMax: 10,
			cookieMax: 20,
			cookieName: 'GCompareShop',
			cookieExpire: 365,
			xhtml: '<dl class="shopUnit"><dt class="shopName"><a href="$shopURL$" class="$shopSC$">$shopName$</a></dt><dd class="shopImg"><a href="$shopURL$" class="$shopSC$"><img src="$shopImg$" title="$shopName$" /></a></dd><dd class="shopType">[$shopType$]</dd><dd class="shopStation">$shopStation$</dd><dd class="shopCtrl"><a href="#compare=$shopID$" class="del">削除</a></dd></dl>',
			msgXhtml: '<p>気になったお店をピックアップして見比べられます。</p><p>「あとで見比べる」ボタンを押してお店を登録してください。</p>'
		},
		history: {
			obj: '#uaHistory',
			query: 'history',
			visibleMax: 5,
			displayMax: 10,
			cookieMax: 15,
			cookieName: 'GHistory',
			cookieExpire: 365,
			xhtml: '<dl class="shopUnit"><dt class="shopName"><a href="$shopURL$" class="$shopSC$">$shopName$</a></dt><dd class="shopType">[$shopType$]</dd><dd class="shopStation">$shopStation$</dd><dd class="shopCtrl"><a href="#history=$shopID$" class="del">削除</a></dd></dl>',
			msgXhtml: '<p>お店のページを見た履歴が表示されます。</p>'
		},
		recommend: {
			obj: '#uaRecommend',
			refObj: '.refresh',
			query: Array( 'score', 'rand' ),
			displayMax: 5,
			historyMax: 3,
			xhtml: '<dl class="shopUnit"><dt class="shopName"><a href="$shopURL$" class="$shopSC$">$shopName$</a></dt><dd class="shopImg"><a href="$shopURL$" class="$shopSC$"><img src="$shopImg$" title="$shopName$" /></a></dd><dd class="shopType">[$shopType$]</dd><dd class="shopStation">$shopStation$</dd></dl>',
			msgFstXhtml: '<p class="readText">お店のページの閲覧履歴を元におすすめのお店を表示します。</p>',
			msgXhtml: '<p>お店のページの閲覧履歴からあなたにおすすめのお店を表示します。</p>'
		}
	}

	if( $( config.general.obj ).size() === 0 ) {
		// control button
		if ( getCompare() ) {
			$.map( getCompare(), function( obj, idx ) {
				if ( obj ) {
					var o = $( 'a[href^=' + config.compare.uri + obj  + ']' );
					o.addClass( 'disable' ).attr( 'title', '' );
				}
			});
		}
	} else {
		$( config.general.obj ).append( config.general.objFootXhtml ).find( config.my.obj ).append( config.my.objFootXhtml );

		showMember();

		if ( config.general.disable ) {
			showInit( config.compare );
			showInit( config.history );
			showInit( config.recommend );
			return false;
		}

		getUserarea()

		var shopInfoQuery = [];
		$( config.general.subObj, config.general.obj ).show();
		if ( getCompare() ) {
			var compareQuery = genQuery( config.compare.query, getCompare() );
			if ( ! $( config.compare.obj ).hasClass( config.effect.toggleClass )  ) {
				getShop( compareQuery, config.general.shopInfoAPI );
			}
		} else {
			showInit( config.compare );
		}
		if ( getHistory() ) {
			var historyQuery = genQuery( config.history.query, getHistory() );
			if ( ! $( config.history.obj ).hasClass( config.effect.toggleClass )  ) {
				getShop( historyQuery, config.general.shopInfoAPI );
			}
			var recommendQuery = genQuery( config.recommend.query[0], getRecentHistory(), 1 );
			if ( ! $( config.recommend.obj ).hasClass( config.effect.toggleClass )  ) {
				getShop( recommendQuery, config.general.recommendAPI );
			}
		} else {
			showInit( config.history );
			showInit( config.recommend );
		}
		// control button
		if ( getCompare() ) {
			$.map( getCompare(), function( obj, idx ) {
				if ( obj ) {
					var o = $( 'a[href^=' + config.compare.uri + obj  + ']' );
					o.addClass( 'disable' ).attr( 'title', '' );
				}
			});
		}
		$( 'a[href^=' + config.compare.uri + ']', config.effect.targetObj ).click(function(){
			var obj = $( this );
			if ( obj.hasClass( 'disable' ) ) {
				return false;
			} else {
				$( 'body' ).append( config.effect.compareOutlineXhtml + config.effect.compareBalloonXhtml );
				var objID = ( ( obj.attr( 'href' ) ).split( '=' ) )[1];
				var o = $( 'a[href^=' + config.compare.uri + objID  + ']' );
				o.addClass( 'disable' ).data( 'title', '後で見比べる' );
				o.attr( 'title', '' );
				
				var src = obj.parents( config.effect.compareObj );
				var objCSS = {
					left: obj.offset().left + obj.width() + config.effect.compareBalloonLoc[0],
					top: obj.offset().top + config.effect.compareBalloonLoc[1]
				}
				var b = config.effect.toggleSpeed * 1.5;
				$( config.effect.compareBalloonObj + ':last' ).css( objCSS ).find( 'span' ).fadeIn(0).delay(b).fadeOut(0).delay(b).fadeIn(0).delay(b).fadeOut(0).delay(b).fadeIn(0).delay(b).fadeOut(0,function(){
					$( this ).parent().fadeOut(b);
				});
				var srcCSS = {
					left: src.offset().left,
					top: src.offset().top,
					width: src.outerWidth(),
					height: src.outerHeight(),
					opacity: config.effect.compareOpacity[0],
					borderWidth: config.effect.compareBorderWidth[0]
				}
				var dest = $( '> dt:first', config.compare.obj );
				var destCSS = {
					left: dest.offset().left,
					top: dest.offset().top + dest.outerHeight(),
					width: dest.outerWidth(),
					height: 1,
					opacity: config.effect.compareOpacity[1],
					borderWidth: config.effect.compareBorderWidth[1]
				}
				$( config.effect.compareOutlineObj + ':last' ).css( srcCSS ).fadeIn( config.effect.toggleSpeed, function(){
					$( this ).animate( destCSS, config.effect.moveSpeed, function(){
						setCompare( objID );
						$( this ).remove();
					});
				});
				return false;
			}
		});

		$( config.effect.toggleObj, config.general.unitObj ).each(function(){
			var toggle = $( this );
			var toggleID = toggle.closest( 'dl' ).attr( 'id' );
			if ( $( '#' + toggleID ).hasClass( config.effect.toggleClass ) ) {
				toggle.attr( 'title', config.effect.toggleOpenTitle );
			} else {
				toggle.attr( 'title', config.effect.toggleCloseTitle );
			}
		}).click(function(){
			var toggle = $( this );
			var toggleID = toggle.closest( 'dl' ).attr( 'id' );
			if ( $( '#' + toggleID ).hasClass( config.effect.toggleClass ) ) {
				toggle.attr( 'title', config.effect.toggleCloseTitle ).closest( config.general.unitObj ).removeClass( config.effect.toggleClass ).find( '>dd' ).slideDown( config.effect.toggleSpeed );
				$( '#' + toggleID ).find( '.loading' ).each( function(){
					switch( '#' + toggleID ) {
						case config.compare.obj:
							if ( getCompare() ) {
								var compareQuery = genQuery( config.compare.query, getCompare() );
								getShop( compareQuery, config.general.shopInfoAPI );
							}
							break;
						case config.history.obj:
							if ( getHistory() ) {
								var historyQuery = genQuery( config.history.query, getHistory() );
								getShop( historyQuery, config.general.shopInfoAPI );
							}
							break;
						case config.recommend.obj:
							if ( getHistory() ) {
								var recommendQuery = genQuery( config.recommend.query[0], getRecentHistory(), 1 );
								getShop( recommendQuery, config.general.recommendAPI );
							}
							break;
						default: break;
					}
				});
			} else {
				toggle.attr( 'title', config.effect.toggleOpenTitle ).closest( config.general.unitObj ).addClass( config.effect.toggleClass ).find( '>dd' ).slideUp( config.effect.toggleSpeed );
			}
			var toggles = [];
			toggles.push( config.compare.obj + ':' + boolChg( $( config.compare.obj ).hasClass( config.effect.toggleClass ) ) );
			toggles.push( config.history.obj + ':' + boolChg( $( config.history.obj ).hasClass( config.effect.toggleClass ) ) );
			toggles.push( config.recommend.obj + ':' + boolChg( $( config.recommend.obj ).hasClass( config.effect.toggleClass ) ) );
			$.cookie( config.general.cookieName, toggles, { expires: config.general.cookieExpire, path: '/', domain: '.gnavi.co.jp' } );
			return false;
		});
	}

	function getUserarea() {
		if ( !$.cookie( config.general.cookieName ) ) {
			$( '.sideUnit:not(#uaGenre)' ).addClass( config.effect.toggleClass ).find( '>dd' ).hide();
		} else {
			var arr = ( $.cookie( config.general.cookieName ).split( ',' ) );
			for ( var i = 0, max = arr.length; i < max; i++ ) {
				var tmp = arr[i].split( ':' );
				if ( Number(tmp[1]) === 0 ) {
					$( tmp[0] ).find( '>dd' ).show();
				} else {
					$( tmp[0] ).addClass( config.effect.toggleClass ).find( '>dd' ).hide();
				}
			}
		}
	}

	function txtLimit( str, max ) {
		return ( str.length > max ) ? ( str.substr( 0, max ) + '...' ) : str;
	}

	function boolChg( val ) {
		return ( ( val ) ? 1 : 0 );
	}

	function showMember() {
		$( config.my.nojsObj ).show();
		if ( $.cookie( config.my.cookieName ) ) {
			var GMemDisp = $.cookie( config.my.cookieName );
			var memberName = ( GMemDisp.split( '&' ) )[4].replace(/\+/g," ");
			memberName = UnescapeEUCJP( memberName );
			$( config.my.nameObj ).text( memberName );
			$( config.my.regObj ).hide();
			$( config.my.logObj ).addClass( 'logout' ).attr( 'href', config.my.logoutURI );
		}
		var locEuc = encodeURIComponent( config.general.loc );
		$( config.my.logObj ).attr( 'href', $( config.my.logObj ).attr( 'href' ) + locEuc );
	}

	function genQuery( objID, objArray, mode ) {
		if ( objArray ) {
			return ( objID + '=' + objArray.join( ',' ) );
		} else if ( mode ) {
			return objID;
		}
	}

	function getCompare() {
		if ( !$.cookie( config.compare.cookieName ) ) {
			return '';
		}
		var arr = ( $.cookie( config.compare.cookieName ).split( ',' ) );
		var shops = [];
		for ( var i = 0, max = arr.length; i < max; i++ ) {
			shops[i] = ( arr[i].split( ':' ) )[0];
		}
		return shops;
	}

	function delCompare( shopID ) {
		if ( !shopID ) {
			return false;
		}
		var nowCompare = getCompare();
		if ( $.inArray( shopID, nowCompare ) !== -1 ) {
			var newCompare = [];
			var newCompareShops = [];
			var compare = 0;
			$.map( nowCompare, function( obj, idx ) {
				objs = obj.split( ':' );
				if ( objs[0] != shopID ) {
					newCompare.push( objs[0] + ':' + compare );
					newCompareShops.push( objs[0] );
					compare++;
				}
			});
			if ( newCompareShops.length ) {
				if( $( config.effect.moreObj, config.compare.obj ).hasClass( 'nomore' ) ) {
					if ( newCompareShops.length  <= config.history.visibleMax ) {
						$( config.effect.moreObj, config.compare.obj ).hide();
					}
				} else {
					getShop( genQuery( config.compare.query, newCompareShops ), config.general.shopInfoAPI, 'del' );
					$( config.general.subObj, config.compare.obj ).show();
				}
			} else {
				showInit( config.compare );
			}
			$.cookie( config.compare.cookieName, newCompare, { expires: config.compare.cookieExpire, path: '/', domain: '.gnavi.co.jp' } );
			var o = $( 'a[href^=' + config.compare.uri + shopID  + ']' );
			o.removeClass( 'disable' ).attr( 'title', o.data( 'title' ) );
		}
		return false;
	}

	function setCompare( shopID ) {
		if ( !shopID ) {
			return false;
		}
		var nowCompare = getCompare();
		var newCompare = [];
		var newCompareShops = [];
		newCompare.push( shopID + ':0' );
		newCompareShops.push( shopID );
		var compare = 1;
		$.map( nowCompare, function( obj, idx ) {
			if ( compare < config.compare.cookieMax ) {
				objs = obj.split( ':' );
				if ( objs[0] != shopID ) {
					newCompare.push( objs[0] + ':' + compare );
					newCompareShops.push( objs[0] );
					compare++;
				}
			} else {
				return false;
			}
		});
		$.cookie( config.compare.cookieName, newCompare, { expires: config.compare.cookieExpire, path: '/', domain: '.gnavi.co.jp' } );
		if ( newCompareShops.length ) {
			getShop( genQuery( config.compare.query, newCompareShops ), config.general.shopInfoAPI, 'add' );
			$( config.general.subObj, config.compare.obj ).show();
		} else {
			showInit( config.compare );
		}
		return true;
	}

	function getHistory() {
		if ( !$.cookie( config.history.cookieName ) ) {
			return false;
		}
		var arr = ( $.cookie( config.history.cookieName ).split( ',' ) );
		var shops = [];
		for ( var i = 0, max = arr.length; i < max; i++ ) {
			shops[i] = ( arr[i].split( ':' ) )[0];
		}
		return shops;
	}

	function getRecentHistory() {
		return ( getHistory() ) ? getHistory().slice( 0, config.recommend.historyMax ) : '';
	}

	function delHistory( shopID ) {
		if ( !shopID ) {
			return false;
		}
		var nowHistory = getHistory();
		if ( $.inArray( shopID, nowHistory ) !== -1 ) {
			var newHistory = [];
			var newHistoryShops = [];
			var History = 0;
			$.map( nowHistory, function( obj, idx ) {
				objs = obj.split( ':' );
				if ( objs[0] != shopID ) {
					newHistory.push( objs[0] + ':' + History );
					newHistoryShops.push( objs[0] );
					History++;
				}
			});
			$.cookie( config.history.cookieName, newHistory, { expires: config.history.cookieExpire, path: '/', domain: '.gnavi.co.jp' } );
			if ( newHistoryShops.length ) {
				if( $( config.effect.moreObj, config.history.obj ).hasClass( 'nomore' ) ) {
					if ( newHistoryShops.length  <= config.history.visibleMax ) {
						$( config.effect.moreObj, config.history.obj ).hide();
					}
				} else {
					getShop( genQuery( config.history.query, newHistoryShops ), config.general.shopInfoAPI, 'del' );
					$( config.general.subObj, config.history.obj ).show();
				}
			} else {
				showInit( config.history );
			}
		}
		return false;
	}

	function showInit( targetObj ) {
		$( config.general.mainObj, targetObj.obj ).html( targetObj.msgXhtml );
		$( config.general.subObj, targetObj.obj ).hide();
	}

	function addLastClass() {
		$( config.history.obj ).each(function(){
			$( config.general.shopObj, this ).filter( '.last' ).removeClass( 'last' ).end().filter( ':visible:last' ).addClass( 'last' );
		});
	}

	function getShop( query, api, mode ) {
		var jsonQuery = ( $.isArray( query ) ) ? query.join( '&' ) : query;
		if ( ( ( query === '' ) || ( api === '' ) || ( api === undefined ) || ( query === undefined ) ) && ( api === config.general.shopInfoAPI ) ) {
			return false;
		}
		$.getJSON( api, 'callback=?&' + jsonQuery, function( json ) {
			$.each( json, function( key, val ) {
				if ( key.match( /^error$/ ) ) {
					queryObj = query.toString();
					if ( queryObj.match( /^compare/ ) ) {
						showInit( config.compare );
					} else if ( queryObj.match( /^history/ ) ) {
						showInit( config.history );
					} else if ( queryObj.match( /^recommend/ ) || queryObj.match( /^score/ ) || queryObj.match( /^rand/ )) {
						showInit( config.recommend );
					}
					return false;
				}
				var shopUnits = '';
				var shopCount = 0;
				switch( key ) {
					case config.compare.query:
						var obj = $( config.general.mainObj, config.compare.obj );
						$.each( val, function( keys, vals ) {
							if ( shopCount >= config.compare.displayMax ) {
								return false;
							};
							if ( vals.shopID && ( vals.shopID ).match( config.shop.formatID ) && ( $.inArray( Number( vals.shopStatus ), config.general.errorStatus ) === -1 ) ) {
								shopCount++;
								var shopUnit = config.compare.xhtml
								var jsonKey = config.general.jsonKey;
								for ( var i in jsonKey ) {
									var jsonVal = ( vals[ jsonKey[i] ] === undefined ) ? '' : vals[ jsonKey[i] ];
									if ( jsonKey[i] === 'shopName' ) {
										jsonVal = txtLimit( jsonVal, config.shop.nameLenMax );
									}
									var myReg = new RegExp( '\\$' + jsonKey[i] + '\\$', 'gi' );
									shopUnit = shopUnit.replace( myReg, jsonVal );
									if ( jsonKey[i] === 'shopStatus' ) {
										shopUnit = shopUnit.replace( /\$shopSC\$/g, config.catalyst.fixCode + ':' + config.catalyst.code.compare + ':' + vals.shopStatus + ':' + vals.shopID );
									}
									if ( jsonKey[i] === 'shopURL' ) {
										var shopImgData = ( $.inArray( Number( vals.shopStatus ), config.general.imgExistStatus ) !== -1 ) ? config.shop.imgPath + vals.shopID + config.shop.imgTail : 0;
										var shopImg = ( shopImgData ) ? ( jsonVal + shopImgData ) : config.shop.noimgURI;
										var shopImgObj = shopImg.toString();
										if (! shopImgObj.match( /^http:\/\/r.gnavi.co.jp/ )) {
											shopImg = config.shop.noimgURI;
										}
										shopImg = shopImg.replace( '/r.gnavi.co.jp', '/r.gnst.jp' );
										shopUnit = shopUnit.replace( /\$shopImg\$/g, shopImg );
									}
								}
								shopUnits += shopUnit;
							}
						});
						if ( shopCount && ( mode === 'add' ) ) {
							if ( shopCount === 1 ) {
								obj.html( shopUnits ).hide().fadeIn();
							} else {
								obj.html( shopUnits ).find( 'dl' ).hide().filter( ':not(:first)' ).show().siblings( ':first' ).fadeIn();
							}
						} else {
							obj.html( shopUnits );
						}
						if ( shopCount > config.compare.visibleMax ) {
							if( ! $( config.effect.moreObj, config.compare.obj ).hasClass( 'nomore' ) ) {
								obj.find( 'dl:gt(' + ( config.compare.visibleMax - 1 ) + ')' ).hide().end().next().find( config.effect.moreObj ).show();
							}
						} else if (shopCount === 0 ) {
							showInit( config.compare );
						} else {
							obj.next().find( config.effect.moreObj ).hide();
						}
						break;
					case config.history.query:
						var obj = $( config.general.mainObj, config.history.obj );
						$.each( val, function( keys, vals ) {
							if ( shopCount >= config.history.displayMax ) {
								return false;
							};
							if ( vals.shopID && ( vals.shopID ).match( config.shop.formatID ) && ( $.inArray( Number( vals.shopStatus ), config.general.errorStatus ) === -1 ) ) {
								shopCount++;
								var shopUnit = config.history.xhtml;
								var shopImgData = '';
								var jsonKey = config.general.jsonKey;
								for ( var i in jsonKey ) {
									var jsonVal = ( vals[ jsonKey[i] ] === undefined ) ? '' : vals[ jsonKey[i] ];
									if ( jsonKey[i] == 'shopName' ) {
										jsonVal = txtLimit( jsonVal, config.shop.nameLenMax );
									}
									if ( jsonKey[i] == 'shopStatus' ) {
										shopUnit = shopUnit.replace( /\$shopSC\$/g, config.catalyst.fixCode + ':' + config.catalyst.code.history + ':' + vals.shopStatus + ':' + vals.shopID );
									}
									var myReg = new RegExp( '\\$' + jsonKey[i] + '\\$', 'gi' );
									shopUnit = shopUnit.replace( myReg, jsonVal );
								}
								shopUnits += shopUnit;
							}
						});
						obj.html( shopUnits );
						if ( shopCount > config.history.visibleMax ) {
							obj.find( 'dl:gt(' + ( config.history.visibleMax - 1 ) + ')' ).hide().end().next().find( config.effect.moreObj ).show();
						} else if (shopCount === 0 ) {
							showInit( config.history );
						} else {
							obj.next().find( config.effect.moreObj ).hide();
						}
						break;
					case config.recommend.query[0]:
					case config.recommend.query[1]:
						var obj = $( config.general.mainObj, config.recommend.obj );
						$.each( val, function( keys, vals ) {
							if ( shopCount >= config.recommend.displayMax ) {
								return false;
							};
							if ( vals.shopID && ( vals.shopID ).match( config.shop.formatID ) ) {
								shopCount++;
								if ( shopCount === 1 ) {
									var shopUnit = config.recommend.msgFstXhtml;
									shopUnit += config.recommend.xhtml;
								} else {
									var shopUnit = config.recommend.xhtml;
								}
								var jsonKey = config.general.jsonKey;
								for ( var i in jsonKey ) {
									var jsonVal = ( vals[ jsonKey[i] ] === undefined ) ? '' : vals[ jsonKey[i] ];
									var myReg = new RegExp( '\\$' + jsonKey[i] + '\\$', 'gi' );
									if ( jsonKey[i] == 'shopName' ) {
										jsonVal = txtLimit( jsonVal, config.shop.nameLenMax );
									}
									shopUnit = shopUnit.replace( myReg, jsonVal );
									if ( jsonKey[i] === 'shopStatus' ) {
										shopUnit = shopUnit.replace( /\$shopSC\$/g, config.catalyst.fixCode + ':' + config.catalyst.code.recommend + ':' + vals.shopStatus + ':' + vals.shopID );
									}
									if ( jsonKey[i] == 'shopURL' ) {
										var shopImgData = ( $.inArray( Number( vals.shopStatus ), config.general.imgExistStatus ) !== -1 ) ? config.shop.imgPath + vals.shopID + config.shop.imgTail : 0;
										var shopImg = ( shopImgData ) ? ( jsonVal + shopImgData ) : config.shop.noimgURI;
										shopImg = shopImg.replace( '/r.gnavi.co.jp', '/r.gnst.jp' );
										shopUnit = shopUnit.replace( /\$shopImg\$/g, shopImg );
									}
								}
								shopUnits += shopUnit;
							}
						});
						if ( shopCount && ( mode === 'refresh' ) ) {
							obj.html( shopUnits ).hide().fadeIn();
						} else if (shopCount === 0 ) {
							showInit( config.recommend );
						} else {
							obj.html( shopUnits );
						}
						break;
					default:
						break;
				};
			});

			$( config.effect.moreObj, config.general.obj ).live( 'click', function(){
				var more = $( this );
				more.toggleClass( 'nomore' );
				var moreID = '#' + more.closest( 'dl' ).attr( 'id' );
				if ( $( more ).hasClass( 'nomore' ) ) {
					$( '> dd:first > div:first', moreID ).find( 'dl:not(:visible)' ).show();
				} else {
					var objMax = ( moreID === config.history.obj ) ? config.history.visibleMax : ( moreID === config.compare.obj ) ? config.compare.visibleMax : 0;
				if ( objMax ) {
						$( '> dd:first > div:first', moreID ).find( 'dl:gt(' + ( objMax - 1 ) + ')' ).hide();
					}
				}
				addLastClass();
				return false;
			});

			$( config.general.delObj, config.general.shopObj ).live( 'click', function(){
				var obj = $( this );
				var delInfo = ( ( obj.attr( 'href' ) ).split( '#' ) )[1].split( '=' );
				if ( delInfo[0] === config.compare.query ) {
					delCompare( delInfo[1] );
				} else if ( delInfo[0] === config.history.query ) {
					delHistory( delInfo[1] );
				}
				obj.closest( config.general.shopObj ).fadeOut( config.effect.fadeSpeed );
				addLastClass();
				return false;
			});

			$( config.recommend.refObj, config.general.unitObj ).live( 'click', function(){
				var recommendQuery = genQuery( config.recommend.query[1], getRecentHistory(), 1 );
				getShop( recommendQuery, config.general.recommendAPI, 'refresh' );
				return false;
			});

			if ( config.catalyst.exist ) {
				$( '[class^=' + config.catalyst.fixCode + ']', config.general.unitObj ).live( 'click', function(){
					trackAjaxName( $( this ).attr( 'class' ) );
				});
			}

			addLastClass();
		});
	}

	function trackAjaxName(sc_menu) {
		s.linkTrackVars = "prop5";
		s.prop5 = sc_menu;
		s.tl( this, "o", sc_menu );
	}

	s.clickOsusume = function() {
 		s.linkTrackVars = 'events';
  		s.linkTrackEvents = 'event39';
  		s.events = s.apl(s.events, 'event39', ',', 2);
  		s.tl(true, 'o', 'Osusume');
	};
	$('.mr').live('click', s.clickOsusume);
	if(s.prop53){
		if(s.un && !(s.un.match(/gnavi2011smartphone/))){
			s.un = "gnavi2011smartphone," + s.un;
		}
	}

	// 3RD PARTY OBJECT
	$( 'body#top' ).each(function(){
		// Search Force
		sf_cookie_name='sf_conv_info3';
		var jValue = '1';
		var jOrderID = rc.id();
		var jconversion_type = 'pageview';
		var jvar1='';
		var jvar2='';
		var jvar3='';
		var jprotocol = 'http';
		if(location.protocol == 'https:'){jprotocol = 'https';}
		ImageJSConversionProcess(jconversion_type, jValue, jOrderID, jvar1, jvar2, jvar3);
	});

	// CHOTTOGU REGIST
	if(location.protocol != 'https:'){
		var chottogu_regist = {
			 code: { 'edm_rest': 1, 'kuchikomi': 2, 'menu_vote': 3, 'social_bookmark': 4, 'others': null }
			,exec: function (shopid, content) {
				if (content) {
					params = {shopid: shopid, content: content}
				} else {
					params = {shopid: shopid}
				}
				var api_url = "";
				var chottogu_regist_url = $("#chotto li.gu a").attr("href");
				if (chottogu_regist_url) { api_url = chottogu_regist_url.replace(/^(.*restaurant).*$/, "$1/api/tsuide/regist.php"); }
				if (api_url.length > 0) {
					jQuery.getJSON(api_url+"?callback=?", params);
				}
			}
		};
		$("#chotto .mr a").click(function() {
			chottogu_regist.exec(rc.id(), chottogu_regist.code.menu_vote);
		});
		$("#shoptoolSB a").click(function() {
			chottogu_regist.exec(rc.id(), chottogu_regist.code.social_bookmark);
		});
	}

	// Heavy user campaign on right side.
	if( typeof dhuc == 'number' && dhuc == 1 ) { // force to hide if dhuc=0 declared on p.js
		var hucset = {
			type: '',
			path: '/',
			yourHost: '.gnavi.co.jp',
			expiresAt: new Date(),
			cname: 'huclimit',
			swfpath: '/c/r/hucswf.swf?111110',
			ref1: 'https://my.gnavi.co.jp/al/contents/regist/?cType=huc&sid=' + rc.id() + '&rUrl=http%3a%2f%2fpoint%2egnavi%2eco%2ejp%2fr%2fhuc%2ffinish%2ephp%3fsid%3d' + rc.id() + '&rType=2',
			ref2: 'http://my.gnavi.co.jp/point/gnpoint.php',
			src: 'http://img-www.gnavi.co.jp/img/lib/huc/huc110801.gif',
			api: 'http://point.gnavi.co.jp/r/huc/ilp.php'
		}
		if( rc.debug() ) {
			hucset.ref1 = hucset.ref1.split( 'https://my.' ).join( 'https://test-my.' );
			hucset.api = hucset.api.split( 'http://point.' ).join( 'http://test-point.' );
		}
		if( ( $.cookie( hucset.cname ) != 'showed' && $( 'body' ).attr( 'id' ) == 'top' ) ) {
			function thu( str, ref ) {
				s.un = "gnavi2010flash,gnavi2008homeglobal";
				s.linkTrackVars = "prop5,eVar5,prop55,eVar55";
				s.prop5 = str;
				s.eVar5 = str;
				s.eVar55 = s.pageName;
				s.prop55 = s.pageName;
				s.tl( this, "o", str );
			}
			function showfixedobj() {
				thu( 'hevyUserOnR' ); // throw request for site-catalyst
				$( '#sidebar' ).prepend( '<div id="huchere" style="height:250px; width: 170px; "></div>' );
				var writtenok = false;
				if( deconcept.SWFObjectUtil.getPlayerVersion().major != '0' ) {
					var so = new SWFObject( hucset.swfpath, 'huchereswf', '170', '240', '9', '#ffffff' );
					so.addParam( 'wmode', 'transparent' );
					so.addParam( 'allowScriptAccess', 'always' );
					so.addVariable( 'buttonUri', escape( hucset.ref1 ) );
					so.addVariable( 'textUri', escape( hucset.ref2 ) );
					writtenok = so.write( 'huchere' );
				}
				if( writtenok ) { // swf have written without any probrem
					$( '#huchere' ).hide().slideDown( 512, function(){} );
					$( '<a href="#" id="huchereA">&nbsp;</a><a href="#" id="huchereB">&nbsp;</a>' ).insertAfter( '#huchere' );
					$( '#huchereA, #huchereB' ).hide().live( 'click', function() {
						if( $( this ).attr( 'id' ) == 'huchereA' ) thu( 'hevyUserOnRClick1', 'ref1' ); // click button
						else thu( 'hevyUserOnRClick2', 'ref2' ); // click text
						return false;
					});
				}
			}
			var gh =  $.cookie( 'GHistory' );
			var ghlen = 0;
			if( gh ) ghlen = gh.split( ',' ).length;
			if ( !$.cookie( 'GMember' ) && !$.cookie( 'GHuc' ) && ghlen >= 3 ) {
				$.getJSON( hucset.api + '?callback=?', {}, function( data ) {
					if( data.huc == '1' ) showfixedobj();
				});
			}
			hucset.expiresAt = new Date( hucset.expiresAt.getFullYear(), hucset.expiresAt.getMonth(), hucset.expiresAt.getDate() );
			hucset.expiresAt.setDate( hucset.expiresAt.getDate() + 1 );
			$.cookie( hucset.cname, 'showed', { domain: hucset.yourHost, expires: hucset.expiresAt, path: hucset.path } );
		}
	}
});

// Heavy user campaign on right side, triggered from swf
function trackFromSwf( str ) {
	if( str == 'button' ) jQuery( '#huchereA' ).trigger( 'click' ); // click button
	else if( str == 'text' ) jQuery( '#huchereB' ).trigger( 'click' ); // click text
}


