var g_bIE;

//checking navigator type and setting helper switch
if (navigator.appName == "Microsoft Internet Explorer") 
		g_bIE = true;
	else
		g_bIE = false;

//HeadNotes class
var HeadNotes = new Class ({
	
	initialize: function() {
		this.hNotes = new Hash();
	}
});
	
HeadNotes.implement({
	
	//new note (visible label + url) adding
	addNote: function(strLabel, strUrl) {
      
    	this.hNotes.set(strLabel, strUrl);
	},
	
	//getting hash map of registered notes
	getAllNotes: function() {
		return this.hNotes;
	},
	
	//getting count of registered notes
	getCount: function() {
		return this.hNotes.keys().length;
	}
});

	
//creating HeadNotes class working instance
var g_HeadNotes = new HeadNotes();

var g_lastRnd;

//setting new head note content
function headNoteChange() {
	
  var spnHeadNote = $('head_note');
	
	if (spnHeadNote == null)
	  return;
	  
  //getting rnd key idx, disabling two same right way idxes
  var rnd;
  do {
   rnd = Math.floor(Math.random() * g_HeadNotes.getCount());
  } while (rnd == g_lastRnd);
  g_lastRnd = rnd;
  
  var keys = g_HeadNotes.getAllNotes().keys();
  
  var strNote = keys[rnd];
  var strUrl = g_HeadNotes.getAllNotes().get(keys[rnd]);
  var strHTML = '';
  
  if (strUrl == '')
    strHTML = strNote;
  else
    strHTML = '<a href="' + strUrl + '">' + strNote + '</a>';
  
  spnHeadNote.innerHTML = strHTML;  
}

//timer stuff
var g_timer;
var g_bIsTimer = 0;
var g_timerCnt = 0;

//loop duration i seconds
var g_timerSecLoop = 4;

function timerWork()
{  
  //disable first cycle - avoid note blinking
  if (g_timerCnt > 0)
    headNoteChange();
            
  g_timer = setTimeout("timerWork()", g_timerSecLoop * 1000);
  g_timerCnt++;
}

function doTimedHeadNoteChange()
{
  if (g_bIsTimer)
    clearTimeout(g_timer);
    
  g_bIsTimer = 1;
  timerWork();
}
