jQuery(document).ready(function($) {

    // fade out error message bg color
    $("#messages, #comment_errors, #comment_msgs").animate({opacity: 1.0}, 3000).animate({backgroundColor: '#ffffff'}, 3000);

    // share bookmarks on thankyou pages
    vanilla.baseUrl = location.href.split('?', 1);
    $(".thankyoubookmarks").bookmark({
        icons: "/images/bookmarks.png",
        url: vanilla.baseUrl,
        sites: ["delicious", "digg", "facebook", "fark", "google", "kaboodle", "mixx", "propeller", "reddit", "stumbleupon", "technorati", "twitthis", "yahoobuzz"]
    });
    $(".thankyoubookmarks").prepend('<p><strong>Share this with your friends:</strong></p>');

    // handlers for fields in signup stub form
    $("#signup_box_email, #signup_box_zip").focus(function() {
        vanilla.swapValue(this, false);
    });
    $("#signup_box_email, #signup_box_zip").blur(function() {
        vanilla.swapValue(this, true);
    });

	//handlers for fields in search and sign up form
	$("#email_address, #zip_code, #search_keywords").focus(function() {
		vanilla.swapValue(this, false);
	});
	$("#email_address, #zip_code, #search_keywords").blur(function()	{
		vanilla.swapValue(this, true);
	});
	
	
	//share icons
	$("#bookmarks").bookmark({
		icons: "/images/bookmarks.png",
		sites: ["facebook", "myspace"]
	});
	$("#bookmarks ul").prepend('<li class="share">Share &#160;</li>');
	
	// rotate thru a set of divs

	    $('#fade').innerfade({
	        speed: 2000,
	        timeout: 8000,
	        containerheight: 339,
	        tracker: 'switcher',
	        trackerclass: 'selected'
	    });

	    $('#stop').click(function() {
	        clearTimeout($('#fade').data('timer'));
	        $('#fade').removeData('timer');
	        $('#stop').hide();
	        $('#start').show();
	        return false;
	    });


	    $('#start').click(function() {
	        $('#start').hide();
	        $('#stop').show();
	        $('.selector').removeClass('selected');
	        $('#fade').innerfade({
	            speed: 2000,
	            timeout: 8000,
	            containerheight: 339,
	            tracker: 'switcher',
	            trackerclass: 'selected'
	        });
	        var id = $('#fade').data('next');
	        $('#' + id).addClass('selected');
	        return false;
	    });

	    $('.selector').click(function() {
	        if (this.id == 'stop' || this.id == 'start') {
	            return;
	        }

	        if($('#fade').data('timer')) {
	            clearTimeout($('#fade').data('timer'));
	            $('#fade').removeData('timer');
	            $('#stop').hide();
	            $('#start').show();
	        }

	        var id = Number(this.id);
	        $('.selector').removeClass('selected');
	        $(this).addClass('selected');
	        $('#fade li:visible').fadeOut(2000);
	        $('#feature_' + id).fadeIn(2000);
	        var num = $('#fade').data('num_elements');
	        if (id < num) {
	            $('#fade').data('next', id);
	        } else {
	            $('#fade').data('next', 0);
	        }
	        return false;
	    });			
	
	
		/* =========================================================

		innerfade.js

		Date: 2008-04-29
		Author: Plus Three LLC (http://plusthree.com/)

		Based heavily on jquery.innerfade.js by Torsten Baldes 
		(http://medienfreunde.com), which in turn is based on the work of 
		Matt Oakes (http://portfolio.gizone.co.uk/applications/slideshow/) 
		and Ralf S. Engelschall (http://trainofthoughts.org/).

		Changes include limiting rotation to sequential/fade, and enabling 
		a control menu.

		// ========================================================= */

		(function($) {

			$.fn.innerfade = function(options) {
				return this.each(function() {   
					$.innerfade(this, options);
				});
			};

			$.innerfade = function(container, options) {
				var settings = {
					'speed': 2000,
					'timeout': 2000,
					'containerheight': 'auto',
					'tracker': null,
					'trackerclass': null
		        };
				if (options) {
					$.extend(settings, options);
				}

				var elements = $(container).children();
				$(container).data('num_elements', elements.length);

				if (elements.length > 1) {

					// set css on parent and elements
					$(container).css('position', 'relative').css('height', settings.containerheight);
					for (var i = 0; i < elements.length; i++) {
						$(elements[i]).css('z-index', String(elements.length-i)).css('position', 'absolute').hide();
					};

					var next, current;
					if ($(container).data('next') == null) { // first run
						next = 1;
						current = 0;
						$(elements[0]).show();

						var timer = setTimeout(function() {
							$.innerfade.next(container, elements, settings, next, current);
						}, settings.timeout);
						$(container).data('timer', timer);
						$(container).data('next', next);
					} else {
						next = $(container).data('next');
						if ( next == 0 ) {
							current = elements.length - 1;
						} else {
							current = next - 1;
						}
						$.innerfade.next(container, elements, settings, next, current);
					}
				}
		    };

		    $.innerfade.next = function(container, elements, settings, next, current) {
				$(elements[current]).fadeOut(settings.speed);
				$(elements[next]).fadeIn(settings.speed, function() {
					if (settings.trackerclass) {
						$('#' + settings.tracker + ' a').removeClass(settings.trackerclass);
						$('#' + (current + 1)).addClass(settings.trackerclass);
					}
				});

				// caluculate for next run
				if ((next + 1) < elements.length) {
					next = next + 1;
					current = next - 1;
				} else {
					next = 0;
					current = elements.length - 1;
				}

				var timer = setTimeout((function() {
		            $.innerfade.next(container, elements, settings, next, current);
		        }), settings.timeout);

				$(container).data('timer', timer);
				$(container).data('next', next);
		    };
		
			$("#switcher a#1").append($("#fade li#feature_1").attr("title"));
			$("#switcher a#2").append($("#fade li#feature_2").attr("title"));
			$("#switcher a#3").append($("#fade li#feature_3").attr("title"));
			$("#switcher a#4").append($("#fade li#feature_4").attr("title"));

		})(jQuery);

		var AUTH_COOKIE_NAME       = 'auth_tkt';
		var PERSISTENT_COOKIE_NAME = 'ARCOS_PERSISTENT_LOGIN';
	
	
	});
	
	
	

