//  [[[[ Toph Flash seal script ]]]]
//  ---------------------------------------

var OpenPanelWidth = 240 ;
var RssKey = 'hotelfusui';
var LayerAlign = 'rightTop';
var LayerOffset = 0;
//  ---------------------------------------
/// SWF URL
var FlashPlaceURLPath = 'http://secure.toph.jp/tophseal/';
/// RSS URL
var RssURL = 'http://secure.toph.jp/rsv/prog/topPlanRSS_list.php?hotel=';
//  ---------------------------------------
var ie = ! ! document.all;
var n4 = ! ! document.layers;
var w3c = ! ! document.getElementById;
var mac45 = navigator.userAgent.indexOf( 'MSIE 4.5; Mac_PowerPC' ) >= 0;
var opr = ! ! window.opera;
var ffox = navigator.userAgent.indexOf( "Firefox" ) >= 0;
if( mac45 ) ie = false;
if( ffox ) ie = false;
if( opr ) ie = false;
// alert( navigator.userAgent );
var CloseObjectID = 'xxxxCloseObject';
var OpenPanelObjectID = 'xxxxOpenPanelObject';
var LayerNum = 200;
window.OpenPanelLock = false;

/*
 * EVENT
 */
//  ---------------------------------------

//

function Event_ClickPlanFlushOpen(){
    if( ! window.OpenPanelLock ){
	    MakeOpenPanel();
	    //DisplaySet( OpenPanelObjectID, true );
	    setTimeout('DisplaySet( CloseObjectID, false );',1);
	    window.OpenPanelLock=true;
    }
}

//  ---------------------------------------

//
function Event_ClickPlanFlushClose(){
    window.OpenPanelLock = false;
    DisplaySet( CloseObjectID, true );
    setTimeout('DisplaySet( OpenPanelObjectID, false );',0);
}

//  ---------------------------------------


function SetupObject(){
    var o1 = MakeObjectLayer( CloseObjectID, LayerNum );
    var o2 = MakeObjectLayer( OpenPanelObjectID, LayerNum+1 );
    document.body.appendChild( o1 );
    document.body.appendChild( o2 );
    MakeClose();
    MakeOpenPanel();
	Event_ClickPlanFlushClose();
}

//  ---------------------------------------

function MakeObjectLayer( id, layerIndex ){
    var objc = document.createElement( 'div' );
    objc.setAttribute( 'id', id );
    objc.style.clear = "both";
    objc.style.position = 'absolute';
    objc.style.left = '0px';
    objc.style.top = '0px';
    objc.style.overflow = 'hidden';
    objc.style.zIndex = layerIndex+'';

    return objc;

}

//  ---------------------------------------


function MakeOpenPanel(){
    DisplaySet( OpenPanelObjectID, false );
    var foOpenPanel = new FlashObject( FlashPlaceURLPath + "TophPlanTabOpen.swf", "tabss", OpenPanelWidth, 520, "8", "#ffffff" );
    foOpenPanel.addParam( "wmode", "transparent" );
    foOpenPanel.addParam( "allowScriptAccess", "always" );
    foOpenPanel.addParam( "menu", "false" );
    foOpenPanel.addVariable( "RssURL", RssURL+RssKey );
    foOpenPanel.write( OpenPanelObjectID );
    LayerFixed_OpenPanel();
    DisplaySet( OpenPanelObjectID, true );
}

//  ---------------------------------------

function MakeClose(){
    OpenPanelLock = true;
    DisplaySet( CloseObjectID, false );
    var foCar = new FlashObject( FlashPlaceURLPath + "TophPlanTabClose.swf", "close",OpenPanelWidth, 40, "8", "#ffffff" );
    foCar.addParam( "wmode", "transparent" );
    foCar.addParam( "menu", "false" );
    foCar.addParam( "allowScriptAccess", "always" );
    foCar.write( CloseObjectID );
    LayerFixed_Close();
    DisplaySet( CloseObjectID, true );
}

//  ---------------------------------------


function FixedObject(){
    LayerFixed_OpenPanel();
    LayerFixed_Close();
}

//  ---------------------------------------

function LayerFixed_OpenPanel(){
    LayerFixed( OpenPanelObjectID, LayerAlign , OpenPanelWidth * - 1 + LayerOffset, 0 )
}

//  ---------------------------------------

function LayerFixed_Close(){
    LayerFixed( CloseObjectID, LayerAlign , OpenPanelWidth * - 1 + LayerOffset, 0 )
}

//  ---------------------------------------

function DisplaySet( id, sts ){
    var obj = __GetControlObject( id );
    if( obj != null ){
        if( sts ){
			obj.style.visibility="visible";
        	obj.style.display = "";
        }else{
			obj.style.visibility="hidden";
        	obj.style.display = "none";
        }
    }
}

//  ---------------------------------------

function __GetControlObject( id ){
    var obj = document.getElementById( id );
    return obj;
}

//  ---------------------------------------

function LayerFixed( id, alignCode, offSetX, offSetY ){

    offSetX = parseInt( offSetX, 10 );
    offSetY = parseInt( offSetY, 10 );
    var offLeft;
    var offTop;
    var WinWidth = GetWindowWidth();
    var WinHeight = GetWindowHeight();
    if( alignCode == 'rightTop' ){
        offLeft = WinWidth + offSetX;
        offTop  = offSetY;

    }
    else if( alignCode == 'rightBottom' ){
        offLeft = WinWidth  + offSetX
        offTop  = WinHeight + offSetY

    }
    else if( alignCode == 'leftBottom' ){
        offLeft = offSetX
        offTop  = WinHeight + offSetY

    }
    else if( alignCode == 'centerTop' ){
        offLeft = WinWidth / 2 + offSetX;
        offTop  = offSetY;

    }
    else if( alignCode == 'center' ){
        offLeft = WinWidth / 2 + offSetX;
        offTop  = WinHeight / 2 + offSetY;

    }
    else if( alignCode == 'leftMiddle' ){
        offLeft = offSetX;
        offTop  = WinHeight / 2 + offSetY;

    }
    else {//leftTop
        offLeft = offSetX;
        offTop  = offSetY;
    }
    // SetTextToObject( "mmmm", "x:" + document.body.clientWidth );
    offLeft = parseInt( offLeft );
    offTop  = parseInt( offTop );
    mx = parseInt( GetScrollX() + offLeft );
    my = parseInt( GetScrollY() + offTop );
    LayerPosSet( id, mx, my );

    // WinIE opera n4
    if( ! ( ie || ffox || opr ) ){
        clearTimeout( LayerFixed[id] )
        LayerFixed[id] = setTimeout( "LayerFixed('"+id+"','"+alignCode+"','" +offSetX+"','"+offSetY+"')", 50 );
    }
}

//  ---------------------------------------

function SetTextToObject( id, val ){
    var obj = __GetControlObject( id );
    if( obj != null ){
        obj.innerHTML = val;
    }
}

//  ---------------------------------------

function LayerPosSet( id, x, y ){
    /*
    if( document.layers ){ id.moveTo( x, y ); return; } // NN4
    // IE5 + , Mozilla, Opera 7
    if( typeof id.style.left != "undefined" && typeof id.style.left == "string" ){
    id.style.left = x + 'px';
    id.style.top = y + 'px';
    }
    else if( typeof id.style.pixelLeft != "undefined" ){ // IE, Opera 6
    id.style.pixelLeft = x;
    id.style.pixelTop = y;
    }
    return;
    */
    if( document.getElementById ){
        document.getElementById( id ).style.left = x + "px";
        document.getElementById( id ).style.top = y + "px";
    }
    else if( document.all ){
        document.all( id ).style.pixelLeft = x;
        document.all( id ).style.pixelTop = y;
    }
    else if( document.layers ){
        document.layers[id].moveTo( x, y );
        // NN4
    }
}

//  ---------------------------------------

function GetScrollX(){
    if( window.scrollX ) return window.scrollX;
    // Moziila
    if( window.pageXOffset ) return window.pageXOffset;
    // Opera, NN4
    if( document.documentElement && document.documentElement.scrollLeft ){
        //  IE
        return document.documentElement.scrollLeft;
    }
    else if( document.body && document.body.scrollLeft ){
        return document.body.scrollLeft;
    }
    return 0;
}

//  ---------------------------------------

function GetScrollY(){
    if( window.scrollY ) return window.scrollY;
    // Mozilla
    if( window.pageYOffset ) return window.pageYOffset;
    // Opera, NN4
    if( document.documentElement && document.documentElement.scrollTop ){
        // IE
        return document.documentElement.scrollTop;
    }
    else if( document.body && document.body.scrollTop ){
        return document.body.scrollTop;
    }
    return 0;
}

//  ---------------------------------------

function GetWindowWidth(){
    var xwidth = 0;
    if( window.innerWidth ){
        xwidth = window.innerWidth;
        // Mozilla, Opera, NN4
    }
    else if( document.documentElement && document.documentElement.clientWidth ){
        // IE
        xwidth = document.documentElement.clientWidth;
    }
    else if( document.body && document.body.clientWidth ){
        xwidth = document.body.clientWidth;
    }
    return xwidth;
}

//  ---------------------------------------

function GetWindowHeight(){
    if( window.innerHeight ) return window.innerHeight;
    // Mozilla, Opera, NN4
    if( document.documentElement && document.documentElement.clientHeight ){
        // IE
        return document.documentElement.clientHeight;
    }
    else if( document.body && document.body.clientHeight ){
        return document.body.clientHeight;
    }
    return 0;
}

//  ---------------------------------------

function __body_onload () {
    xxxxInit();
    //setTimeout( "xxxxInit()", 300 );
}

//  ---------------------------------------

function xxxxInit () {
    SetupObject();
    FixedObject();
    if( ie  ){
        window.onresize = FixedObject;
        window.onscroll = FixedObject;
    }
    else if( w3c ){
        window.addEventListener( 'resize', FixedObject , false );
        window.addEventListener( 'scroll', FixedObject, false );
    }
}

//  ---------------------------------------

( function(){
	if( typeof window.onload == "function" ){
	    var oldonload = window.onload;
	    window.onload = function(){
	        __body_onload();
	        oldonload();
	    };
	}else{
	    window.onload = __body_onload;
	}
/*    if( ie  ){
        document.body.onload = __body_onload;
    }
    else if( w3c ){
        window.addEventListener( 'load', __body_onload , false );
    }
    else{
        setTimeout( "__body_onload()", 1000 );
    }*/
}() );

// str = '<b><div id="mmmm" style="border 1px;">xxxxx</div></B>' ;
// document.write( str );

