

objPromoTileEffects = {};

function handle_promoTileOver( objEvent )
{

	objElem = $( objEvent.target );

	if( objElem.get( 'tag' ) == 'img' )
	{
		// Stop the link from being followed
		objEvent = new Event( objEvent ).stop();

		// Stop the event from bubbling
		objEvent.stopPropagation();

		objPromoTileEffects[ objElem.id ].start({
			'background-position': '1px -68px'
		});
	}
}

function handle_promoTileOut( objEvent )
{
	objElem = $( objEvent.target );

	if( objElem.get( 'tag' ) == 'img' )
	{
		// Stop the link from being followed
		objEvent = new Event( objEvent ).stop();

		// Stop the event from bubbling
		objEvent.stopPropagation();

		objPromoTileEffects[ objElem.id ].start({
			'background-position': '1px 0'
		});
	}
}

function launchOverlay()
{
  // Note: langoverlay will not exist unless the site is on the US domain.
  if( jQuery( '#langoverlay' ))
  {
    jQuery( '#langoverlay' ).overlay({
      mask: { color: '#000', opacity: 0.9 },
      onBeforeLoad: function(){ this.getOverlay().load( '/region-select' ); },
      closeOnClick: true,
      load: true
    });
  }
}

function checkOverlay()
{
  jQuery.get( '/info.js', function( data )
  {
    data = eval( data );

    if( data.HTTP_X_AKAMAI_EDGESCAPE )
    {
      edgescape = data.HTTP_X_AKAMAI_EDGESCAPE;
  
      edgescape = edgescape.split( "," );
  
      country_code = '';
  
      // Loop the edgescape array looking for the country_code
      for( var i in edgescape )
      {
        esvar = edgescape[i].split( "=" );
  
        if( esvar[0] == 'country_code' )
        {
          country_code = esvar[1];
          break;
        }
      }
  
      if( country_code != 'US' )
      {
        launchOverlay();
      }
    }
  });
}

function closeOverlay()
{
  jQuery( '#langoverlay' ).overlay().close();
}




window.addEvent( 'domready', function()
{
	objPromoShow = new PromoShow( 'promo-primary' );

	/* addPromo( promoIdAppend, promo border color, 
	             default bg color, default border color, default text color, 
	             hover bg color, hover border color, hover text color, 
	             selected bg color, selected border color, selected text color )
	*/
    
	objPromoShow.addPromo( '01', '#000000',
					'#000000', '#333333', '#9B9B9B',
					'#262626', '#575757', '#FFFFFF', 
					'#7fa9bf', '#5e98aa', '#FFFFFF' ); //shoes

	objPromoShow.addPromo( '02', '#000000',
					'#000000', '#333333', '#9B9B9B',
					'#262626', '#575757', '#FFFFFF', 
					'#7fa9bf', '#5e98aa', '#FFFFFF' ); //jewelry
	
	objPromoShow.addPromo( '03', '#000000',
					'#000000', '#333333', '#9B9B9B',
					'#262626', '#575757', '#FFFFFF', 
					'#7fa9bf', '#5e98aa', '#FFFFFF' ); //handbags
	
	objPromoShow.addPromo( '04', '#000000',
					'#000000', '#333333', '#9B9B9B',
					'#262626', '#575757', '#FFFFFF', 
					'#7fa9bf', '#5e98aa', '#FFFFFF' ); //beauty
	
	
	objPromoShow.addPromo( '05', '#000000',
					'#000000', '#333333', '#9B9B9B',
					'#262626', '#575757', '#FFFFFF', 
					'#7fa9bf', '#5e98aa', '#FFFFFF' ); //beauty5

	objPromoShow.addPromo( '06', '#000000',
					'#000000', '#333333', '#9B9B9B',
					'#262626', '#575757', '#FFFFFF', 
					'#7fa9bf', '#5e98aa', '#FFFFFF' ); //beauty6


objPromoShow.attach();
	objPromoShow.startTimer();

	$$( '.promo-tile img' ).each( function( objTile ){

		objPromoTileEffects[ objTile.id ] = new Fx.Morph( objTile, { transition: Fx.Transitions.Bounce.easeOut, duration: 500, link: 'cancel' } );

		objTile.addEvent( 'mouseover', handle_promoTileOver.bind( objPromoTileEffects ) );
		objTile.addEvent( 'mouseout', handle_promoTileOut.bind( objPromoTileEffects ) );
	});

  checkOverlay();
});
