$(function () {
	try {
		$("ul").each(function() {
			$(this).find("> li:first").addClass('li_first');
			$(this).find("> li:last").addClass('li_last');
			$(this).find("> li:even").addClass('li_even');
			$(this).find("> li:odd").addClass('li_odd');
	    }); 
	    
	    $(':text').addClass('input_text');
	    $(':password').addClass('input_password');
	    $(':radio').addClass('input_radio');
	    $(':checkbox').addClass('input_checkbox');
    } catch(e) {}
    
    
    $('.dsrefdownload').bind('click', function() {
    	 alert('Note: The photo will download to your computer. It will not open in your browser.'); 
    });
    


	/* mc stuff */
	$('.box.sign_up input.btn_subscribe').hide();
	$('.box.sign_up a.btn_subscribe').show();
	
	$('.btn_subscribe').bind('click', function(ev) {
		var args = {};
		var form = $(ev.target).parents("form");
		var isLesson = form.hasClass("lesson_sign_up");
		form.find('input').each(function() {
				var i = $(this); 
				var n = i.attr('name');
				if (n && n.substr(0, 3) == "mc_") args[n] = i.val();
			}
		);
		
		var count = 0;
		for (var i in args) count++;
		if (count == 0) return true; // use default post method
		
		args.ajax = 1;
		var alert = form.find('.mc_alert');
		alert.css('color', 'black').html('Please wait...');
		$.ajax('/mc/subscribe.php', {
				data: args,
				complete : function (xhr, status) {
					if (status == "success") {
						var res = eval( "(" + xhr.responseText + ")"); 
						if (isLesson && res.action != "subscribe") {
							window.location.replace( unescape(window.location.pathname) );
						}
						if (res.success == 0) {
							alert.css('color', 'red');
						} else {
							alert.css('color', 'black');
						}
						var msg = res.message ? res.message : "You are already signed up!";
					} else {
						var msg = 'An error occurred. Please reload the page and try again.';
					}
					alert.html(msg);					
				}
			}
		);
		return false;
	});
})

