/* -------------------------------------------------------------------------- */
/**
 *    @fileoverview
 *
 *    @version rev003.2008-06-08
 *    @requires estateFinder.js
 *    @requires swfobject.js
 */
/* -------------------------------------------------------------------------- */

var BA_WELCOME_SWF_AREA;
var BA_lang = '';
var BA_vlFrame = '';

/* -------------------- Settings -------------------- */
var BA_WELCOME_SWF_AREA_ID        = 'welcome-swf-area';
var BA_WELCOME_SWF_ID             = 'welcome-swf';
var BA_WELCOME_SWF_ALT_ID         = "welcome-swf-alternate";
var BA_WELCOME_SWF_PATH           = '/common/swf/welcome.swf';
var BA_WELCOME_XML_PATH           = '/${0}/common/xml/welcome.xml';
var BA_WELCOME_SWF_WIDTH          = '100%';
var BA_WELCOME_SWF_HEIGHT         = '100%';
var BA_WELCOME_SWF_MIN_WIDTH      = '920';
var BA_WELCOME_SWF_MIN_HEIGHT     = '540';
var BA_WELCOME_SWF_REQ_VER        = '8';
var BA_WELCOME_SWF_BGCOLOR        = '#fff';

var BA_GLOBALNAV_SWF_PATH         = '/common/swf/navi.swf';
var BA_GLOBALNAV_XML_PATH         = "/${0}/common/xml/navigation.xml";

var BA_WELCOME_VL_PATH            = '/${0}/welcome/vl/${1}.html';

/* hide global nav */
BA_GLOBALNAV_ENABLE = false;

/* -------------------- BALoadVL -------------------- */
function BALoadVL ( VLID ) {
	if ( !VLID || VLID.match(/[^0-9]+/) ) VLID = '01';
	var tmp = ( VLID.substr(0,1) != 0 ) ? VLID : VLID.substr(1,1);
	if ( tmp <= 0 || tmp > 14 ) VLID = '01';

	BA_vlFrame.setContent( VLID );
}

function BALoadVLFrame () {
	this.id = 'welcome_vl';
	this.contentFrame = '';
	this.frameName = 'welcome_vl_frame';

	this.init();
}

BALoadVLFrame.prototype.init = function () {
	var body  = document.getElementsByTagNameBA('body')[0];
	this.node = document.createElementBA('ins');
	this.node.setAttributeBA('id', this.id);
	body.appendChildBA(this.node);

	var iframe = new BATag('iframe');
	iframe.setAttributeBA('name', this.frameName);
	iframe.setAttributeBA('src' , 'about:blank');
	iframe.setAttributeBA('border'     , '0' );
	iframe.setAttributeBA('frameborder', '0' );
	iframe.setAttributeBA('scrolling'  , 'no');
	iframe.appendChildBA('');

	this.node.appendChildBA(iframe, true);

	this.frame = this.node.getElementsByTagNameBA('iframe')[0];
	this.node.style.display = 'none';
	this.node.style.position = 'absolute';
}

BALoadVLFrame.prototype.setContent = function ( VLID ) {
	window.frames[this.frameName].location.replace(BA_WELCOME_VL_PATH.formatTextBA([BA_lang,VLID]));
}

/* -------------------- Main : register start-up -------------------- */

if (typeof BA == 'object' && BA.ua.isDOMReady && typeof SWFObject == 'function') {
(function() {

    var swf = new SWFObject(
                BA_WELCOME_SWF_PATH
                , BA_WELCOME_SWF_ID
                , BA_WELCOME_SWF_WIDTH
                , BA_WELCOME_SWF_HEIGHT
                , BA_WELCOME_SWF_REQ_VER
                , BA_WELCOME_SWF_BGCOLOR
                );

    var path = location.pathname;
    if ( swf.installedVer.major >= BA_WELCOME_SWF_REQ_VER && path.split('/')[2] == 'welcome' && !(path.match(/index\.html$/) || path.match(/\/welcome\/$/) ) ) {
		location.href = './index.html';
    }

    BA_lang = (function() {
		return (path.split('/')[2]) ? path.split('/')[1] : (path.match(/\.html\.(\w+)$/) || ['', 'ja'])[1];
	})();

    var glonav_xml = BA_GLOBALNAV_XML_PATH.formatTextBA([BA_lang]);
    var contents_xml_url = BA_WELCOME_XML_PATH.formatTextBA([BA_lang]);

    // hide alternate html source.
    var styleSheetBase = document.getStyleSheetsBA()[0];
    styleSheetBase.addRuleBA(
        '#${0}{ display : none }'.formatTextBA([BA_WELCOME_SWF_ALT_ID])
    );

	BAAddOnload(function () {
		BA_WELCOME_SWF_AREA = document.getElementByIdBA('structure-base');
		if ( BA_WELCOME_SWF_AREA && swf.installedVer.major >= BA_WELCOME_SWF_REQ_VER ) {

			styleSheetBase.addRuleBA(
				'#structure-base{height: 100% !important; width: 100% !important;}'
			);

			styleSheetBase.addRuleBA(
				'#${0} { height: 100% !important; width: 100% !important; margin:0 !important; padding:0 !important; min-height:${1}px; min-width:${2}px; }'.formatTextBA([BA_WELCOME_SWF_AREA_ID,BA_WELCOME_SWF_MIN_HEIGHT,BA_WELCOME_SWF_MIN_WIDTH])
			);

            styleSheetBase.addRuleBA(
				'#${0}{ height: 100% !important; width: 100% !important; min-height:${1}px; min-width:${2}px; }'.formatTextBA([BA_WELCOME_SWF_ID, BA_WELCOME_SWF_MIN_HEIGHT, BA_WELCOME_SWF_MIN_WIDTH])
            );

			var div = new BATag('div');
			div.setAttributeBA('id', BA_WELCOME_SWF_AREA_ID);
			document.getElementByIdBA('structure-base').appendChildBA( div, true );

			swf.addParam('salign', 'lt');
			swf.addParam('menu'  , 'false');
			swf.addParam('scale' , 'noscale');
			swf.addParam('allowScriptAccess','always');
			swf.addVariable('language', BA_lang);
			swf.addVariable('xml_url', glonav_xml);
			swf.addVariable('contents_xml_url', contents_xml_url);
			swf.addVariable('navi_url', BA_GLOBALNAV_SWF_PATH);
			swf.addVariable('stayMenu', 1);
			swf.write(BA_WELCOME_SWF_AREA_ID);
        } else {
            // reshow html-based global nav.
            styleSheetBase.addRuleBA(
                '#${0} { display : block }'.formatTextBA([BA_WELCOME_SWF_ALT_ID])
            );
        }

		BA_vlFrame = new BALoadVLFrame();
		BA_vlFrame.setContent( '01' );
    });

})();
}
