/*==================================================*
 $Id: gkutil.js ver 20090624
 Copyright 20093 gk@techtrade.se
 http://www.techtrade.se/

 *==================================================*/

// ---------------------------------------------------------------
// yet another version by John Middlemas Apr 16, 2009 10:01 AM
// http://haacked.com/archive/2006/04/06/StopTheWindow.OnloadMadness.aspx
//
// usage:
//   addWinOnLoad(myInitFunction);
// or to pass arguments
//   addWinOnLoad(function(){myInitFunction(arg1)});

function addWinOnLoad(func) {
  if(window.addEventListener && !window.opera) { 
    // Firefox 1.5+, Gecko/Mozilla 1.0.1+, Konqueror, Safari 3.0
    window.addEventListener('load', func, false)
  } else if (window.attachEvent) {
    // Microsoft IE 5+, Opera 8.0+
    window.attachEvent('onload', func)
  } else { // Incomplete solution
    // Add func to any existing window.onload.
    // Any later inconsiderate window.onload can
    // overwrite the window.onload set here
//  alert('hejsan');
    var o=window.onload
    window.onload = function() { o ? o() : o;func() }
  }
  return
}
// ---------------------------------------------------------------


// ---------------------------------------------------------------
// adding flashing effect to SPAN elements
// by gk 2009-06-24 22:18
//
// usage:
//   <span class="flashing">slowly flashing text</span>
// ---------------------------------------------------------------


function doFlash(){
//	flash+=dflash;
//	dflash=(flash<0||flash>255)?-dflash:dflash;
//	flash=Math.max(0,flash);
//	flash=Math.min(255,flash);

	flash+=dflash;
	if (flash <= 8 )
  	flash+=dflash*4;
	if (flash <= 0 ) {
	  flash = 0;
	  dflash = flashStep;
	} else if (flash >= 15 ) {
	  flash = 15;
	  dflash = -flashStep;
	}
	
//	flashClass.style.color="rgb("+flash+","+flash+","+flash+")";

//var flashColor = flash*65536 + flash*256 + flash;                          //fungerar EJ i FF
//var flashColor = "rgb(" + flash + ", " + flash + ", " + flash + ")";
//  var flashColor = '#' + (flash*65536 + flash*256 + flash).toString(16);

//var flashColorHex = '000000' + (flash*65536 + flash*256 + flash).toString(16);
//var flashColor = '#' + flashColorHex.substr(flashColorHex.length - 6);

//var flashHex = (((flash < 16) ? '0' : '') + flash.toString(16)).substr(0,1);
//var flashHex = ((flash < 16) ? '0' : '') + flash.toString(16);
  var flashHex = flash.toString(16);
  var flashColor = '#' + flashHex + flashHex + flashHex;


//  document.getElementById("flashElement1").style.color = flashColor;
//  document.getElementById("orTotals").style.color = flashColor;
//document.getElementById("flashElement1").style.textDecoration = 'blink';

//window.status = 'flashColor = ' + flashColor;
  for (var i=0; i<flashClassColl.length; i++) {
    flashClassColl[i].style.color = flashColor;
  }

}

function initFlashClassColl(fInt) {
  if (fInt > 10) {
    flashInterval = fInt;
  }
  var aSpans = document.getElementsByTagName("SPAN");
//for (elementx in aSpans) {
  for (var i=0;i<aSpans.length;i++) {
    var elementx = aSpans[i];
    if (elementx != null) {
      var cn = elementx.className;
      if (cn != null) {
        if ((' ' + cn + ' ').indexOf(' flashing ') > -1)  {
          flashClassColl[foundFlashElements++] = elementx;
        }
      }
    }
  }

/*  
 alert('initFlashClassColl()\n  aSpans.length=' + aSpans.length +
       '\n  foundFlashElements=' + foundFlashElements +
       '\n  flashClassColl.length=' + flashClassColl.length);
*/
  
  if (foundFlashElements > 0)  {
    flashTimer = setInterval(doFlash, flashInterval);
  }
}

var flashTimer = null;
var flashInterval = 50;              // in ms (default)
var flashClassColl = new Array();    // flashing SPAN elements
var foundFlashElements=0;
var flash=0;                         // starting from black
var flashStep=1;
var dflash=flashStep;


//addOnloadEvent(initFlashClassColl);
//addOnloadEvent(function(){initFlashClassColl(400)});

//addWinOnLoad(initFlashClassColl);
addWinOnLoad(function(){initFlashClassColl(100)});

