function SK__PageInfo() {
   this.Set = function( opts ) {
      if ( !this.opts || typeof this.opts == 'undefined' )
            this.opts = new Object();
      for ( var key in opts ) {
         if ( !this.opts[ key ] || typeof this.opts[ key ] == 'undefined' )
            this.opts[ key ] = new Object();
         this.opts[ key ] = opts[ key ];
      }
   }
   this.Get = function( key ) {
      return this.opts[ key ];
   }
}

var THE_PAGE_IS_LOADED     = false;

////////////////////////////////////////
// Workaround for missing Array.push
// method in IE/Mac. Redefining push
// method breaks arrays on other
// browsers!!!
if ( navigator.userAgent.match( /MSIE.*Mac/ ) ) {
   Array.prototype.push = function( str_value ) {
      this[ this.length ] = str_value;
   }
}
////////////////////////////////////////

var ONLOAD_FUNCTIONS       = new Array( );

////////////////////////////////////////
function Goto(form_name, tmpl, pairs_to_set)
{
   var form = document.forms[form_name];
   form.template.value = tmpl;

   //
   // "Zero" the news_id if any...
   //
   if (typeof(form.news_id) != 'undefined') form.news_id.value = '';

   //
   // The user may pass several name & values to
   // be set, i.e. the user passes
   //    name1=value1&name2=value2&...&nameN=valueN
   // and we set
   // form.name1.value = value1, etc...
   //
   if (typeof(pairs_to_set) != 'undefined') {
      var array = pairs_to_set.split('&');
      for (var i = 0; i < array.length; i++) {
         var pair = array[i].split('=');
         var obj  = eval('form.' + pair[0]);
         if (typeof(obj) != 'undefined') {
            obj.value = pair[1];
         }
      }
   }

   if ( form.action.indexOf( "javascript:Goto" ) != -1 ) {
      form.action = tmpl;
   }

   form.submit();
}

////////////////////////////////////////
function GotoEx(window_obj, form_name, tmpl)
{
   window_obj.Goto(form_name, tmpl);
}


////////////////////////////////////////
function Trim(str)
{
   str = str.replace(/^\s*/, "");
   str = str.replace(/\s*$/, "");

   return str;
}

////////////////////////////////////////
function IsValidInteger(str)
{
   str = Trim(str);
   return str.length > 0 && IsValid(str, '0123456789-');
}

////////////////////////////////////////
function IsValidNatural(str)
{
   str = Trim(str);
   return str.length > 0 && str.indexOf('0') != 0 && IsValid(str, '1234567890');
}

////////////////////////////////////////
function IsValidReal(str)
{
   str = Trim(str);
   return str.length > 0 && IsValid(str, '0123456789.-');
}

////////////////////////////////////////
function IsValid(str, alphabet)
{
   for (var i = 0; i < str.length; i++) {
      if (alphabet.indexOf(str.charAt(i)) == -1) return false;
   }

   return true;
}

function IsValidIdentifier(str)
{
   str = Trim( str );
   return IsValid( str, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890-_' );
}

function IsValidEmail(strEmail)
{
   var validEmailRegExp = /^[a-z0-9]([a-z0-9_\-\.]*)@([a-z0-9_\-\.]+)(\.[a-z]{2,6}(\.[a-z]{2,6}){0,2})$/i;
   return validEmailRegExp.test(strEmail);
}

function IsValidSQLDate(sql_date)
{
   sql_date = Trim( sql_date );
   var parts = sql_date.split( ' ' );
   var time_str = parts.length > 1 ? parts[ 1 ] : "";
   var date_str = parts.length > 0  ?parts[ 0 ] : "";

   if ( date_str == "" ) { return false; }

   if ( time_str != "" ) {
      var time_parts = time_str.split( /:/ );
      if ( time_parts.length != 3 ) return false;
      var time_parts_valid =
             ( time_parts[ 0 ] != "" && time_parts[ 0 ] >= 0 && time_parts[ 0 ] <= 23 &&
               time_parts[ 1 ] != "" && time_parts[ 1 ] >= 0 && time_parts[ 1 ] <= 59 &&
               time_parts[ 2 ] != "" && time_parts[ 2 ] >= 0 && time_parts[ 2 ] <= 59 );
      if ( ! time_parts_valid ) return false;
   }

   var date_parts = date_str.split( /-/ );
   if ( date_parts.length != 3 ) return false;
   var date_obj = new Date( date_parts[ 0 ], date_parts[ 1 ] - 1, date_parts[ 2 ] );
   return date_parts[ 0 ] == date_obj.getFullYear() &&
         date_parts[ 1 ] == date_obj.getMonth() + 1 &&
         date_parts[ 2 ] == date_obj.getDate();
}

function SKPopup( url, width, height, options )
{
   SKPopupHandle( url, width, height, options );
}

////////////////////////////////////////
function SKPopupHandle( url, width, height, options )
{
   var left       = screen.width  / 2  - width  / 2;
   var top        = screen.height / 2  - height / 2;
   var name       = 'OpenedPopupWindow' + width + height;
   var resizable  = "yes";
   var scrollbars = "yes";
   var status     = "no";
   var toolbar    = "no";
   var menubar    = "no";
   var modal      = "no";

   if ( typeof( options ) != 'undefined' ) {
      if ( typeof( options[ 'resizable' ] ) != 'undefined' )
         resizable   = options[ 'resizable' ];

      if ( typeof( options[ 'scrollbars' ] ) != 'undefined' )
         scrollbars  = options[ 'scrollbars' ];

      if ( typeof( options[ 'left' ] ) != 'undefined' )
         left        = options[ 'left' ];

      if ( typeof( options[ 'top' ] ) != 'undefined' )
         top         = options[ 'top' ];

      if ( typeof( options[ 'name' ] ) != 'undefined' )
         name        = options[ 'name' ];

      if ( typeof( options[ 'status' ] ) != 'undefined' )
         status      = options[ 'status' ];

      if ( typeof ( options[ 'toolbar' ] ) != 'undefined' ) {
         toolbar     = options[ 'toolbar' ];
      }

      if ( typeof ( options[ 'modal' ] ) != 'undefined' ) {
         modal      = options[ 'modal' ];
      }

      if ( typeof ( options[ 'menubar' ] ) != 'undefined' ) {
         menubar    = options[ 'menubar' ];
      }
   }

   var options = 'left=' + left +
                 ',top=' + top +
                 ',width=' + width +
                 ',height=' + height +
                 ',resizable=' + resizable +
                 ',scrollbars=' + scrollbars +
                 ',toolbar=' + toolbar +
                 ',menubar=' + menubar +
                 ',modal=' + modal +
                 ',status=' + status;

   // This exception handling is for FireFox' sake only
   try {
     document.body.style.cursor = 'wait';
     var handle  = window.open( url, name, options );

      if ( handle )
         handle.focus();
      else
         AlertSystemMessage(
            "<font class=\"heading1\">Please, enable pop-up windows</font>\n" +
            "<font class=\"plain\">Your browser is set up to block pop-up windows or you have a 3rd party pop-up blocker installed. To be able to administer your site, please enable pop-ups.<br><img width=\"375\" height=\"130\" src=\"http://img.sitekreator.com/Shared/Images/popup_blocker_anim.gif\" border=\"0\" style=\"margin-top:15px\"></font>"
         );
      document.body.style.cursor = 'default';
      return handle;
   } catch (e) {
      document.body.style.cursor = 'default';
      return null;
   }
}

///////////////////////////////////////
function AreCookiesEnabled( )
{
   var test_cookie_string = "TestingIfCookiesAreEnabled=TestValue";
   document.cookie = test_cookie_string;
   if ( document.cookie.indexOf( test_cookie_string ) == -1 ) {
      return false;
   }
   document.cookie = test_cookie_string + 'Expires: ' + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
   return true;
}

function AlertNotEnabledCookiesMessage( )
{
   AlertSystemMessage(
      "<font class=\"heading1\">Your cookies are disabled</font>\n" +
      "<font class=\"plain\">Session cookies are not allowed in your browser settings. To be able to administrate your website, please allow cookies.</font>"
   );
}

function AlertSystemMessage( message )
{
   var box = document.createElement( 'div' );
   box.setAttribute( 'class', 'SystemAlertPlaceholder' );
   box.className = 'SystemAlertPlaceholder';
   box.id = 'SystemAlertPlaceholderID';
   box.setAttribute( 'id', 'SystemAlertPlaceholderID' );
   box.innerHTML = '<div class="content"><div class="text">' +
                        message + '<div class="break"></div><a href="javascript:{}" class="plain" onclick="document.body.removeChild(document.getElementById(\'SystemAlertPlaceholderID\'));">Hide This Message</a><br>' +
                   '</div></div>' +
                   '<div class="bl"></div><div class="bm"></div><div class="br"></div>';
   document.body.appendChild( box );
}

///////////////////////////////////////
function RefreshCachedImages( )
{
}
///////////////////////////////////////
function LoginToEdit( login, login_page, template_path )
{
   var options = new Array( );
   options[ 'resizable' ] = 'no';
   options[ 'scrollbars' ] = 'no';

   if ( typeof( template_path ) == 'undefined' || template_path == '' ) {
      template_path = document.location.pathname.substring( document.location.pathname.lastIndexOf( '/' ) + 1 );
      if ( template_path == "" ) {
         template_path = "index.html";
      }
   }

   SKPopup( login_page + '?template_path=' + escape( template_path ) +
                         '&domain=' + document.location.host +
                         '&target_window=top.opener' +
                         '&login=' + login, 300, 200, options );
}
///////////////////////////////////////
function Logout( page_been_published, login_cookie_name, admin_part )
{
   var url     = document.location.href;
   var begin   = url.indexOf( '?' );

   //
   // Cut off the `?...' string
   //
   if ( begin != -1 )
      url = url.substring( 0, begin );

   //
   // The url is like
   //    <Domain_URL>/<Admin/<PageName>.html
   // We must remove the "/Admin/" part
   //
   url = url.replace( admin_part, "" );
   var eua_page   = url;
   if ( !page_been_published )
      eua_page    = 'http://' + document.location.hostname + '/index.html';

   //
   // Reset the login cookie
   //
   if ( login_cookie_name != '' ) {
      DeleteCookie( login_cookie_name, "/" );
   }

   top.location.href = eua_page;
}

///////////////////////////////////////////////////
function ExecuteOnLoadFunctions( )
{
   THE_PAGE_IS_LOADED      = true;

   for ( var i = 0; i < ONLOAD_FUNCTIONS.length; i++ ) {
/*
      alert("onload funciton nr " + i);
*/
      eval( ONLOAD_FUNCTIONS[ i ] );
   }
}

///////////////////////////////////////////////////

function ExecuteOnLoadFunctions_FramedVersion(page_id)
{
   /* avmarkera förra sidan */
   eval ("si_current_" + SK__PAGE_ID + " = false;");
   LxMouseOut ("image_" + SK__PAGE_ID, SK__PAGE_ID);

   /* markera nuvarande sidan */
   SK__SetPageID(page_id);
   eval ("si_current_" + page_id + " = true;");

/*
   alert ("page_id = " + page_id);
*/
   ExecuteOnLoadFunctions();
   LxUpdateCurrent ( 1, "image_" + page_id, page_id );
   LxCurrentSubItem ( "image_" + page_id, 1, '', '' );
   MouseOver("image_" + page_id, page_id);
   
}

///////////////////////////////////////////////////
function IsPageLoaded( )
{
   return THE_PAGE_IS_LOADED;
}

///////////////////////////////////////////////////
function OpenHelp( root_dir )
{
   SKPopup( root_dir + ( root_dir.charAt(root_dir.length - 1) == '/' ? '' : '/' ) + 'help_index.html', 500, 266 );
}

///////////////////////////////////////////////////
function FixURL( url )
{
   url = Trim( url );
   url = url.replace( /\"/g, escape( '"' ) );
   url = url.replace( /\'/g, escape( "'" ) );
   url = url.replace( / /g, escape( " " ) );

   if ( url.toLowerCase( ).indexOf( '://' ) == -1 && url.toLowerCase().indexOf( 'mailto:' ) != 0 ) {
      if ( url.indexOf( '@' ) != -1 && url.indexOf( '.' ) != -1 ) {
         //
         // This is an email
         //
         return 'mailto:' + url;
      } else {
         return 'http://' + url;
      }
   }

   return url;
}

///////////////////////////////////////////////////
function ScrollTop () {
   window.scrollTo( 0, 0);
}

///////////////////////////////////////////////////
function GetCurrentLocationFileName () {
   var loc = document.location.pathname;
   return loc.substring( loc.lastIndexOf('/') + 1, loc.length );
}


var MOUSEOVERS       = {};
var MOUSEOUTS        = {};
var SK__PAGE_ID      = new Array();

function MouseOver(image_name, layer_name)
{
   if ( !IsPageLoaded( ) )
      return;

   var _document  = document;

   if ( !document.all && typeof( layer_name ) != 'undefined' ) {
      _document   = ( new Layer( layer_name ) ).Document;
   }

   if ( typeof _document.images[image_name] != 'undefined' ) {
      if ( typeof( MOUSEOVERS[ image_name ] ) != 'undefined' ) {
         _document.images[image_name].src = MOUSEOVERS[ image_name ].src;
      } else {
         _document.images[image_name].src = eval( image_name + '_h' ).src;
      }
   }
}

function MouseOut(image_name, layer_name)
{
   if ( !IsPageLoaded( ) )
      return;

   var _document  = document;

   if ( !document.all && typeof( layer_name ) != 'undefined' ) {
      _document   = ( new Layer( layer_name ) ).Document;
   }

   if ( typeof _document.images[image_name] != 'undefined' ) {
      if ( typeof( MOUSEOUTS[ image_name ] ) != 'undefined' ) {
         _document.images[image_name].src = MOUSEOUTS[ image_name ].src;
      } else {
         _document.images[image_name].src = eval( image_name ).src;
      }
   }
}

function MouseClick(image_name, template)
{
   if ( !IsPageLoaded( ) )
      return;

   document.ObjEditForm.current_highlighted_image_name.value  = image_name;

   Goto('ObjEditForm', template);
}

function SK__ImageHL(cfg)
{
   MOUSEOUTS[cfg.name]     = new Image();
   MOUSEOUTS[cfg.name].src = cfg.base;

   MOUSEOVERS[cfg.name]     = new Image();
   MOUSEOVERS[cfg.name].src = cfg.base + ( cfg.base.charAt( cfg.base.length - 1 ) == '&' ? "" : "&" ) + "over=1";
}

function SK__CurrentItem(cfg)
{
   // Must be invoked after SK__ImageHL
   if (cfg.link == SK__PAGE_ID) {
      MOUSEOUTS[cfg.name] = MOUSEOVERS[cfg.name];
      var old_onload = window.onload;
      window.onload = function( ) {
         if ( old_onload ) {
            old_onload( );
         }
         MouseOver(cfg.name);
      };
   };
}

function SK__SetPageID(id)
{
   SK__PAGE_ID = id;
}

function SK__IsCurrentPage(link_id)
{
   return link_id == SK__PAGE_ID;
}

///////////////////////////////////////////////////////////////////////////////
//
// Module:           layer.js
//
///////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////
//
// C O N S T A N T S
//
///////////////////////////////////////////////////////////////////////////////
var NN_4          = (document.layers)  ? 1 : 0;                         // Netscape Navigator 4
var IE            = (document.all)     ? 1 : 0;                         // Internet Explorer
var NN_6          = (!document.all && document.getElementById) ? 1 : 0; // Netscape Navigator 6
var VISIBLE       = NN_4 ? "show" : "visible"; /// FIX
var HIDDEN        = NN_4 ? "hide"  : "hidden";
var DISPLAY_ON    = "block";
var DISPLAY_OFF   = "none";
var LAYER__IS_NETSCAPE = (navigator.appName.indexOf( "Explorer" ) == -1);
var LAYER__NETSCAPE_TIME_PATCH_COEFFICIENT           = NN_4  ? 0 : 0;



///////////////////////////////////////////////////////////////////////////////
//
// G L O B A L S
//
///////////////////////////////////////////////////////////////////////////////
var inited_mouse_actions      = false;
var LAYERS_HASH               = {};   // where all layers will be stored
                                                // also having some properties for each layer
var old_mouse_pos             = new Object( );
old_mouse_pos.left            = 0;
old_mouse_pos.top             = 0;

var allow_default_dragging    = false;

//
// Those pointers to functions below will be used in case the
// `allow_default_dragging' variable is `true' and none of the draggable
// layer is being currently dragged
//
var default_mousedown         = null;
var default_mousemove         = null;
var default_mouseup           = null;

///////////////////////////////////////////////////////////////////////////////
//
// P U B L I C    F U N C T I O N S
//
///////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////
//
// Function:            Layer
//
// Description:         Constructs a `Layer' object
//
// Parameters:          layer_name    - the name of the layer
//
// Returns:             a reference to the constructed object
//
///////////////////////////////////////////////////////////////////////////////
function Layer( layer_name )
{
   //
   // Re-initialize those, because when we've initialized them above
   // the `document' object may have not been initialized. This is a
   // fix for Netscape Navigator
   //
   NN_4          = (document.layers)  ? 1 : 0;                         // Netscape Navigator 4
   IE            = (document.all)     ? 1 : 0;                         // Internet Explorer
   NN_6          = (!document.all && document.getElementById) ? 1 : 0; // Netscape Navigator 6

   if ( typeof( LAYERS_HASH ) == 'undefined' )
      LAYERS_HASH   = new Array( );

   //
   // Properties
   //
   this.LayerName    = layer_name;
   this.Layer        = Layer__GetLayerObj( layer_name );
   this.LayerStyle   = Layer__GetLayerObjStyle( layer_name );
   this.Draggable    = false;

   if ( typeof( this.Layer ) == 'undefined' || typeof( this.LayerStyle ) == 'undefined' ) {
      this.Success   = false;
      return null;
   }


   //
   // Methods
   //
   this.SetPosition     = Layer__SetLayerPosition;
   this.GetPosition     = Layer__GetLayerPosition;
   this.SetVisible      = Layer__SetLayerVisible;
   this.IsVisible       = Layer__IsLayerVisible;
   this.SetDisplay      = Layer__SetLayerDisplay;
   this.Move            = Layer__Move;
   this.GetDimentions   = IE || NN_6 ? Layer__GetLayerDimentions : Layer__GetLayerDimentions_NN;
   this.SetDimentions   = IE || NN_6 ? Layer__SetLayerDimentions : Layer__SetLayerDimentions_NN;
   this.HTML            = IE || NN_6 ? Layer__HTML : Layer__HTML_NN; // FIX
   this.DocumentMargins = IE || NN_6 ? Layer__GetDocumentMargins : Layer__GetDocumentMargins_NN;
   this.Document        = IE ? document : ( NN_6 ? document : this.Layer.document );
   this.InitDrag        = Layer__InitDrag;
   this.ReleaseDrag     = Layer__ReleaseDrag;   // if the layer must be clickable the
                                                // mousedown action must not take place
   this.Maximize        = Layer__Maximize;
   this.Center          = Layer__Center;

   this.DocumentMargins();

   LAYERS_HASH[ this.LayerName ]             = this;

   this.Success   = true;

   return this;
}


///////////////////////////////////////////////////////////////////////////////
//
// Function:            Layer__DefaultDragging
//
// Description:         Sets the functions that will be used as default functions
//                      on mouse{down|move|up} if the `default_dragging' is allowed
//                      and none of the layers is currently dragged
//
// Parameters:          func_handler_mousedown     - mousedown handler
//                      func_handler_mousemove     - mousemove handler
//                      func_handler_mouseup       - mouseup handler
//
// Returns:             (nothing)
//
///////////////////////////////////////////////////////////////////////////////
function Layer__DefaultDragging( func_handler_mousedown,
                                 func_handler_mousemove,
                                 func_handler_mouseup )
{
   default_mousedown       = func_handler_mousedown;
   default_mousemove       = func_handler_mousemove;
   default_mouseup         = func_handler_mouseup;

   allow_default_dragging  = true;
}

///////////////////////////////////////////////////////////////////////////////
//
// Function:            Layer__AllowDefaultDragging
//
// Description:         Allows default dragging
//
// Parameters:          (none)
//
// Returns:             (nothing)
//
///////////////////////////////////////////////////////////////////////////////
function Layer__AllowDefaultDragging( )
{
   allow_default_dragging  = true;
}

///////////////////////////////////////////////////////////////////////////////
//
// Function:            Layer__ForbidDefaultDragging
//
// Description:         Forbids default dragging
//
// Parameters:          (none)
//
// Returns:             (nothing)
//
///////////////////////////////////////////////////////////////////////////////
function Layer__ForbidDefaultDragging( )
{
   allow_default_dragging  = false;
}



///////////////////////////////////////////////////////////////////////////////
//
// P R I V A T E    F U N C T I O N S
//
///////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////
//
// Function:         Layer__GetLayerObj
//
// Description:      Gets a reference to a layer object in the document
//
// Parameters:       layer_name     - the name of the layer
//                   nested_ref     - the parent of the layer (if `undefined',
//                                    the parent will be == `document'
//
// Returns:          Layer object reference
//
///////////////////////////////////////////////////////////////////////////////
function Layer__GetLayerObj ( layer_name, nested_ref )   {
   var layer;
   if ( NN_6 || IE ) {
      layer = document.getElementById( layer_name );
   } else if ( NN_4 ) {
      var layer_parent;
      if ( typeof( nested_ref ) != 'undefined' ) {
         layer_parent = document.layers[nested_ref].document;
      } else {
         layer_parent = document;
      }
      layer = layer_parent.layers[ layer_name ];
   }

   return layer;
}


///////////////////////////////////////////////////////////////////////////////
//
// Function:         Layer__GetLayerObj
//
// Description:      Gets a reference to a layer object in the document, but also
//                   returns a reference to the `.style' property (if any)
//
// Parameters:       layer_name     - the name of the layer
//                   nested_ref     - the parent of the layer (if `undefined',
//                                    the parent will be == `document'
//
// Returns:          Reference to the Layer object's `.style' property
//
///////////////////////////////////////////////////////////////////////////////
function Layer__GetLayerObjStyle ( layer_name, nested_ref )   {
   var layer = Layer__GetLayerObj( layer_name, nested_ref );

   if ( !layer) return;

   if ( NN_6 ) {
      layer = layer.style;
   } else if ( IE ) {
      layer = layer.style;
   } else if ( NN_4 ) {
      // do nothing...
   }

   return layer;
}


///////////////////////////////////////////////////////////////////////////////
//
// Function:         Layer__SetLayerPosition
//
// Description:      Moves the layer on a certain postion
//
// Parameters:       left     - the left coordinate (relative to the window)
//                   top      - the top coordinate
//
// Returns:          (nothing)
//
///////////////////////////////////////////////////////////////////////////////
function Layer__SetLayerPosition( left, top )
{
   this.LayerStyle.left = left + (( left + "" ).indexOf( "px" ) == -1 ? "px" : "");
   this.LayerStyle.top  = top  + (( top + "" ).indexOf( "px" ) == -1 ? "px" : "");
}

///////////////////////////////////////////////////////////////////////////////
//
// Function:         Layer__GetLayerPosition
//
// Description:      Gets the layer position
//
// Parameters:       (none)
//
// Returns:          returns an object with properties `.left' and `.top'
//
///////////////////////////////////////////////////////////////////////////////
function Layer__GetLayerPosition( )
{
   var pos = new Object();

   pos.left = parseInt( this.LayerStyle.left );
   pos.top  = parseInt( this.LayerStyle.top  );

   return pos;
}

///////////////////////////////////////////////////////////////////////////////
//
// Function:         Layer__SetLayerDimentions
//
// Description:      Sets layer dimentions
//
// Parameters:       width    - the desired width
//                   height   - the desired height
//
// Returns:          (nothing)
//
///////////////////////////////////////////////////////////////////////////////
function Layer__SetLayerDimentions( width, height )
{
   this.LayerStyle.width   = width  + (( width + "" ).indexOf( "px" ) == -1 ? "px" : "");
   this.LayerStyle.height  = height + (( height + "" ).indexOf( "px" ) == -1 ? "px" : "");
}

///////////////////////////////////////////////////////////////////////////////
//
// Function:         Layer__SetLayerDimentions_NN
//
// Description:      Sets layer dimentions (Netscape version)
//
// Parameters:       width    - the desired width
//                   height   - the desired height
//
// Returns:          (nothing)
//
///////////////////////////////////////////////////////////////////////////////
function Layer__SetLayerDimentions_NN( width, height )
{
// alert ("1 Layer__SetLayerDimentions_NN");
   this.LayerStyle.clip.width   = width  + (( width + "" ).indexOf( "px" ) == -1 ? "px" : "");
   this.LayerStyle.clip.height  = height + (( height + "" ).indexOf( "px" ) == -1 ? "px" : "");
}



///////////////////////////////////////////////////////////////////////////////
//
// Function:         Layer__GetLayerDimentions
//
// Description:      Gets the layer dimentions {left, top, width, height}
//
// Parameters:       (none)
//
// Returns:          an object with properties `.left', `.top', `.width', `.height'
//
///////////////////////////////////////////////////////////////////////////////
function Layer__GetLayerDimentions( )
{
   var dimentions       = this.GetPosition( );
   dimentions.width     = parseInt( this.LayerStyle.width );
   dimentions.height    = parseInt( this.LayerStyle.height );

   return dimentions;
}


///////////////////////////////////////////////////////////////////////////////
//
// Function:         Layer__GetLayerDimentions_NN
//
// Description:      Gets the layer dimentions {left, top, width, height} (Netscape version)
//
// Parameters:       (none)
//
// Returns:          an object with properties `.left', `.top', `.width', `.height'
//
///////////////////////////////////////////////////////////////////////////////
function Layer__GetLayerDimentions_NN( )
{
   var dimentions       = this.GetPosition( );
//   alert ("2 Layer__GetLayerDimentions_NN");

   dimentions.width     = parseInt( this.LayerStyle.clip.width  );
   dimentions.height    = parseInt( this.LayerStyle.clip.height );

   return dimentions;
}



///////////////////////////////////////////////////////////////////////////////
//
// Function:         Layer__Move
//
// Description:      Moves a layer from one position to another using a timeout,
//                   that makes the layer as animation
//
// Parameters:       start_left        - the starting left position
//                   start_top         - the starting top position
//                   end_left          - the ending left position
//                   end_top           - the ending top position
//                   timeout           - the timeout for each movement
//                   speed_coefficient - number (e.g. 2 means 2x faster...)
//                   name              - the layer name (not obligatory)
//
// Returns:          (nothing)
//
///////////////////////////////////////////////////////////////////////////////
function Layer__Move( start_left, start_top, end_left, end_top, timeout, speed_coefficient, name )
{
   var layer      = typeof( name ) == 'undefined' ? this : new Layer( name );

   if ( start_left == end_left && start_top == end_top ) {
      layer.SetPosition( start_left, start_top );
      return;
   }

   if ( typeof( speed_coefficient ) == 'undefined' ) {
      speed_coefficient       = 1;
   }

   var sign_left     = __Layer__Sign( start_left, end_left );
   var sign_top      = __Layer__Sign( start_top, end_top );

   var dleft         = __Layer__Distance( start_left, end_left );
   var dtop          = __Layer__Distance( start_top, end_top );

   var offset_left   = 1;
   var offset_top    = 1;

   if ( dleft > dtop ) {
      if ( dtop == 0 ) {
         offset_top     = 0;
         offset_left    = 1;
      } else {
         offset_top     = 1;
         offset_left    = Math.floor( dleft / dtop );
      }
   } else {
      if ( dleft == 0 ) {
         offset_top     = 1;
         offset_left    = 0;
      } else {
         offset_top     = Math.floor( dtop  / dleft );
         offset_left    = 1;
      }
   }

   if ( start_left != end_left ) {
      start_left    += speed_coefficient * sign_left * offset_left + LAYER__NETSCAPE_TIME_PATCH_COEFFICIENT;
   }

   if ( start_top  != end_top ) {
      start_top     += speed_coefficient * sign_top * offset_top;
   }

   layer.SetPosition( start_left, start_top );

   var new_sign_left     = __Layer__Sign( start_left, end_left );
   var new_sign_top      = __Layer__Sign( start_top, end_top );

   if ( sign_left * new_sign_left <= 0 && sign_top * new_sign_top <= 0 ) {
      return;
   }

   var _name    = typeof( name ) == 'undefined' ? this.LayerName : name;

   if ( timeout > 0 ) {

      window.setTimeout( 'Layer__Move(' + start_left + ', ' + start_top + ', ' + end_left + ', ' + end_top + ', ' + timeout + ', ' + speed_coefficient + ', "' + _name + '")', timeout );
   } else {
      Layer__Move( start_left, start_top, end_left, end_top, 0, speed_coefficient, _name );
   }
}


///////////////////////////////////////////////////////////////////////////////
//
// Function:         __Layer__Distance
//
// Description:      Gets the distance between two numbers
//
// Parameters:       start    - the start number
//                   end      - the end number
//
// Returns:          the distance (an absolute value)
//
///////////////////////////////////////////////////////////////////////////////
function __Layer__Distance( start, end )
{
   if ( start > 0 && end > 0 ) {
      return Math.abs( end - start );
   }

   return Math.abs( start ) + Math.abs( end );
}

function __Layer__Sign( start, end )
{
   if ( start < end )
      return 1;

   if ( start == end )
      return 0;

   return -1;
}

///////////////////////////////////////////////////////////////////////////////
//
// Function:         Layer__SetLayerVisible
//
// Description:      Sets the layer visibility
//
// Parameters:       visible     - a boolean variable
//
// Returns:          (nothing)
//
///////////////////////////////////////////////////////////////////////////////
function Layer__SetLayerVisible(visible)
{
   this.LayerStyle.visibility = visible ? VISIBLE : HIDDEN;
}

///////////////////////////////////////////////////////////////////////////////
//
// Function:         Layer__IsLayerVisible
//
// Description:      Checks if a layer is visible
//
// Parameters:       (none)
//
// Returns:          boolean value
//
///////////////////////////////////////////////////////////////////////////////
function Layer__IsLayerVisible( )
{
   return this.LayerStyle.visibility == VISIBLE;
}


///////////////////////////////////////////////////////////////////////////////
//
// Function:         Layer__SetLayerDisplay
//
// Description:      Sets the layer display to (on|off)
//
// Parameters:       visible     - a boolean variable
//
// Returns:          (nothing)
//
///////////////////////////////////////////////////////////////////////////////
function Layer__SetLayerDisplay( visible )
{
   this.LayerStyle.display       = visible ? DISPLAY_ON : DISPLAY_OFF;
}

///////////////////////////////////////////////////////////////////////////////
//
// Function:         Layer__HTML
//
// Description:      Sets an HTML body for the layer (IE version)
//
// Parameters:       code     - the HTML code to be set
//
// Returns:          (nothing)
//
///////////////////////////////////////////////////////////////////////////////
function Layer__HTML( code )
{
   this.Layer.innerHTML = code;
}

///////////////////////////////////////////////////////////////////////////////
//
// Function:         Layer__HTML_NN
//
// Description:      Sets an HTML body for the layer (Netscape version)
//
// Parameters:       code     - the HTML code to be set
//
// Returns:          (nothing)
//
///////////////////////////////////////////////////////////////////////////////
function Layer__HTML_NN( code )
{
   this.Document.open();
   this.Document.write( code );
   this.Document.close();
}


///////////////////////////////////////////////////////////////////////////////
//
// Function:         Layer__GetDocumentMargins
//
// Description:      Gets the current document mangins (for IE )and sets them into
//                   the `DocumentWidth' and `DocumentHeight' properties
//
// Parameters:       (none)
//
// Returns:          (nothing)
//
///////////////////////////////////////////////////////////////////////////////
function Layer__GetDocumentMargins()
{
   this.DocumentWidth            = document.body.clientWidth + document.body.scrollLeft;
   this.DocumentHeight           = document.body.clientHeight + document.body.scrollTop;
   this.FullDocumentWidth        = document.body.scrollWidth;
   this.FullDocumentHeight       = document.body.scrollHeight;
   this.ScrollLeft               = document.body.scrollLeft;
   this.ScrollTop                = document.body.scrollTop;
   this.WindowWidth              = document.body.clientWidth;
   this.WindowHeight             = document.body.clientHeight;
}


///////////////////////////////////////////////////////////////////////////////
//
// Function:         Layer__GetDocumentMargins_NN
//
// Description:      Gets the current document mangins (for Netscape) and sets
//                   them into the `DocumentWidth' and `DocumentHeight' properties
//
// Parameters:       (none)
//
// Returns:          (nothing)
//
///////////////////////////////////////////////////////////////////////////////
function Layer__GetDocumentMargins_NN()
{
   this.DocumentWidth            = window.innerWidth + window.pageXOffset;
   this.DocumentHeight           = window.innerHeight + window.pageYOffset;
   this.FullDocumentWidth        = this.DocumentWidth;
   this.FullDocumentHeight       = this.DocumentHeight;
   this.ScrollLeft               = window.pageXOffset;
   this.ScrollTop                = window.pageYOffset;
   this.WindowWidth              = window.innerWidth;
   this.WindowHeight             = window.innerHeight;
}



///////////////////////////////////////////////////////////////////////////////
//
// Function:         Layer__Maximize
//
// Description:      Makes the layer's width and height dimentions as wide as
//                   the window is
//
// Parameters:       (none)
//
// Returns:          (nothing)
//
///////////////////////////////////////////////////////////////////////////////
function Layer__Maximize()
{
   this.DocumentMargins( );
   this.SetDimentions( this.WindowWidth, this.WindowHeight );
}

///////////////////////////////////////////////////////////////////////////////
//
// Function:         Layer__Center
//
// Description:      Positions a layer in the center {horizontally or vertically}
//
// Parameters:       horizontally         - boolean value
//                   vertically           - boolean value
//
// Returns:          (nothing)
//
///////////////////////////////////////////////////////////////////////////////
function Layer__Center( horizontally, vertically )
{
   var pos           = this.GetPosition( );
   var dimentions    = this.GetDimentions( );

   this.DocumentMargins( );

   if ( horizontally )
      pos.left    = this.WindowWidth  / 2  - dimentions.width  / 2;
   if ( vertically )
      pos.top     = this.WindowHeight / 2  - dimentions.height / 2;

   this.SetPosition( pos.left, pos.top );
}


///////////////////////////////////////////////////////////////////////////////
//
// Function:         Layer__InitDrag
//
// Description:      Initializes the `onmousemove', 'onmousedown', 'onmouseup'
//                   functions (if they are not initialized yet) and adds the
//                   current layer to the list of draggable layers
//
// Parameters:       (none)
//
// Returns:          (nothing)
//
///////////////////////////////////////////////////////////////////////////////
function Layer__InitDrag( )
{
   if ( !inited_mouse_actions ) {

      if ( IE ) {
         document.onmousedown    = Layer__System__MOUSEDOWN;
         document.onclick        = Layer__System__MOUSEUP;
         document.onmousemove    = Layer__System__MOUSEMOVE;
      } else {
         document.onmousedown    = Layer__System__MOUSEDOWN;
         document.captureEvents(Event.MOUSEDOWN);

         document.onmouseup      = Layer__System__MOUSEUP;
         document.captureEvents(Event.MOUSEUP);

         document.onmousemove    = Layer__System__MOUSEMOVE;
         document.captureEvents(Event.MOUSEMOVE);
      }

      inited_mouse_actions       = true;
   }

   LAYERS_HASH[ this.LayerName ].Draggable = true;
}

///////////////////////////////////////////////////////////////////////////////
//
// Function:         Layer__ReleaseDrag
//
// Description:      Locks the layer for dragging. This is made because if the
//                   layer contains some link, after clicking on the link the
//                   layer may be dragged in Netscape.
//
// Parameters:       (none)
//
// Returns:          (nothing)
//
///////////////////////////////////////////////////////////////////////////////
function Layer__ReleaseDrag( )
{
   LAYERS_HASH[ this.LayerName ].Dragging = false;
}



///////////////////////////////////////////////////////////////////////////////
//
// Function:         Layer__System__MOUSEDOWN
//
// Description:      Mousedown handler
//
// Parameters:       event_obj      - event object, needed by Netscape
//
// Returns:          (nothing)
//
///////////////////////////////////////////////////////////////////////////////
function Layer__System__MOUSEDOWN( event_obj )
{
   var dragged_some        = false;
   for ( var key in LAYERS_HASH ) {
      if ( LAYERS_HASH[ key ].Draggable && Layer__System__ClickedOverLayer( LAYERS_HASH[ key ], event_obj ) ) {
         //
         // Yes this is a click over our layer... Set the `Dragging' to `true'
         // so that the `MOUSEMOVE' handle will move the layer while the mouse
         // is moving...
         //
         if ( IE )
            LAYERS_HASH[ key ].Dragging   = true;
         else
            LAYERS_HASH[ key ].Dragging   = !LAYERS_HASH[ key ].Dragging;

         dragged_some   = true;
      }
   }

   if ( !dragged_some && allow_default_dragging ) {
      var current_pos   = Layer__System__CurrentMousePosition( event_obj );
      default_mousedown( current_pos );
   }
}


///////////////////////////////////////////////////////////////////////////////
//
// Function:         Layer__System__MOUSEMOVE
//
// Description:      Mousemove handler
//
// Parameters:       event_obj      - event object, needed by Netscape
//
// Returns:          (nothing)
//
///////////////////////////////////////////////////////////////////////////////
function Layer__System__MOUSEMOVE( event_obj )
{
   var old_pos       = old_mouse_pos;  // because `Layer__System__CurrentMousePosition'
                                       // will reset the `old_mouse_pos' value
   var current_pos   = Layer__System__CurrentMousePosition( event_obj );
   var dragged_some  = false;

   for ( var key in LAYERS_HASH ) {
      if ( LAYERS_HASH[ key ].Draggable && LAYERS_HASH[ key ].Dragging ) {
         //
         // This layer has been started for dragging... Move it according
         // to the `old_mouse_pos' and the current position
         //
         LAYERS_HASH[ key ].LayerStyle.left     = parseInt( LAYERS_HASH[ key ].LayerStyle.left ) + ( current_pos.left - old_pos.left );
         LAYERS_HASH[ key ].LayerStyle.top      = parseInt( LAYERS_HASH[ key ].LayerStyle.top  ) + ( current_pos.top  - old_pos.top  );
         dragged_some = true;
      }
   }

   if ( !dragged_some && allow_default_dragging ) {
      default_mousemove( old_pos, current_pos );
   }
}


///////////////////////////////////////////////////////////////////////////////
//
// Function:         Layer__System__MOUSEUP
//
// Description:      Mouseup handler
//
// Parameters:       event_obj      - event object, needed by Netscape
//
// Returns:          (nothing)
//
///////////////////////////////////////////////////////////////////////////////
function Layer__System__MOUSEUP( event_obj )
{
   var dragged_some     = false;
   for ( var key in LAYERS_HASH ) {
      if ( LAYERS_HASH[ key ].Draggable &&
           LAYERS_HASH[ key ].Dragging ) {
         //
         // Our layer is released... Set the `Dragging' to `false' ONLY if
         // the browser is IE. In case of `Netscape' the layer will be
         // released on the next `MouseDown' event...
         //
         if ( IE )
            LAYERS_HASH[ key ].Dragging = false;

         dragged_some   = true;
      }
   }

   if ( !dragged_some && allow_default_dragging ) {
      var current_pos   = Layer__System__CurrentMousePosition( event_obj );
      default_mouseup( current_pos );
   }
}


///////////////////////////////////////////////////////////////////////////////
//
// Function:         Layer__System__ClickedOverLayer
//
// Description:      Checks if the current mouse position is over a certain
//                   layer
//
// Parameters:       layer       - a handle to a Layer object
//                   event_obj   - an event object, needed by Netscape
//
// Returns:          boolean value
//
///////////////////////////////////////////////////////////////////////////////
function Layer__System__ClickedOverLayer( layer, event_obj )
{
   var pos        = Layer__System__CurrentMousePosition( event_obj );

   //
   // For a more beautiful code...
   //
   var layer_pos     = layer.GetDimentions( );
   layer_pos.right   = layer_pos.left + layer_pos.width;
   layer_pos.bottom  = layer_pos.top  + layer_pos.height;

   return ( pos.left >= layer_pos.left && pos.left <= layer_pos.right &&
            pos.top  >= layer_pos.top  && pos.top  <= layer_pos.bottom );
}


///////////////////////////////////////////////////////////////////////////////
//
// Function:         Layer__System__CurrentMousePosition
//
// Description:      Gets the current mouse position
//
// Parameters:       event_obj         - event object, needed by Netscape
//
// Returns:          an object with `.left' and `.top' properties
//
///////////////////////////////////////////////////////////////////////////////
function Layer__System__CurrentMousePosition( event_obj )
{
   var pos     = new Object( );
   if ( IE ) {
      pos.left           = event.clientX  + document.body.scrollLeft;
      pos.top            = event.clientY  + document.body.scrollTop;
   } else {
      pos.left           = event_obj.pageX + window.pageXOffset;
      pos.top            = event_obj.pageY + window.pageYOffset;;
   }

   old_mouse_pos         = pos;

   return pos;
}


/**
 * SWFObject v1.4: Flash Player detection and embed - http://blog.deconcept.com/swfobject/
 *
 * SWFObject is (c) 2006 Geoff Stearns and is released under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 * **SWFObject is the SWF embed script formerly known as FlashObject. The name was changed for
 *   legal reasons.
 */
if(typeof deconcept=="undefined"){var deconcept=new Object();}
if(typeof deconcept.util=="undefined"){deconcept.util=new Object();}
if(typeof deconcept.SWFObjectUtil=="undefined"){deconcept.SWFObjectUtil=new Object();}
deconcept.SWFObject=function(_1,id,w,h,_5,c,_7,_8,_9,_a,_b){
if(!document.createElement||!document.getElementById){return;}
this.DETECT_KEY=_b?_b:"detectflash";
this.skipDetect=deconcept.util.getRequestParameter(this.DETECT_KEY);
this.params=new Object();
this.variables=new Object();
this.attributes=new Array();
if(_1){this.setAttribute("swf",_1);}
if(id){this.setAttribute("id",id);}
if(w){this.setAttribute("width",w);}
if(h){this.setAttribute("height",h);}
if(_5){this.setAttribute("version",new deconcept.PlayerVersion(_5.toString().split(".")));}
this.installedVer=deconcept.SWFObjectUtil.getPlayerVersion(this.getAttribute("version"),_7);
if(c){this.addParam("bgcolor",c);}
var q=_8?_8:"high";
this.addParam("quality",q);
this.setAttribute("useExpressInstall",_7);
this.setAttribute("doExpressInstall",false);
var _d=(_9)?_9:window.location;
this.setAttribute("xiRedirectUrl",_d);
this.setAttribute("redirectUrl","");
if(_a){this.setAttribute("redirectUrl",_a);}};
deconcept.SWFObject.prototype={setAttribute:function(_e,_f){
this.attributes[_e]=_f;
},getAttribute:function(_10){
return this.attributes[_10];
},addParam:function(_11,_12){
this.params[_11]=_12;
},getParams:function(){
return this.params;
},addVariable:function(_13,_14){
this.variables[_13]=_14;
},getVariable:function(_15){
return this.variables[_15];
},getVariables:function(){
return this.variables;
},getVariablePairs:function(){
var _16=new Array();
var key;
var _18=this.getVariables();
for(key in _18){
_16.push(key+"="+_18[key]);}
return _16;
},getSWFHTML:function(){
var _19="";
if(navigator.plugins&&navigator.mimeTypes&&navigator.mimeTypes.length){
if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","PlugIn");}
_19="<embed type=\"application/x-shockwave-flash\" src=\""+this.getAttribute("swf")+"\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\"";
_19+=" id=\""+this.getAttribute("id")+"\" name=\""+this.getAttribute("id")+"\" ";
var _1a=this.getParams();
for(var key in _1a){_19+=[key]+"=\""+_1a[key]+"\" ";}
var _1c=this.getVariablePairs().join("&");
if(_1c.length>0){_19+="flashvars=\""+_1c+"\"";}
_19+="/>";
}else{
if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","ActiveX");}
_19="<object id=\""+this.getAttribute("id")+"\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\">";
_19+="<param name=\"movie\" value=\""+this.getAttribute("swf")+"\" />";
var _1d=this.getParams();
for(var key in _1d){_19+="<param name=\""+key+"\" value=\""+_1d[key]+"\" />";}
var _1f=this.getVariablePairs().join("&");
if(_1f.length>0){_19+="<param name=\"flashvars\" value=\""+_1f+"\" />";}
_19+="</object>";}
return _19;
},write:function(_20){
if(this.getAttribute("useExpressInstall")){
var _21=new deconcept.PlayerVersion([6,0,65]);
if(this.installedVer.versionIsValid(_21)&&!this.installedVer.versionIsValid(this.getAttribute("version"))){
this.setAttribute("doExpressInstall",true);
this.addVariable("MMredirectURL",escape(this.getAttribute("xiRedirectUrl")));
document.title=document.title.slice(0,47)+" - Flash Player Installation";
this.addVariable("MMdoctitle",document.title);}}
if(this.skipDetect||this.getAttribute("doExpressInstall")||this.installedVer.versionIsValid(this.getAttribute("version"))){
var n=(typeof _20=="string")?document.getElementById(_20):_20;
n.innerHTML=this.getSWFHTML();
return true;
}else{
if(this.getAttribute("redirectUrl")!=""){document.location.replace(this.getAttribute("redirectUrl"));}}
return false;}};
deconcept.SWFObjectUtil.getPlayerVersion=function(_23,_24){
var _25=new deconcept.PlayerVersion([0,0,0]);
if(navigator.plugins&&navigator.mimeTypes.length){
var x=navigator.plugins["Shockwave Flash"];
if(x&&x.description){_25=new deconcept.PlayerVersion(x.description.replace(/([a-z]|[A-Z]|\s)+/,"").replace(/(\s+r|\s+b[0-9]+)/,".").split("."));}
}else{try{
var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
for(var i=15;i>6;i--){
try{
axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+i);
_25=new deconcept.PlayerVersion([i,0,0]);
break;}
catch(e){}}}
catch(e){}
if(_23&&_25.major>_23.major){return _25;}
if(!_23||((_23.minor!=0||_23.rev!=0)&&_25.major==_23.major)||_25.major!=6||_24){
try{_25=new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));}
catch(e){}}}
return _25;};
deconcept.PlayerVersion=function(_29){
this.major=parseInt(_29[0])!=null?parseInt(_29[0]):0;
this.minor=parseInt(_29[1])||0;
this.rev=parseInt(_29[2])||0;};
deconcept.PlayerVersion.prototype.versionIsValid=function(fv){
if(this.major<fv.major){return false;}
if(this.major>fv.major){return true;}
if(this.minor<fv.minor){return false;}
if(this.minor>fv.minor){return true;}
if(this.rev<fv.rev){return false;}return true;};
deconcept.util={getRequestParameter:function(_2b){
var q=document.location.search||document.location.hash;
if(q){
var _2d=q.indexOf(_2b+"=");
var _2e=(q.indexOf("&",_2d)>-1)?q.indexOf("&",_2d):q.length;
if(q.length>1&&_2d>-1){
return q.substring(q.indexOf("=",_2d)+1,_2e);
}}return "";}};
if(Array.prototype.push==null){
Array.prototype.push=function(_2f){
this[this.length]=_2f;
return this.length;};}
var getQueryParamValue=deconcept.util.getRequestParameter;
var FlashObject=deconcept.SWFObject; // for backwards compatibility
var SWFObject=deconcept.SWFObject;


var MEDIA_OBJECT_PROPS =
   [
      'src',
      'width',
      'height',
      'align',
      'style',
      'controller',
      'uimode',
      'showcontrols',
      'scale',
      'showlogo',
      'autoplay',
      'autostart',
      'loop',
      'playcount'
   ];


function MediaObject(src, width, height, align, controls, autoplay, loop, style) {
   this.html = function() {
      var ebd = [];

      // Set common properties
      ebd.src = src;

      if (width)  ebd.width  = width;
      if (height) ebd.height = height;
      if (align)  ebd.align  = align;
      if (style)  ebd.style  = style;

      // Show/hide controls
      ebd.controller    = (controls ? 'true' : 'false');
      ebd.uimode        = (controls ? 'full' :  'none');
      ebd.showcontrols  = (controls ?      1 :       0);
      ebd.scale         = 'tofit';
      ebd.showlogo      = 'false';

      // Autoplay
      ebd.autoplay   =                  (autoplay ? 'true' : 'false');
      ebd.autostart  = document.all   ? (autoplay ? 'true' : 'false'):
                                        (autoplay ?      1 :       0);
      // Loop
      ebd.loop       = (loop ? 'true' : 'false');
      ebd.playcount  = (loop ? 999999 :       1);

      // Build embed element
      var chunks = ['<embed'];
      // Add embed attributes
      for (var idx=0; idx < MEDIA_OBJECT_PROPS.length; idx++) {
         var prop = MEDIA_OBJECT_PROPS[idx];
         if (prop in ebd) {
            chunks.push(prop + '="'+ebd[prop]+'"');
         }
      }
      chunks.push('/>');

      return chunks.join(' ');
   }
   this.write = function() {
      document.write(this.html());
   }
}


var CVI_PENDING   = [];
var CVI_LOADED    = false;
var CVI_LOADER    = null;

var CVI_EFFECTS   = {
   reflex: function(image, options) {
      cvi_reflex.add(image, options);
   },
   instant: function(image, options) {
      cvi_instant.add(image, options);
   }
};

function ApplyImageEffect(image) {
   /* Schedule image for effect application */
   if (image) {
      var config = null;
      try {
         eval('config = ' + image.getAttribute('options'));
      } catch (ex) {
         /* Leave configuration as null */
      }
      CVI_PENDING.push([image,config]);
   }

   if (CVI_LOADED) {
      var curr;
      /* Apply image effect on pending images */
      while (curr = CVI_PENDING.pop()) {
         var image  = curr[0];
         var config = curr[1];
         if (config && config.name in CVI_EFFECTS) {
            /* Apply effect on current image */
            CVI_EFFECTS[config.name](curr[0], curr[1]);
         }
      }
   } else {
      if (!CVI_LOADER) {
         CVI_LOADER = new Loader;
         CVI_LOADER.loadScript(CVI_LIBRARY_URL);
         CVI_LOADER.onload = function() {
            CVI_LOADED = true;
            if (document.all)
               setTimeout(ApplyImageEffect, 0);
            else
               ApplyImageEffect();
         }
         CVI_LOADER.load();
      }
   }
}


/* --- C O N S T A N T S ---------------------------------------------------- */

var LOADER_SINK = 'image_sink';

/* --- G L O B A L S -------------------------------------------------------- */

var LOADER_POOL  = [];
var LOADER_COUNT = 0;

/* --- C O N S T R U C T O R ------------------------------------------------ */

function Loader() {
   /* Properties */
   this.id           = LOADER_COUNT++;

   /* Event handlers */
   this.onerror      = null;
   this.onload       = null;
   this.onchange     = null;

   /* Object methods */
   this.loadScript   = Loader__loadScript;
   this.loadImage    = Loader__loadImage;
   this.loadElement  = Loader__loadElement;
   this.clear        = Loader__clear;
   this.load         = Loader__load;
   this.ready        = Loader__ready;
   this.merge        = Loader__merge;

   /* --- P R I V A T E  M E T H O D S -------------------------------------- */

   this.addResource  = Loader__addResource;
   this.getResource  = Loader__getResource;
   this.setLoaded    = Loader__setLoaded;
   this.setFailed    = Loader__setFailed;
   this.notify       = Loader__notify;

   /* Initialize object properties */
   this.clear();

   /* Store loader in the global loader pool */
   LOADER_POOL[this.id] = this;
}


/* --- M E T H O D S -------------------------------------------------------- */

function Loader__clear() {
   this.resources = {};
   this.pending   = 0;
   this.total     = 0;
   this.loaded    = 0;
   this.failed    = 0;
   this.preloaded = 0;
   this.prefailed = 0;
   this.loading   = false;
}

function Loader__load() {
   // Update the state of the loader
   this.loading = true;

   // Update the loaded/failed statistics
   this.loaded = this.preloaded;
   this.failed = this.prefailed;

   // Calculate how much is left to load
   this.pending -= this.loaded;
   this.pending -= this.failed;

   // Reset the pre-counters to keep them ready for next usage
   this.preloaded = 0;
   this.prefailed = 0;

   this.notify();
}

function Loader__loadElement(elem, url, sink) {
   /* Add this element as new resource */
   if (!this.addResource(url)) return;

   elem.onload  = LoadedHandler;
   elem.onerror = FailedHandler;
   elem.owner   = this.id;
   elem.url     = url;
   elem.src     = url;

   if (!sink) {
      sink = document.getElementById(LOADER_SINK);
      if (!sink) {
         sink = document.createElement('DIV');
         sink.style.display = 'none';
         sink.id = LOADER_SINK;
         document.body.appendChild(sink);
      }
   }

   /* Keep reference to the object by adding it to sink */
   sink.appendChild(elem);
}

function Loader__loadScript(url) {
   /* Create a script element to instrument the loading */
   var scriptObj = document.createElement('SCRIPT');
   scriptObj.id = "loader_gen_scr_"+this.id+"_"+genuid();
   scriptObj.onreadystatechange = function() {
      if (scriptObj.readyState == 'loaded' ||
          scriptObj.readyState == 'complete') {
         this.onload();
      }
   }

   /* Schedule the loading of this element */
   this.loadElement(scriptObj, url, document.getElementsByTagName("head")[0]);
}

function Loader__loadImage(url) {
   /* Create a script element to instrument the loading */
   var imageObj = document.createElement('IMG');
   imageObj.id = "loader_gen_img_"+this.id+"_"+genuid();

   /* Schedule the loading of this element */
   this.loadElement(imageObj, url);
}

function Loader__ready() {
   return (this.loading == false);
}

function Loader__merge(that) {
   for (var url in that.resources) {
      // Add resource found in the other object
      this.addResource(url);
      // Mark it as loaded
      this.setLoaded(url, { id : that.resources[url] });
   }
}

/* --- P R I V A T E  M E T H O D S ----------------------------------------- */


function Loader__addResource(url) {
   /* Do we need to load this */
   if (url in this.resources || !url) return false;

   /* Add script in table of resources being loaded */
   this.resources[url] = null;
   this.pending++;
   this.total++;

   this.notify();

   return true;
}

function Loader__getResource(url) {
   var resource = null;
   /* Fetch resource from its cached id (if present) */
   if (url in this.resources) {
      resource = document.getElementById(this.resources[url]);
      if (resource) {
         /* Copy the resource */
         resource    = resource.cloneNode(false);
         resource.id = 'resource_' + genuid();
      }
   }
   return resource;
}

function Loader__setLoaded(url, obj) {
   /* Don't allow multiple onload events, because this will
    * screw up the statistics and may trigger incorrect overall onload
    */
   if (this.resources[url]) return;

   /* Update the counters */
   if (this.loading) {
      this.pending--;
      this.loaded++;
   } else {
      this.preloaded++;
   }

   this.resources[url] = obj.id;

   /* Check if loading finished */
   this.notify();
}

function Loader__setFailed(url) {
   /* Update the counters */
   if (this.loading) {
      this.pending--;
      this.failed++;
   } else {
      this.prefailed++;
   }

   this.resources[url] = null;

   /* Check if loading finished */
   this.notify();
}


function Loader__notify() {
   /* No notification unless the loading has started */
   if (!this.loading) return;

   /* If user specified onchange method, this is the time to call it */
   if (this.onchange) this.onchange();

   /* Notify for finish of loading */
   if (this.pending == 0) {
      this.loading = false;
      if (this.failed == 0) {
         if (this.onload)  this.onload();
      } else {
         if (this.onerror) this.onerror();
      }
   }
}


/* --- H A N D L E R S ------------------------------------------------------ */

function LoadedHandler() {
   var owner = LOADER_POOL[this.owner];
   if (owner) {
      /* Notify the owner loader for the loaded url */
      owner.setLoaded(this.url, this);
   }
}

function FailedHandler() {
   var owner = LOADER_POOL[this.owner];
   if (owner) {
      /* Notify the owner loader for the loaded url */
      owner.setFailed(this.url);
   }
}

function genuid() {
   return (new Date).getMilliseconds()+"_"+Math.floor(Math.random() * 10000000000);
}



