
$(function() {
    Cufon.replace('#main-nav a, #menu-nav a, #category-nav ul a');
    Cufon.replace('.button');
    Cufon.replace('#current-location h2', { fontFamily: 'Knockout Junior Light' });

    $('#category-nav .list-container').serialScroll({
        items: 'a',
        step: 5,
        duration: 800,
        axis: 'x',
        prev: 'a.previous',
        next: 'a.next',
        force: true,
        stop: true,
        lock: false,
        cycle: false
    });

    $('#page-wrapper').localScroll({
        target: '#content',
        items: '.page',
        queue: true,
        duration: 800,
        axis: 'x',
        onAfter: function() {

            return true;
        }
    }).find('.page').fakeCenter();

    $('h1 .logo').click(function() { $('#main-nav li').removeClass('selected'); });
    $('#main-nav a').click(function() {
        $('html, body').animate({ scrollTop: 0 }, 'slow');
        $(this).parent().siblings('li').removeClass('selected');
        $(this).parent().addClass('selected');

    });

    $(window).bind('resize', function() {
        $('.page').fakeCenter();
    });

    $('.search-now').interceptEnter('#SubmitZipButton');
//    $('.contactus').interceptEnter('#contactussubmit');

    $('#zipCode').defaultVal('City, State or Zip');
    $('input[id=<%=EmailSignupRegistration.ClientID%>]').defaultVal('Your email address.');
    $('input[id=<%=departure_Address.ClientID%>]').defaultVal('Your starting address.');

    $('#current-location .change .button, .current-location .change .button').click(function() { $('#location-modal').trigger('show'); LoadMap(); return false; });
    $('#overlay, .cancel').click(function() { $('.modal').trigger('hide'); $('#overlay').hide(); return false; });


    $('.gototop').click(function() {
        $('html,body').animate({ scrollTop: 0 }, 'slow');
    });

    $('.exploretherewardscms').click(function() {
        $('html,body').animate({ scrollTop: $('#exploretherewards').offset().top }, 'slow');
    });

    $('.faqcms').click(function() {
        $('html,body').animate({ scrollTop: $('#faqcms').offset().top }, 'slow');
    });

    $('.programrulescms').click(function() {
        $('html,body').animate({ scrollTop: $('#programrulescms').offset().top }, 'slow');
    });

    $("#footer .top .inner h1").mouseover(function() {
        $(this).css('cursor:pointer');
    }).mouseout(function() {
        $(this).css('cursor:default');
    });

    $('.open').each(function(i) {
        $(this).click(function() {
            var strclass;
            strclass = $(this).attr('class').replace('open ', '');
            $('#modal-'+strclass).trigger('show');
            return false;
        });
    });

    $('.modal').bind('show', function() {
        $('#overlay').show();
        if ($(window).height() < $(this).height()) {
            $(this).css({ height: ($(window).height() * .745) + 'px' });
        }
        if ($(this).height() < 200) {
            $(this).css({ height: ($(window).height() * .745) + 'px' });
        }
        $(this).css({ top: ($(window).height() * .025) + 'px' }).show();
    });
    $('.modal').bind('hide', function() { $(this).css({ height: 'auto' }); $(this).hide(); });
});

jQuery.fn.fakeCenter = function() {
  var padding = ($(window).width()-$(this).width())/2;
  if (padding < 0) padding = 0;
  $(this).css({paddingLeft: padding+'px'});
}

jQuery.fn.defaultVal = function(value) {
    $(this).val(value);
    $(this).focus(
		function() { if ($(this).val() == value) $(this).val(''); }
	).blur(
		function() { if ($(this).val() == '') $(this).val(value); }
	);
}
