var MxUtil      = new Object();
MxUtil.Cleaner  = new Object();
MxUtil.Flash    = function( flash_movieUrl, flash_id, flash_width, flash_height, obj_width, obj_height, flash_color, flash_params, flash_sessionId, flash_transparant ){    

    if( !document.getElementById ){
        alert("Function is not supported!!!");
        return;
    }
    this.params = new Array();
    
    this.Key_Url        = "flash.movieUrl";
    this.Key_Id         = "flash.movieId";
    this.Key_Width      = "flash.movieStageWidth"; //this is the actual width the movie was created in
    this.Key_Height     = "flash.movieStageHeight";//this is the actual width the movie was created in
    this.Key_ObjWidth   = "flash.movieWidth";
    this.Key_ObjHeight  = "flash.movieHeight";
    this.Key_Color      = "flash.color";
    this.Key_Params     = "flash.params";
    this.Key_SessionId  = "flash.web.enviroment.sessionId";
    this.Key_Transparant  = "flash.web.transparant";
    
    
    this.SetParam( this.Key_Url         , flash_movieUrl );
    this.SetParam( this.Key_Id          , flash_id );
    this.SetParam( this.Key_Width       , flash_width );
    this.SetParam( this.Key_Height      , flash_height );
    this.SetParam( this.Key_ObjWidth    , obj_width );
    this.SetParam( this.Key_ObjHeight   , obj_height );
    this.SetParam( this.Key_Color       , flash_color );
    this.SetParam( this.Key_Params      , flash_params );
    this.SetParam( this.Key_SessionId   , flash_sessionId );    
    this.SetParam( this.Key_Transparant   , flash_transparant );    
}

MxUtil.Flash.prototype = {
    SetParam:function( key, value ){        
        this.params[key] = this.IsNull(value) ? "" : value;
    },
    
    GetParam:function(key){
        return this.params[key];
    },
    
    IsNull:function(obj){
        if( obj==null || obj=="undefined" ) return true;
        else return false;
    },
    
    GetContent:function(){
        var mxScript = "";
        mxScript += "<object ";
        mxScript += "classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" ";
        mxScript += "codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\" ";
        mxScript += "width=\"" + this.GetParam(this.Key_ObjWidth)    + "\" ";
        mxScript += "height=\"" + this.GetParam(this.Key_ObjHeight)  + "\" ";
        mxScript += "id=\"" + this.GetParam(this.Key_Id) + "\" ";
        mxScript += "align=\"middle\" ";
        mxScript += ">";
        
        if(this.GetParam(this.Key_Transparant)) mxScript += "<param name=\"wmode\" value=\"transparent\" />";
        
        mxScript += "<param name=\"allowScriptAccess\" value=\"sameDomain\" /> ";
        mxScript += "<param name=\"FlashVars\" value=\"" + this.GetParam(this.Key_Params) + "\" /> ";
        mxScript += "<param name=\"movie\" value=\"" + this.GetParam(this.Key_Url) + "\" /> ";
        mxScript += "<param name=\"quality\" value=\"best\" /><param name=\"bgcolor\" value=\"" + this.GetParam(this.Key_Color) + "\" /> ";
        mxScript += "<embed name=\"" + this.GetParam(this.Key_Id) + "\" src=\"" + this.GetParam(this.Key_Url) + "\" FlashVars=\"" + this.GetParam(this.Key_Params) + "\" quality=\"best\" bgcolor=\"" + this.GetParam(this.Key_Color) + "\" width=\"" + this.GetParam(this.Key_Width) + "\" height=\"" + this.GetParam(this.Key_Height) + "\"";
        
        if(this.GetParam(this.Key_Transparant)) mxScript += " wmode=\"transparent\" ";
        
        mxScript += " align=\"left\" allowScriptAccess=\"sameDomain\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" /> ";
        
       
        mxScript += "</object>";
        //alert("mxScript:\n"+mxScript);
        return mxScript;
    },
    
    Write:function(){        
        document.write( this.GetContent() );
        
        //register movieId
        if( this.IsNull( window[this.GetParam(this.Key_Id)] ) ){            
            window[this.GetParam(this.Key_Id)] = document.getElementById(this.GetParam(this.Key_Id));
        }
        
        return true;
    },
    
    WriteToDiv:function( divId ){        
        var divContainer        = document.getElementById(divId);
        divContainer.innerHTML  = this.GetContent();
        return true;
    }
}

var MxFlash = MxUtil.Flash;

//=============================================================================================================================================================================================================================================================================================================================================================================================================================================================================//
//This code part was taken from --> SWFObject is (c) 2006 Geoff Stearns
MxUtil.Cleaner.cleanupSWFs=function(){
    if(window.opera||!document.all){return;}
    var _2d=document.getElementsByTagName("OBJECT");
    for(var i=0;i<_2d.length;i++){
        _2d[i].style.display="none";
        for(var x in _2d[i]){
            if(typeof _2d[i][x]=="function"){
                _2d[i][x]=function(){};
            }
        }
    }
};

MxUtil.Cleaner.prepUnload=function(){
    __flash_unloadHandler=function(){};
        
    __flash_savedUnloadHandler=function(){};
    
    if(typeof window.onunload=="function"){
        var _30=window.onunload;
        window.onunload=function(){
            MxUtil.Cleaner.cleanupSWFs();
            _30();
        };
    }
    else{
        window.onunload=MxUtil.Cleaner.cleanupSWFs;
    }
};


if(typeof window.onbeforeunload=="function"){
    var oldBeforeUnload=window.onbeforeunload;
    
    window.onbeforeunload=function(){
        MxUtil.Cleaner.prepUnload();
        oldBeforeUnload();
    };
    
}else{
    window.onbeforeunload=MxUtil.Cleaner.prepUnload;
}

//=============================================================================================================================================================================================================================================================================================================================================================================================================================================================================//

