(function ($) {
  // VERTICALLY ALIGN FUNCTION
  $.fn.vAlign = function() {
  	return this.each(function(i){
  	var ah = $(this).height();
  	var ph = $(this).parent().height();
  	var mh = Math.ceil((ph-ah) / 2);
  	$(this).css('margin-top', mh);
  	
  	});
  };
})(jQuery);

$(document).ready(function(){	

  /***********
   * For the Silder in the header [+]
   ***********/
/*
	$("#slider").easySlider({
		auto: true,
		continuous: true, 
		speed: 500,
		prevText: '',
		nextText: '',
		fx: fade
	});			
*/
    $("#slider").cycle({fx: "fade",speed: 2000});


  /***********
   * For the Silder in the header [-]
   ***********/
   
  /**********
   * Fading the mid nav [+]
   **********/     
   
  $("#mid_nav_bg").fadeTo(0,0.8);
   
  /**********
   * Fading the mid nav [-]
   **********/                 
   
   
  
  /***********
   * Hide notification boxes on click [+]
   ***********/
   
  $('.infobox').click(function() {
    $(this).slideUp();
  });
  
  /***********
   * Hide notification boxes on click [+]
   ***********/


  /***********
   * The nice buttons (by mac@homac.at) [+]
   ***********/

  //a href links
  $('a.button').each(function(){
    var bt = $(this);
    var txt = bt.text();
    bt.html("<span class='start'>&nbsp;</span><span class='txt'>" + txt  + "</span><span class='end'>&nbsp;</span>");
  });

  //form buttons
  $('input.button').each(function(){
    $(this).wrap('<div class="fbutton" />');
  });

  /***********
   * The nice buttons (by mac@homac.at) [+]
   ***********/


  /***********
   * Article List Heights [+]
   ***********/
  $('#wrapper_article_list .bl').each(function(index) {
    var thish = $(this).height();
    var prevh = $(this).prev(".listele").height();
    //alert (thish + " - " + prevh)
    if (thish > prevh) {
      $(this).prev(".listele").height(thish);
    } else if (prevh > thish) {
      $(this).height(prevh);
    }
  });
  /***********
   * Article List Heights [-]
   ***********/
  
  /***********
   * Team Member Heights [+]
   ***********/
  $('#wrapper_team .bl').each(function(index) {
    var thish = $(this).height();
    var prevh = $(this).prev(".listele").height();
    if (thish > prevh) {
      $(this).prev(".listele").height(thish);
    } else if (prevh > thish) {
      $(this).height(prevh);
    }
  });
  /***********
   * Team Member Heights [-]
   ***********/


  /***********
   * Dynamic Topnews/Content wrapper height [+]
   ***********/
   if ($('#content').innerHeight() > $('#wrapper_topnews').innerHeight()) {
    $('#wrapper_topnews').height($('#content').innerHeight());
   } else if ($('#wrapper_topnews').innerHeight() > $('#content').innerHeight()) {
    var imgfactsH = parseInt($('#wrapper_imagefacts').innerHeight());
    if (imgfactsH>0) {
      $('#content').height($('#wrapper_topnews').innerHeight() + imgfactsH);
    } else {
      $('#content').height($('#wrapper_topnews').innerHeight());      
    }
   }
  /***********
   * Dynamic Topnews/Content wrapper height [-]
   ***********/
  
  /***********
   * imagebox VertCentering [+]
   ***********/
  //$('#wrapper_article_list .imgholder').vAlign();
  $('#wrapper_imagefacts .imagebox').vAlign();
  
  /***********
   * imagebox VertCentering [-]
   ***********/
   

   
  /***********
   * Search blur and ... [+]
   ***********/
   
  if (!defaultValue) var defaultValue = $('#mid_nav .searchf').val();
  $('#mid_nav .searchf').focus( function() {
    if ($(this).val() == defaultValue) {
      $(this).val("");
    }
  });
  $('#mid_nav .searchf').blur( function() {
    if (!$(this).val()) {
      $(this).val(defaultValue);
    }
  });
  /***********
   * Search blur and ... [-]
   ***********/
  
  /***********
   * MidNav [+]
   *********** /
   $('#mid_nav ul li').hover(
    function() {
      //$('#mid_nav li ul').slideUp();      
      $("#mid_nav ul ul").hide();
      $("#mid_nav ul a.amidmain").css('background-image', 'none');
      $(this).find('a.amidmain:first').css('background-image', 'url(/l7i/mid_nav_hoverbg.png)');
      $(this).find('ul:first').show();
    }
   );
   $("body, #mid_nav ul li a").click(function(){	
     $("#mid_nav ul ul").hide();
     $("#mid_nav ul a.amidmain").css('background-image', 'none');
   });
  /***********
   * MidNav [-]
   ***********/
   /*
   $('#mid_nav ul li').hover(
    function() {
      clearTimeout($(this).data('timeout'));
      $(this).find('ul:first').slideDown();
      $(this).find('a.amidmain:first').css('background-image', 'url(/l7i/mid_nav_hoverbg.png)');
    },
    function() {
      var t = setTimeout(function() {
        $(this).find('ul:first').slideUp();
        $(this).find('a.amidmain:first').css('background-image', 'none');
      }, 1000);
      $(this).data('timeout', t);
    }
   );*/
   
   var ua = $.browser;
   if (ua.msie && ua.version < 8) {
    $('#mid_nav ul li').mouseenter(
      function() {
        /*var ele = $(this);
        if ($(this).find('ul:first').is(":visible")) {
          $('#mid_nav ul li').each(function(index, el) {
            if (el != ele) {
              $(this).find('ul:first').slideUp();
              $(this).find('a.amidmain:first').css('background-image', 'none');
            }     
          }); 
        }*/
        
        $(this).find('a.amidmain:first').css('background-image', 'none');
        if (!$(this).find('ul:first').is(":visible")) {
          $(this).find('ul:first').slideDown();
          $(this).find('a.amidmain:first').css('background-image', 'url(/l7i/mid_nav_hoverbg.png)');
        }
      }
    );
   } else {
    $('#mid_nav ul li').hoverIntent(
      function() {
        $(this).find('ul:first').slideDown();
        $(this).find('a.amidmain:first').css('background-image', 'url(/l7i/mid_nav_hoverbg.png)');
      },
      function() {
        $(this).find('ul:first').slideUp();
        $(this).find('a.amidmain.midnonsel:first').css('background-image', 'none');
      }
     );
   }
   
  
   /*
  WORKING EVERYWHERE EXPECT IE7 
   $('#mid_nav ul li').hoverIntent(
    function() {
      $(this).find('ul:first').slideDown();
      $(this).find('a.amidmain:first').css('background-image', 'url(/l7i/mid_nav_hoverbg.png)');
    },
    function() {
      $(this).find('ul:first').slideUp();
      $(this).find('a.amidmain.midnonsel:first').css('background-image', 'none');
    }
   );
   */
      //$(this).find('ul').slideUp();
      //$(this).find('ul:first').slideDown();
      //$(this).find('a.amidmain:first').css('background-image', 'url(/l7i/mid_nav_hoverbg.png)');
      //$(this).find('ul:first').width($(this).find('a:first').width());
     /*,}
     function() {      
      $(this).find('ul:first').slideUp();
      $(this).find('a.amidmain:first').css('background-image', 'none');
     }*/
     
     
   
     
     
  /***********
   * MidNav [-]
   ***********/
  
});

