/* friedenschauplätze */
div_content = "";
div_show = "";
// var für anzeige von inhalt 
last_content = "";
last_id = "";
last_lime = 0;
// aufklapptext
zh = 14;



/******* ajax *********/
//  anzeige funktionen
function content_zeigen(page,id, divc, divs) {
    div_content = divc;
    div_show = divs;
    last_content = page;
    last_id = id;
    if(page.indexOf("html") >-1) page = "stat.php?"+getsp+"_"+page;
  var myAjax = new Ajax.Request(
    page,
    { method: 'GET', 
    parameters: id,
    onComplete: zeige_dat }
  );
}
function zeige_dat( originalRequest ) {
   //alert(div_id);
   $(div_content).innerHTML = originalRequest.responseText;
   $(div_show).show();
   //ausklapp text
   initDesc();
   // nach oben scrollen
   if(last_id.indexOf('pid') > -1) {
       var lip = last_id.split('&');
       var stp = "pro"+lip[0].substr(4);
       //alert(stp);
       st(stp);
   }
   else st(false);
   // karte bewegen und Eintrag anzeigen
   moma();
}

function st(st){
    if(st) {
	$('content_wrap').scrollTop = ($(st).cumulativeOffset()[1]-$('content_wrap').cumulativeOffset()[1])+6;
	//alert( $(st).cumulativeOffset()[1]+" - "+$('content_wrap').cumulativeOffset()[0]);
    }
    else $('content_wrap').scrollTop = 0;
}

/** zoom **/
//init zoom 
ws = new Array(1000, 1500, 2500, 4000, 6000, 9000);
hs = new Array(570, 855, 1425, 2280, 3420, 5130);
s_in = 2;
w_init = 2500;
s_step = 100;
steps = 20;
w_act = w_init;
// offset position im browserfenster
def_zx = 700;
def_zy = 340;
// aktuelle position
act_x = 0;
act_y = 0;

function zoom(scale){
    //alert(scale);
    //scalieren
    if(scale == undefined) $('map2500').show();
    else if(scale > 1) {
    	for(var i=0;i<ws.length;i++) if(ws[i] == scale) s_in = i;
    }
    else if(scale) {
		if(s_in< (ws.length -1)) {
	    	s_in++;
		} else return;
    }
    else {
		if(s_in > 0) {
	    	s_in--;
		} else return;
    }
    // alle maps aus
	for(var i=0;i<ws.length;i++) {
		var mapid = "map"+ws[i];
		$(mapid).hide();
    }
    w_act = ws[s_in];
    h_act = hs[s_in];
    $('wmap').setStyle({width: w_act});
    $('wmap').setStyle({height: h_act});
    //alert(s_in);
    
    /*if(scale != "init") {
	document.images['map'].src = nema.src;
    }*/
    // map anschalten
    var mapon = "map"+ws[s_in];
    $(mapon).show();
    
    cntr();
}


/*function zoom(scale){
    //alert(scale);
    //scalieren
    if(scale == "init");
    else if(scale) {
	s_act += (s_step+(20*steps));
	steps++;
	}
    else {
	steps--;
	s_act -= (s_step+(20*steps));
	}
    $('wmap').setStyle({width: s_act});
    // alert(s_act);
    cntr();
}*/

function cntr(xp,yp){
    //alert("cntr"+xp+" ,"+yp+", "+s_act);
    // irgendwann wirds zu groß, ca. 1:20
    //factor
    if(xp){
	nx = xp;
	act_x = xp;
	}
    else nx = act_x;
    if(yp){
	ny = yp;
	act_y = yp;
	}
    else ny = act_y;
    var fac = w_act/w_init;
    //alert("cntr"+act_x+" ,"+act_y+" ,"+fac+", "+(act_x*fac));
    nx = Math.round((-nx*fac))+def_zx;
    ny = Math.round((-ny*fac))+def_zy;
    
    $('wmap').setStyle({left: nx, top: ny});
    
}

function move(){
    drag = new Draggable('wmap', {
	stareffect: false, 
	endeffect: false, 
	zindex: false,
	onEnd: function() {
	    var co = $('wmap').cumulativeOffset();
	    dx = co.shift();
	    dy = co.shift();
	    
	    var fac = w_act/w_init;
	    
	    act_x = Math.round((-dx+def_zx)/fac);
	    act_y = Math.round((-dy+def_zy)/fac);
	    //alert("x"+act_x+", y"+act_y+", "+fac);
	}
    });
}

function moma(momaid, off){
    // eintrag anzeigen
    // z-index setzen
    if(momaid == undefined) return;
    var mmid = momaid;
    var smi;
    //alert(mmid);
    for(i=0;i<mait.length;i++){
	smi = "mit"+mait[i][1];
	var aa = $(smi).ancestors();
	var fa = aa.shift();
	// mit off kommt die did
	if(off){
	    if(mait[i][1] != mmid){
		$(smi).hide();
		fa.setStyle("z-index: 20");
		continue;
	    }
	    else {
		$(smi).show();
		fa.setStyle("z-index: 21");
	    }
	} 
	// ohne off dann kommt die gpid
	else {
	    if(mait[i][0] == mmid){
		$(smi).show();
		fa.setStyle("z-index: 21");
		//alert(mmid);
		if(mait[i][2] == 1 & !off) cntr(mait[i][3],mait[i][4]);
	    } else {
		$(smi).hide();
		fa.setStyle("z-index: 20");
	    }
	}
    }
}

/** content scroll resize **/
window.onresize = versch;

function nh_re() {
    //alert("v");
    var endcont;
    
    if (self.innerHeight) // all except Explorer
    {
	endcont = self.innerHeight;
    }
    else if (document.documentElement && document.documentElement.clientHeight)
	// Explorer 6 Strict Mode
    {
	endcont = document.documentElement.clientHeight;
    }
    else if (document.body) // other Explorers
    {
	endcont = document.body.clientHeight;
    }
    //alert(endcont);
    nh = endcont;
    //alert(nh);
    return nh;
    
}

function versch(Ereignis) {
    nh = (nh_re() < 60) ? 60 : nh_re();

    //document.getElementById('content').style.height = nh;
    nhc = nh-104;
    nhl = nh-236;
    //alert($('liste_menu').getHeight());
    nh_opli = nhl-$('liste_menu').getHeight() -25;
    //$('content').setStyle({height: nhc });
    $('content_wrap').setStyle({height: nhc });
    $('liste').setStyle({height: nhl });
    $('op_li').setStyle({height: nh_opli });
    
}

/** highlite menueinträge **/
function li_me(id, n){
    last_lime = n;
    for(i=1;i<=lime_all;i++) {
	mi = id + i;
	//alert(mi);
	if($(mi).hasClassName('act')){
	    //alert("aus"+mi);
	    $(mi).toggleClassName('act');
	}
    }
    if(n == false) return;
    if(!$(id+n).hasClassName('act')) $(id+n).toggleClassName('act');
}


/** sprachumschaltung mit richtigem inhalt **/
function spum(nsp){
    window.location.href = "index.php?sp="+nsp+"&lc="+last_content+"&ll="+last_lime+"&lid="+last_id+"&sa="+w_act+"&ax="+act_x+"&ay="+act_y;
}

/** preloader maps **/
function pre_load(){
    /*map1000.src = "bilder/map1000.gif";
    map1500.src = "bilder/map1500.gif";
    map2500.src = "bilder/map2500.gif";
    map4000.src = "bilder/map4000.gif";
    map6000.src = "bilder/map6000.gif";
    map9000.src = "bilder/map9000.gif";*/
}
    
/** image galerie **/
function img_ss(idiv,hid,sid){
    h = idiv+hid;
    $(h).hide();
    s = idiv+sid;
    $(s).show();  
}

/* aufklapptext */
function initDesc(){
    var dt = $(div_content).adjacent('div.cont_dscr');
    dt.each(function(node){
      //alert(node.id + ': ' + $(node.id).getHeight());
      if($(node.id).getHeight() >160){
	  $(node.id).setStyle("height:160px");
	  var am = node.id+"_auf";
	  $(am).show();
      }
      
   });
}

function az(id,auf){
    var ida = id+"_auf";
    var idz = id+"_zu";
    if(auf) {
	$(id).setStyle("height:auto");
	$(ida).hide();
	$(idz).show();
    } else {
	$(id).setStyle("height:160px");
	$(idz).hide();
	$(ida).show();
    }
}
	
    
