// ---------------  Slide-FX for Sitemap ------------------
$(document).ready(function () {

  var layer = (window.location.pathname.indexOf("/awdat")==0 || window.location.pathname.indexOf("/beratungszentrum")==0)? "/awdat":"";
  
	
  var _states = new Array();

  $('#sitemap-level-0').show();
  _states[0] = 'open';
  $('#sitemap-level-1').hide();
  _states[1] = 'closed';
  $('#sitemap-level-2').hide();
  _states[2] = 'closed';

  $('#sitemap-toggle-0').click( function () {
    if (_states[0] == 'closed') {     
      $('#sitemap-level-0').slideDown('fast');
      _states[0] = 'open';      
      $('#sitemap-status-0').attr({ src: '/img' + layer + '/btn-font-size-minus.gif'  });      
    } else {
      $('#sitemap-level-0').slideUp('fast');
      _states[0] = 'closed';
      $('#sitemap-status-0').attr({ src: '/img' + layer + '/btn-font-size-plus.gif'  });
    }
    window.setTimeout("setFooterPos();", 500); //wait for slide-effect to finish;
  });

  $('#sitemap-toggle-1').click( function () {
    if (_states[1] == 'closed') {     
      $('#sitemap-level-1').slideDown('fast');
      _states[1] = 'open';      
      $('#sitemap-status-1').attr({ src: '/img' + layer + '/btn-font-size-minus.gif'  });      
    } else {
      $('#sitemap-level-1').slideUp('fast');
      _states[1] = 'closed';
      $('#sitemap-status-1').attr({ src: '/img' + layer + '/btn-font-size-plus.gif'  });
    }
    window.setTimeout("setFooterPos();", 500);
  });

  $('#sitemap-toggle-2').click( function () {
    if (_states[2] == 'closed') {     
      $('#sitemap-level-2').slideDown('fast');
      _states[2] = 'open';      
      $('#sitemap-status-2').attr({ src: '/img' + layer + '/btn-font-size-minus.gif'  });      
    } else {
      $('#sitemap-level-2').slideUp('fast');
      _states[2] = 'closed';
      $('#sitemap-status-2').attr({ src: '/img' + layer + '/btn-font-size-plus.gif'  });
    }
    window.setTimeout("setFooterPos();", 500);
    
  });


/* ==========>> extend treeview <<============ */

  //Blendout all matched elements
  $('.flip-box').parent().children('.flip-content').hide();

  //fetch the click-event
  $('.flip-box').click( function() {

    //reset all content-boxes ( do not use... )
    //$('.flip-box').parent().children('.flip-content').slideUp('fast');
    //$('.flip-box').attr('src','img' + layer + '/btn-sitemap-plus.gif');
    
    //define short-references
    var content = $(this).parent().children('.flip-content');
    var btn = $(this);
    
    //toggle display state
    if ( content.css('display') == 'block' ) {
      content.slideUp('fast');
      btn.attr('src','/img' + layer + '/btn-sitemap-plus.gif');
    } else {
      content.slideDown('fast');
      btn.attr('src','/img' + layer + '/btn-sitemap-minus.gif');
    }
    window.setTimeout("setFooterPos();", 500);
  });
  

  setFooterPos();
  
});

function setFooterPos() {

  if( $('#main-content-area-default-page').height() > $('body').height() ) {
    $('#footer').css('top', $('#main-content-area-default-page').height() + 80 );
  } else {
    //$('#main-content-area-default-page').height( $('body').height() - 140 )
    $('#footer').css('top', $('body').height() -50 );
  }
}


