jQuery.noConflict();
jQuery( document ).ready( function () {

  // initialize external links
  jQuery( 'a' ).each( function () {
    if (jQuery( this ).attr( 'href' )) {
      var sURL = jQuery( this ).attr( 'href' );
      if (sURL.match( /^http\:\/\// ) && !sURL.match( /hansler/ )) { jQuery( this ).attr( 'target', 'new' ); }
    }
  } );

  // initialize image hover
  jQuery( 'a:not([class*=hover]) img:not([src*=_0]), a.hover' ).hover(
    function () { jQuery( this ).css( 'opacity', 0.7 ); },
    function () { jQuery( this ).css( 'opacity', 1.0 ); }
  );

  _Initialize.form();
  _Initialize.menu();

} );

function _Initialize() {}

_Initialize.form = function () {

  // initialize contact submit
  jQuery( 'input[type=button]' ).click( function () {

    // assign subject
    if (jQuery( '#cboSubject' ).val() != null) { jQuery( '#hdnSubject' ).val( jQuery( '#cboSubject' ).val() ); }

    jQuery.post(

      '/wp-hansler/wp-content/themes/hansler/ajax.php',

      {
        hdnMode    : jQuery( '#hdnMode'    ).val(),
        hdnSubject : jQuery( '#hdnSubject' ).val(),
        txtCompany : jQuery( '#txtCompany' ).val(),
        txtName    : jQuery( '#txtName'    ).val(),
        txtPhone   : jQuery( '#txtPhone'   ).val(),
        txtEmail   : jQuery( '#txtEmail'   ).val(),
        txtMessage : jQuery( '#txtMessage' ).val()
      },

      function ( oMessage ) {

        jQuery( 'div.form > p' ).fadeOut( function () {
          jQuery( this ).removeClass().addClass( 'message_' + oMessage.type ).text( oMessage.value ).fadeIn();
        } )

        // if focus... set element
        if (oMessage.focus) { jQuery( '#' + oMessage.focus ).focus(); }

        // if confirm... hide form
        if (oMessage.type == 'confirm') { jQuery( 'div.form > div' ).slideUp(); }
      },

      'json'
    );

    return false;

  } );

}

_Initialize.menu = function () {

  /*** top menu ***/

  // initialize current
  jQuery( '#divMenu_top li.current img' ).each( function () { jQuery( this ).attr( 'src', jQuery( this ).attr( 'src' ).replace( '_0', '_1' ) ); } );

  // initialize menu hover
  jQuery( '#divMenu_top li' ).dequeue().hover(

    function () {
      jQuery( this ).find( 'ul' ).slideDown( 'fast' );
      if (jQuery( this ).hasClass( 'current' ) == false) {
        jQuery( this ).find( 'img' ).attr( 'src', jQuery( this ).find( 'img' ).attr( 'src' ).replace( '_0', '_1' ) );
      }
    },

    function () {
      jQuery( this ).find( 'ul' ).slideUp( 'fast' );
      if (jQuery( this ).hasClass( 'current' ) == false) {
        jQuery( this ).find( 'img' ).attr( 'src', jQuery( this ).find( 'img' ).attr( 'src' ).replace( '_1', '_0' ) );
      }
    }
  );


  /*** left menu ***/

  // initialize anchors
  jQuery( '#divMenu_left ul.children a' ).each( function () {
    jQuery( this ).attr( 'href', jQuery( this ).attr( 'href' ).replace( /.*\/([^\/]+)\/$/, '#$1' ) );
  } );

  // hide/show sub links
  jQuery( '#divMenu_left ul.children' ).hide();
  jQuery( '#divMenu_left li.current_page_item ul.children' ).show();
}

