$().ready(function(){
	smartRollover();
	if(navigator.userAgent.indexOf("Safari") != -1 && navigator.userAgent.indexOf("Chrome") == -1) $("body").css("font-size", "11px");
	$("<img />").attr("src","item/images/basemake/kit_img.png");

	// clorbox
	if($(".cb_close").size()>0) $(".cb_close").click(function(){ parent.$.fn.colorbox.close();});
	var cl_obj;
	var cl_h;
	var cl_w;
	if($(".movie_link").size()>0)
	{
		cl_obj = $(".movie_link a");
		cl_w = 630;
		cl_h = 480;
	}
	if($(".howto_bn").size() > 0) 
	{
		cl_obj = $(".howto_bn a");
		cl_w = 680;
		cl_h = 480;
	}
	if($(".teq_bn").size() > 0)
	{
		cl_obj = $(".teq_bn a");
		cl_w = 680;
		cl_h = 480;
	}
	if($(".foundation_kit").size() > 0)
	{
		cl_obj = $(".foundation_kit a");
		cl_w = 883;
		cl_h = 652;
	}
	if(cl_obj)
	{
		cl_obj.colorbox({innerWidth:cl_w, innerHeight:cl_h, iframe:true, overlayClose:false, opacity: 0.9});
		var param = getRequest();
		if(param && param['frame'] && param['frame'].match(".html"))
			$.colorbox({innerWidth:cl_w, innerHeight:cl_h, iframe:true, overlayClose:false, opacity: 0.9, href:param['frame']});
	}
});

/*cf*/
var docURL=document.URL;

if(location.pathname.search("/cf/movie/") != -1)
{
	var host = new RegExp(location.hostname+"\/cf\/", "i");
	if(!document.referrer.match(host)) location.href="/cf/?frame="+docURL;
}
/*item*/
if(location.pathname.search("/item/movie/") != -1)
{
	var a_path = location.pathname.split("/");
	var file = a_path[a_path.length-1].replace("-mv01","");
	if(docURL.match(/base|foundation|concealer|facepowder/))
	{
		file = "basemake_"+file;
	}
	var host = new RegExp(location.hostname+"\/item\/", "i");
	if(!document.referrer.match(host)) location.href="/item/"+file+"?frame="+docURL;
}
/*kit*/
if(docURL.search("/item/basemake_foundation_kit.html") != -1 && docURL.search("frame") == -1)
{
	var host = new RegExp(location.hostname, "i");
	if(!document.referrer.match(host)) location.href="/?frame=/item/basemake_foundation_kit.html";
}

function setTwDataText(){
	var tw_txt = $("#og_title").attr("content").replace("｜ESPRIQUE"," #ESPRIQUE");
	$(".twitter-share-button").attr("data-text",tw_txt);
}

function getRequest(){
	if(location.search.length > 1) {
		var get = new Object();
		var ret = location.search.substr(1).split("&");
		for(var i = 0; i < ret.length; i++) {
			var r = ret[i].split("=");
			get[r[0]] = r[1];
		}
		return get;
	} else {
		return false;
	}
}

function smartRollover() {
	if(typeof document.documentElement.style.maxHeight != "undefined")
	{
		$("img, input").each(function (){
			if($(this).attr("src"))
			{
				if($(this).attr("src").match("_default."))
				{
					$('<img/>').attr( 'src', $(this).attr("src").replace("_default.", "_over.") );

					$(this).mouseover(
						function() {
							$(this).attr("src", $(this).attr("src").replace("_default.", "_over."));
						}
					);
					$(this).mouseout(
						function() {
							$(this).attr("src", $(this).attr("src").replace("_over.", "_default."));
						}
					);
				}
			}
		});
	}
	else
	{
		$("img, input").each(function()
		{
			if($(this).attr("src").match("_default.png"))
			{
				$(this)
				.data("src",$(this).attr("src"))
				.attr("src","/common/images/blank.gif")
				.css("filter","progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+$(this).data("src")+"',sizingMethod='scale')");
				$('<img/>').attr( 'src', $(this).data("src").replace("_default.", "_over.") );
				$(this).mouseover(
					function() {
						$(this).css("filter","progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+$(this).data("src").replace("_default.", "_over.")+"',sizingMethod='scale')")
					}
				);
				$(this).mouseout(
					function() {
						$(this).css("filter","progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+$(this).data("src")+"',sizingMethod='scale')")
					}
				);
			}
			else if($(this).attr("src").match("_default."))
			{
				$('<img/>').attr( 'src', $(this).attr("src").replace("_default.", "_over.") );

				$(this).mouseover(
					function() {
						$(this).attr("src", $(this).attr("src").replace("_default.", "_over."));
					}
				);
				$(this).mouseout(
					function() {
						$(this).attr("src", $(this).attr("src").replace("_over.", "_default."));
					}
				);
			}
			else if($(this).attr("src").match(".png"))
			{
				$(this)
				.data("src",$(this).attr("src"))
				.attr("src","/common/images/blank.gif")
				.css("filter","progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+$(this).data("src")+"',sizingMethod='scale')");
			}
		});
	}
}


/*
 * Google Analytics
 */
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-22119728-1']);
_gaq.push(['_trackPageview']);

(function() {
  var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
  ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
  var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();


