﻿// ポップアップウィンドウ用のインターバルIDs
var windowTimer;

// ドキュメント
var doc=document;

// モニタの表示色を取得
var cbit=32;
try{cbit=screen.colorDepth;}catch(err){}

// デバイス判別
$.browser.android=/android/.test(navigator.userAgent.toLowerCase());
$.browser.iphone=/iphone/.test(navigator.userAgent.toLowerCase());
$.browser.ipad=/ipad/.test(navigator.userAgent.toLowerCase());
$.browser.ipod=/ipod/.test(navigator.userAgent.toLowerCase());
$.browser.iOS=($.browser.ipod||$.browser.ipad||$.browser.iphone)?true:false;

// スマフォ判定
var smp=($.browser.android||$.browser.iOS);

// Flashバージョン
var version="120201";


// ****************************************************************
//   
//   実行処理
//   
// ****************************************************************
// URLからブランド名を取得
var loc=String(doc.location).replace(/\#.*?$/,"");
var locr=loc.replace(/\?.*?$/,"");
var dir_arr=locr.split("/");
var brand_name=dir_arr.pop().replace(/\.html$/,"");
if(brand_name=='')brand_name='birkenstock';

// ハッシュ取得
var hash=(doc.location.hash).substr(1);
var q=$.getQueryParams(hash);

// --- 各ブランドFlashの設定
var brand_swf_data={
	'birkenstock':{w:750,h:330},
	'papillio':{w:750,h:330},
	'birkis':{w:750,h:330},
	'footprints':{w:750,h:330},
	'alpro':{w:750,h:330}
};

if(brand_swf_data[brand_name]){
	var bdata=brand_swf_data[brand_name];
	var bw=bdata['w'];
	var bh=bdata['h'];
	var bswf="/brand/"+brand_name+"/index.swf?v="+version;
	var bf={colorDepth:cbit};
	var bp={menu:'false',wmode:'transparent',quality:'autolow'};
	//var bp={menu:'false',wmode:'opaque',bgColor:'#FFFFFF',quality:'autolow'};
	//if(cbit<=16)bp.bgColor='#FFFFFF';
	swfobject.embedSWF(bswf,"brand_swf",bw,bh,"9.0.115","/swf/expressInstall.swf",bf,bp,null);
}
$(function(){
	// 商品コンテンツを補完
	var product_src=$('#product_content').html();
	
	// --- BRAND NAVI > ALL
	$('ul.brand_navi a[rel!=]').click(function(){
		$('ul.brand_navi > li > a').removeClass('active');
		$(this).addClass('active');
		
		// URLにハッシュを追加
		var rel=$(this).attr('rel');
		//if(rel=='products')rel='';
		if(document.location.hash!=rel)document.location.hash=rel;
		
		// popup のバインドを外す
		$("#product_content a[rel=popup]").unbind("click");
		return false;
	});
	
	// --- BRAND NAVI > PRODUCTS
	$('ul.brand_navi a[rel=products]').click(function(){
		if(smp){
			// スマートフォンページにリダイレクト
			if(brand_name=='birkenstock'||brand_name=='papillio'||brand_name=='birkis'||brand_name=='footprints'||brand_name=='alpro'){
				document.location.href='/smp/brand.php?b='+brand_name;
			}
			return false;
		}
		
		if(product_src!=$('#product_content').html()){
			$('#product_content').html(product_src);
		}
		
		// --- ENTRY MODEL
		$('#product_content a[rel=popup]').bind("click",function(){
			windowOpen(this.href);
			return false;
		});
		
		$('#product_content').css({"height":"auto"});
		createSWFContent("/products/itemlist.swf?v="+version,750,350,brand_name,"/products/");
		return false;
	});
	
	// --- BRAND NAVI > FOOT HEALTH
	$('ul.brand_navi a[rel=foot-health]').click(function(){
		var h=1160;
		var d=$('<div>').css({"background-image":"url(/brand/birkenstock/foot-health.jpg)","width":750,"height":h});
		$('#product_content').css({"height":h});
		$('#product_content').html(d);
		return false;
	});
	
	// --- BRAND NAVI > FUNCTION
	$('ul.brand_navi a[rel=function]').click(function(){
		var h=2560;
		$('#product_content').css({"height":h});
		$('#product_content').html('<div id="swfcontent">');
		createSWFContent("/brand/birkenstock/function.swf?v="+version,750,h,"/brand/");
		return false;
	});
	
	// --- BRAND NAVI > HOW TO FIT
	$('ul.brand_navi a[rel=how-to-fit]').click(function(){
		var h=567;
		var d=$('<div>').css({"background-image":"url(/brand/birkenstock/how-to-fit.gif)","width":750,"height":h});
		$('#product_content').css({"height":h});
		$('#product_content').html(d);
		return false;
	});
	
	// --- BRAND NAVI > SIZE ChART
	$('ul.brand_navi a[rel=size-chart]').click(function(){
		//var h=480;
		//if(brand_name=='papillio')h=411;
		//else if(brand_name=='birkis')h=480;
		//else if(brand_name=='footprints')h=513;
		//else if(brand_name=='alpro')h=411;
		var d=$('<div class="sizechart_'+brand_name+'">').css({"background-image":"url(/brand/"+brand_name+"/size-chart.gif)"});
		//var d=$('<div ="sizechart_'+brand_name+'">').css({"background-image":"url(/brand/"+brand_name+"/size-chart.gif)","width":750,"height":h});
		$('#product_content').css({"height":"auto"});
		//$('#product_content').css({"height":d.height()});
		$('#product_content').html(d);
		return false;
	});
	
	// --- BRAND NAVI > NAME OF EACH PART
	$('ul.brand_navi a[rel=name-of-each-part]').click(function(){
		var h=900;
		var d=$('<div>').css({"background-image":"url(/brand/footprints/name-of-each-part.jpg)","width":750,"height":900});
		$('#product_content').css({"height":h});
		$('#product_content').html(d);
		return false;
	});
	
	// --- 商品詳細
	$('a[rel^=detail]').click(function(){
		$("#java_content").css({"visibility":"hidden"});
		var tmp=($(this).attr("rel")).split("_");
		var code=tmp[1];
		var group=tmp[2]||"ba";
		openProductDetail(code,group,function(){
			$("#java_content").css({"visibility":"visible"});
		});
		return false;
	});
	
	// --- BRAND NAVI > デフォルト表示
	if(hash=='')hash='products';
	var target=$('ul.brand_navi a[rel='+hash+']');
	if($(target).length){
		$(target).click();
	}else if($('ul.brand_navi li:first-child a').length){
		$('ul.brand_navi li:first-child a').click();
	}else if($('#swfcontent').length){
		// BIRKO対応
		var b_name=(brand_name=="birko")?"insole":brand_name;
		$('#product_content').css({"height":"auto"});
		createSWFContent("/products/itemlist.swf?v="+version,750,350,b_name,"/products/");
	}
	
	// --- 商品詳細をデフォルトコードを取得
	var pcode=q["c"]||"";
	if(pcode!=''){
		var g=q["g"]||"ba";
		setTimeout(function(){
			openProductDetail(pcode,g);
		},1000);
	}
	
	// --- ハッシュをチェックして、戻るを押したときにも反応させる
	setInterval(function(){
		var hash2=(doc.location.hash).substr(1);
		if(hash2!=hash){
			hash=hash2;
			if(hash=='')hash='products';
			var target=$('ul.brand_navi a[rel='+hash+']');
			if($(target).length)$(target).click();
		}
	},50);
	
	// --- タイトルを戻す（IE限定、バグ対策）
	if(navigator.userAgent.indexOf('MSIE')!=-1){
		var title=String(doc.title);
		setInterval(function(){doc.title=title;},50);
	}
});


// ****************************************************************
//   
//   Flashを読み込み
//   
// ****************************************************************
function createSWFContent(hr,w,h,brand_name,base){
	// Flash設定
	var v="9.0.115";
	if(swfobject.hasFlashPlayerVersion(v)){
		var a={data:hr,width:w,height:h};
		var p={menu:'false',wmode:'opaque',allowScriptAccess:'always',bgColor:'#FFFFFF',salign:'T',id:"swfcontent",name:"swfcontent"};
		if(cbit<=16)p.bgColor='#FFFFFF';
		//var p={menu:'false',wmode:'transparent',allowScriptAccess:'always',bgColor:'#f8f7f1',salign:'T',id:"swfcontent",name:"swfcontent"};
		if(base)p.base=base;
		if(brand_name)p.flashvars="brand="+brand_name;
		p.flashvars+="&colorDepth="+cbit;
		swfobject.createSWF(a,p,"swfcontent");
		if(navigator.userAgent.indexOf('MSIE')!=-1)document.title=String(document.title).replace(/(.+)#.*?$/,"$1");
	}else{
		var noflash=$('<p class="noflash">Flash Playerをインストールしていないか、古いバージョンのFlash Playerがインストールされています。<br>ページを適切に表示するには、Flash Player9以上が必要となります。最新のFlash Playerをダウンロードしてご利用下さい。<br><a href="http://www.adobe.com/go/getflashplayer" target="_blank"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player"></a></p>');
		$("#swfcontent").append(noflash);
	}
	return false;
}


// ****************************************************************
//   
//   This scrollTo animation for Flash content
//   
// ****************************************************************
function scrollToEvent(ax,ay){$.scrollTo(ay,{axis:'y',duration:800,easing:'swing'});}


