﻿/******************************************************************************
	初期設定
******************************************************************************/
//var host = 'http://test.bangkokmadam.net';

var dtm = new Date();
//var dtmp = Date.parse(dtm.getFullYear() + '/' + (dtm.getMonth() + 1) + '/' + dtm.getDate());
//var requestUrl = host + '/ci/index.php/fortune/fortune/get_today_fate/' + dtmp;
//var requestUrl = host + '/ci/index.php/fortune/fortune/get_today_fate/' + (new Date()).getTime();
var requestUrl = '/ci/index.php/fortune/fortune/get_today_fate/' + (new Date()).getTime();
var SWF_TBL = new Array(
    'fairy_charge1.swf',
    'fairy_charge2.swf',
    'fairy_charge3.swf',
    'fairy_seed1.swf',
    'fairy_growth1.swf',
    'fairy_decision1.swf',
    'fairy_health1.swf',
    'fairy_popularity1.swf',
    'fairy_mentality1.swf',
    'fairy_rise1.swf',
    'fairy_economy1.swf',
    'fairy_fulfillment1.swf');

var NUMBER;
GetNumber();

function GetNumber()
{
//    alert(requestUrl);
    var myAjax = new Ajax.Request(
        requestUrl,
        {
            method: 'get'
            ,onComplete: _requestOnComplete
            ,onFailure: _requestOnFailure
        });
}
function _requestOnComplete(originalRequest)
{
    NUMBER = Number(originalRequest.responseText);
}
function _requestOnFailure()
{
    NUMBER = Math.floor(Math.random() * (11 - 0 + 1));
}
function ShowPage(mode){
    if (mode != 1) {
    }
    else {
        _createFlashLayer();
    }
}
function _createFlashLayer()
{
    if (!NUMBER) {NUMBER = Math.floor(Math.random() * (11 - 0 + 1));}
    var swfName = SWF_TBL[NUMBER];

    //占いFLASH用背景レイヤー生成
    var flashLayer = document.createElement('div');
    flashLayer.setAttribute('id', 'flashLayer');
    flashLayer.style.backgroundColor = '#999999';
    flashLayer.style.backgroundImage = 'url(assets/images/fortune/floatingbg_g.png)';
    flashLayer.style.position = 'absolute';
    flashLayer.style.left = '0px';
    flashLayer.style.top = '0px';
    flashLayer.style.width = _getFullWidth() + 'px';
    flashLayer.style.height = _getFullHeight() + 'px';
    $('wrapper').appendChild(flashLayer);
    
    //CLOSEでリロードなのが前提で、為替converterをhidden(IE対策・SELECT)
    if ($('fortune')) {
        $('fortune').style.display = 'none';
    }
    if ($('converter')) {
        $('converter').style.display = 'none';
    }
    if ($('flash_banner')) {
        $('flash_banner').style.display = 'none';
    }

    if ($('vote')) {
        $('vote').style.display = 'none';
    }
    
	var sHtml = "";
	sHtml += '<table style="background-color:transparent; border:none; padding:0; margin:0; text-align:center; vertical-align:middle"  border="0" cellpadding="0" cellspacing="0" width="100%" height="100%">';
	sHtml += '<tr><td align="center" valign="middle" style="padding:0; margin:0; border:none; background-color:transparent; text-align:center; vertical-align:middle">';
	sHtml += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="800" height="600" align="middle">';
	sHtml += '<param name="bgcolor" value="#666666" />';
	sHtml += '<param name="allowScriptAccess" value="always" />';
	sHtml += '<param name="movie" value="assets/swf/fortune/' + swfName + '" />';
	sHtml += '<param name="quality" value="high" />';
	sHtml += '<param name="salign" value="lt" />';
	sHtml += '<param name="SWLIVECONNECT" value="TRUE" />';
	sHtml += '<embed bgcolor="#666666" SWLIVECONNECT="TRUE" salign="lt" align="middle" src="assets/swf/fortune/' + swfName + '" quality="high" width="800" height="600" align="middle" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
	sHtml += '</object></td></tr></table>';
	flashLayer.innerHTML = sHtml;

	xPos = Math.floor((_getFullWidth() - _getClientWidth()) / 2); 
	yPos = Math.floor((_getFullHeight() - _getClientHeight()) / 2); 
	window.scrollTo(xPos, yPos);
	
    window.onresize = function() {
        _setLayerSize();
    };
}

function _getFullWidth() {
    var clientWidth;
    try {
        clientWidth = document.documentElement.scrollWidth;
        if (clientWidth == undefined) {throw '';}
    }catch(e) {
        try {
            clientWidth = document.body.scrollWidth;
            if (clientWidth == undefined) {throw '';}
        }catch(e) {
        }
    }
    return clientWidth;
}
function _getClientWidth() {
    var clientWidth;
    try {
        clientWidth = window.innerWidth;
        if (clientWidth == undefined) {throw '';}
    }catch(e) {
        try {
            clientWidth = document.documentElement.clientWidth;
            if (clientWidth == undefined) {throw '';}
        }catch(e) {
            try {
                clientWidth = document.body.clientWidth;
                if (clientWidth == undefined) {throw '';}
            }catch(e) {
            }
        }
    }
    return clientWidth;
}

function _getFullHeight() {
    var clientHeight;
    try {
        clientHeight = document.documentElement.scrollHeight;
        if (clientHeight == undefined) {throw '';}
    }catch(e) {
        try {
            clientHeight = document.body.scrollHeight;
            if (clientHeight == undefined) {throw '';}
        }catch(e) {
        }
    }
    return clientHeight;
}
function _getClientHeight() {
    var clientHeight;
    try {
        clientHeight = window.innerHeight;
        if (clientHeight == undefined) {throw '';}
    }catch(e) {
        try {
            clientHeight = document.documentElement.clientHeight;
            if (clientHeight == undefined) {throw '';}
        }catch(e) {
            try {
                clientHeight = document.body.clientHeight;
                if (clientHeight == undefined) {throw '';}
            }catch(e) {
            }
        }
    }
    return clientHeight;
}

function _setLayerSize()
{
    if (!$('flashLayer')) {return;}

    var flashLayer = $('flashLayer');
    flashLayer.style.width = _getFullWidth() + 'px';
    flashLayer.style.height = _getFullHeight() + 'px';

	xPos = Math.floor((_getFullWidth() - _getClientWidth()) / 2); 
	yPos = Math.floor((_getFullHeight() - _getClientHeight()) / 2); 
	window.scrollTo(xPos, yPos);
}
