$(document).ready(function() {
	//$('#news_wrapper').load('/admin/ajax/news');
	
	$("a.zoom").fancybox();
	//$('#buyonitunes').fadeIn(3000);
	$(".videoLink").bind('click', function() {
		pageTracker._trackPageview('#'+this.id);
		$.fancybox({
				'padding'		: 0,
				'autoScale'		: false,
				'transitionIn'	: 'none',
				'transitionOut'	: 'none',
				'title'			: this.title,
				'width'		: 680,
				'height'		: 495,
				'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
				'type'			: 'swf',
				'swf'			: {
					'allowfullscreen'	: 'true'
				}
			});

		return false;
	});
	$(".purchaseLink").bind('click', function() {
		pageTracker._trackPageview('#purchase');
		$.fancybox({
				'padding'		: 0,
				'autoScale'		: false,
				'transitionIn'	: 'none',
				'transitionOut'	: 'none',
				'title'			: this.title,
				'width'		: 680,
				'height'		: 620,
				'href'			: this.href,
				'type'			: 'iframe'
			});

		return false;
	});
	
	$('button[name=submitContact]').bind('click', function(){
		var problems = false;
		$.each($('#contactForm :input'), function(i,v){
			if (v.value == ''){
				$(this).css({'border': '1px solid red'});
				problems = true;
			}else{
				
			}
		});
		if (!problems){
			return true
		}	
		return false;
	});
	
	$('button[name=submitMailing]').bind('click', function(){
		var problems = false;
		$.each($('#mailingList :input'), function(i,v){
			if (v.value == ''){
				$(this).css({'border': '1px solid red'});
				problems = true;
			}else{
				
			}
		});
		if (!problems){
			return true
		}	
		return false;
	});
	
});

function trackPageView(which){
	which = which.split('The Debbie Miller - ')[1].replace(' ', '_');
	pageTracker._trackPageview('#'+which);
}

function toggleCarousel(which){
	pageTracker._trackPageview('#'+which);
	var howmuch;
	
	switch(which){
	
		case 'about':{
			howmuch = "-280px";
			break;
		}
		case 'contact':{
			howmuch = "-560px";
			break;
		}
		case 'press':{
			howmuch = "-840px";
			break;
		}
		case 'news':{
			howmuch = "0px";
			break;
		}
	}
	$("#carousel_slide").animate({
	      top: howmuch
	    }, { duration: 500});
}
function checkCode(){
	
	var code = $('input#promocode')[0].value;
	$.ajax({
	  url: '/handlepromos.php?code='+code,
	  success: function(data) {
	    if (data == 1){
			$.fancybox({
					'padding'		: 0,
					'autoScale'		: false,
					'transitionIn'	: 'none',
					'transitionOut'	: 'none',
					'title'			: this.title,
					'width'		: 680,
					'height'		: 620,
					'href'			: '/downloads.php?code='+code,
					'type'			: 'iframe'
				});
		}else{
			alert('You have either entered an invalid or already used promotional code!');
		}
	  }
	});
}
