// proto block
//------------

// global vars
//------------
var activeReiter;
var normBgColor;
var clickBgColor;
var overBgColor = "#CCCCCC";
var isHref = false;

var Reiterswitch = Class.create();

Reiterswitch.prototype = {
	initialize: function() {
	  if (!document.getElementsByClassName){ return; }

	  var rdivs = document.getElementsByClassName('ritema');
	  for (var i=0; i<rdivs.length; i++){
	    if( i == 0 ){
        activeReiter = rdivs[i];
        clickBgColor = $(rdivs[i]).getStyle('backgroundColor');
      }
	    var rdiv = rdivs[i];
	    Event.observe(rdiv.firstChild, 'click', function () {isHref=true;});
	    rdiv.onclick = function () {myReiterswitch.clicked(this); return false;}
	    rdiv.onmouseover = function () {myReiterswitch.over(this); return false;}
	    rdiv.onmouseout = function () {myReiterswitch.out(this); return false;}	    
	  }
	  
	  var rdivs = document.getElementsByClassName('ritem');
	  for (var i=0; i<rdivs.length; i++){
	    if( i == 0 ){
        normBgColor = $(rdivs[i]).getStyle('backgroundColor');
      }
	    var rdiv = rdivs[i];
	    Event.observe(rdiv.firstChild, 'click', function () {isHref=true;});
	    rdiv.onclick = function () {myReiterswitch.clicked(this); return false;}
	    rdiv.onmouseover = function () {myReiterswitch.over(this); return false;}
	    rdiv.onmouseout = function () {myReiterswitch.out(this); return false;}	    
	  }
  },
  clicked: function(objdiv){
    if( activeReiter != objdiv ){
      if(!isHref) myLoadbox.start(objdiv.firstChild);
      else isHref = false;
    
      $(objdiv).setStyle({backgroundColor: ''+clickBgColor+''});
      $(activeReiter).setStyle({backgroundColor: ''+normBgColor+''});
      activeReiter = objdiv;
    }
  },
  over: function(objdiv){
    if( activeReiter != objdiv ) $(objdiv).setStyle({backgroundColor: ''+overBgColor+''});
  },
  out: function(objdiv){
    if( activeReiter != objdiv ) $(objdiv).setStyle({backgroundColor: ''+normBgColor+''});
  }
}

// proto init
//-----------
function initReiterswitch() { myReiterswitch = new Reiterswitch(); }
Event.observe(window, 'load', initReiterswitch, false);

// proto end