/**
 * (c) Copyright 2008 Oakley, Inc.
 *
 * @requires com/oakley/PromoShow.class.js
 */

objPromoTileEffects = new Object();

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 -70px'
		});
	}
}

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'
		});
	}
}

window.addEvent( 'domready', function()
{
	objPromoShow = new PromoShow( 'promo-primary' );
	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 ) );
	});
});
