/*******************************************************************************
**
**  main.js
**
**  Project: HomepageMS
**
**  ----------------------------------------------------------------------------
**
**  Description:
**  Common Javascript file with all Javascript functions, which are used in this
**  project.
**
**  ----------------------------------------------------------------------------
**  Created: 01-01-09 07:00 by Marco Stolz
*******************************************************************************/

/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
 History:
 29-04-09 18:26 MS  Funktionen jsGetWindowHeight() und jsGetWindowWidth() durch
                    jQuery-Funktionen $(window).height() bzw $(window).width()
                    ersetzt.
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/


/******************************************************************************/
/** Includes                                                                 **/
/******************************************************************************/

/******************************************************************************/
/** File specific defines                                                    **/
/******************************************************************************/

/******************************************************************************/
/** Global variables                                                         **/
/******************************************************************************/

var BrowserName    = 'unknown';
var BrowserVersion = 0;

/******************************************************************************/
/** Global calculations                                                      **/
/******************************************************************************/

/*----------------------------------------------------------------------------*/
/* get name and version of the used internet browser */
/*----------------------------------------------------------------------------*/
/* if Microsoft Internet Explorer */
if ( navigator.appName.indexOf( 'Explorer' ) != -1 ) {
   BrowserName = 'IE';
   var ver = navigator.appVersion.substring( 0, navigator.appVersion.indexOf( "." ) );
   if ( (ver==4) && (navigator.appVersion.indexOf('MSIE 5') != -1) )
      BrowserVersion = 5;
   else if ( (ver==4) && (navigator.appVersion.indexOf('MSIE 6') != -1) )
      BrowserVersion = 6;
   else if ( (ver==4) && (navigator.appVersion.indexOf('MSIE 7') != -1) )
      BrowserVersion = 7;
   else if ( ver==4 )
      BrowserVersion = 4;
}

/* if Netscape, Mozilla, Firefox */
else if ( navigator.appName.indexOf( 'Netscape' ) != -1 ) {
   BrowserName = 'NN';
   BrowserVersion = navigator.appVersion.substring( 0, navigator.appVersion.indexOf( "." ) );
}

/* if Opera */
else if ( navigator.appName.indexOf( 'Opera' ) != -1 ) {
   BrowserName = 'OP';
   BrowserVersion = navigator.appVersion.substring( 0, navigator.appVersion.indexOf( "." ) );
}

/* test the result via alert */
//alert( 'appName: ' + navigator.appName + '\n' +
//       'appVersion: ' + navigator.appVersion + '\n' +
//       'Result: browserName = ' + BrowserName + ', BrowserVersion = ' + BrowserVersion );

/******************************************************************************/
/** Functions                                                                **/
/******************************************************************************/

/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
*
*  Function :  jsPreloadImages()     defined in :  main.js
*
*  Created     :  01-01-09 07:56 by Marco Stolz
*  Last update :  20-03-09 11:32 by Marco Stolz
*
*  Description :
*  Preload the images in the argument.
*/
/*============================================================================*/
function jsPreloadImages ()
/*============================================================================*/
{

   var i;
   var img_src = jsPreloadImages.arguments;

   if ( !document.preloadImg )
   { document.preloadImg = new Array(); }

   var arr_len = document.preloadImg.length;

   for ( i = 0; i < img_src.length; i++ ) {
      if ( img_src[i].indexOf("#") != 0 ) {
         document.preloadImg[arr_len] = new Image;
         document.preloadImg[arr_len++].src = img_src[i];
      }
   }

} /*==========   eofn: jsPreloadImages()   ==========*/

/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
*
*  Function :  jsSetFooter()     defined in :  main.js
*
*  Created     :  11-03-09 09:29 by Marco Stolz
*  Last update :  11-03-09 09:29 by Marco Stolz
*
*  Description :
*  Calculate the Position of the footer in depandent of the window and content
*  size and set the respective elemtens of the footer.
*/
/*============================================================================*/
function jsSetFooter ()
/*============================================================================*/
{

   /* get the inner height and width of the window of the browser */
   var win_height = $(window).height();
   var win_width  = $(window).width();
   /* get the footer element, which should be set */
   var footerElement = document.getElementById( 'idDivFooter' );

   if ( win_height > 0 ) {

      /* calculate the height of the total website */
      var contentHeight = 20 + document.getElementById('idDivBgImage').offsetHeight +
                               document.getElementById('idDivBefFooter').offsetHeight;

      /* add the height of the left menu, if the left menu is heigher then the
       * content area.. */
      if ( document.getElementById('idDivMenuLeft').offsetHeight > document.getElementById('idDivContent').offsetHeight )
         contentHeight = contentHeight + document.getElementById('idDivMenuLeft').offsetHeight;
      /* or add the height of the left menu, if the content area is heigher then
       * the left menu.. */
      else
         contentHeight = contentHeight + document.getElementById('idDivContent').offsetHeight;

      /* if the height of the inner part of the browser window is heigher than
       * the website.. */
      if( win_height >= contentHeight ) {
         /* place the footer at the bottom of the browser window */
         footerElement.style.top      = win_height - 21 + 'px';
         footerElement.style.left     = (win_width-document.getElementById('idDivBgImage').offsetWidth) / 2 + 'px';
         footerElement.style.position = 'absolute';
         footerElement.style.display  = 'block';
      }
      else
         /* place the footer at the end of the website */
         footerElement.style.display = 'block';
   }

} /*==========   eofn: jsSetFooter()   ==========*/

/******************************************************************************/
/** Events                                                                   **/
/******************************************************************************/

/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
*
*  Function :  window.onresize     defined in :  main.js
*
*  Created     :  18-03-09 07:40 by Marco Stolz
*  Last update :  18-03-09 07:40 by Marco Stolz
*
*  Description :
*  Event which will triggered if the broswer window resizes.
*/
/*============================================================================*/
window.onresize = function ()
/*============================================================================*/
{

   jsSetFooter();

} /*==========   eofn: window.onresize   ==========*/

$(document).ready( function ()
{

   $('.clImgLangflag').mouseenter(
      function () {
         var newSrc = 'pics/flag' + $(this).attr('src').substr( 9, 2 ) + '_A.png';
         $(this).attr( 'src', newSrc );
      }
   );
   $('.clImgLangflag').mouseleave(
      function () {
         var newSrc = 'pics/flag' + $(this).attr('src').substr( 9, 2 ) + '.png';
         $(this).attr( 'src', newSrc );
      }
   );

   $('input:text,input:password,select,textarea').mouseenter(
      function () { $(this).addClass( 'clIptHover' ); }
   );

   $('input:text,input:password,select,textarea').mouseleave(
      function () { $(this).removeClass( 'clIptHover' ); }
   );

   $('input:text,input:password,select,textarea').focus(
      function () { $(this).addClass( 'clIptFocus' ); }
   );

   $('input:text,input:password,select,textarea').blur(
      function () { $(this).removeClass( 'clIptFocus' ); }
   );

   $('#idDivMsgWin').click(
      function () { $(this).hide( 'drop', { direction: 'down' }, 800 ); }
   );
} );



/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
*
*  Function :  jsShowLoginWin     defined in :  main.js
*
*  Created     :  18-03-09 07:40 by Marco Stolz
*  Last update :  18-03-09 07:40 by Marco Stolz
*
*  Description :
*  Event which will triggered if the broswer window resizes.
*/
/*============================================================================*/
function jsShowLoginWin ()
/*============================================================================*/
{

   /* if the login window should be shown */
   if ( $('#idDivLoginWin').css('display') == 'none' ) {

      /* show the element (only for a short time, so offsetWidth does not return 0) */
      $('#idDivLoginWin').css('display', 'block');

      /* calculate the left position of the window in depandend of the width of
       * the body and the window */
      var leftPos_s = ($(window).width() - $('#idBody').attr('offsetWidth')) / 2 +
                      $('#idBody').attr('offsetWidth') -
                      $('#idDivLoginWin').attr('offsetWidth') + 'px';

      /* hide the window again */
      $('#idDivLoginWin').css('display', 'none');
      /* set the top position of the window */
      $('#idDivLoginWin').css('top', '300px');
      /* set the left position of the window */
      $('#idDivLoginWin').css('left', leftPos_s);

      /* now, show the window with a jQuery effect; set the focus to the input
       * element for the name, if the effect will has finished */
      $('#idDivLoginWin').show( 'slide', { direction: 'up' }, 500,
                                function () { $('#idIptLoginName').focus(); } );
   }

   /* if the login window should be hided */
   else {
      $('#idDivLoginWin').hide( 'slide', { direction: 'up' }, 500 );
   }

} /*==========   eofn: jsShowLoginWin   ==========*/


/***********   eof: main.js   ***********/