/* =============================================================================
   avona Hover Image Library v1.4
   (c) 2005 by avona media GbR, Germany
   -----------------------------------------------------------------------------
   written by Thomas Werner
   http://www.avona.com
   .............................................................................

   LICENSE

   This script is commercial software exclusively licensed to avona media GbR's
   customer (from now on called licensee) of webdesign service.
   
   You, the licensee, may not rent, lease, lend, distribute, sell, or modify
   this file, unless explicitly granted by avona media GbR.
   
   In case of downloadable contents like JavaScript, Cascading Style Sheet or
   HTML files the above statement about distribution must be extended since
   these contents are electronically transfered to the website's visiting
   browser application - a circumstance that implies distribution of the
   licensed file but which is inherently legal.
   Therefore in terms of this license distribution means the intentional
   transfer of the licensed script to third parties for the sole purpose of
   sharing or providing the script itself out of the context of avona media
   GbR's webdesign service.
   
   This script is not sold to the licensee. Therefore avona media GbR retains
   all rights not explicitly granted to the licensee.
   
   In no event will avona media GbR be liable for any damages, data loss, or
   data corruption that may arise out of the use or misuse of this software.
   
   You may not modify or remove this copyright and license notice.
   =============================================================================
   Dependency: browsercheck.js
*/

// ---------------------------------------------------------------------------------------------
// The image object list
// ---------------------------------------------------------------------------------------------
var hiImages = new Array();

// ---------------------------------------------------------------------------------------------
// Image names for Demand functions 																								
// ---------------------------------------------------------------------------------------------
var hiDemandNL = new Array();
var hiDemandHL = new Array();
var hiDemandSL = new Array();

// ---------------------------------------------------------------------------------------------
// Demand function constants
// ---------------------------------------------------------------------------------------------
var hiNormal = 0;
var hiHilite = 1;
var hiPushed = 2;

// ---------------------------------------------------------------------------------------------
// A helping function for extracting a file name from a full path
// ---------------------------------------------------------------------------------------------
function hiExtractFileName ( fullPath )
{
 	lastSlash = fullPath.lastIndexOf ( "/" );
	return fullPath.substring ( lastSlash + 1, fullPath.length );
}

// ---------------------------------------------------------------------------------------------
// This function preloads a single image
// ---------------------------------------------------------------------------------------------
function hiPreload ( image )
{
	idxImage = hiExtractFileName ( image );
	eval ( "hiImages['"+idxImage+"'] = new Image();" );
	eval ( "hiImages['"+idxImage+"'].src = image;" ); 
}

// ---------------------------------------------------------------------------------------------
// This function preloads an array of images
// ---------------------------------------------------------------------------------------------
function hiPreloadArray ()
{
	arguments = hiPreloadArray.arguments;
	for ( var cnt = 0; cnt < arguments.length; cnt++ ) hiPreload ( arguments[cnt] );
}

// ---------------------------------------------------------------------------------------------
// This function replaces the image
// ---------------------------------------------------------------------------------------------
function hiReplaceImage ( element, image )
{
 	eval ( "window.document."+element+".src = hiImages['"+image+"'].src;" );
}

// ---------------------------------------------------------------------------------------------
// ---------------------------------------------------------------------------------------------
function hiReplaceImagePNG ( img, div, newImg )
{
    if ( DOMa )
    {
        var divObj = document.getElementById ( div );
        divObj.style.filter = "progid:DXImageTransform.Microsoft." +
                              "AlphaImageLoader(src='" + 
                              hiImages[newImg].src + "');";
    }
     else hiReplaceImage ( img, newImg );
}

// ---------------------------------------------------------------------------------------------
// This function registers a single <image> object with according image states + pushed state
// ---------------------------------------------------------------------------------------------
function hiRegister ( element, normal, hilite, pushed )
{
    var obj = document.getElementById ( element );
    
    var overFunc = function ()
                    {
                        eval ( "hiReplaceImage ( '"+element+"', '"+hilite+"' );" );
                    }

    var outFunc = function ()
                    {
                        eval ( "hiReplaceImage ( '"+element+"', '"+normal+"' );" );
                    }

    var downFunc = function ()
                    {
                        eval ( "hiReplaceImage ( '"+element+"', '"+pushed+"' );" );
                    }

    var upFunc = function ()
                    {
                        eval ( "hiReplaceImage ( '"+element+"', '"+hilite+"' );" );
                    }
    
    if ( DOMa )
    {
        obj.attachEvent ( 'onmouseover', overFunc );
        obj.attachEvent ( 'onmouseout', outFunc );
        
        if ( pushed )
        {
            obj.attachEvent ( 'onmousedown', downFunc );
            obj.attachEvent ( 'onmouseup', upFunc );
        }
    }
     else
    if ( DOMg )
    {
        obj.addEventListener ( 'mouseover', overFunc, false );
        obj.addEventListener ( 'mouseout', outFunc, false );
        
        if ( pushed )
        {
            obj.addEventListener ( 'mousedown', downFunc, false );
            obj.addEventListener ( 'mouseup', upFunc, false );
        }
    }
}

// -----------------------------------------------------------------------------
// MSIE workaround method for PNG images
// -----------------------------------------------------------------------------
function hiRegisterPNG ( img, div, normal, hilite, pushed )
{
    var imgObj = document.getElementById ( img );
    var divObj = document.getElementById ( div );
    
    var overFunc = function ()
                    {
                        eval ( "hiReplaceImagePNG ( '"+img+"', '"+div+"', '"+hilite+"' );" );
                    }

    var outFunc = function ()
                    {
                        eval ( "hiReplaceImagePNG ( '"+img+"', '"+div+"', '"+normal+"' );" );
                    }

    var downFunc = function ()
                    {
                        eval ( "hiReplaceImagePNG ( '"+img+"', '"+div+"', '"+pushed+"' );" );
                    }

    var upFunc = function ()
                    {
                        eval ( "hiReplaceImagePNG ( '"+img+"', '"+div+"', '"+hilite+"' );" );
                    }
    
    if ( DOMa )
    {
        divObj.attachEvent ( 'onmouseover', overFunc );
        divObj.attachEvent ( 'onmouseout', outFunc );
        
        if ( pushed )
        {
            divObj.attachEvent ( 'onmousedown', downFunc );
            divObj.attachEvent ( 'onmouseup', upFunc );
        }
    }
     else
    if ( DOMg )
    {
        divObj.addEventListener ( 'mouseover', overFunc, false );
        divObj.addEventListener ( 'mouseout', outFunc, false );
        
        if ( pushed )
        {
            divObj.addEventListener ( 'mousedown', downFunc, false );
            divObj.addEventListener ( 'mouseup', upFunc, false );
        }
    }
}

function hiRegisterOnDemand ( element, normal, hilite, pushed )
{
 	hiDemandNL[element] = normal; 	
 	hiDemandHL[element] = hilite; 	
 	hiDemandSL[element] = pushed; 	
}

function hiDemandState ( element, state )
{
 	switch ( state )
	{
	 	   case hiNormal: var img = hiDemandNL[element]; break;
	 	   case hiHilite: var img = hiDemandHL[element]; break;
	 	   case hiPushed: var img = hiDemandSL[element]; break;
	}
	hiReplaceImage ( element, img );
}

// ---------------------------------------------------------------------------------------------
// This function registers an object for beveled border effect 
// ---------------------------------------------------------------------------------------------
function hiRegisterBevel ( element, borderwidth )
{
 	 if ( DOMa )
	 {
		eval ( "window.document."+element+".onmouseover = function() { hiBevel ( '"+element+"', '"+borderwidth+"', 1 ); }" );  
  	 	eval ( "window.document."+element+".onmouseout = function() { hiBevel ( '"+element+"', '"+borderwidth+"', 0 ); }" );  
  	 	eval ( "window.document."+element+".onmousedown = function() { hiBevel ( '"+element+"', '"+borderwidth+"', -1 ); }" );  
  	 	eval ( "window.document."+element+".onmouseup = function() { hiBevel ( '"+element+"', '"+borderwidth+"', 1 ); }" );  
	   	eval ( 'document.'+element+'.style.borderStyle = "none";' );
	    eval ( 'document.'+element+'.style.margin = "'+borderwidth+'";' );
	   	eval ( 'document.'+element+'.style.padding = "0px";' );
	   	eval ( 'document.'+element+'.style.borderColor = "white black black white";' );
	 }

	 if ( DOMg )
	 {
	  	eval ( 'document.getElementById("'+element+'").onmouseover = function() { hiBevel ( "'+element+'", "'+borderwidth+'", 1 ); }' );
	  	eval ( 'document.getElementById("'+element+'").onmouseout = function() { hiBevel ( "'+element+'", "'+borderwidth+'", 0 ); }' );
	  	eval ( 'document.getElementById("'+element+'").onmousedown = function() { hiBevel ( "'+element+'", "'+borderwidth+'", -1 ); }' ); 
	  	eval ( 'document.getElementById("'+element+'").onmouseup = function() { hiBevel ( "'+element+'", "'+borderwidth+'", 1 ); }' ); 
	    eval ( 'document.getElementById ( "'+element+'" ).style.borderStyle = "none";' );
	    eval ( 'document.getElementById ( "'+element+'" ).style.margin = "'+borderwidth+'";' );
	   	eval ( 'document.getElementById ( "'+element+'" ).style.padding = "1px";' );
 	    eval ( 'document.getElementById ( "'+element+'" ).style.borderColor = "white black black white";' );
	 }
}

function hiBevel ( element, borderwidth, state )
{
 	switch ( state )
	{
	 	case -1:
			 var bstyle = "inset";
			 var bwidth = borderwidth;
			 var bmargin = "0px";
			 break;			 

	 	case 0:
			 var bstyle = "none";
			 var bwidth = "0px";
			 var bmargin = borderwidth;
			 break;			 

	 	case 1:
			 var bstyle = "outset";
			 var bwidth = borderwidth;
			 var bmargin = "0px";
			 break;

		default:
			 var bstyle = "none";
			 var bwidth = "0px";
			 var bmargin = borderwidth;
			 break;			 
	}

	if ( DOMa )
	{
	   eval ( 'document.'+element+'.style.borderStyle = "'+bstyle+'";' );
	   eval ( 'document.'+element+'.style.borderWidth = "'+bwidth+'";' );
	   eval ( 'document.'+element+'.style.margin = "'+bmargin+'";' );
	   eval ( 'document.'+element+'.style.padding = "0px";' );
	}
	
	if ( DOMg )
	{
	   eval ( 'document.getElementById ( "'+element+'" ).style.borderStyle = "'+bstyle+'";' );
	   eval ( 'document.getElementById ( "'+element+'" ).style.borderWidth = "'+bwidth+'";' );
	   eval ( 'document.getElementById ( "'+element+'" ).style.margin = "'+bmargin+'";' );
	   eval ( 'document.getElementById ( "'+element+'" ).style.padding = "1px";' );
	}	
}

function hiBlink ( timing, length, element )
{
    this.timing = timing;
    this.length = length;
    this.element = element;
    
    var state = hiNormal;
    
    var reference;
    
    function Start ( ref, normal, hilite )
    {
        reference = ref;
        hiRegisterOnDemand ( element, normal, hilite, null );
        _startBlink();
    }
    
    function _startBlink()
    {
        if ( state == hiNormal )
        {
            state = hiHilite;
            var timerlen = length;
        }
         else
        {
            state = hiNormal;
            var timerlen = timing;
        }
        
        hiDemandState ( element, state );
        
        timer = setTimeout ( reference+"._startBlink();", timerlen );
    }
    
    this.Start = Start;
    this._startBlink = _startBlink;
}
