/*******************************************************************************
**
**  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
*
*  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
*
*  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 ()
/*============================================================================*/
{

   if ( $(window).height() > 0 ) {

      /* begin calculating the height of the total website */
      var contentHeight = 20 + $('#idDivBgImg').attr('offsetHeight') + 
                               $('#idDivBefFooter').attr('offsetHeight');

      /* add the height of the left menu, if the left menu is heigher than the
       * content area.. */
      if ( $('#idDivMenuLeft').attr('offsetHeight') > $('#idDivContent').attr('offsetHeight') )
         contentHeight = contentHeight + $('#idDivMenuLeft').attr('offsetHeight');

      /* ..or add the height of the left menu, if the content area is heigher
       * than the left menu.. */
      else
         contentHeight = contentHeight + $('#idDivContent').attr('offsetHeight');

      /* if the height of the inner part of the browser window is heigher than
       * the website.. */
      if( $(window).height() >= contentHeight ) {
         /* place the footer at the bottom of the browser window */
         $('#idDivFooter').css('top', $(window).height() - 25 + 'px');
         $('#idDivFooter').css('left', ($(window).width() - $('#idDivBgImg').attr('offsetWidth')) / 2 + 'px');
         $('#idDivFooter').css('position', 'absolute');
      }
      else {
         /* place the footer at the end of the website */
         $('#idDivFooter').css('position', '');
      }

      /* show the footer */
      $('#idDivFooter').css('display', 'block');
   }

} /*==========   eofn: jsSetFooter()   ==========*/

/******************************************************************************/
/** Events                                                                   **/
/******************************************************************************/

$(document).ready( function ()
{

   $(window).resize(
      function () { jsSetFooter(); }
   );

   $('input:text,input:password,select,textarea').mouseenter(
      function () { $(this).removeClass( 'clIptNoHover' ).addClass( 'clIptHover' ); }
   );

   $('input:text,input:password,select,textarea').mouseleave(
      function () { $(this).removeClass( 'clIptHover' ).addClass( 'clIptNoHover' ); }
   );

   $('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
*
*  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 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 has finished */
      $('#idDivLoginWin').show( 'slide', { direction: 'up' }, 500,
                                function () { $('input[name$="pLoginName"]').focus(); } );
   }

   /* if the login window should be hided */
   else {
      $('#idDivLoginWin').hide( 'slide', { direction: 'up' }, 500 );
   }

} /*==========   eofn: jsShowLoginWin   ==========*/

/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
*
*  Function : jsShowHideDiv()     defined in : main.js
*
*  Created : 25-03-10 13:55 by Marco Stolz
*
*  Description :
*  Show or hide a <div> and switch the plus-minus-image of the link.
*  
*  id [IN] : Last part of the id of the Div and the Img. Must be: idDiv<id> and
*            idImg<id>. 
*/
/*============================================================================*/
function jsShowHideDiv ( id )
/*============================================================================*/
{

   /* if the div should be shown.. */
   if ( $('#idDiv'+id).css('display') == 'none' ) {
      $('#idA'+id).attr( 'href', '#idA'+id );            /* set the anchor of the headline */
      $('#idDiv'+id).show( 'scale', {}, 500 );           /* show the div */
      $('#idImg'+id).attr( 'src', '../pics/minus.png' ); /* set the headline picture 'minus' */
      /* set the footer */
      jsSetFooter();
   }
   /* if the div should be hided.. */
   else {
      $('#idA'+id).attr( 'href', '#' );                      /* delete the anchor of the headline */
      $('#idDiv'+id).hide( 'scale', {}, 500,
                           function () { jsSetFooter(); } ); /* show the div and set the footer, if hide is ready */
      $('#idImg'+id).attr( 'src', '../pics/plus.png' );      /* set the headline picture 'plus' */
   }


} /*==========   eofn: jsShowHideDiv   ==========*/

/***********   eof: main.js   ***********/