$.backstretch( 'assets/img/backgrounds/' + Math.round( 1 + ( Math.random() * ( 3 - 1 ) ) ) + '.jpg' );
var blnCanCloseSubmenu = false;
var bannersInterval = null;

$( document ).ready( function()
{
  $( '#submenu, #header' ).bind( 'mouseleave', function(){ $( '#submenu ul' ).fadeOut(); } );
} );

function showSubmenu( id, position )
{
  object = $( '#' + id );
  position = $( position ).position();
  
  if( $( '#submenu ul:visible' ).length > 0 )
  {
    $( '#submenu ul:visible' ).fadeOut( 'slow' );
  }

  object.fadeIn( 'slow' );
  
  $( '#submenu' ).animate({ left: position.left + 'px' }, 700, 'backout' );
}

function runBanners()
{
  clearInterval( bannersInterval );

  bannersInterval = setInterval(
    function()
    {
      if( $( '.dots-active' ).prev( 'a' ).length == 0 )
      {
        prevDot = $( '#dots a' ).last();
      }
      else
      {
        prevDot = $( '.dots-active' ).prev( 'a' );
      }

      $( '.dots-active' ).removeClass( 'dots-active' );

      $( '#banners img:first-child' ).css( 'z-index', '2' );
      
      $( '#banners img:first-child' ).after( '<img src="assets/img/banners_'+currentLang+'/' + prevDot.attr( 'id' ).replace( 'banner-', '' ) + '.png" alt="" style="z-index: 1;" />' );

      $( '#banners img:first-child' ).fadeOut( 'slow', function(){ $( this ).remove(); } );

      prevDot.addClass( 'dots-active' );
    },
    5000
    );
}

function show404() 
{
  $( '#msg' ).html( '<a style="cursor: pointer;" onclick="hideMsg();"><img src="' + strBaseUrl + 'assets/img/msg-404-'+currentLang+'.png" alt="" /></a>' );
  $( '#msg' ).show();
}

function showSent()
{
  $( '#msg' ).html( '<a style="cursor: pointer;" onclick="hideMsg();"><img src="' + strBaseUrl + 'assets/img/msg-sent-'+currentLang+'.png" alt="" /></a>' );
  $( '#msg' ).show();
}

function hideMsg()
{
  $( '#msg' ).hide();
}

function manualBanners( obj )
{
  clearInterval( bannersInterval );

  prevDot = $( obj );

  $( '.dots-active' ).removeClass( 'dots-active' );

  $( '#banners img:first-child' ).css( 'z-index', '2' );

  $( '#banners img:first-child' ).after( '<img src="assets/img/banners_'+currentLang+'/' + prevDot.attr( 'id' ).replace( 'banner-', '' ) + '.png" alt="" style="z-index: 1;" />' );

  $( '#banners img:first-child' ).fadeOut( 'slow', function(){ $( this ).remove(); } );

  prevDot.addClass( 'dots-active' );

  runBanners();
}
