/* THIS CAN PROBABLY BE MERGED WITH A GENERIC CUSTOM SCRIPTS FILE */

// On load, do these things...
jQuery(document).ready(function($) {

	if ($('#nhp')){
		
		// Activate carousel for lead
		$('#lead .wrapper').smartCarousel({
			autoplay : 7500,
			loop: true,
			transition: "cover-up",
			menuTransitionSpeed: 400,	
			slideTransitionSpeed: 1000,	
			wrapperElement: '#features-wrap',
			cardElements: '.feature-item',
			paginateElement: '#features-nav',
			animatePagination: true,
			minHeight: 420
		});
		
		// Activate ticker
		$("ul#ticker00").liScroll();
		$('.winners').append('<span class="gradient"></span>');
		
		// Style offer text
		$('#lead h3 .offer').FontEffect({
			shadow:true,
			shadowColor:"#000",
			shadowOffsetLeft:7, 
			shadowOffsetLeft:3,
			shadowBlur:3,
			shadowOpacity :0.1,
			gradient :true,
			gradientColor :"#e9c559",
			gradientPosition:20, 
			gradientLength:40,
			gradientSteps :10
		}); 
		
		// Promo boxes - set up
		var promos = $('.quick-feature');
		promos.each(function(i){
			var el = $(this);
			var box = i;
			el.find('h2').after('<ul class="nav"></ul>');
			var nav = el.find('.nav');
			el.find('h3').each(function(i){
				var id = 'b'+box+'i'+i;
				$(this).siblings('.inner').append('<a href="#" class="close">Contract this view</a>').parent('li').attr('id',id);
				$(this).appendTo(nav).replaceWith( '<li><a href="#' + id + '"><span>' + $(this).text() + '</span></a></li>') ;
			});
			el.addClass('activated').find('.buttons .lesser').hide();
			var target = el.find('.nav a:first').attr('hash');
			$(target).addClass('on');
		});
		
		// Promo boxes - events
		promos.find('.nav a').mouseover(function(){
			var target = $(this).attr('hash');
			$(target).addClass('on').siblings('.on').removeClass('on');
		}).click(function(){
			var target = $(this).attr('hash');
			$(target).parent('ul').css({'z-index':5});
			$(target).animate({'width':'257px'}).find('.buttons .lesser').show();
			return false;
		});
		promos.find('.close').click(function(){
			var target = $(this).parent('.inner').parent('li');
			target.find('.buttons .lesser').hide();
			target.animate({'width':'130px'},function(){
				target.parent('ul').css({'z-index':2});
			});
			return false;
		});
		
		// Promo boxes - even heights
		$('.feature-row').each(function(){
			var nav = $(this).find('.nav');
			var minHeight = 0;
			nav.each(function(){
				if ($(this).height() > minHeight){
					minHeight = $(this).height();
				}
			});
			nav.css({'min-height':minHeight});
			$(this).find('.content .inner').css({'min-height':minHeight-5});
		});
				
	}		
});
