$(document).ready(function() {

    //active tab
    var loc = window.location;

    if (loc.href.indexOf('menu') != -1) {
        $('#n1 a').addClass('current');
    } else if (loc.href.indexOf('our-story') != -1) {
        $('#n2 a').addClass('current');
    } else if (loc.href.indexOf('community') != -1) {
        $('#n3 a').addClass('current');
    } else if (loc.href.indexOf('franchising') != -1) {
        $('#n4 a').addClass('current');
    }

    var i = 2;
    var position = null;
    while (position == null && i > 0) {
        position = $.url.segment(i);
        i--;
    }
    //console.log(position);
    if (position != null) {
        $('#local a.' + position.toLowerCase()).addClass('current');
    } else {
        $('#local a.landing').addClass('current');
    }

    // focus/blur form fields
    $("#FindAnother, #Email, #EmailAddress, #zip, #zip2, #zip3, #VisitMonth, #VisitDay, #VisitYear, #AreaCity1, #AreaCity2, #AreaCity3").focus(
		function() {
		    if (this.value == this.defaultValue) {
		        this.value = "";
		    }
		}
	).blur(
		function() {
		    if (!this.value.length) {
		        this.value = this.defaultValue;
		    }
		}
	);

    // submit comment button hover
    $('#SubmitComments').hover(
		function() { // Change the input image's source when we "roll on"
		    $(this).attr({ src: '/images/bttn_submit-comments-over.gif' });
		},
		function() { // Change the input image's source back to the default on "roll off"
		    $(this).attr({ src: '/images/bttn_submit-comments.gif' });
		}
	);

    // submit comment button hover
    $('#Submit').hover(
		function() { // Change the input image's source when we "roll on"
		    $(this).attr({ src: '/images/bttn_submit-over.gif' });
		},
		function() { // Change the input image's source back to the default on "roll off"
		    $(this).attr({ src: '/images/bttn_submit.gif' });
		}
	);

    // Contact me button hover
		$('#Contact-Me').hover(
		function() { // Change the input image's source when we "roll on"
		    $(this).attr({ src: '/images/bttn_contact-me-over.gif' });
		},
		function() { // Change the input image's source back to the default on "roll off"
		    $(this).attr({ src: '/images/bttn_contact-me.gif' });
		}
	);

    // submit comment button hover
    $('#Search').hover(
		function() { // Change the input image's source when we "roll on"
		    $(this).attr({ src: '/images/bttn_search-over.gif' });
		},
		function() { // Change the input image's source back to the default on "roll off"
		    $(this).attr({ src: '/images/bttn_search.gif' });
		}
	);

    // create custom animation algorithm for jQuery called "bouncy" 
    $.easing.bouncy = function(x, t, b, c, d) {
        var s = 1.70158;
        if ((t /= d / 2) < 1) return c / 2 * (t * t * (((s *= (1.525)) + 1) * t - s)) + b;
        return c / 2 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2) + b;
    }
    // create custom tooltip effect for jQuery Tooltip 
    $.tools.tooltip.addEffect("bouncy",

    // opening animation 
        function(done) {
            this.getTip().animate({ top: '+=15' }, 500, 'bouncy', done).show();
        },

    // closing animation 
        function(done) {
            this.getTip().animate({ top: '-=15' }, 500, 'bouncy', function() {
                $(this).hide();
                done.call();
            });
        }
    );

    // print coupon link
    $('#print-coupon').prepend('<p class="print"><a href="#print">Print this coupon.</a></p>');
    $('#print-coupon p.print a').click(function() {
        window.print();
        return false;
    });

    // locations tooltip
    //    $("#label").tooltip({
    //        tip: '#locationtip',
    //        effect: 'bouncy',
    //        offset: [-5, -120] 	// tweak the position   
    //    }).click(function() { window.location.href = "/Locations"; });

    // cufon
    Cufon.replace('h1');
    Cufon.replace('h2');

});
