( function leadPromotion() {
	$( document ).ready( function() {
			var timer;
			var index = 1;
			var length = $( '#promotion div.lead ul.paging li' ).length;
			var thumbnail;
			var mainImage;
			var currentItem = $( '#promotion div.lead ul.paging li:first' );
			var pagingAnchors = $( '#promotion div.lead ul.paging a' );
			var leadContainer = $( '#promotion div.lead' );
			
			function periodicallyUpdate() {
				if ( timer != null ) {
					clearTimeout( timer );
					timer = null;
					if ( index < length ) {
						currentItem.next().find( 'a' ).trigger( 'click' );
					}
					else {
						$( '#promotion div.lead ul.paging li:first' ).find( 'a' ).trigger( 'click' );
						index = 0;
					};
					index ++;
				};
				timer = setTimeout( periodicallyUpdate, 4000 );
			};
			periodicallyUpdate();
			
			leadContainer.mouseover( function() {
				clearTimeout( timer );
				timer = null;
			} );
			leadContainer.mouseout( function() {
				periodicallyUpdate();
			} );
			
			pagingAnchors.click( function( event ) {
				if ( $( event.target ).is( 'a' ) ) {
					currentItem = $( this ).parent( 'li' );
					if ( $( this ).parent().hasClass( 'active' ) ) {
						return false;
					}
					else {
						$( '#promotion div.lead ul.paging li:first' ).find( 'a' ).addClass( 'normal' );
						
						var target = $( this ).attr( 'rel' );
						$( '#promotion > div.lead > ol.content > li' ).hide();
						$( target ).show();
					};
					$( '#promotion div.lead ul.paging li' ).removeClass( 'active' );
					$( this ).parent().addClass( 'active' );
					return false;
				};
			} );
			pagingAnchors.mouseover( function( event ) {
				clearTimeout( timer );
				timer = null;
				if ( $( event.target ).is( 'a' ) ) {
					if ( $( this ).parent().hasClass( 'active' ) ) {
					}
					else {
						if ( thumbnail ) {
							thumbnail.stop();
							thumbnail.remove();
							thumbnail = null;
						};
						var target = $( this ).attr( 'rel' );
						thumbnail = $( target + ' p.thumImage img' ).clone();
						thumbnail.css( {
							height : '0',
							width : '0',
							position : 'absolute',
							right : '0',
							bottom : '2.5em'
						} );
						thumbnail.appendTo( $( target ).parent().parent() );
						thumbnail.animate( {
							height : '70px',
							width : '145px',
							border : '2px solid #fff',
							margin: '2px'
						} );
					};
				};
			} );
			pagingAnchors.mouseout( function( event ) {
				if ( $( event.target ).is( 'a' ) ) {
					if ( $( this ).parent().hasClass( 'active' ) ) {

					}
					else {
						if ( thumbnail ) {
							thumbnail.stop();
							thumbnail.animate( {
								height : '0',
								width : '0'

							}, 'fast', 'linear', function() {
								thumbnail.remove();
								thumbnail = null;
							} );
						};
					};
				};
			} );
			pagingAnchors.focus( function( event ) {
				clearTimeout( timer );
				timer = null;
				if ( $( event.target ).is( 'a' ) ) {
					if ( $( this ).parent().hasClass( 'active' ) ) {

					}
					else {
						if ( thumbnail ) {
							thumbnail.stop();
							thumbnail.remove();
							thumbnail = null;
						};
						var target = $( this ).attr( 'rel' );
						thumbnail = $( target + ' p.thumImage img' ).clone();
						thumbnail.css( {
							height : '0',
							width : '0',
							position : 'absolute',
							right : '0',
							bottom : '2.5em'
						} );
						thumbnail.appendTo( $( target ).parent().parent() );
						thumbnail.animate( {
							height : '70px',
							width : '145px',
							border : '2px solid #fff',
							margin: '2px'
						} );
					};
				};
			} );
			pagingAnchors.blur( function( event ) {
				if ( $( event.target ).is( 'a' ) ) {
					if ( $( this ).parent().hasClass( 'active' ) ) {

					}
					else {
						if ( thumbnail ) {
							thumbnail.stop();
							thumbnail.animate( {
								height : '0',
								width : '0'
							}, 'fast', 'linear', function() {
								thumbnail.remove();
								thumbnail = null;
							} );
						};
					};
				};
			} );
			currentItem.find( 'a' ).trigger( 'click' );
	} );
}() );
