dispatcher('(?:)', function () {
	// ログイン確認機能 
	var ready_dispatcher = dispatcher;
	ready_dispatcher.clear_funcs();
	var data;
	$(function () {
		load_CrossDomainXMLHttpRequest();
		// クロスドメイン通信 
		var req = new CrossDomainXMLHttpRequest();
		req.open('GET', 'https://kawatsuku.com/api/member/statuses', true);
		req.setRequestHeader('content-type', 'application/x-www-form-urlencoded; charset=UTF-8');
		req.onreadystatechange = function() {
			if (req.readyState != 4) return;
			var data = req.responseText;
			eval(data);
			// ログイン状態に合わせたswf出力 
			if (!data) data = { 'point_status' : {} };
			var flashvars = {
				'api_url' : 'https://kawatsuku.com/api/point/add',
				'button_id' : (location.href || '').replace(/index.html$/, '').replace(/#.+/, '').replace(/\W/g, '')
			};
			var params = {wmode: "transparent"};
			var attributes = {};
			// button idの生成 
			var swfid = 1;
			function write_swf () {
				flashvars.button_id = $('#swfKyunBtnAlternative input:hidden').val() || flashvars.button_id + '__' + (swfid++);
				var swf_path = ({
					'200' : '/kawatsuku/swf/src/kyunbutton/loginenabled.swf',
					'403' : '/kawatsuku/swf/src/kyunbutton/notlogin.swf',
					'409' : '/kawatsuku/swf/src/kyunbutton/logindisabled.swf'
				})[data.point_status[flashvars.button_id] || '200'];
				swfobject.embedSWF(swf_path, "swfKyunBtnAlternative", "140", "140", "9.0.0", "/kawatsuku/swf/src/expressInstall.swf", flashvars, params, attributes);
			};
			ready_dispatcher('^/kawatsuku/tvcm/cm/', write_swf);
			ready_dispatcher('^/kawatsuku/tvcm/hairmake/', write_swf);
			ready_dispatcher('^/kawatsuku/hairmake/', write_swf);
			ready_dispatcher('^/kawatsuku/tvcm/rooms/vh', write_swf);
			ready_dispatcher('^/kawatsuku/tvcm/rooms/sn', write_swf);
			ready_dispatcher('^/kawatsuku/tvcm/rooms/yy', write_swf);
			ready_dispatcher('^/kawatsuku/tvcm/beauty/vh', write_swf);
			ready_dispatcher('^/kawatsuku/tvcm/beauty/sn', write_swf);
			ready_dispatcher('^/kawatsuku/tvcm/beauty/yy', write_swf);
			ready_dispatcher('^/kawatsuku/essential/check/01', write_swf);
			ready_dispatcher('^/kawatsuku/essential/check/02', write_swf);
			ready_dispatcher('^/kawatsuku/essential/check/03', write_swf);
			ready_dispatcher(location.pathname);
			// ユーザログイン認証の確認 
			if (data.user) {
				$('#navUtility li:last').html('<a href="/kawatsuku/members/">カワつく団のご紹介</a> &nbsp;&nbsp;ようこそ <a href="https://kawatsuku.com/pc/member/index">' + data.user.nickname + '</a> さん');
				$('#navUtility li').not(':last').filter(':last').remove();
				return;
			};

			$('#navUtility li:last a').click(function () {
				jquery_cookie('redirect_path', location.pathname, { path: '/' });
			});
		};
		req.send('');
	});

	dispatcher('^/kawatsuku/fashion/', function () { $(function () {
		$('#navContents, #footerLocal').find('.link li').hover(function () {
			var self = $(this);
			var idx = self.parent().find('li').map(function (i) {
				return self.filter(this).length ? i : undefined;
			}).get(0);
			var li = self.closest('dl').find('.img li');
			if (li.eq(idx).not(':hidden').length) return;
			li.removeClass('show').eq(idx).addClass('show');
		}, function () {
			$(this).closest('dl').find('.img li').removeClass('show').eq(0).addClass('show');
		});
	}); });

	// slideDown menu 
	$(function () {
    //added gnav elements.
    var gnavEle = {};
    gnavEle.URL = '/kawatsuku/navElement.html';
    gnavEle.suffix = '-content';
    //list of global navigation item.
    gnavEle.navList = [
      'gnav-essential',
      'gnav-fashion',
      'gnav-cm',
      'gnav-present'
    ];
    $.get(gnavEle.URL, function(data) {
      for( var i=0; i<gnavEle.navList.length; i++ ) {
        gnavEle[gnavEle.navList[i]+gnavEle.suffix] = $(data).find('#' + gnavEle.navList[i]+gnavEle.suffix);
        $('#' + gnavEle.navList[i] + ' div').append(gnavEle[gnavEle.navList[i]+gnavEle.suffix]);
      }
      $('#navGlobal .bg img').meca('pngfix');
      $('#navGlobal .links .btn').meca('hover');
    });

		var cname = (function () {
			if (!location.pathname.match(/^\/kawatsuku\/(index.html)?$/)) return;
			if ($(window).height() > 670) return;
			return '.gnavContent';
		})() || '.gnavContent';

		$('#navGlobal li>div').hover(function () {
			var self = $(this);
			var gnav = self.children(cname);
			//self.css('z-index', '1000').width(self.find('img:first').width()).height(gnav.find('.bg img').attr('height'));
			self.css('z-index', '1000');
			gnav.stop().hide().slideDown(300);
			gnav.mouseleave(mouseleave);
		}, mouseleave);
		function mouseleave () {
			var self = $(this);
			var gnav = self.children(cname);
			gnav.unbind('mouseleave');
			gnav.stop().slideUp(200, function () {
				gnav.attr('style', '');
				self.removeAttr('height').css('height', '');
			});
		};
	});

	// footer div 
	$(function () {
		$('#container~div:first').addClass('MicroSiteFoot');
	});
});

/*
 * 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
 *
 * modified from @kyo_ago
 *
 */
window.jquery_cookie=function(d,e,b){if(arguments.length>1&&(e===null||typeof e!=="object")){b=b||{};if(e===null){b.expires=-1}if(typeof b.expires==="number"){var g=b.expires,c=b.expires=new Date();c.setDate(c.getDate()+g)}return(document.cookie=[encodeURIComponent(d),"=",b.raw?String(e):encodeURIComponent(String(e)),b.expires?"; expires="+b.expires.toUTCString():"",b.path?"; path="+b.path:"",b.domain?"; domain="+b.domain:"",b.secure?"; secure":""].join(""))}b=e||{};var a,f=b.raw?function(h){return h}:decodeURIComponent;return(a=new RegExp("(?:^|; )"+encodeURIComponent(d)+"=([^;]*)").exec(document.cookie))?f(a[1]):null};

// thanks from http://d.hatena.ne.jp/holidays-l/20070718/p1
function load_CrossDomainXMLHttpRequest () {
(function(){var a=setInterval(function(){if(document.body){clearInterval(a);var c=document.createElement("div");c.style.position="absolute";document.body.appendChild(c);var b={swf:"/kawatsuku/js/CrossDomainXMLHttpRequest.swf",id:"externalCrossDomainXMLHttpRequest",flashvars:"nocache="+(new Date()).getTime()};if(navigator.plugins&&navigator.mimeTypes&&navigator.mimeTypes.length){c.innerHTML='<embed type="application/x-shockwave-flash" name="$id" quality="low" flashvars="$flashvars" src="$swf" id="$id" width="0" height="0" style="position:absolute" />'.replace(/\$(\w+)/g,function(e,d){return b[d]})}else{c.innerHTML='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="$id" width="0" height="0" style="position:absolute"><param name="movie" value="$swf" /><param name="quality" value="low" /><param name="flashvars" value="$flashvars" /></object>'.replace(/\$(\w+)/g,function(e,d){return b[d]})}}},100)})();function CrossDomainXMLHttpRequest(){this.CrossDomainXMLHttpRequest.apply(this,arguments)}CrossDomainXMLHttpRequest.proxy=null;CrossDomainXMLHttpRequest.id=0;CrossDomainXMLHttpRequest.instance={};CrossDomainXMLHttpRequest.addPolicyFile=function(a){CrossDomainXMLHttpRequest.addPolicyFile.policyFiles.push(a)};CrossDomainXMLHttpRequest.addPolicyFile.policyFiles=[];CrossDomainXMLHttpRequest.prototype={id:null,method:null,uri:null,async:false,requestHeaders:{},data:null,onreadystatechange:null,readyState:0,responseText:null,status:0,statusText:"",open:function(c,b,a){this.method=c;this.uri=b;this.async=a;this.callback(1)},setRequestHeader:function(b,a){b=b.toLowerCase().replace(/(^|[^a-z])([a-z])/g,function(d,c,e){return c+e.toUpperCase()});this.requestHeaders[b]=a},overrideMimeType:function(){throw"NOT_IMPLEMENTED_YET"},send:function(b){var a=this;var c=setInterval(function(){CrossDomainXMLHttpRequest.proxy=(function(){var e=["object","embed"];for(var g=0;g<e.length;++g){var h=document.getElementsByTagName(e[g]);for(var f=0;f<h.length;++f){if(typeof h[f].addPolicyFile!="undefined"){return h[f]}}}return null})();if(CrossDomainXMLHttpRequest.proxy){clearInterval(c);for(var d=0;d<CrossDomainXMLHttpRequest.addPolicyFile.policyFiles.length;++d){CrossDomainXMLHttpRequest.proxy.addPolicyFile(CrossDomainXMLHttpRequest.addPolicyFile.policyFiles[d])}CrossDomainXMLHttpRequest.addPolicyFile=function(e){CrossDomainXMLHttpRequest.proxy.addPolicyFile(e)};CrossDomainXMLHttpRequest.prototype.send=function(e){this.data=e;CrossDomainXMLHttpRequest.proxy.request("CrossDomainXMLHttpRequest.instance."+this.id+".callback",this.method,this.uri,this.async,this.data,{headers:this.requestHeaders});this.callback(2)};a.send=CrossDomainXMLHttpRequest.prototype.send;a.send(b)}},100)},abort:function(){},callback:function(a){this.readyState=a;if(arguments.length==2){var b=arguments[1];if(typeof b.status!="undefined"){this.status=b.status}if(typeof b.responseText!="undefined"){this.responseText=b.responseText}}if(this.onreadystatechange){this.onreadystatechange()}if(this.readyState==4){delete CrossDomainXMLHttpRequest.instance[this.id]}},getAllResponseHeaders:function(){throw"NOT_IMPLEMENTED_YET"},getResponseHeader:function(a){throw"NOT_IMPLEMENTED_YET"},CrossDomainXMLHttpRequest:function(){this.id="id"+CrossDomainXMLHttpRequest.id++;CrossDomainXMLHttpRequest.instance[this.id]=this}};
window.CrossDomainXMLHttpRequest = CrossDomainXMLHttpRequest;
};

function dispatcher (path, func) {
	dispatcher.path_func = dispatcher.path_func || []
	if (func) return dispatcher.path_func.push([path, func]);
	for(var i = 0, l = dispatcher.path_func.length; i < l; ++i) {
		var func = dispatcher.path_func[i];
		var match = path.match(func[0]);
		match && func[1](match);
	};
};
dispatcher.clear_funcs = function () {
	dispatcher.path_func = [];
};
dispatcher(location.pathname);

