function toggleShouts()
{
  try
  {
    var shoutBox = jQuery( '#shouts' );

    if ( shoutBox )
    {
      if ( shoutBox.hasClass( 'shouts-hide-me' ) )
      {
        shoutBox.removeClass( 'shouts-hide-me' );
        shoutBox.addClass( 'shouts-show-me' );
      }
      else
      {
        shoutBox.removeClass( 'shouts-show-me' );
        shoutBox.addClass( 'shouts-hide-me' );
      }
    }

    return false;
  }
  catch ( e ) {
//    alert( e );
  }
}

function showShouts()
{
  try
  {
    var shoutBox = jQuery('#shouts');

    shoutBox.removeClass( 'shouts-hide-me' )
    shoutBox.addClass( 'shouts-show-me' )

    return false;
  }
  catch ( e ) {}
}

function hideShouts()
{
  try
  {
    var shoutBox = jQuery( '#shouts' );

    shoutBox.removeClass( 'shouts-show-me' );
    shoutBox.addClass( 'shouts-hide-me' );

    return false;
  }
  catch ( e ) {}
}

// submenu / subsubmenu
var wasActive = false;

function showSub( elem, subm, active, dropshadow, dropshadowWidth, offsetTop )
{
  try
  {
    var subMenu = jQuery( '#' + subm );
    var elemObj = jQuery( elem );
    var pos = elemObj.offset();
    var mLink = elemObj.children('a');
    var width = subMenu.width() + dropshadowWidth;
    var height = subMenu.height() + dropshadowWidth;

    wasActive = false;

    if ( active != '' )
    {
      wasActive = true;
    }

    if ( !offsetTop )
    {
      offsetTop = 20;
    }

    if ( dropshadow == true )
    {
//      subMenu.parents( "div.shadow1" ).css( { left: pos.left - 10, top: ( pos.top - 10 + offsetTop ) } );
      subMenu.parents( "div.shadow1" ).css( { left: pos.left - 10, top: ( offsetTop ) } );
      subMenu.parents( "div[class^='shadow']" ).css( { visibility: 'visible', width: width + 'px', height: height + 'px' } );
      subMenu.css( { display: 'inline', visibility: 'visible' } );
    }
    else
    {
//      subMenu.css( { visibility: 'visible', left: pos.left - 10, top: ( pos.top - 10 + offsetTop ) } );
      subMenu.css( { visibility: 'visible', left: pos.left - 10, top: ( offsetTop ) } );
    }

    mLink.addClass( 'active' );
  }
  catch (e)
  {
    //alert(e);
  }
}

function hideSub( elem, subm, dropshadow )
{
  try
  {
    var subMenu = jQuery( '#' + subm );
    var mLink = jQuery( elem ).children( 'a' );

    if ( dropshadow == true )
    {
      subMenu.parents( "div[class^='shadow']" ).css( { visibility: 'hidden' } );
      subMenu.css( { display: 'block' } );
    }

    subMenu.css( { visibility: 'hidden' } );

    if ( !wasActive )
    {
      mLink.removeClass( 'active' );
    }
  }
  catch (e)
  {
    //alert(e);
  }
}

function showSubsub( elem, subsubm, active, dropshadow, dropshadowWidth )
{
  try
  {
    var subsubMenu = jQuery( '#' + subsubm );
    var mLink = jQuery( elem ).children('a');
    var posP = jQuery( elem ).parent().offset();
    var pos = jQuery( elem ).offset();
    var width = subsubMenu.width() + dropshadowWidth;
    var height = subsubMenu.height() + dropshadowWidth;

    if ( dropshadow == true )
    {
      subsubMenu.parents( "div.sub-shadow1" ).css( { left: ( jQuery( elem ).width() ), top: ( pos.top - posP.top ) } );
      subsubMenu.parents( "div[class^='sub-shadow']" ).css( { visibility: 'visible', width: width + 'px', height: height + 'px' } );
      subsubMenu.css( { display: 'inline', visibility: 'visible' } );
    }
    else
    {
//    subsubMenu.css( { visibility: 'visible', top: ( ( pos.top - posP.top ) + 7 ), left: ( jQuery( elem ).width() - 8 ) } );
      subsubMenu.css( { visibility: 'visible', top: ( pos.top - posP.top ), left: ( jQuery( elem ).width() ) } );
    }
    mLink.addClass( 'active2' );
  }
  catch (e)
  {
//    alert(e);
  }
}

function hideSubsub( elem, subm, dropshadow )
{
  try
  {
    var subMenu = jQuery( '#' + subm );
    var mLink = jQuery( elem ).children( 'a' );

    if ( dropshadow == true )
    {
      subMenu.parents( "div[class^='sub-shadow']" ).css( { visibility: 'hidden' } );
      subMenu.css( { display: 'block' } );
    }

    subMenu.css( { visibility: 'hidden' } );
    mLink.removeClass( 'active2' );
  }
  catch (e)
  {
    //alert(e);
  }
}

function lighten( obj )
{
  setOpacity( obj, '1.0' );
}

function darken( obj )
{
  setOpacity( obj, '0.6' );
}

// opacity helper
function setOpacity( obj, opacity )
{
  try
  {
    if ( jQuery )
    {
      var elem = jQuery( obj );

      if ( elem )
      {
        if ( !opacity )
        {
          opacity = '1.0';
        }

        elem.css( 'opacity', opacity );
      }
    }
  }
  catch ( e ) {}
}

var timeoutEventInfoBox;

function showEventInfo( elem, infoid )
{
  try
  {
    clearTimeout( timeoutEventInfoBox );

    var box = jQuery( '#box-extrainfo-event' );
    box.css( { display:'none' } );
    var head = box.find( 'div.head' );
    var offset = jQuery( elem ).offset();
    var data = jQuery( '#' + infoid );
    var count = 0;
    var events = new Array();

    data.find( 'div.event_element' ).each( function() {
      events[count++] = jQuery( this );
    } );

    head.html( '' );

    events[count] = jQuery( data.find( 'div.last_event' ) );

    if ( count > 0 )
    {
      var tabs = jQuery( '<div class="tabs"></div>' );
      var html = '';

      for ( i = 0; i <= count; i++ )
      {
        if ( i == 0 )
        {
          html += '<div class="tab tab-first">' + ( i + 1 ) + '</div>';
        }
        else if ( i == count )
        {
          html += '<div class="tab tab-last">' + ( i + 1 ) + '</div>';
        }
        else
        {
          html += '<div class="tab">' + ( i + 1 ) + '</div>';
        }
      }

      html += '<div class="clear"></div>';
      tabs.html( html );
      head.append( tabs );
    }
    
    var event_id = events[0].find( 'span.event_id' ).html();

    box.find( 'div.event' ).html( events[0].html() );
    head.append( events[0].find( 'span.event_photo' ).html() );
    box.find( 'a.btn-big' ).attr( 'href', '/event/view/e_id:' + event_id );

    box.find( 'div.tab' )
      .mouseover( function() {
        jQuery( this ).addClass( 'tab-active' );
      })
      .mouseout( function() {
        jQuery( this ).removeClass( 'tab-active' );
      })
      .click( function() {
        var act_tab = jQuery( this ).html() - 1;
        var act_event_id = events[act_tab].find( 'span.event_id' ).html();
        box.find( 'div.event' ).html( events[act_tab].html() );
        head.find( "a[class~='image']" ).replaceWith( events[act_tab].find( 'span.event_photo' ).html() );
        if ( window.overlayFlyer )
        {
          overlayFlyer( '#box-extrainfo-event a[class~=flyer]', { func: 'showEventInfo', elem: elem, infoid: infoid, event_id: act_event_id } );
        }
        box.find( 'a.btn-big' ).attr( 'href', '/event/view/e_id:' + act_event_id );
      } );

    box.css( { display: 'block',
               left: ( offset.left - ( box.width() / 2 ) + 6 ) + 'px',
               top:     ( offset.top - box.height() ) + 'px' } );

    if ( window.overlayFlyer )
    {
      overlayFlyer( '#box-extrainfo-event a[class~=flyer]', { func: 'showEventInfo', elem: elem, infoid: infoid, event_id: event_id } );
    }

    box
      .mouseleave( function() { hideEventInfoBox( jQuery( this ), 800 ); } )
      .mouseenter( function() { clearTimeout( timeoutEventInfoBox ); } );

    hideEventInfoBox( box, 3000 );
  }
  catch ( e )
  {
//    alert( e );
  }
}

function hideEventInfo()
{
  // nothing happens here, but function will be called on mouseout on calendar bar
}

function hideEventInfoBox( elem, delay )
{
  if ( timeoutEventInfoBox )
  {
    clearTimeout( timeoutEventInfoBox );
  }

  timeoutEventInfoBox = setTimeout( function() { elem.fadeOut(); }, delay );
}