﻿/**
 * Description: general javascript actions and functions that should be present at all times
 * User: antonio.r
 * Date: 20/Set/2011
 **/

var bol_animateBoxShare = true,
    bol_submitForm = true;

$( function() {

  /* if is not iPad, iPhone and not iPod load the flash background and remove the background from the div*/
  if ( navigator.platform != 'iPad' && navigator.platform != 'iPhone' && navigator.platform != 'iPod' ) {

    var str_userAgent = navigator.userAgent.toLowerCase(),
        bol_isAndroid = str_userAgent.indexOf( "android" ) > -1; //&& ua.indexOf("mobile");

    if ( !bol_isAndroid ) {
      $( "#backgroundMovie>div" ).flash( {
        src: '/Files/Templates/Designs/DeltaQ/flash/VideoPlayback.swf',
        width: 600,
        height: 100,
        allowfullscreen:true
      } );

      $( ".flash-replaced embed" ).attr( "height" , "100%" );
      $( ".flash-replaced" ).height( "100%" );

      setTimeout( function() {
        $( "#backgroundMovie" ).css( {"background":"0 none"} );
      } , 1500 )

    }
    else {
      $( "#backgroundMovie" ).css( {"background":"url(/Files/Templates/Designs/DeltaQ/images/deltaQSmoke.jpg) no-repeat center center"} );
    }
  }
  else {
    $( "body" ).addClass( "ios" );
    $( "#backgroundMovie" ).css( {"background":"url(/Files/Templates/Designs/DeltaQ/images/deltaQSmoke.jpg) no-repeat center center"} );
  }

  onLoadAddBackgroundBorderEffect();

  searchFocusBlur( null , obj_editables , 'ExtUserForm_Main' );
  searchFocusBlur( null , obj_editables , 'globalSearch' );
  searchFocusBlur( null , obj_editables , 'searchForm' );

  onLoadRemoveMarginOnMainContentMultipleParagraphs();

} )
    ;


function onLoadRemoveMarginOnMainContentMultipleParagraphs() {
  if ( $( "#mainContentWithTitle>.paragraph" ).length >= 2 ) {
    $( "#mainContentWithTitle>.paragraph" ).css( {"margin-bottom":"0px"} );
    $( "#mainContentWithTitle>.paragraph" ).eq( $( "#mainContentWithTitle>.paragraph" ).length - 1 ).css( {"margin-bottom":"5px"} );
  }
}

function closePopUp() {
  $( '.errorWindow' ).css( {"display":"none"} );
  bol_showCustomAlert = false;
}

/* function that add transparent background on mainContent to make the border effect
 * this is added by script to not load the background in other sections not needed */
function onLoadAddBackgroundBorderEffect() {

  if ( bol_addBackgroundBorder ) {
    $( "#mainContent" ).css( {background:'url("/Files/Templates/Designs/DeltaQ/images/borderBox.png") repeat scroll 0 0 transparent'} );
  }
}

function onLoadLogin() {
  document.ExtUserForm_Login.usernameLogin.focus();

  $( "#mainContent" ).addClass( "paragraphContent" );

  if ( $( "#mainContent .titlePages" ).length >= 2 ) {
    $( "#mainContent>.titlePages" ).remove();
  }
}

/* function that get the width of the wider .pageLevel2>li and apply to .pageLevel2 */
function onLoadWidthPageLevel2() {

  var int_biggestLiWidth = 0,
      int_liWidth = 0;

  $( "#mainMenu .pageLevel2" ).find( "li a" ).each( function() {
    int_liWidth = $( this ).width() + parseInt( $( this ).parents( "ul" ).css( 'padding-left' ).replace( /px$/ , "" ) );

    if ( int_liWidth > int_biggestLiWidth ) {
      int_biggestLiWidth = int_liWidth;
    }
  } );

  $( "#mainMenu .pageLevel2" ).animate( {"width":int_biggestLiWidth + "px"} , "fast" );
}
