var FlvVideoPlayer_Global;
function FlvVideoPlayer(swf_fl, swf_w, swf_h, htp_x, htp_y, d_name, j_link_url)
{
    this.src = swf_fl;
    this.width = swf_w;
    this.height = swf_h;
    this.Position;
    this.Location = new this.Point();
    this.Location.X = htp_x;
    this.Location.Y = htp_y;
    this.PositionMode = 'absolute';
    this.positionFrom = 'fromBottom';
    this.positionHorizontalFrom = 'fromLeft';
    this.ReferenceID = 'cmsite_reg';
    this.RequiredVersionMajor = 9;
    this.RequiredVersionMinor = 0;
    this.needFlashString = "Flash Version " + this.RequiredVersionMajor + "." + this.RequiredVersionMinor + " is needed.<br/><a href='http://www.adobe.com/go/getflash/' target='_blank'>Get it here</a>";
    if (document.body.attachEvent) {
        this.isIE = true;
    }
    else {
        this.isIE = false;
    }
    this.ParseBrowser();
    this.backgroundImage = 'images/transparent.gif';
    this.NeedsFix = false;
    this.WriteWrapper = true;
    this.FlashVars = '';
    this.urlArray = null;
    this.anchorMode = 'static';
    this.InitialX = 0;
    this.d_name = d_name;
    this.j_link_url = j_link_url;
}
//必要
FlvVideoPlayer.prototype.Point = function (x, y)
{
    this.X = x;
    this.Y = y;
}
//必要
FlvVideoPlayer.prototype.ParseBrowser = function ()
{
    this.isNetscape = false;
    this.isFirefox = false;
    this.isIE = false;
    this.isOpera = false;
    this.isSafari = false;
    this.appName = navigator.appName;
    this.appVersion = navigator.appVersion;
    if (this.appName == "Netscape" && parseFloat(this.appVersion) > 4.7)
    {
        var uai = navigator.userAgent.indexOf("Firefox");
        if (uai !=- 1)
        {
            this.isFirefox = true;
						this.browserVersionMaj = parseInt(navigator.userAgent.charAt(uai + 8));
        }
        else {
            this.isNetscape = true;
            this.browserVersionMaj = parseFloat(this.appVersion);
        }
    }
    else
    {
        var uai = navigator.appVersion.indexOf("MSIE");
        if (uai !=- 1)
        {
            this.isIE = true;
            var temp = navigator.appVersion.split("MSIE");
						this.appVersion = parseFloat(temp[1]);
            this.browserVersionMaj = parseInt(this.appVersion);
            if (this.appVersion == 6) {
                this.Ime_no_flag = true;
                //				alert("AAA" + this.appVersion);
            }
        }
        else
        {
            var uai = navigator.userAgent.indexOf("Opera");
            if (uai !=- 1)
            {
                this.isOpera = true;
                this.browserVersionMaj = parseInt(navigator.userAgent.charAt(uai + 6));
            }
        }
    }
    if (document.compatMode == 'CSS1Compat') {
        this.isCompatible = true;
    }
    else {
        this.isCompatible = false;
    }
}
//必須
FlvVideoPlayer.prototype.el = function (e)
{
    return document.getElementById(e);
}
//必須
FlvVideoPlayer.prototype.Intialize = function ()
{
    FlvVideoPlayer_Global = this;
    this.InitialX = this.Location.X;
    if (this.ReferenceID != null && this.el(this.ReferenceID) != null) {
        this.AnchorToObjectX();
        this.LockInitialX();
    }
    if (this.anchorMode == 'static')
    {
        this.positionMode = 'fixed';
        if (this.isIE)
        {
            if (this.appVersion == 8) { }
            else
            {
                if (this.appVersion != 7 || !this.isCompatible) {
                    this.positionMode = 'absolute';
                    this.NeedsFix = true;
                }
            }
        }
        if (this.isFirefox && this.browserVersionMaj < 2)
        {
            this.positionMode = 'absolute';
            window.addEventListener('scroll', RestorePosition, false);
            window.addEventListener('size', RestorePosition, false);
        }
        this.WriteDiv();
    }
    else {
        this.positionMode = 'absolute';
        this.WriteDiv();
    }
    if (this.ReferenceID != null && this.el(this.ReferenceID) != null) {
        this.AnchorToObjectX();
    }
}
//必須
FlvVideoPlayer.prototype.CheckFlashVersion = function ()
{
    var maj = 0;
    var min = 0;
    if (navigator.plugins != null && navigator.plugins.length > 0)
    {
        if (navigator.plugins["Shockwave Flash"])
        {
            var d = navigator.plugins["Shockwave Flash"].description;
            var a = d.split(" ");
            var version = a[2];
            var a1 = version.split(".");
            maj = a1[0];
            min = a1[1];
        }
    }
    else
    {
        try
        {
            // version will be set for 7.X or greater players
            var o = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
            var d = o.GetVariable("$version");
            var a = d.split(" ");
            var version = a[1];
            var a1 = version.split(",");
            maj = a1[0];
            min = a1[1];
        }
        catch (e) { }
    }
    if (maj > this.RequiredVersionMajor || (maj == this.RequiredVersionMajor && min >= this.RequiredVersionMinor)) {
        return true;
    }
    else {
        return false;
    }
}
//必須
FlvVideoPlayer.prototype.WriteStandardContainer = function ()
{
    document.write('<div id="FlvVideoPlayer_Container" style="z-index:1000;');
    this.WritePositionStyleInfo();
    document.write('border: 0px;height:' + this.height + ';">');
}
//必須
FlvVideoPlayer.prototype.WritePositionStyleInfo = function ()
{
    document.write('position: ' + this.positionMode + '; ');
    if (this.positionFrom == 'fromBottom') {
        document.write('bottom: ');
    }
    else {
        document.write('top: ');
    }
    document.write(this.Location.Y + 'px; ');
    if (this.positionHorizontalFrom == 'fromLeft') {
        document.write('left: ');
    }
    else {
        document.write('right: ');
    }
    document.write( this.InitialX + 'px;');
    //	this.Location.X
}
FlvVideoPlayer.prototype.WriteNeedFlashContainer = function ()
{
    document.write('<div id="LayerMoviePlayer_Container" style="');
    this.WritePositionStyleInfo();
    document.write('z-index: 100;border: 0px; width:' + this.width + 'px; background-color:#FFF; padding:4px 4px 4px 4px; border:inset 3px #F00 ">');
}
//必須
FlvVideoPlayer.prototype.WriteDiv = function ()
{
    if (this.CheckFlashVersion())
    {
        if (this.WriteWrapper) {
            this.WriteStandardContainer();
        }
        if (this.Ime_no_flag) {
            //IE6は別に動作
            //alert("Ime_no_flag=" + this.Ime_no_flag);
            //this.WriteMovieObject();
        }
        else {
            this.WriteMovieObject();
        }
    }
    else {
        this.WriteNeedFlashContainer();
        this.WriteNeedFlash();
    }
    if (this.NeedsFix) {
        this.FixIEFixed();
    }
    if (this.WriteWrapper) {
        document.write('</div>');
    }
}
var shown = 0;
var lastNum = 0;
//必須
function getIEFixHeight()
{
    var loc;
    var scrollTop;
    var clientHeight;
    if ( typeof ( window.innerWidth ) == 'number' ) {
        //Non-IE
        clientHeight = window.innerHeight;
    }
    else if ( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
    {
        //IE 6+ in 'standards compliant mode'
        clientHeight = document.documentElement.clientHeight;
    }
    else if ( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        //IE 4 compatible
        clientHeight = document.body.clientHeight;
    }
    if ( typeof ( window.pageYOffset ) == 'number' ) {
        //Netscape compliant
        scrollTop = window.pageYOffset;
    }
    else if ( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
        //DOM compliant
        scrollTop = document.body.scrollTop;
    }
    else if ( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
        //IE6 standards compliant mode
        scrollTop = document.documentElement.scrollTop;
    }
    else {
        scrollTop = 0;
    }
    if (FlvVideoPlayer_Global.positionFrom == 'fromBottom')
    {
        loc = scrollTop + clientHeight - FlvVideoPlayer_Global.Location.Y - FlvVideoPlayer_Global.el('FlvVideoPlayer_Container').clientHeight ;
    }
    else {
        loc = scrollTop + FlvVideoPlayer_Global.Location.Y;
    }
    //	alert("AAA" + loc);
    //if(shown<2 && lastNum!=loc)
    //	{ alert(loc);shown++;lastNum=loc;}
    return loc;
}
//必須
FlvVideoPlayer.prototype.WriteMovieObject = function ()
{
    //alert("view_swf_A");
    this.Dimension = document.body.clientWidth;
    this.sp_wid = (Math.floor(this.Dimension - 900) / 2) + parseInt(this.width);
    if (this.sp_wid < this.width) {
        this.sp_wid = this.width;
    }
    //alert("width=" + this.width);
    //alert("sp_wid=" + this.sp_wid);
    document.write('<div id="firefox_div" style="width:' + this.sp_wid + 'px;">');
    document.write('<a href="'+this.j_link_url+'" target="_blank"><div style="float:right; width:' + this.width + 'px; z-index:1000;"><div id="' + this.d_name + '" style="margin: 0px; padding: 0px"></div></div></a><div style="clear:both"></div>');
    document.write('</div>');
}
//必須
FlvVideoPlayer.prototype.FixIEFixed = function ()
{
    if (document.body.currentStyle['backgroundImage'] == 'none')
    {
        document.body.style.backgroundImage = 'url(' + this.backgroundImage + ')';
        document.body.style.backgroundRepeat = 'no-repeat';
        document.body.style.backgroundAttachment = 'fixed';
    }
    //2009/07/16
    //this.el('FlvVideoPlayer_Container').style.setExpression('top','getIEFixHeight()');
}
/**********************************************
***********************************************/
function swf_action(act, d_name)
{
    switch (act)
    {
            //
        case 'close':
            swf_out_action('stop', d_name);
            $(d_name).style.display = 'none';
            break;
            //
        case 'f_close':
            swf_out_action('stop', d_name);
            $(d_name).style.display = 'none';
            break;
            //
        case 'open':
            $(d_name).style.display = '';
            //swf_out_action('restart',d_name);
            break;
            //ムービー終了時
        case 'mov_end':
            //$(d_name).style.display='none';
            break;
    }
    //window.event.cancelBubble = true;
}
//SWFへアクションを送る
function swf_out_action(act, d_name)
{
    //	alert(act);
    $(d_name).setMessage(act);
}
