$(document).ready(function(){

	// Show/hide req asterisks
	
	$(".cc_method").click(function(){
		$(".req_hide").show();
	});
	
	$(".cheque_method").click(function(){
		$(".req_hide").hide();
	});
	
	$(".imo_method").click(function(){
		$(".req_hide").hide();
	});
	
	//FancyBox Calls
	
	//Login Form
	
	$("#login_btn").fancybox({
		'scrolling'		: 'no',
		'titleShow'		: false,
		'padding'		: 0
	});
	
	$("#login_btn_foot").fancybox({
		'scrolling'		: 'no',
		'titleShow'		: false,
		'padding'		: 0
	});
	
	$(".book_login").fancybox({
		'scrolling'		: 'no',
		'titleShow'		: false,
		'padding'		: 0
	});
	
	$(".sub_login").fancybox({
		'scrolling'		: 'no',
		'titleShow'		: false,
		'padding'		: 0
	});
	
	//Change 'Continue Shopping' Link
	//$('#catCartDetails').find('a').attr('href', '/store/index.html');
	
	// Secure Zones Subscriptions Nav
	
	 $("ul.zoneSubscriptions li ul li.zoneName").each(function(){
	 	var itemName = $(this).text();
	 	var itemLink = $(this).find("a").attr("href");
	 	
	 	var listFormat = '<li><a href="' + itemLink + '">' + itemName + '</a></li>';
	 	
	 	$("#subscriptions").append(listFormat);
	 	
	 	//alert(listFormat);
	 });

	
	// Assign MP3 CD Tables Unique Classes
	$("table.productTable").each(function(index){
		var $classNum = index + 1;
		$(this).addClass("mp3_table" + $classNum);
	});
	
	$('table.mp3_table1 h5 a').contents().unwrap();
	$('table.mp3_table2 h5 a').contents().unwrap();
	$('table.mp3_table3 h5 a').contents().unwrap();
	$('table.mp3_table4 h5 a').contents().unwrap();

	// Show subscription forms
	
	$("#btn_mp3_wed").click(function(){
		$("form.sub_wed").hide();
		$(".mp3_table1").toggle();
		return false;
	});
	
	$("#btn_mp3_free").click(function(){
		$("form.sub_free").hide();
		$(".mp3_table2").toggle();
		return false;
	});
	
	$("#btn_mp3_mira").click(function(){
		$("form.sub_mira").hide();
		$(".mp3_table3").toggle();
		return false;
	});
	
	$("#btn_mp3_abudance").click(function(){
		$("form.sub_abudance").hide();
		$(".mp3_table5").toggle();
		return false;
	});
	
	$("#btn_mp3_wknd").click(function(){
		$("form.sub_wknd").hide();
		$(".mp3_table4").toggle();
		return false;
	});
	
	$("#btn_sub_wed").click(function(){
		$(".mp3_table1").hide();
		$("form.sub_wed").slideToggle();
		return false;
	});

	
	$("#btn_sub_free").click(function(){
		$(".mp3_table2").hide();
		$("form.sub_free").slideToggle();
		return false;
	});
	
	$("#btn_sub_mira").click(function(){
		$(".mp3_table3").hide();
		$("form.sub_mira").slideToggle();
		return false;
	});
	
	$("#btn_sub_abudance").click(function(){
		$(".mp3_table5").hide();
		$("form.sub_abudance").slideToggle();
		return false;
	});
	

	
	$("#btn_sub_wknd").click(function(){
		$(".mp3_table4").hide();
		$("form.sub_wknd").slideToggle();
		return false;
	});
	
	// Colour Events Date List
	
	$("ul.event_dates li:odd").addClass("odd");
	$("ul.event_dates li:even").addClass("even");
	
	// Populate Contribution Form Amount Field
	
	$(".cont_amount").click(function(){
		var contValue = $(this).val();
		$("#Amount").val(contValue);
	})
	
	$(".cont_amount_input").blur(function(){
		var contValue = $(this).val();
		$("#Amount").val(contValue);
	})
	
	// Random Quote Generator
	
	firstLoad = function(){
	
	var pause = 50; // define the pause for each tip (in milliseconds) 
		var length = $("#goodies_rotator li").length; 
		var temp = -1;		
	
		this.getRan = function(){
			// get the random number
			var ran = Math.floor(Math.random()*length) + 1;
			return ran;
		};
		this.show = function(){
			var ran = getRan();
			// to avoid repeating
			while (ran == temp){
				ran = getRan();
			}; 
			temp = ran;
			$("#goodies_rotator li").hide();	
			$("#goodies_rotator li:nth-child(" + ran + ")").show();		
		};
		
		show(); 
	
	}

	randomTip = function(going){
	
	if(going == 1) {

		var pause = 50; // define the pause for each tip (in milliseconds) 
		var length = $("#goodies_rotator li").length; 
		var temp = -1;		
	
		this.getRan = function(){
			// get the random number
			var ran = Math.floor(Math.random()*length) + 1;
			return ran;
		};
		this.show = function(){
			var ran = getRan();
			// to avoid repeating
			while (ran == temp){
				ran = getRan();
			}; 
			temp = ran;
			$("#goodies_rotator li").hide();	
			$("#goodies_rotator li:nth-child(" + ran + ")").show();		
		};
		
		show(); 
		
		int = setInterval(show,pause);
	
	} else {		
		clearInterval(int);
	}
	
	};
	
	firstLoad();
	
	$('#go').click(function(){
		randomTip(1);
	})
	
	$('#stop').click(function(){
		randomTip(0);
	})
	
	//Make shipping and billing addresses the same
	
	$('.ship_bill input:checkbox').change(function(){
	
		if ($('.ship_bill input:checkbox').is(':checked')){
			var shippingAddress = $('#ShippingAddress').val();
			var shippingCity = $('#ShippingCity').val();
			var shippingState = $('#ShippingState').val();
			var shippingZip = $('#ShippingZip').val();
			var shippingCountry = $('#ShippingCountry option:selected').val();
			
			$('#BillingAddress').val(shippingAddress);
			$('#BillingCity').val(shippingCity);
			$('#BillingState').val(shippingState);
			$('#BillingZip').val(shippingZip);
			$('#BillingCountry option[value=' + shippingCountry + ']').attr('selected','selected');

		
		}else{
			
			$('#BillingAddress').val('');
			$('#BillingCity').val('');
			$('#BillingState').val('');
			$('#BillingZip').val('');
			$("#BillingCountry option[value=' ']").attr('selected','selected');
		}	
	});
	
	// Hide 'New User' checkout info if logged in
	if($('body').hasClass('loggedin-1')){
		$('.newcust').hide();
	}
	
	// Hide 'Downloads' = 'MP3 CDs' from Catalog List
	
	$('ul.catalogueitemdump li').each(function(){
		if($(this).text() == 'Downloads'){
			$(this).hide();
		} else if ($(this).text() == 'MP3 CDs') {
			$(this).hide();
		}
	})
});
