/** - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/** Namespace defenitions.                                                    */
/** - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
var toyota;
try {
if (!toyota) {
toyota = {};
} else if (typeof toyota != 'object') {
throw new Error('[toyota] already exists and is not an object.');
}
if (!toyota.recommend) {
toyota.recommend = {};
} else if (typeof toyota.recommend != 'object') {
throw new Error('[toyota.recommend] already exists and is not an object.');
}
if (!toyota.recommend.OverlayInformation) {
toyota.recommend.OverlayInformation = {};
} else if (typeof toyota.recommend.OverlayInformation != 'object') {
throw new Error('[toyota.recommend.OverlayInformation] already exists and is not an object.');
}
} catch (e) { // nop.
}

/** - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/** anonymous function: toyota.recommend.OverlayInformation.CONST             */
/** - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
(function() {

// 'jquery-runtime-plugin.js'がロード済みでなければ終了.
if (!jQuery || !jQuery.Runtime) {
return;
}
// 'toyota.recommend.OverlayInformation.CONST'がロード済みであれば終了.
if (toyota.recommend.OverlayInformation.CONST) {
return;
}
// variable & function.
var overlayInformation = toyota.recommend.OverlayInformation;
overlayInformation.CONST = {};
overlayInformation.CONST['CURRENT_TIME'] = new Date().getTime();
overlayInformation.CONST['PANE_ID'] = 'toyota.recommend.OverlayInformation'.toLowerCase().replace(/[\.]/g, '_') + overlayInformation.CONST['CURRENT_TIME'];
overlayInformation.CONST['PARTS_URL'] = '/parts/dc/recommendparts';
overlayInformation.CONST['PARTS_PARAMS'] = '?charset=utf-8&data_type=xhtml&pid=overlayinfomation&prefix=overlayinfomation##DEFAULT_KEYWORDS####REFERER##';
// public function定義.
overlayInformation.printPane = printPane;
// synchro import js & execute js.
var r;
r = jQuery.Runtime.requireExecute('jQuery.HandleListener', '/syscommon/js/jquery-drag-plugin.js');
r = jQuery.Runtime.requireJS('/syscommon/js/jquery-json-plugin.js');
// asynchro css import.
r = jQuery.Runtime.requireCSS('/recommend/sc/css/floater.css');
r = jQuery.Runtime.requireCSS('/recommend/sc/css/layout.css');

/**
 * ロードした埋め込みパーツを流し込みdiv要素を出力し,ロードFunctionをコールする.<br>
 *
 * @param defaultKeyword デフォルトキーワード.
 * @param _left オーバーレイパーツの左位置.
 * @param _top オーバーレイパーツの上位置.
 */
function printPane(defaultKeyword, _left, _top) {
// オーバーレイパーツの表示位置. -> ロードするパーツで使用する.
overlayInformation.CONST['POSITION_LEFT'] = _left || 400;
overlayInformation.CONST['POSITION_TOP'] = _top || 400;
// // div要素を出力.
jQuery.Runtime.lazyExecute('document', function() {
document.write('<div id="', overlayInformation.CONST['PANE_ID'], '">', '</di', 'v>');
_loadRecommendParts(defaultKeyword, document.referrer);
}, 10);
}

/**
 * 埋め込みパーツをロードする.<br>
 *
 * @param defaultKeyword デフォルトキーワード.
 * @param referer リファラー.
 */
function _loadRecommendParts(defaultKeyword, referer) {
defaultKeyword = defaultKeyword || '';
referer = referer || '';
jQuery.Runtime.lazyExecute('document.getElementById("' + overlayInformation.CONST['PANE_ID'] + '")', function() {
var encDefaultKeyword = encodeURIComponent(defaultKeyword);
var encReferer = encodeURIComponent(referer);
var url = overlayInformation.CONST['PARTS_URL'] + overlayInformation.CONST['PARTS_PARAMS'];
url = url.replace(/##DEFAULT_KEYWORDS##/gi, encDefaultKeyword == '' ? '' : '&keyword=' + encDefaultKeyword);
url = url.replace(/##REFERER##/gi, encReferer == '' ? '' : '&referer=' + encReferer);
jQuery('div#' + overlayInformation.CONST['PANE_ID']).load(url);
}, 10);
}

})();
