var hostName = "tonan-go";
//--------------------
// Smooth Scrolling
//--------------------
$(document).ready(function(){
	$("a.smoothScroll[href*=#]").click(function() {
		if (location.pathname.replace(/^\//,"") == this.pathname.replace(/^\//,"") && location.hostname == this.hostname) {
			var $target = $(this.hash);
			$target = $target.length && $target || $("[name=" + this.hash.slice(1) +']');
			if ($target.length) {
				var targetOffset = $target.offset().top;
				$('html,body').animate({scrollTop: targetOffset}, 500);
				return false;
			} else {
				$('html,body').animate({scrollTop: 0}, 500);
				return false;
			}
		}
	});
	$("a[class!='thickbox'][href^='/'],a[href*='"+hostName+"']").click(function() {
		if ( $(this).hasClass("thickbox") ) return;
		try { this.href = this.href+"#"+SWFAddress.getValue(); } catch(e) {}
		return true;
	});
	$("form").submit(function() {
		try { this.action = this.action+"#"+SWFAddress.getValue(); } catch(e) {}
		return true;
	});
});
//--------------------
// Thickbox
//--------------------
$(document).ready(function(){
	$("div.article-content a").each(function(){
		if ( $(this).children("img").length && $(this).attr("href").match(/\.(jpg|JPG|jpeg|JPEG|gif|GIF|png|PNG)$/) ) {
			$(this).removeAttr("onclick");
			$(this).attr({target:"_blank"});
			$(this).addClass("thickbox");
		} else {
			if ( ! $(this).attr("href").match(/^((http:\/\/(www\.)?tonan-go\.jp)\/)/) ) {
				$(this).attr({target:"_blank"});
			}
		}
	});
});
//--------------------
// NoFlash
//--------------------

var u = document.location.href;
var category = u.split("/")[3];
var noFlash = (u.match(/NoFlash/) != null);

//--------------------
// CSS Switch
//--------------------

$(document).ready( function() {
	//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("8.0.0") ) {
		$(document.body).addClass("flashEnabled");
	}

});

//--------------------
// Floor Map Flash
//--------------------

//if ( ! noFlash && swfobject.hasFlashPlayerVersion("8.0.0") && !jQuery.browser["opera"] ) {
if ( ! noFlash && swfobject.hasFlashPlayerVersion("8.0.0")  ) {
	
	var floorDefaultSelected;
	var floorInit = false;
	var categories = {fourwheel:1,twowheel:1,others:1,students:1, about:1};
	var onlyPages = {
		coursenormal:"fourwheel",
		estimatenormal:"fourwheel",
		coursepro:"fourwheel",
		estimatepro:"fourwheel",
		entryfourwheel:"fourwheel",
		coursemotorcycle:"twowheel",
		estimatemotorcycle:"twowheel",
		entrytwowheel:"twowheel",
		paper:"others",
		corporate:"others",
		education:"students",
		plan:"students",
		schedule:"students"
	};
	
	function onInitSWFAddress() {
		var h = document.location.href;
		var r = h.match(/^http:\/\/[^\/]+\/([^\/]+)\//);
		var f = r ? r[1] : "";
		if ( f && onlyPages[f] ) SWFAddress.setValue("/"+onlyPages[f]+"/");
		onChangeSWFAddress();
	}

	function onChangeSWFAddress() {
		try {
			var p = SWFAddress.getValue();
			var c;
			var h = document.location.href;
			var r = h.match(/^http:\/\/[^\/]+\/([^\/]+)\//);
			var f = r ? r[1] : "";
			for ( c in categories ) 	$("div#CONTAINER").removeClass(c);
			c = ( p && p.split("/")[1] ) ? p.split("/")[1] : "";
			if ( f && onlyPages[f] ) {
				$("div#CONTAINER").addClass(onlyPages[f]);
			} else if ( p && categories[c]) {
				$("div#CONTAINER").addClass(c);
			} else {
				$("div#CONTAINER").addClass("fourwheel");
			}
		} catch (e) {
			alert(e);
		}
	}
	
	//----------
	// Embed SWF
	//----------
	swfobject.embedSWF("/flash/navi.swf", "HEADNAVI", "100%", "265", "8.0.0", false, {defaultCategory:category}, {wmode:"transparent"}, {id:"HeadNaviSwf"});
	SWFAddress.addEventListener("init",onInitSWFAddress);
	SWFAddress.addEventListener("change",onChangeSWFAddress);
	SWFAddress.setTracker(null);
}

