//--------------------
// NoFlash
//--------------------

var u = document.location.href;
var noFlash = (u.match(/NoFlash/) != null);
var testMode = (u.match(/TestMode/) != null);

//--------------------
// CSS Switch
//--------------------
$(document).ready( function() {
	if ( testMode ) $(document.body).css("background-image","url(/images/common/head-bg02.gif)");
	//CSS
	if (
		!( jQuery.browser["safari"] && jQuery.browser.version<2 ) && 
		!( jQuery.browser["mozilla"] && jQuery.browser.version<1.5 ) && 
		!( jQuery.browser["msie"] && jQuery.browser.version<6 ) && 
		!( jQuery.browser["opera"] && jQuery.browser.version<9 )
	)
		$(document.body).addClass("jsEnabled");
	
	//If Flash Enabled
	if ( ! noFlash && swfobject.hasFlashPlayerVersion("7.0.0") ) {
		$(document.body).addClass("flashEnabled");
	}
	
	if ( ! noFlash && swfobject.hasFlashPlayerVersion("8.0.0") ) {
		$(document.body).addClass("flash8Enabled");
	}
});

//--------------------
// Page Top Smooth Scroll
//--------------------

$(document).ready( function() {
	$('a[href*="#HEAD"]').click(function() {
		$('html,body').animate({scrollTop: 0, scrollLeft:0}, 500);
		return false;
	});
});


//--------------------
// Floor Map Flash
//--------------------



if ( u.match(/PrintOnLoad/) ) $(window).load(function(){window.print();});

//if ( ! noFlash && swfobject.hasFlashPlayerVersion("8.0.0") && !jQuery.browser["opera"] ) {
if ( ! noFlash && swfobject.hasFlashPlayerVersion("8.0.0") && ! u.match(/\/floor\//) && !jQuery.browser["opera"] ) {
	var floorDefaultSelected;
	var floorPath = "";
	
	//On Change
	function changePath(p) {
		floorPath = p;
		// Reset Floor Navi Class
		$("li#LMENU-FLOOR ul li a").removeClass("open");
		$("li#LMENU-FLOOR ul li a").removeClass("selected");
		//Set Floor Navi Class ,Animate and Scroll
		if ( floorPath && floorPath.match(/(B?[12]|[1-9])F/) ) {
			$("li#LMENU-"+floorPath+" a").addClass("open");
			$("div#WRAPPER").animate({marginLeft:"0px"},500, null, changeFlashPath);
			var sTop = $("div#WRAPPER").offset().top;
			var sLeft = $("div#WRAPPER").offset().left;
			$('html,body').animate({scrollTop: sTop, scrollLeft:sLeft}, 1000);
			try { pageTracker._trackPageview("/flash/floor/"+floorPath+"/"); } catch(e) {}
		} else {
			$("div#WRAPPER").animate({marginLeft:"-600px"},500, null, onResize);
			if ( floorDefaultSelected ) $(floorDefaultSelected).addClass("selected");
		}
	}

	//On Resize / Scroll 
	function onResize() {
		if ( ! floorPath || ! floorPath.match(/(B?[12]|[1-9])F/) ) return;
		var flashHeight = $("div#WRAPPER").height();
		var winHeight = self.innerHeight || document.documentElement.clientHeight;
		var scrollOffset = $(window).scrollTop() - $("div#HEAD").height() -8;
		var flashScrollHeight = winHeight + scrollOffset;
		if ( flashScrollHeight > flashHeight ) flashScrollHeight = flashHeight;
		$("#FloorMapSwf").css("height", flashScrollHeight+"px");
	}
	
	function changeFlashPath() {
		var swf= document.all? window["FloorMapSwf"] : document["FloorMapSwf"];
		if ( swf.flashChangePath ) swf.flashChangePath(floorPath);
	}
	
	// On Floor Navi Clicked
	function onFloorLinkClick(e) {
		var path = "";
		var pathArr;
		pathArr = e.target.href.match(/(B?[12]|[1-9])F/);
		if ( pathArr ) path = pathArr[0];
		if ( path && path == floorPath ) path = "";
		changePath(path);
		changeFlashPath();
		return false;
	}
	
	// On Load
	$(document).load( function() {
		onResize();
		$('.ui-tabs-nav').bind('tabsshow',onResize);
	});
	
	// On Ready
	$(document).ready( function() {
		$(document.body).addClass("floorFlashEnabled");
		//FLOOR NAVI
		//$('a[href*="/floor/"]').click(onFloorLinkClick);
		$('li#LMENU-FLOOR a[href*="/floor/"]').click(onFloorLinkClick);
		$("li#LMENU-FLOOR ul li a").each( function() {
			if ( $(this).hasClass("selected") ) floorDefaultSelected = $(this);
		});
		//Event
		$(window).scroll(onResize);
		$(window).resize(onResize);
	});
	//----------
	// Embed SWF
	//----------
	swfobject.embedSWF("/flash/floor.swf", "FLOOR-MAP-FLASH", "600", "100%", "8.0.0", false, {}, {wmode:"opaque",allowScriptAccess:"always"}, {id:"FloorMapSwf"});
	
}


//--------------------
// Head Flash
//--------------------

if ( typeof(isMainPage) != "undefined" && isMainPage ) {
} else if ( ! noFlash && typeof(noFlashBg) == "undefined"  ) {
	if ( swfobject.hasFlashPlayerVersion("7.0.0") ) {
		$(document).ready(function() {
			var h;
			var s;
			if ( typeof(visualSizeSmall) != "undefined" && visualSizeSmall ) {
				h = 213;
				s = "head_s.swf";
			} else {
				h = 423;
				s = "head.swf";
			}
			$("#HEAD-BG").before('<div id="HEAD-BG-WRAPPER" style="position:absolute; width:170px; height:'+h+'px;">&nbsp;</div>');
			swfobject.embedSWF("/flash/"+s, "HEAD-BG-WRAPPER", "170", h, "7.0.0", false, {}, {wmode:"transparent"}, {id:"HeadSwf"});
		});
	}
}


//--------------------
// Form and Thickbox
//--------------------

$(document).ready(function() {
	//
	// Register Mail Magazine
	//
	$("div#CONTAINER").after('<div id="MagRegisterWrapper" style="display:none"><div><a href="#" class="closeTB"><img src="/images/common/tb-close.gif" width="60" height="20" alt="閉じる" /></a></div><iframe name="MagRegisterFrame" id="MagRegisterFrame" frameborder="0" src="" width="600" height="300"></iframe></div>');
	
	$("input#F-MAILFORM").css("color","#494949");
	$("input#F-MAILFORM").focus(function(){
		if ( this.value == "メールアドレス" ) this.value = "";
		$(this).css("color","#ffffff");
	});
	$("input#F-MAILFORM").blur(function(){
		if ( this.value == "" ) {
			this.value = "メールアドレス";
			$(this).css("color","#494949");
		}
	});
	$("input#BT").click(function() {
		if ( $("input#F-MAILFORM")[0].value == "メールアドレス" ) $("input#F-MAILFORM")[0].value = "";
		tb_show("メルマガ登録","#TB_inline?height=340&width=600&inlineId=MagRegisterWrapper&modal=true","");
		this.form.target = "MagRegisterFrame";
		this.blur();
		try { pageTracker._linkByPost(this.form); } catch(e) {}
		return true;
	});
	
	$("a#MagRegister").click(function() {
		tb_show("メルマガ登録","#TB_inline?height=340&width=600&inlineId=MagRegisterWrapper&modal=true","");
		return true;
	});
	
	//
	// Introduce friends
	//
	$("div#MagRegisterWrapper").after('<div id="IntroduceWrapper" style="display:none"><div><a href="#" class="closeTB"><img src="/images/common/tb-close.gif" width="60" height="20" alt="閉じる" /></a></div><iframe name="IntroduceFrame" id="IntroduceFrame" frameborder="0" src="" width="600" height="250"></iframe></div>');
	
	$("a#INTRODUCE-FRIEND").click(function() {
		tb_show("友達に紹介する","#TB_inline?height=300&width=600&inlineId=IntroduceWrapper&modal=true","");
		$("iframe#IntroduceFrame")[0].src = "/introduce/?u="+escape(document.location.href);
		return false;
	});
	
	//
	// Send to mobile
	//
	
	$('form#SEND-TO-MOBILE input[type*="text"]').css("color","#999999");
	$('form#SEND-TO-MOBILE input[type*="text"]').focus(function(){
		if ( this.value == "メールアドレス" ) this.value = "";
		$(this).css("color","#000000");
	});
	$('form#SEND-TO-MOBILE input[type*="text"]').blur(function(){
		if ( this.value == "" ) {
			this.value = "メールアドレス";
			$(this).css("color","#999999");
		}
	});
	
	$("form#SEND-TO-MOBILE a").click(function() {
		if ( $('form#SEND-TO-MOBILE input[type*="text"]').attr("value") == "" || $('form#SEND-TO-MOBILE input[type*="text"]').attr("value") == "メールアドレス" ) {
			$('form#SEND-TO-MOBILE input[type*="text"]')[0].focus();
			alert("携帯のメールアドレスを入力してください。");
			$('form#SEND-TO-MOBILE input[type*="text"]')[0].value = "";
			return false;
		}
		var h = "mailto:"+$('form#SEND-TO-MOBILE input[type*="text"]').attr("value")+"?body="+escape(document.location.href.replace("http://www.hepfive.jp/","http://www.hepfive.jp/m/"));
		document.location.href=h;
		return false;
	});
	
	//
	// Close Thickbox
	//
	$("a.closeTB").click(function() {
		tb_remove();
		return false;
	});
});


