
var BANA_HEADER_FLASH;
var BANA_TOPICS_TABVIEW;



/* -------------------- Settings for header flash movie -------------------- */

var BANA_HEADER_FLASH_SETTING = {
	  "required"          : "8"
	, "src"               : "./swf/header_flash_001.swf"
	, "FlashVars"         : "fieldXMLPath=swf/am_field_list.xml&imageXMLPath=swf/am_image_list.xml"
	, "name"              : "amexternal"
	, "id"                : "amexternal"
	, "className"         : "flash"
	, "alternate"         : "flash-alternate"
	, "width"             : "100%"
	, "height"            : "100%"
	, "salign"            : "lt"
	, "bgcolor"           : "black"
	, "quality"           : "high"
	, "menu"              : "false"
	, "allowScriptAccess" : "sameDomain"
};

var BANA_HEADER_FLASH_USE_VISUAL_EFFECT = true;



/* -------------------- Settings for BANATopicsTabViewSetup -------------------- */

var BANA_TOPICS_TABVIEW_BASENODE_ID   = 'tabtopi';
var BANA_TOPICS_TABVIEW_ADJUST_HEIGHT = false;






/* -------------------- Constructor : BANAHeaderFlash -------------------- */

function BANAHeaderFlash(setting, useEffect) {
	this.flash      = (typeof BAFlashGenerator == 'function') ?
	                  	new BAFlashGenerator(setting) :
	                  	null                          ;
	this.htmlReady  = false;
	this.collapsed  = true;
	this.container  = null;
	this.useEffect  = useEffect;
	this.effect     = null;
}

BANAHeaderFlash.prototype.init = function(setting) {
	if (!this.flash) {
		throw 'BANAHeaderFlash.init: BAFlashGenerator is required.';
	} else if (!this.htmlReady) {
		this.flash.hideAlternate();
		BAAddOnload(this.onHtmlLoaded, this);
	}
}

BANAHeaderFlash.prototype.write = function() {
	if (!this.htmlReady) {
		this.flash.write();
	}
}

BANAHeaderFlash.prototype.onHtmlLoaded = function() {
	this.htmlReady = true;
	if (!this.flash.node) {
//		it does'nt satisfy required plug-in version.
//		throw 'BANAHeaderFlash.onHtmlLoaded: object element as flash movie is not found.';
	} else {
		// get container node
		this.container = BARegisterDOMMethodsTo(this.flash.node.parentNode);

		// setup resize effect
		if (this.useEffect && typeof BAEffect_Resize == 'function') {
			this.effect = new BAEffect_Resize(this.container, 5, 10, 250);
			this.effect.setCallBack('onStart'   , this.onResizeStart   , this);
			this.effect.setCallBack('onComplete', this.onResizeComplete, this);
		}

		// call flash external interface function
		if (this.flash.node.callLoadComplete) {
			this.flash.node.callLoadComplete();
		}

		// measuring for tab-focus moving
		try {
			document.focus();
		} catch(err) { }
	}
}

BANAHeaderFlash.prototype.isHtmlReady = function () {
	return this.htmlReady;
}


BANAHeaderFlash.prototype.getHeight = function () {
	return this.container.offsetHeight;
}

BANAHeaderFlash.prototype.resizeTo = function (height, timeLimit) {
	if (this.effect) {
		this.effect.resizeTo(height, timeLimit);
	} else {
		this.container.style.height = (height > 0 ? height : 0) + 'px';
	}
}

BANAHeaderFlash.prototype.onResizeStart = function () {
}

BANAHeaderFlash.prototype.onResizeComplete = function () {
}






/* -------------------- Function : BANAResizeFlash -------------------- */

function BANAResizeFlash(height, timeLimit) {
	if (typeof BANA_HEADER_FLASH == 'object') {
		BANA_HEADER_FLASH.resizeTo(height, timeLimit);
	}
}



/* -------------------- Function : BANAIsHtmlReady -------------------- */

function BANAIsHtmlReady() {
	return (typeof BANA_HEADER_FLASH == 'object') ? BANA_HEADER_FLASH.isHtmlReady() : false;
}



/* -------------------- Function : BANATopicsTabViewSetup -------------------- */

function BANATopicsTabViewSetup() {
	if (typeof BATabView == 'function') {
		var node = document.getElementByIdBA(BANA_TOPICS_TABVIEW_BASENODE_ID);
		if (node) {
			BANA_TOPICS_TABVIEW = new BATabView(node, BANA_TOPICS_TABVIEW_ADJUST_HEIGHT);
		}
	}
}






/* -------------------- Main : register start-up -------------------- */

if (typeof BA == 'object' && BA.ua.DOMok) {
	BANA_HEADER_FLASH = new BANAHeaderFlash(BANA_HEADER_FLASH_SETTING, BANA_HEADER_FLASH_USE_VISUAL_EFFECT);
	BANA_HEADER_FLASH.init();
	BAAddOnload(BANATopicsTabViewSetup);
/*
	// for expansion and contraction test
	BAAddOnload(function() {
		var btn = document.createElementBA('button');
		btn.appendChildBA('\u4F38\u7E2E\u30C6\u30B9\u30C8');
		btn.style.position = 'absolute';
		btn.style.top      = '510px';
		btn.style.left     = '920px';
		btn.style.zIndex   = '10000';
		btn.style.width    = '6em';
		btn.__TOGGLEFLAG__ = false;
		btn.addEventListenerBA('click', function(e) {
			BANA_HEADER_FLASH.resizeTo((this.__TOGGLEFLAG__ ? 320 : 420), 200);
			this.__TOGGLEFLAG__ = !this.__TOGGLEFLAG__;
		});
		document.body.appendChildBA(btn);
	});
*/
}