function Numsort (a, b) {
  return a - b;
}


var myGallery;

function startGallery() {
    if(window.gallery)
    {
        try
        {
/*            var firstElement = $('myGallery').getFirst('.imageElement');
            firstElement = firstElement.getLast('img');
            firstElement = firstElement.getProperty('src');

            startPic=new Image();
            startPic.src=firstElement;
            starthoehe = startPic.height + 51;
            starthoehe = starthoehe + 'px';

            $('myGallery').setStyle('height', starthoehe);
            document.getElementById("myGallery").style.height = starthoehe;
*/
            myGallery = new gallery($('myGallery'), {
            timed:false,
            lightbox: 1
            });
            
        }catch(error){
        window.setTimeout("startGallery();",2500);
        }
    }else{
    
    window.gallery=true;
    
        if(this.ie)
        {
            window.setTimeout("startGallery();",3000);
        }else{
            window.setTimeout("startGallery();",100);
        }
    }
}

var accordion= '';

window.addEvent('domready', function() {

    accordion = new Accordion($('accordion'), 'div.toggler', 'div.element', {
    	display:false,
    	alwaysHide:true,
    	opacity: false,
        wait: false,
        
   		onActive: function(toggler, element, first){

			toggler.setStyle('background', 'url(/fileadmin/templates/img/firstBgACT.gif) no-repeat top left');
            toggler.addClass('open');
             if (!toggler.hasClass('last')){toggler.firstChild.firstChild.setProperty('href', 'javascript:void(0)');}
			element.setStyle('background', 'url(/fileadmin/templates/img/firstBgACTmid.gif) no-repeat center left');
            element.setStyle('height', 'auto');            
//            parentelement = element;
		},
		onBackground: function(toggler, element, first){
             if (!toggler.hasClass('last')){toggler.firstChild.firstChild.setProperty('href', 'javascript:void(0)');}
			toggler.setStyle('background', '');
			element.setStyle('background', '');
            toggler.removeClass('open');	
		}
    });

  function checkHash(){
    var found = false;
    var offset = 0;
    var tmp = 0;

    $$('.toggler').each(function(anchorid, i) {
      if (anchorid.hasClass('open') && !found) {
          accordion.display(offset);

//parentelement.setStyle('height', 'auto');
//height: false,
//          accordion.itemsOpen(3);
          found = true;
      } else {
        offset++;
      }
    });

    if (!found) accordion.display(-1);
  }


  
  
var x = new Chain();
x.chain(checkHash);  
x.callChain();
x.callChain.delay(500, x);

if(document.getElementById("myGallery")){
            var firstElement = $('myGallery').getFirst('.imageElement');
            firstElement = firstElement.getLast('img');
            firstElement = firstElement.getProperty('src');

            startPic=new Image();
            startPic.src=firstElement;
            starthoehe = startPic.height + 51;
            starthoehe = starthoehe + 'px';

//            window.setTimeout("$('myGallery').setStyle('height', starthoehe);",5000);
            

//alert(starthoehe);
$('myGallery').setStyle('height', '530px');
}

startGallery();

});
