$(function(){
    /***************************************************************************
		 *  Reverse Order
		 **************************************************************************/
    $.fn.reverseOrder = function() {
      return this.each(function() {
        $(this).prependTo( $(this).parent() );
      });
    };

    /***************************************************************************
		 *  SUB - MENU
		 **************************************************************************/
    var active = $('#menu > ul > li.active > ul > li.active');
    if(active.length == 1)
    {
      var parent = active.parent();
      $('#menuActive').html($('<ul>').html($(parent.html())))
      $('#menuActive li').each(function() {
        $(this).prepend('<div>');
      });
      $('#menuActive li').reverseOrder();
      $('#menuActive').show();
    }

    var subActive = $('#menu > ul > li.active > ul > li.active ul');

    if(active.length != 1 && subActive.length != 1)
      subActive = $('#menu > ul > li.active ul');

    

    if(subActive.length == 1)
    {
      var parent = subActive.parent();
      $('#sub-page').html($('<ul>').html(subActive.html()))
      $('#sub-page li').each(function() {
        $(this).prepend('<div>');
      });
      $('#sub-page').show();
    }
    /***************************************************************************
		 *  MENU
		 **************************************************************************/
		function onAnimate(show) {
				//$(this).fadeIn('slow').show();
				if (show) {
    			$(this).hide();
				} else {
					$(this).show();
				}
			}
    $('ul.jd_menu').jdMenu({});
    var opener = function(){
			href = $(this).find('> a').attr('href');
			if(href != '' && href !='#' && href!= undefined)
				window.location = href;
		}
		$('#menu ul > li').click(opener)
    $('#menu > li > ul > li').click(opener)
		/***************************************************************************
		 *  in Field Label
		 **************************************************************************/
		$("label.infield").inFieldLabels();
		/***************************************************************************
		 *  Partners
		 **************************************************************************/
    if($('body#partners').length == 1)
    {
      $('div.halfBox > ul > li').each(function(){
        var item = $(this);
        var img = item.find('img');
        if(img.length == 1)
        {
          item.css('background-position', '2px '+parseInt(img.height()/2 - 3) + 'px');
        }
          
      })
    }
		/***************************************************************************
		 *  News
		 **************************************************************************/
    if($('body#news').length == 1)
    {
      $('.news-year-item').each(function(){
        var item = $(this);
        var event = item.find('.news-event');
        var news = item.find('.news-news');
        
        var date = item.find('.news-date');
        var maxHeight = Math.max(event.height(), news.height())

        
        date.css('margin-top',parseInt(maxHeight/2)-10 + 'px');
        item.find('.news-box').height(maxHeight);
      })
      
    }

		/***************************************************************************
		 *  PUBLICATION
		 **************************************************************************/
//    if($('body#publicationspage').length == 1)
//    {
//      var ul = $('<ul>').html($('#publication-categorie').html())
//      $('#sub-page').html(ul).show();
//    }

		/***************************************************************************
		 *  SHADOWBOX
		 **************************************************************************/
    Shadowbox.init({
        handleOversize: "resize",
        modal: true
    });


})



