/**
 * Dateiname       : javascript/index.js
 * Letzte Akt.     : 23.09.2008 (RP)
 * 
 * (c) Copyright SECRA GmbH
 */

/*global secra, openDiv, closeDiv */

window.aregion   = [];
window.greybox = null;
window.showreg = null;

window.onload = function() {
  var i;
  secra.Rollover.baseimagepath  = "/bitmaps/map_index/";
  secra.Rollover.postfix        = "_hover";
  secra.Rollover.fileext        = ".gif";
  for(i=0; i<4; i+=1) {
    new secra.Rollover("region_"+(i+1));
    window.aregion[i] = document.getElementById("a_region_"+(i+1));
    window.aregion[i].regnr = i;    
    window.aregion[i].onclick = function(){
    	show_reg(this.regnr + 1);
    	return false;
    };
  }

  var loadimg = new Image();
  loadimg.src = 'bitmaps/indicator.gif';  

  window.greybox = new secra.Overlayer('/bitmaps/');
  window.greybox.addClose(closeDiv);
  
  Handler.add(window, "scroll", positionMap);
  
};

function installEvents(nr){
    document.getElementById('close_'+nr).onclick = closeDiv;
	switch(nr){
		case 1:
			  document.getElementById('showhs1').onmouseover = function(){ showHoverRegion('boxhs1'); };
			  document.getElementById('hidehs1').onmouseout  = function(){ hideHoverRegion('boxhs1'); };
			  document.getElementById('showhs2').onmouseover = function(){ showHoverRegion('boxhs2'); };
			  document.getElementById('hidehs2').onmouseout  = function(){ hideHoverRegion('boxhs2'); };
			  document.getElementById('showhs3').onmouseover = function(){ showHoverRegion('boxhs3'); };
			  document.getElementById('hidehs3').onmouseout  = function(){ hideHoverRegion('boxhs3'); };
			  document.getElementById('showhs4').onmouseover = function(){ showHoverRegion('boxhs4'); };
			  document.getElementById('hidehs4').onmouseout  = function(){ hideHoverRegion('boxhs4'); };
			  document.getElementById('showhs21').onmouseover = function(){ showHoverRegion('boxhs21'); };
			  document.getElementById('hidehs21').onmouseout  = function(){ hideHoverRegion('boxhs21'); };
			  document.getElementById('showhs5').onmouseover = function(){ showHoverRegion('boxhs5'); };
			  document.getElementById('hidehs5').onmouseout  = function(){ hideHoverRegion('boxhs5'); };
			  break;
		case 2:
		      document.getElementById('showhs21_1').onmouseover = function(){ showHoverRegion('boxhs21_1'); };
			  document.getElementById('hidehs21_1').onmouseout  = function(){ hideHoverRegion('boxhs21_1'); };
			  document.getElementById('showhs5_1').onmouseover = function(){ showHoverRegion('boxhs5_1'); };
			  document.getElementById('hidehs5_1').onmouseout  = function(){ hideHoverRegion('boxhs5_1'); };
			  document.getElementById('showhs6').onmouseover = function(){ showHoverRegion('boxhs6'); };
			  document.getElementById('hidehs6').onmouseout  = function(){ hideHoverRegion('boxhs6'); };
			  document.getElementById('showhs7').onmouseover = function(){ showHoverRegion('boxhs7'); };
			  document.getElementById('hidehs7').onmouseout  = function(){ hideHoverRegion('boxhs7'); };
			  document.getElementById('showhs8').onmouseover = function(){ showHoverRegion('boxhs8'); };
			  document.getElementById('hidehs8').onmouseout  = function(){ hideHoverRegion('boxhs8'); };
			  document.getElementById('showhs9').onmouseover = function(){ showHoverRegion('boxhs9'); };
			  document.getElementById('hidehs9').onmouseout  = function(){ hideHoverRegion('boxhs9'); };
			  document.getElementById('showhs10').onmouseover = function(){ showHoverRegion('boxhs10'); };
			  document.getElementById('hidehs10').onmouseout  = function(){ hideHoverRegion('boxhs10'); };
			  document.getElementById('showhs11').onmouseover = function(){ showHoverRegion('boxhs11'); };
			  document.getElementById('hidehs11').onmouseout  = function(){ hideHoverRegion('boxhs11'); };
			  document.getElementById('showhs12').onmouseover = function(){ showHoverRegion('boxhs12'); };
			  document.getElementById('hidehs12').onmouseout  = function(){ hideHoverRegion('boxhs12'); };
			  document.getElementById('showhs13').onmouseover = function(){ showHoverRegion('boxhs13'); };
			  document.getElementById('hidehs13').onmouseout  = function(){ hideHoverRegion('boxhs13'); };
			  document.getElementById('showhs14').onmouseover = function(){ showHoverRegion('boxhs14'); };
			  document.getElementById('hidehs14').onmouseout  = function(){ hideHoverRegion('boxhs14'); };		
			  break;
		case 3:
			  document.getElementById('showhs14_1').onmouseover = function(){ showHoverRegion('boxhs14_1'); };
			  document.getElementById('hidehs14_1').onmouseout  = function(){ hideHoverRegion('boxhs14_1'); };
			  document.getElementById('showhs15').onmouseover = function(){ showHoverRegion('boxhs15'); };
			  document.getElementById('hidehs15').onmouseout  = function(){ hideHoverRegion('boxhs15'); };
			  document.getElementById('showhs16').onmouseover = function(){ showHoverRegion('boxhs16'); };
			  document.getElementById('hidehs16').onmouseout  = function(){ hideHoverRegion('boxhs16'); };
			  break;
		case 4:
			  document.getElementById('showhs17').onmouseover = function(){ showHoverRegion('boxhs17'); };
			  document.getElementById('hidehs17').onmouseout  = function(){ hideHoverRegion('boxhs17'); };
			  document.getElementById('showhs18').onmouseover = function(){ showHoverRegion('boxhs18'); };
			  document.getElementById('hidehs18').onmouseout  = function(){ hideHoverRegion('boxhs18'); };
			  document.getElementById('showhs19').onmouseover = function(){ showHoverRegion('boxhs19'); };
			  document.getElementById('hidehs19').onmouseout  = function(){ hideHoverRegion('boxhs19'); };
			  document.getElementById('showhs20').onmouseover = function(){ showHoverRegion('boxhs20'); };
			  document.getElementById('hidehs20').onmouseout  = function(){ hideHoverRegion('boxhs20'); };
			  break;
	}
}

function add_map(code){
  document.body.appendChild(this.toDOM(code));
  openDiv();
}

function toDOM(HTMLContent) {
  var docFrag = document.createDocumentFragment();
  var d = document.createElement('div');
  d.innerHTML = HTMLContent;
  while(d.firstChild) {
    docFrag.appendChild(d.firstChild);
  }
  return docFrag;
}

function show_reg(regnr){
	window.showreg = regnr;
	if(document.getElementById("region"+(regnr))){
	  openDiv();
	  return false;	  
	} else {
	  getDataReturnText("/templates_main/map_div_reg_"+(regnr)+"_cont.php", add_map);
	}
}

function openDiv() {
  var obj = document.getElementById("region"+window.showreg);
  if(obj){
  	  installEvents(window.showreg);
	  obj.style.display = "block";
	  positionMap();
	  window.greybox.show();
  }
  return false;
}

function closeDiv() {
  var obj;
  for(i=1; i<5; i+=1) {
  	obj = document.getElementById("region"+i);
  	if(obj){
	    obj.style.display = "none";
  	}
  }
  if(window.greybox){
    window.greybox.hide();
  }
}

function showHoverRegion(id){
	if(document.getElementById(id)){
		document.getElementById(id).style.visibility = 'visible';
	}
	// für alle anderen Bereiche die verstecken Funktion aufrufen
	var lid, slid;
	for(var i = 1; i < 30; i++){
		lid = 'boxhs'+i;
		if(document.getElementById(lid) && lid!=id){
			hideHoverRegion(lid);
		}
		for(var h = 1; h < 6; h++){
			slid = lid + '_' + h;
			if(document.getElementById(slid) && slid!=id){
				hideHoverRegion(slid);
			}
		}
	}
}

function hideHoverRegion(id){
	if(document.getElementById(id)){
		document.getElementById(id).style.visibility = 'hidden';
	}
}

function positionMap(){
  var obj;
  for(i=1; i<5; i+=1) {
    obj = document.getElementById("region"+i);
    if(obj){
	  obj.style.top = (Geometry.getVerticalScroll() + 100)+"px";
    }
  }
}