jQuery( document ).ready( function () {

  // initialize carousel
  jQuery( 'ul.carousel' ).jcarousel( {

    animation: 3000,
    auto: 10,
    easing: 'easeInOutExpo',
    scroll: 1,
    wrap: 'circular',
    buttonNextHTML: null,
    buttonPrevHTML: null,

    initCallback: function ( carousel ) {
      jQuery( 'a.carousel_next' ).bind( 'click', function() { carousel.next(); return false; } );
      jQuery( 'a.carousel_prev' ).bind( 'click', function() { carousel.prev(); return false; } );
    },

    itemVisibleInCallback: {

      onBeforeAnimation: function ( carousel, item, i, state, evt ) {
        var nIndex = carousel.index( i, aCarousel.length );
        carousel.add( i, '<h1>' + aCarousel[nIndex - 1].title + '</h1>' + (aCarousel[nIndex - 1].statusID ? '<div class="status status_' + aCarousel[nIndex - 1].statusID + '" href=""><!----></div>' : '') + (aCarousel[nIndex - 1].url != '' ? '<a ' + (aCarousel[nIndex - 1].url.match( /^https?\:\/\// ) ? ' class="external"' : '') + '" href="' + aCarousel[nIndex - 1].url + '">' : '') + '<img src="asset/upload/image/' + aCarousel[nIndex - 1].src + '" alt="' + aCarousel[nIndex - 1].title + '" />' + (aCarousel[nIndex - 1].url != '' ? '</a>' : '') );
        jQuery( 'ul.carousel a.external' ).click( function() { window.open( jQuery( this ).attr( 'href' ) ); return false; } );
        jQuery( 'ul.carousel h1, ul.carousel div.status' ).hide();
        jQuery( 'div.left div' ).fadeOut( 'fast' );

        // if (stupid) IE... assign path/set css values
        if (jQuery.browser.msie && jQuery.browser.version <= 7 && aCarousel[nIndex - 1].statusID) {
          var sSelector = 'ul.carousel div.status_' + aCarousel[nIndex - 1].statusID;
          var sSRC      = jQuery( sSelector ).css( 'backgroundImage' ).replace( /(^url\("|"\)$)/g, '' );
          jQuery( sSelector ).css( { 'background' : '', 'filter' : 'progid:DXImageTransform.Microsoft.AlphaImageLoader( src="' + sSRC + '", sizingMethod="crop" )' } );
        }
      },

      onAfterAnimation: function ( carousel, item, i, state, evt ) {

        var nIndex = carousel.index( i, aCarousel.length );

        // if (stupid) IE...
        if (jQuery.browser.msie && jQuery.browser.version <= 7) {

          // show heading/image
          jQuery( 'ul.carousel h1, ul.carousel div.status' ).show();

        } else { jQuery( 'ul.carousel h1, ul.carousel div.status' ).fadeIn( 'slow' ); }

        jQuery( 'div#divProperty_' + aCarousel[nIndex - 1].id ).fadeIn( 'slow' );
      }
    },

    itemVisibleOutCallback: { onAfterAnimation: function ( carousel, item, i, state, evt ) { carousel.remove( i ); } }

  } );

  // initialize arrow hover
  jQuery( 'a.arrow img' ).hover(
    function () { jQuery( this ).css( 'opacity', 0.7 ); },
    function () { jQuery( this ).css( 'opacity', 1.0 ); }
  );

  // initialize promotion hover
  jQuery( 'div.promotion' ).css( 'opacity', 0.7 );
  jQuery( 'div.promotion' ).hover(
    function () { jQuery( this ).css( 'opacity', 0.9 ); jQuery( this ).animate( { width: 240 }, 400, 'easeOutExpo', function() { if (jQuery( this ).css( 'opacity' ) != 0.7) { jQuery( this ).children( 'p' ).fadeIn( 'fast' ); } } ); },
    function () { jQuery( this ).css( 'opacity', 0.7 ); jQuery( this ).children( 'p' ).fadeOut( 100, function () { jQuery( this ).parent( 'div' ).animate( { width: 110 }, 400, 'easeOutExpo' ); } ); }
  );

} );

