var bError = false

/* *******************

 fl_placement values
 -------------------
 1 = bottom left
 2 = bottom center
 3 = bottom right
 4 = top left
 5 = top center
 6 = top right
 7 = center screen

******************* */

// set this to one of the values above

if(typeof fl_placement === "undefined"){
    bError=true
    alert('Please set value for fl_placement above this script call')
}

function moveDiv(){
    if(bError===false){
        var myDiv = document.getElementById("flmove")
        if(myDiv!==null){
            var x = 0;
            var y = 0;

            // get the width and height of the flmove div
            var w = myDiv.style.width;
            var h = myDiv.style.height;
            var w2 = w.indexOf('px');
            var h2 = h.indexOf('px');
            if(w2 > 0){
                w = w.substr(0, w2);   
            };
            if(h2 > 0){
                h = h.substr(0, h2);   
            };


            if(fl_placement === 1 || fl_placement === 4){
                x = 10;
            }else if(fl_placement === 2 || fl_placement === 5 || fl_placement === 7){
                // get the center position
                x = (getWidth() / 2);
                x = x - (w/2);
            }else if(fl_placement === 3 || fl_placement === 6){
                x = (getWidth() - w) - 10;
            };

            // set div left posotion
            myDiv.style.left = x + "px";
	
            // set top position (if required)
            if(fl_placement > 3 && fl_placement < 7){
                myDiv.style.top = "10px";
            }else if(fl_placement === 7){
                 y = (getHeight() / 2);
                 y = y - (h/2);
                 myDiv.style.top = y + "px";
            };
        };
    };
    return true;
};

function getWidth(){
    var x = 0;
    if(self.innerHeight) {
        x = self.innerWidth;
    }else if (document.documentElement && document.documentElement.clientHeight) {
        x = document.documentElement.clientWidth;
    }else if (document.body) {
        x = document.body.clientWidth;
    };
    return x;
}

function getHeight(){
    var y = 0;
    if(self.innerHeight) {
        y = self.innerHeight;
    }else if (document.documentElement && document.documentElement.clientHeight) {
        y = document.documentElement.clientHeight;
    }else if (document.body) {
        y = document.body.clientHeight;
    };
    return y;
}






function createFlash_FLVPlayer(obj){
   if(use_cookie === false){
      cookie_onetime = null;
   }
   // if cookie is null then the user has not set it yet, so let's show the flash file
   if(cookie_onetime === null) {
      var bg_color = obj.div_bg_color
      if(bg_color===null){
         bg_color = ''
      }else{
         bg_color = 'background-color:' + bg_color +';'
      }
      // first time in lets dynamically write the flash code
      document.write("<div id='flmove' style='"+bg_color+"position:fixed; _position:absolute; bottom: 0; _top:expression(document.body.scrollTop+document.body.clientHeight-this.clientHeight); width: "+obj.flash_width+"px; height: "+obj.flash_height+"px; z-index:100; left: 470px;'><scr" + "ipt type='text/javascript'> AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0','width','"+obj.flash_width+"','height','"+obj.flash_height+"','id','FLVPlayer','src','"+obj.flash_file+"','flashvars','"+obj.flash_vars+"','quality','high','scale','noscale','name','FLVPlayer','salign','lt','pluginspage','http://www.macromedia.com/go/getflashplayer','movie','"+obj.flash_file+"','wmode','transparent' );</scr" + "ipt><nos" + "cript><object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='"+obj.flash_width+"' height='"+obj.flash_height+"' id='FLVPlayer'><param name='movie' value='"+obj.flash_file+".swf' /><param name='salign' value='lt' /><param name='quality' value='high' /><param name='scale' value='noscale' /><param name='wmode' value='transparent' /><param name='FlashVars' value='"+obj.flash_vars+"' /><embed src='"+obj.flash_file+".swf' wmode='transparent' width='"+obj.flash_width+"' height='"+obj.flash_height+"' align='bottomright' salign='lt' flashvars='"+obj.flash_vars+"' quality='high' scale='noscale' name='FLVPlayer' salign='LT' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer'></embed></object></no" + "script></div>");

      // set cookie so the next time the user will not see this flash
      // set the cookie to expire in x days
      if(use_cookie === true){
         Set_Cookie(cookie_name, 'true', day_to_expire_cookie)
      };
      if(typeof moveDiv !== "undefined"){
         moveDiv();
      };
   };
};


function scFlashVars(){
   this.use_cookie = null;
   this.cookie_name = null;
   this.day_to_expire_cookie = null;
   this.cookie_onetime = null;
   this.flash_width = null;
   this.flash_height = null;
   this.flash_file = null;
   this.flash_vars = null;
   this.div_bg_color = null;
   return this;
}



///////////////////////////////
//
// cookie functions 
//
///////////////////////////////

function Get_Cookie( check_name ) {
   // first we'll split this cookie up into name/value pairs
   // note: document.cookie only returns name=value, not the other components
   var a_all_cookies = document.cookie.split( ';' );
   var a_temp_cookie = '';
   var cookie_name = '';
   var cookie_value = '';
   var b_cookie_found = false; // set boolean t/f default f
   var i = '';
   
   for ( i = 0; i < a_all_cookies.length; i++ ) {
      // now we'll split apart each name=value pair
      a_temp_cookie = a_all_cookies[i].split( '=' );      
      
      // and trim left/right whitespace while we're at it
      cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
   
      // if the extracted name matches passed check_name
      if ( cookie_name == check_name ) {
         b_cookie_found = true;
         // we need to handle case where cookie has no value but exists (no = sign, that is):
         if ( a_temp_cookie.length > 1 ) {
            cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
         }
         // note that in cases where cookie is initialized but no value, null is returned
         return cookie_value;
         break;
      }
      a_temp_cookie = null;
      cookie_name = '';
   }
   if ( !b_cookie_found ) {
      return null;
   }
}
 
function Set_Cookie( name, value, expires, path, domain, secure ) {
   // set time, it's in milliseconds
   var today = new Date();
   today.setTime( today.getTime() );
   // if the expires variable is set, make the correct expires time, the
   // current script below will set it for x number of days, to make it
   // for hours, delete * 24, for minutes, delete * 60 * 24
   if ( expires ){
      expires = expires * 1000 * 60 * 60 * 24;
   }
   //alert( 'today ' + today.toGMTString() );// this is for testing purpose only
   var expires_date = new Date( today.getTime() + (expires) );
   //alert('expires ' + expires_date.toGMTString());// this is for testing purposes only
 
   document.cookie = name + "=" +escape( value ) +
      ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + //expires.toGMTString()
      ( ( path ) ? ";path=" + path : "" ) + 
      ( ( domain ) ? ";domain=" + domain : "" ) +
      ( ( secure ) ? ";secure" : "" );
}
 
 
function Delete_Cookie( name, path, domain ) {
   if ( Get_Cookie( name ) ) document.cookie = name + "=" +
         ( ( path ) ? ";path=" + path : "") +
         ( ( domain ) ? ";domain=" + domain : "" ) +
         ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

if(typeof moveDiv !== "undefined"){
   window.onresize = moveDiv;
}