/**
 * (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 -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'
		});
	}
}

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',
						'#191919', '#303030', '#9b9b9b',
						'#3e3e3e', '#575757', '#ffffff',
						'#9f0101', '#ff0000', '#ffffff' ); //elite

	objPromoShow.addPromo( '02', '#130E2F',
						'#e3e2e2', '#ffffff', '#656565',
						'#1e7cba', '#3db2fc', '#ffffff', 
						'#82ae44', '#b0ea5d', '#ffffff' ); //custom jawbone

	objPromoShow.addPromo( '03', '#000000',
	                    '#191919', '#303030', '#9b9b9b',
						'#3e3e3e', '#575757', '#ffffff',
	                    '#0097bb', '#88e9ff', '#e2f9ff' ); //gretchen

	objPromoShow.addPromo( '04', '#000000',
	                    '#121212', '#272727', '#787B7B',
	                    '#3F3E3E', '#575757', '#FFFFFF',
	                    '#990000', '#F45700', '#FFFFFF' ); //snowyakkers


	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 ) );
	});
});