




/*

1. SPEZIELL GEMEINDE
    - showDetail (geschichte)
    - hideDetail (geschichte)
    
2. UTILITIES
    - dalert
    - dalert
    - resizeThumbnailCss
    - resizeThumbnail
    - popup
    - popupAndWrite
    - overButton
    - outButton
    - overRow
    - outRow
    - catchEnter

*/


/* SPEZIELL GEMEINDE */

var headerindex = 0;
var headerarr2 = new Array();


function startHeaderChange(divid) {
    window.setTimeout("changeHeader('" + divid + "');", 10000);
}

function changeHeader(divid) {

    if (headerarr2 != null) {
        
        if (headerarr2.length > 1 && headerarr2.length > headerindex) {
            var condiv = $(divid);
           
            if (condiv != null) {
               

                var headerarr = new Array();
                condiv.style.backgroundImage = "url(" + headerarr2[headerindex] + ")";
                headerindex++;

                if (headerindex >= headerarr2.length)
                    headerindex = 0;


                window.setTimeout("changeHeader('" + divid + "');", 10000);
            }
        }
    }
}

function checkScreenSize()
{
    
        
        if(window.screen.width <= 1024)
        {
            $('masterdiv').style.height = "595px";
            
            if($('leftarea') != null)
                $('leftarea').style.top = "16px";
                
            if($('rightarea') != null)
                $('rightarea').style.top = "16px";
                
             if($('fullarea') != null)
                $('fullarea').style.top = "16px";
            
            if($('topnavigation') != null)
                $('topnavigation').style.top = "1px";
                
            $('footer').style.top = "583px";
            
            if($('fakescrollbar') != null)
                $('fakescrollbar').style.top = "16px";
        }

}


function menu(id, level)
{
    this.id = id;
    this.level = level;
}


var openmenus = new Array();


var last = null;

var mySlide = null;
var toelem = null;

function slideMenu(div, level, id)
{
    
    var submenu =  $('sub' + id);
    var fixmenu = $('menulevel' + (level+1));
    
    if(fixmenu != null)
        fixmenu.style.display = "none";
       
    if(last != null && last.id != div.parentNode.id )
        last.style.visibility = "hidden";
        
    $('mainnavigation').addEvent("mouseleave",check);
   
    if(submenu != null)
    {
        if(last != null)
            openmenus.remove(last.id);
            
      
        last = submenu;
 
        
        submenu.style.visibility = "visible";  
       
         
//        var lastleft = submenu.getStyle("left").replace("px","");
//        
//        submenu.style.left = "0px";
//        
//       
//       
//        var fx = new Fx.Styles(submenu, {duration: 1000, wait: true});
//        
//        fx.options.transition = Fx.Transitions['Expo']['easeInOut'];
//        
//        fx.start({
//	        'left': [lastleft]
//	       
//        });
       
           
        openmenus.push(new menu(submenu.id, level+1));
   }
   
}



function check(){
   window.setTimeout('hide()',500);
}


function hide()
{
    for(var i=0;i<openmenus.length;i++)
    {
        var el = $(openmenus[i].id);
      
        if(el != null)
        {
            el.style.visibility = 'hidden';
        }
    }
    
    var m1 = $('menulevel1');
    var m2 = $('menulevel2');
   
    if(m1 != null)
        m1.style.display = 'block';
        
     if(m2 != null)
        m2.style.display = 'block';
}




var lastclass;

function mouseover(div, className)
{
    lastclass = div.className;
    div.className = className;
}

function mouseout(div)
{
    if(lastclass != null)
        div.className = lastclass;
   
    lastclass = null;
    
}



/* GALERIE */


var lastsel = null;

function onImageSet(id)
{
      var pic =  s.getImageById(id);
      $('leftarea').style.backgroundImage = "url(" + pic.url + ")";
      
      var prevdiv =   $('prev' + id);
      
      if(lastsel != null)
        lastsel.className = lastsel.className.replace("_sel","");
     
     prevdiv.className = "gal_preview_sel";
     lastsel = prevdiv;
     
     if(prevdiv.getLeft() > 1036)
        right();
     else if(prevdiv.getLeft() < 626)
        left();
}



/* BLÄTTERN */

var step = 492;  
var curr = 0;

function left()
{
  if(curr < 0)
  {
        curr += step;
      
        fx.start('left',curr);
  }
  

   setButtons();
}
      
function right()
{
    
  if(curr > -$('innercon').offsetWidth + step)
  {
        curr -= step;
       
        fx.start('left',curr);
        $('next').style.visibility = "visible";
   }
  

   setButtons();
}


function setButtons()
{
    var innerdiv = $('innercon');
    var outerdiv = $('outercon');

    if(innerdiv.getSize().x <= outerdiv.getSize().x)
    {
      $('prev').style.visibility = "hidden";
      $('next').style.visibility = "hidden";
    } else {
        $('prev').style.visibility = "visible";
        $('next').style.visibility = "visible"; 
    }
    
    // am start
    if(curr >= 0)
        $('prev').style.visibility = "hidden";
    else
        $('prev').style.visibility = "visible";
        
    // div ist ganz rechts und es geht nicht mehr weiter
    if(curr*(-1) >= (innerdiv.offsetWidth - step))
       $('next').style.visibility = "hidden"; 
    else
       $('next').style.visibility = "visible"; 
       
}








/* UTILITIES */

/* verzögerter alert */
function dalert(msg)
{
    window.setTimeout("alert('" + msg + "');",500);
}

/* verzögerter alert mit eigener zeitangabe im millisekunden */
function dalert(msg,ms)
{
    window.setTimeout("alert('" + msg + "');", ms);
}


/* This method resizes thumbnails */
function resizeThumbnailCss(img,horizontalClass,verticalClass){

if(horizontalClass == null ||horizontalClass == "")
    horizontalClass = "horizontalThumb";

if(verticalClass == null || verticalClass == "")
    verticalClass = "verticalThumb";
      
if(img != null){
		if(img.width >= img.height)
			img.className = horizontalClass; 
		else
			img.className = verticalClass;	
	}
}

/* This method resizes thumbnails */
function resizeThumbnail(img,maxWidth,maxHeight){

if(img != null){
		if(maxWidth > 0 && img.width > maxWidth)
			img.width = maxWidth; 
		
		if(maxHeight > 0 && img.height >= maxHeight)
			img.height = maxHeight; 
	}
}


/* popup */

var lastwindow = null;

function popup(url,title)
{

	var fenster2 = window.open(url, title, "left=0,top=0,menubar=0,fullscreen=1,resizable=1,status=1");	
	fenster2.focus();
}

function popupAndWrite(url,title,html,parameter, print)
{
   
    if(lastwindow != null)
        lastwindow.close();
        
	var fenster2 = window.open(url, title, parameter);	
	fenster2.document.write(html);
	fenster2.focus();
	lastwindow = fenster2;
	
	
}


/* highlighting buttons */

var isOutActive = true;

/* highlihts button on mouseover */
function overButton(img)
{
	if(img != null)
	{
		img.src = img.src.toLowerCase().replace("_off.gif","_on.gif");
	}
}

/* change to original button on mouseout */
function outButton(img)
{
	if(img != null && isOutActive)
	{
		img.src = img.src.toLowerCase().replace("_on.gif","_off.gif");
	}
}

var lastbgcolor;

/* highlights complete row on mouseover */
function overRow(tr)
{
	if(tr != null)
	{
		lastbgcolor = tr.style.backgroundColor;
		tr.style.backgroundColor = '#F0F0F0';
		
		for(var i=0;i<tr.childNodes.length;i++)
		{
			var td = tr.childNodes[i];
			td.style.backgroundColor = '#F0F0F0';
			
		}
	}
}

/* unhighlights complete row on mouseover */
function outRow(tr)
{
	if(tr != null && isOutActive)
	{
		tr.style.backgroundColor = lastbgcolor;
		
		for(var i=0;i<tr.childNodes.length;i++)
		{
			var td = tr.childNodes[i];
			td.style.backgroundColor = "";
		}
	}
}



var gAutoPrint = false; 
var gSpecialPrint = null;


/* print function */
function printscreen(divid)
{

	var printdiv = $(divid);
	
	
	if(printdiv != null && printdiv.id == "scrollbox")
	    printdiv = printdiv.childNodes[0];
    
    if(gSpecialPrint != null && gSpecialPrint != '')
        printdiv = $(gSpecialPrint);
        
    if(printdiv == null)
	    return;
	    

	var content = printdiv.innerHTML;
	
	try 
	{
	    if(getPrintContent)
	        content = getPrintContent();
	}catch(ex){} 
	
	//content = content.replace(/<\/?(script)(.|\n)*?>/gi, "");
	content = content.replace(/<script /gi, "<!--<script");
	content = content.replace(/<\/script>/gi, "</script>-->");
	
	var parameter = "menubar=yes,toolbar=yes,scrollbars=yes,statusbar=no,location=no,resizable=no,width=" + (printdiv.offsetWidth+100) + "px";
	
	var text = "<div class=\"printdiv\" style=\"width:" + printdiv.offsetWidth + "\">";
	text += "<div id=\"masterdiv2\"><div id=rightarea  style=\"font-size:11px\">" + content.replace(/headlinec/,"headerprint").replace(/headline2/,"headerprint").replace("headline","headerprint") + "</div></div>";
	text += "</div>";
	
	var today = new Date();
	popupAndWrite("","Druckversion"+today.getSeconds(),"<html><head><link href='css/vaduz.css' rel='stylesheet' type='text/css'></link><link href='css/gkview.css' rel='stylesheet' type='text/css'></link></head><body><form onsubmit='return false;'>" + text + "</form></body></html>",parameter);

}

function preZero(nr)
{
    if(nr.length == 1)
        return "0" + nr;
        
    return nr;
}

/* if enterkey is pressed than special button will be activated */
function catchEnter(evt,buttonid)
{
      if (evt.keyCode == 13)
      {
		evt.returnValue=false;
        evt.cancel = true;
        var button = $(buttonid);
        if(button != null)
            button.click();
      } 
}



