var seed;

function scrollDown() {
	var curr = $("#ten-holidays ul").offset().top;
	var height = $("#ten-holidays ul").height(); //alert(height);
	if (curr >= seed-height+75) {
		$("#ten-holidays ul").animate({"top": "-=25px"}, "slow");
	} else {
		$("#ten-holidays ul").animate({"top": "0px"}, "slow");
	}
}

$(function() {
	// Homepage: Rotate Featured Videos
	$('#video-highlight li div.sel-holder a.vid-slide').click(function() { 
		var context = $(this).parent().parent(); 

		$('div.feature', context.parent()).slideUp('fast');
   		$('div.feature', context).slideDown('fast');

		return false;
	});
	  
	seed=$("#ten-holidays ul").offset().top;

	if (seed > 75) {
		scrolltimer = setInterval(scrollDown,1500);
		$('#ten-holidays').hover(function() {
			clearInterval(scrolltimer);
		}, function() {
			scrolltimer = setInterval(scrollDown,1500);
			scrollDown(seed);
		});
	}
	  
	$('form#searchForm').submit(function() {
		var start = new Date($('input#dateFrom', $(this)).val()); var month = start.getMonth() + 1;
		$('input#dateFrom_month', $(this)).val(start.getFullYear()+'-'+((month<10)?'0'+month:month));
		$('input#dateFrom_day', $(this)).val((start.getDate()<10)?'0'+start.getDate():start.getDate());
		$('input#dateFrom', $(this)).remove();

		var end = new Date($('input#checkout', $(this)).val()); month = end.getMonth() + 1;
		$('input#checkout_month', $(this)).val(end.getFullYear()+'-'+((month<10)?'0'+month:month));
		$('input#checkout_day', $(this)).val((end.getDate()<10)?'0'+end.getDate():end.getDate());
		$('input#checkout', $(this)).remove();
	});

	$('div.feature', $(this).parent().parent()).slideToggle('normal');

 	$('#video-thumbnails ul>li>div>a').click();

	// Searh Boxes: Clear the default Text
	$('#searchterm').focus(function() { if ($(this).val() == 'Search') { $(this).val(''); this.style.color = '#000'; } });
	$('#searchterm').blur(function() { if (this.value=='') { this.value='Search'; this.style.color = '#757575'; } });

	$('#video-searchterm').focus(function() { if ($(this).val() == 'Search') { $(this).val(''); this.style.color = '#000'; } });
	$('#video-searchterm').blur(function() { if (this.value=='') { this.value='Search'; this.style.color = '#757575'; } });

	// Newsletter Box: Clear default text
	$('#email', '#newsletter-signup-body').focus(function(){ if ($(this).val() == 'Enter your email') { $(this).val(''); this.style.color = '#000'; } });
	$('#email', '#newsletter-signup-body').blur(function(){ if (this.value=='') { this.value='Enter your email'; this.style.color = '#757575'; } });
	$('#newsletter-form').submit(function(){ if ($('#email', '#newsletter-signup-body').val() == 'Enter your email') return false; });

	$('#firstname', '#newsletter-signup-body').focus(function(){ if ($(this).val() == 'Enter your full name') { $(this).val(''); this.style.color = '#000'; } });
	$('#firstname', '#newsletter-signup-body').blur(function(){ if (this.value=='') { this.value='Enter your full name'; this.style.color = '#757575'; } });

	$('#phonenumber', '#newsletter-signup-body').focus(function(){ if ($(this).val() == 'Enter your daytime phone') { $(this).val(''); this.style.color = '#000'; } });
	$('#phonenumber', '#newsletter-signup-body').blur(function(){ if (this.value=='') { this.value='Enter your daytime phone'; this.style.color = '#757575'; } });

	$('#countdown-email').focus(function(){ if ($(this).val() == 'Enter your email') { $(this).val(''); this.style.color = '#000'; } });
	$('#countdown-email').blur(function(){ if (this.value=='') { this.value='Enter your email'; this.style.color = '#757575'; } });

	// Change focus photo on product detail page
	var selectedPhoto = undefined;

	$('#product-photos img.non-focus-photo').click(function() {
		selectedPhoto = MEDIA_URL_170x170 + this.src.substr((this.src.search('80x80/')+6));
		$('#focus-photo').attr('src', selectedPhoto);
	});
	$('#product-photos img.non-focus-photo').mouseover(function() {
		$('#focus-photo').attr('src', MEDIA_URL_170x170 + this.src.substr((this.src.search('80x80/')+6)));
	});
	$('#product-photos img.non-focus-photo').mouseout(function() {
		$('#focus-photo').attr('src', selectedPhoto);
	});

	// Open external CTA links in a new window
//	$('ul#cta-links a[href^=http]').each(function() {
//		$(this).click(function(){window.open(this.href);return false;});
//	});

	$('a.product-video-link').click(function(){
		$('#product-video-feature').html('');
		$('#blanket').fadeIn(1000, function() {
           	createMovie();
			$('#product-video-feature').show(1);
		});
		return false;
	});
	$('a.product-video-close').click(function(){
		$('#blanket').fadeOut(1000 ,function(){
			$('#product-video-feature').html('');
		});
		return false;
	});
	
	$('li#nav-cars a').each(function() {
			$(this).click(function(){window.open(this.href);return false;});
		}
	);

});