( 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, 3000 );
			};
			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 : '90px',
							width : '120px',
							border : '2px solid #fff',
							margin: '5px'
						} );
					};
				};
			} );
			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 : '90px',
							width : '120px',
							border : '1px solid #fff',
							margin: '5px'
						} );
					};
				};
			} );
			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' );
	} );
}() );

( function tracks() {
	$( document ).ready( function() {
		$( "#promotion div.tracks h2 a" ).click( function() {
			var block = $( this ).attr( "rel" );
			$( '#promotion div.tracks div.content:visible' ).hide('fast').addClass("inactive").removeClass("active");
			$( '#promotion div.tracks div.content:hidden' ).show('fast').addClass("active").removeClass("inactive");
			$( "#promotion div.tracks h2 a" ).toggleClass("arrowDown");
			$( "#promotion div.tracks h2 a" ).toggleClass("active");
			return false;
		} );
	} );
}() );

(function($) {
	function runTicker(settings) {
		if(settings.firstRun == 1){
			currentLength = settings.currentLength;
			currentItem = settings.currentItem;
			settings.firstRun = 0;
		}
		
		if(currentItem == settings.newsItemCounter + 1){
			currentItem = 0;
		}
		
		if(currentLength == 0) {
			$(settings.newsList).empty().append('<li><a href="'+ settings.newsLinks[currentItem] +'"></a></li>');
		}
		
		if( currentLength % 2 == 0) {
				placeHolder = settings.placeHolder1;
		}
		else {
			placeHolder = settings.placeHolder2;
		}
		
		if( currentLength <= settings.newsItems[currentItem].length + 1) {
			var tickerText = settings.newsItems[currentItem].substring(0,currentLength);
			$(settings.newsList + ' li a').text(tickerText + placeHolder);
			currentLength ++;
			setTimeout(function(){runTicker(settings); settings = null;},settings.tickerRate);
		}
		else {
			$(settings.newsList + ' li a').text(settings.newsItems[currentItem]);
			currentLength = 0;
			currentItem ++;
			setTimeout(function(){runTicker(settings); settings = null;},settings.loopDelay);	
		}	
	}
	
	$.fn.extend({
		newsTicker: function(settings) {
			settings = jQuery.extend({
		 	  	newsList: "#news",
		   		tickerRate: 40,
		    	startDelay: 50,
		    	loopDelay: 3000,
		    	placeHolder1: " |",
		    	placeHolder2: "_"
			}, settings);
			
			var newsItems = new Array();
			var newsLinks = new Array();
			var newsItemCounter = 0;
			
			$(settings.newsList + ' li a').each(function(){
				newsItems[newsItemCounter] = $(this).text();
				newsLinks[newsItemCounter] = $(this).attr('href');
				newsItemCounter ++;
			});
			
			settings = jQuery.extend(settings,{
				newsItems: newsItems,
				newsLinks: newsLinks,
				newsItemCounter: newsItemCounter - 1,
				currentItem: 0,
				currentLength: 0,
				firstRun:1
			});
			
			setTimeout(function(){runTicker(settings); settings = null;},settings.startDelay);
		}
	});
})(jQuery);

( function newsTicker() {
	$( document ).ready( function() {
		$( '#newsTicker > ul > li' ).show()
		if ( $( '#newsTicker' ).width() == 770 ) {
			var options = {
			  	newsList: "#newsTicker ul",
			 	startDelay: 10,
			 	placeHolder1: " "
			}
			$().newsTicker(options);
		};
	} );
}() );