var yagsheaderimage = {
  
  init: function() {
    
    // Start slideshow if it has more than 1 picture
    if(jQuery('#slideshow').length > 0 && jQuery('#slideshow div').length > 1) {


      jQuery('#slideshow div').css({opacity: 0});
      jQuery('#slideshow div:first').css({opacity: 100});
      
      jQuery(function() {
          setInterval("yagsheaderimage.slideSwitch()", 5000 );
      });
    }
    
    // Dropshadow for active and hover
    jQuery('#nav li.active a span').dropShadow({left: -1, top: -2, opacity: 0.5, blur: 1});
    jQuery('#nav li').live('mouseover mouseout', function(event) {
      if (event.type == 'mouseover') {
        if(!jQuery(this).hasClass('active')) {
          jQuery(this).find('span').dropShadow({left: -1, top: -2, opacity: 0.5, blur: 1});
        }
      } else {
        if(!jQuery(this).hasClass('active')) {
          jQuery(this).find('span').removeShadow();
        }
      }
    });
    
    
  },
  
  slideSwitch: function() {
    yagsheaderimage.active = jQuery('#slideshow div.active');
    if ( yagsheaderimage.active.length == 0 ) yagsheaderimage.active = jQuery('#slideshow div:last');
    yagsheaderimage.next =  this.active.next().length ? yagsheaderimage.active.next() : jQuery('#slideshow div:first');
    yagsheaderimage.active.addClass('last-active');
    yagsheaderimage.active.animate({opacity: 0.0}, 1000);
    yagsheaderimage.next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            yagsheaderimage.active.removeClass('active last-active');
        });
  },
  
  fixHeight: function(sel) {
    var height = 0;
    jQuery(sel).each(function(){
      var elem_height = jQuery(this).height();
      if(elem_height > height) {
        height = elem_height;
      }
    });
    
    jQuery(sel).each(function(){
      jQuery(this).height(height);
    });
  },
  
  removeEmptyRightNav: function() {

    if(jQuery('.aside').length > 0) {
      if(
        jQuery('.aside-navigation').html() == '<div class="title"></div>' ||
        jQuery('.aside-navigation').html() == '' ||
        jQuery('.aside-navigation').html() == '<DIV class=title></DIV>'
      ) {
        jQuery('.aside-navigation').remove();
      }
      if((jQuery('.aside-content').html() == '' || jQuery('.aside-content').html() == null) && (jQuery('.aside-navigation').html() == '' || jQuery('.aside-navigation').html() == null)) {
        jQuery('.aside').remove();
        var content_width = jQuery('.content').width();
        jQuery('.content').css({'margin-right':'21px'});
        jQuery('.content').width(content_width-21);
      }
      
      if(jQuery('.tagcloud').length > 0) {
        jQuery('.tagcloud').width(jQuery('.text-info').width()-22);
      }
      
    }
  }
  
  
}

jQuery(document).ready(function() {
  
  yagsheaderimage.init();
  
  // Fix heights for home page boxes
  yagsheaderimage.fixHeight(jQuery('.onecolumn .c33l .subcl, .onecolumn .c33l .subc, .onecolumn .c33r .subcr'));
  
  yagsheaderimage.removeEmptyRightNav();
  
});
