$(document).ready(function(){
	
	$('#subForm').submit(function(event){
		event.preventDefault();
		newsletter_submit();
	});
	
// MIKE - this block of code was erroring out and causing rest of script not to run
// Not sure what it does or how to fix
// BTW - the north america foxycart site's name has changed to reiki-us.foxycart.com, not reiki-north-america
	
//	if (FoxyDomain != 'reiki-north-america') {
	//	var cart_href = $('#searchbar a.foxycart').attr('href');
	//	cart_href = cart_href.replace('reiki-north-america.foxycart.com', FoxyDomain);
	//	$('#searchbar a.foxycart').attr('href',cart_href);
	//}
	
	if ($('#shop #tabs').length > 0) {
	
		$.featureList(
			$("#tabs li a"),
			$("#output li"), {
				start_item	:	0
			}
		);

	}
	
	if ($('#course-option-groups, #event-option-groups').length > 0) {

		var url = window.location.host.split('.');
		var sign = '';
		if (url[0] == 'eu') {
			sign = '\u20AC';
		} else if (url[0] == 'uk') {
			sign = "\u00A3";
		} else if (url[0] == 'au') {
			sign = "AU$";
		} else {
			sign = "US$";
		}
	
		$('#course-option-groups input[name=price], #event-option-groups input[name=price]').each(function(){
			var price = $(this).val();
			var price_cell = $(this).closest('tr').prev().find('td.event-price');
			if (price_cell.find('.sale').length > 0) {
				price.cell.find('.sale').text(sign+price);
			} else {
				price_cell.text(sign+price);			
			}
			
		});

	}

/*
	$("a.zoom").fancybox();

	$("a.zoom1").fancybox({
		'overlayOpacity'	:	0.8,
		'overlayColor'		:	'#000',
		'zoomSpeedIn'		:	600,
		'zoomSpeedOut'		:	600
	});
*/
			
	$(".country_changer").change(function() {
		
		var new_url = $(this).children("option:selected").val();
		// check for Foxycart items
		if (fc_json.products.length > 0) {
        	
        	// prompt user
			var clear_cart = confirm("All items in your cart will be removed when switching countries. Are you sure you wish to switch?");
			
			if (clear_cart == true)
				{
					
					$.get('https://' + FoxyDomain + '/cart?output=json&empty=true&callback=?' + fc_AddSession(), function(data){
						window.location = new_url;
					});
					
				}
			else
				{
					return false;
				}                

        } else {
        
	        // no items, forward to new country
    		window.location = new_url;                

    	}

    })

	$('a').click(function(){
		var href = $(this).attr('href');
		
		// see if the link is a full url
		var http_check = href.indexOf("http");
		var reiki_com = href.indexOf("reiki.com");
		
		if ((http_check != -1) && (reiki_com == -1)) {
			//$(this).attr('target', '_blank');
		}
		
	});
	
});

function newsletter_submit(){
	var form = $('#subForm');

	var name = form.find('input[name=name]').val();
	var email = form.find('input[name=email]').val();	
	var username = 'webservice';
	var password = 'reiki';
	
	if (name == '') {
		alert('Please fill in your name');
		return false;
	} else if (email == '') {
		alert('Please fill in your email address');
		return false;
	}

	$.get("/newsletters/add", { username:'webservice', password:'reiki', first_name:name, email:email },
	   function(data){
		if (data.indexOf("success") != -1) {
			form.fadeOut('slow', function(){
				$('#email_success').fadeIn();
			});
		} else {
			alert('Sorry, there was an error processing your sign up. Please try again shortly.');
		}		
	});
		
}

$(document).ready(function(){
	
	$(".section_01").addClass("active");
	$(".section_02").removeClass("active");
	$(".section_03").removeClass("active");
	$(".section_04").removeClass("active");
	$("#tabs_01").show();
	$("#tabs_02").hide();
	$("#tabs_03").hide();
	$("#tabs_04").hide();
	
	$(".section_01").click(function(){
		$(".section_01").addClass("active");
		$(".section_02").removeClass("active");
		$(".section_03").removeClass("active");
		$(".section_04").removeClass("active");
		$("#tabs_01").show();
		$("#tabs_02").hide();
		$("#tabs_03").hide();
		$("#tabs_04").hide();
	});
	$(".section_02").click(function(e){
		$(".section_01").removeClass("active");
		$(".section_02").addClass("active");
		$(".section_03").removeClass("active");
		$(".section_04").removeClass("active");
		$("#tabs_01").hide();
		$("#tabs_02").show();
		$("#tabs_03").hide();
		$("#tabs_04").hide();
	});
	$(".section_03").click(function(){
		$(".section_01").removeClass("active");
		$(".section_02").removeClass("active");
		$(".section_03").addClass("active");
		$(".section_04").removeClass("active");
		$("#tabs_01").hide();
		$("#tabs_02").hide();
		$("#tabs_03").show();
		$("#tabs_04").hide();
	});
	$(".section_04").click(function(){
		$(".section_01").removeClass("active");
		$(".section_02").removeClass("active");
		$(".section_03").removeClass("active");
		$(".section_04").addClass("active");
		$("#tabs_01").hide();
		$("#tabs_02").hide();
		$("#tabs_03").hide();
		$("#tabs_04").show();
	});
	
});

