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

  // if working locally...
  if (jQuery( 'base' ).exists() && jQuery( 'base' ).attr( 'href' ).match( '127.0.0.1' )) {

    var sPath = jQuery( 'base' ).attr( 'href' ).replace( /\/application\/.+\//, '' );

    // prepend absolute links with (abbreviated) local path
    jQuery( 'a[href^=/]' ).each( function () { jQuery( this ).attr( 'href', sPath + jQuery( this ).attr( 'href' ) ); } );

    // prepend form actions with (abbreviated) local path
    jQuery( 'form' ).each( function () {
      if (jQuery( this ).attr( 'action' ).match( /^\// )) { jQuery( this ).attr( 'action', sPath + jQuery( this ).attr( 'action' ) ); }
    } );

  } else {

    // prepend form actions with (abbreviated) local path
    jQuery( 'form' ).each( function () {
      if (jQuery( this ).attr( 'action' ).match( /^\// )) { jQuery( this ).attr( 'action', jQuery( this ).attr( 'action' ) ); }
    } );

    // prepend absolute links with (abbreviated) local path
    jQuery( 'a[href^=/]' ).each( function () { jQuery( this ).attr( 'href', jQuery( this ).attr( 'href' ) ); } );
  }

  // if focus... blur
  jQuery( 'a' ).focus( function () { this.blur() } );

  // initialize external links
  jQuery( 'a.external' ).click( function() {
    window.open( jQuery( this ).attr( 'href' ) );
    return false;
  } );

  // assign name (to avoid: id="txtFoo" name="txtFoo")
  jQuery( 'form :input[id]' ).each( function () {
    if (jQuery( this ).attr( 'name' ) == '' || jQuery( this ).attr( 'name' ) == null) {
      jQuery( this ).attr( 'name', jQuery( this ).attr( 'id' ) );
    }
  } );

  // remove textarea resize (for safari)
  jQuery( 'textarea' ).css( 'resize', 'none' );

  // if carousel exists... preload carousel images
  if (typeof( window['aCarousel'] ) != 'undefined' && aCarousel.length) {
    for (var i in aCarousel) { jQuery.preloadImage( 'asset/upload/image/' + aCarousel[i].src ); }
  }

  // if (stupid) IE... simulate fixed positioning
  if (jQuery.browser.msie && jQuery.browser.version <= 6) {
    jQuery( 'div#divFooter' ).css( { 'position' : 'absolute' } );
    jQuery( window ).scroll( function() { jQuery( 'div#divFooter' ).css( 'top', (jQuery( this ).scrollTop() + jQuery( window ).height() - 39) + 'px' ); } );
  }

} );

/*
 * Custom jQuery methods
 */
jQuery.fn.exists = function() { return jQuery( this ).length > 0; }

var aCache = [];
jQuery.preloadImage = function() {
/*
  var oImage = document.createElement( 'img' );
  for (var i = arguments.length; i--;) {
    oImage.src = arguments[i];
    aCache.push( oImage );
  }
*/
}

