/*
 * All JavaScript to be fired when the DOM is ready
 */
jQuery(function($) {

    // Load Flickr photos
    $("#flickr-thumbs")
        .flickr({
                "flickrID" : "27972196@N08",
                "displayNum" : "12",
                "callback" : function(el){
                            $(el).thumbBox({
                                        "previewWidth" : "60",
                                        "previewHeight" : "60"
                                    });
                        }
            });

    // Displays a popover to new users (and every 30 days thereafter)
/*    if ( $.cookie('bfts_newsletter')==undefined )
    {
        $('<div>')
			.addClass("thumbbox-overlay")
			.css({"opacity":"0"})
			.bind("click", function(){
					$(".thumbbox-overlay, .thumbbox-main")
						.fadeOut(300, function(){ $(this).remove(); });
				})
			.appendTo('html')
			.fadeTo(300, .5),
		$('<div>')
			.addClass("thumbbox-main")
			.css({
				"top":$(window).scrollTop()+100+"px",
				"width":"400px",
				"height":"auto",
				"margin-left":"-200px"
			})
			.html('<div class="thumbbox-main-modal">'
                    + '<h2>Stay in Touch!</h2>'
                    + '<p>Enter Your Name and Email to Stay Updated on New '
                    + 'Class Times, News and Facility Locations and '
                    + 'Automatically Receive: </p>'
					+ '<ul><li>Why Sit-Ups Suck</li>'
                    + '<li>15 Motivational Tips for Your Best Year Ever</li>'
                    + '<li>Printable <a href="/blog/memento-mori/">Memento '
                    + 'Mori</a> Graph</li></ul>'
                    + '<form action="http://www.getresponse.com/cgi-bin/add.cgi"'
                    + 'method="post" accept-charset="UTF-8">'
					+ '<fieldset id="overlay-nl-capture">'
                    + '<label for="subscriber_name">Name</label>'
                    + '<input id="subscriber_name" name="subscriber_name" '
                    + 'type="text" class="thumbbox-main-modal-input" value="" />'
                    + '<label for="subscriber_email">Email</label>'
                    + '<input id="subscriber_email" name="subscriber_email" '
                    + 'type="text" class="thumbbox-main-modal-input" value="" />'
                    + '<input type="submit" class="thumbbox-main-modal-submit" '
                    + 'value="Sign Up" />'
                    + '<input type="hidden" name="error_url" id="error_url" '
                    + 'value="http://barefootfts.com#nlerror" />'
                    + '<input type="hidden" name="confirmation_url" '
                    + 'id="confirmation_url" value="http://barefootfts.com#signedup" />'
                    + '<input type="hidden" name="campaign_name" '
                    + 'id="campaign_name" value="nategreenfitness" />'
                    + '<input type="hidden" name="custom_ref" id="custom_ref" '
                    + 'value="" />'
                    + '<p class="no-spam"><strong>Spam Free Zone</strong> Your '
                    + 'email address will not be shared or solicited</p>'
                    + '</fieldset></form>'
                    + '<a href="#" class="thumbbox-close-btn">CLOSE</a></div>')
			.bind("click", function(){
					$(".thumbbox-overlay, .thumbbox-main")
						.fadeOut(300, function(){ $(this).remove(); });
					return false;
				})
			.appendTo("html");
        $(".thumbbox-main-modal input").bind("click", function(e){e.stopPropagation();});
        $.cookie('bfts_newsletter', 1, { "path":"/", "expires":30 });
    }

  	if(document.location.hash=="#signedup")
  	{
  		$overlay = $('<div>')
			.addClass("thumbbox-overlay")
			.css({"opacity":"0"})
			.bind("click", function(){
					$(".thumbbox-overlay, .thumbbox-main")
						.fadeOut(300, function(){ $(this).remove(); });
				})
			.appendTo('body')
			.fadeTo(300, .5),
		$thumbbox = $('<div>')
			.addClass("thumbbox-main")
			.css({
				"top":$(window).scrollTop()+100+"px",
				"width":"630px",
				"height":"auto",
				"margin-left":"-330px"
			})
			.html('<div class="thumbbox-main-modal"><h2>Your Reports Are on the Way!</h2>'
					+'<h3>Thank You - Please Confirm Your Email Address!</h3><p>Thank you '
					+'for your registering to receive your special reports, <strong>"Why Sit-Ups Suck"</strong> and '
					+'<strong>"15 Motivational Tips for Your Best Year Ever"</strong>, as well as your '
                    +'<strong>Printable Memento Mori Graph!</strong></p><p>To maintain a high '
					+'quality mailing list, we need to verify that you are a REAL personal '
					+'with a REAL email address (and not a robot), so we\'ll need you to '
					+'confirm your email address by clicking on the link in the email we '
					+'just sent to the address you signed up with.</p><p>Once you confirm '
					+'your email address by clicking on the link in that email, you will '
					+'have immediate access to download your free stuff.</p><p>If you do '
					+'not see the email, please be sure to check your spam/junk folder as '
					+'the confirmation emails are sometimes mistakenly filtered as such.</p>'
					+'<p>Also, if you have any kind of spam blocking software or internet '
					+'service provider (ISP) filters, add crg.weller@gmail.com '
					+'to your list of approved senders (also known as a "Whitelist" or '
					+'"safelist").</p><p>Because of spam problem these days, less and less '
					+'email actually reaches its intended destination due to over-aggressive '
					+'spam blocking measures. If you subscribed from a work email, you might '
					+'want to consider re-subscribing from your home or personal account, '
					+'since corporate email security is more likely to block our email '
					+'messages...which you don\'t want to miss.</p><p>For support, email '
					+'<a href="mailto:answers@ennuidesign.com">answers@'
					+'ennuidesign.com</a></p><a href="#" class="thumbbox-close-btn">CLOSE</a></div>')
			.bind("click", function(){
					$(".thumbbox-overlay, .thumbbox-main")
						.fadeOut(300, function(){ $(this).remove(); });
					return false;
				})
			.appendTo("body");
  	}
*/
    // Technically valid workaround for target="_blank"
    $('a[rel="external"]').attr('target', '_blank');

    // Newsletter input label visibility toggle
    $("[name=name],[name=email]")
        .each(function(){

                    $(this)
                        .data("oval", $(this).val())
                        .bind("focusin", function(){

                                    if( $(this).val()===$(this).data("oval") )
                                    {
                                        $(this).val("");
                                    }

                                })
                        .bind("focusout", function(){

                                    if( $(this).val()==="" )
                                    {
                                        $(this).val($(this).data("oval"));
                                    }

                                });

                });

});

