
	var Sf = Sf || {

		init : function() {

			Sf.sub_form();
			Sf.tweaks();

		},	//	init : function()



		sub_form : function() {

			$('.sub_form').submit(function() {

				sub_errors = false;

				mlist_name  = $('.sub_form input#mlist_name');
				mlist_email = $('.sub_form input#mlist_email');

				if (mlist_name.val()  == 'Name')  mlist_name.val('');
				if (mlist_email.val() == 'Email') mlist_email.val('');

				if (mlist_name.val() == '') {
					mlist_name.addClass('error');
					sub_errors = true;
				}

				if (mlist_email.val() == '') {
					mlist_email.addClass('error');
					sub_errors = true;
				}

				if (sub_errors) {
					$('.sub_message')
						.addClass('error')
						.html('You must provide both your name <em>and</em> your email address');
				} else {
					$('.sub_form input').removeClass('error');

					$.ajax({
						dataType : 'html',
						data     : 'ajax=true&name=' + mlist_name.val() + '&email=' + mlist_email.val(),
						success  : function(response) {
							Sf.sub_handle_response(response);
						},
						type     : 'POST',
						url      : '/incs/actions/ajax_subscribe.php'
					});
				}

				return false;
			});
		
		},



		sub_handle_response : function(response) {

			switch (response) {

				case 'win' :
					$('#footer .grid_3:first').animate({ opacity : 0 }, 'fast', 'linear', function() {
						$('.sub_message').remove();
						$('.sub_form').remove();
						$(this)
							.html('<h2>Thank you</h2><p>You are now signed up to the Snowsfields newsletter!</p>')
							.animate({opacity : 1 }, 'fast');
					});
				break;

				case 'fail' :
					$('.sub_message')
						.addClass('error')
						.html('There was an error processing your request. Please try again.');
				break;

				case 'already_registered' :
					$('input#mlist_email').addClass('error');
					$('.sub_message')
						.addClass('error')
						.html('Your email address is already registered. Would you like to <a href="/site/our-newsletter/">unsubscribe</a>?');
				break;

				case 'invalid_email' :
					$('input#mlist_email').addClass('error');
					$('.sub_message')
						.addClass('error')
						.html('Your email address is invalid. Please check it and try again.');
				break;

			}

		},



		tweaks : function () {

			$('body').addClass('js');

			//	Multi images
			if ($('.multi_images').get(0)) {
				$('ul.main_image').cycle({ 
					speed:   500,
					timeout: 5000,
					pager:   'ul.triggers', 
					pagerAnchorBuilder: function(slide) { 
						return 'ul.triggers li:eq(' + slide + ')';
					}
				});

				$('ul.triggers a').click(function() {	
					$('ul.main_image').cycle('pause'); 
				});
			}

			//	Google maps
			if ($('.jmap').get(0)) {
/*
				$('.jmap').jmap('init', {
					'mapType'   : 'hybrid',
					'mapCenter' : [37.4419, -122.1419]
				});
*/
			}

			//	Fix the product list up
			if ($('.products_list').get(0)) {
				$('.products_list').equalHeights();

				$('.products_list li').hover(
					function() { $(this).find('div').addClass('hover'); },
					function() { $(this).find('div').removeClass('hover'); }
				);

				$('.products_list li div a').bigTarget();
			}

			//	Subscribe form labels
			$('input.clicfield').clicfields();

			//	FireBug, yeah? - Load it up, load it up real good!
			if ($.isFunction(window.loadFirebugConsole)) window.loadFirebugConsole();

		}	//	tweaks : function ()

	};	//	var Sf = {}

	//	That's the anthem - get your damn hands up!
	$(function() {
		if (css_on() && !print_mode()) Sf.init();
	});
