
// Defining the App namespace as an object literal
var App = {
	debug:false,
	routes: {
		'home' : homeCallback,
		'shop' : shopCallback,
		'item' : itemCallback,
		'about' : aboutCallback,
		'menu' : menuCallback,
		'locations' : locationsCallback,
		'press' : pressCallback,
		'news' : newsCallback
	} 
}

// App.namespace = window.location.pathname.split('/')[1] || 'index';

/**** Template ****************************************************/

$(document).ready(function(){
  /***Shop Coming Soon***/
  $('#shop-link a').mouseover(function() {
       $(".shop_soon").css("opacity","1");
   });
   $('#shop-link a').mouseout(function() {
        $(".shop_soon").css("opacity","0");
    })
  var window_height = $(window).height(); 
  var loader_height = $('#loader').height();
  var window_loader = (window_height-loader_height);
    $('.loader_container').show(0,function(){
      $(this).css({ 'top': window_loader/2});
    });
});

/**** Callback Functions ***************************************************/

/**** HOME **************************************************************/
function homeCallback() {
   VideoJS.setupAllWhenReady();
   
   $(window).load(function(){
    $('.loader_container').delay(300).fadeOut(1000,function(){  
		$('#container, .footer').fadeIn(1000);
		windowResize();
		$('.video-js-box').css({'width': '470px','height': '264px'});
		$('#about_preview').css({ 'height': '264px', 'float': 'left', 'margin': '0 auto', 'width': '470px'});
		// $('.iPhone .video-js-box').css({'width': '100%','height': 'auto'});
		// $('.iPhone #about_preview').css({'width': '100%','height': 'auto'});
    });
   
		$('.vjs-controls').css({'display': 'none'});
		$(".vjs-big-play-button").click(function(){
		$('.vjs-controls').css({'display': 'block'});
		$(".vjs-big-play-button").fadeOut(600);
		$('.vjs-controls').css({'display': 'block'});
    });
  });

   $(window).resize(function(){
       windowResize();
   });

   $(document).ready(function(){
      $("#tumblr_button_abc123 a").css({"background":"url('images/home_share_spt.png') top right no-repeat transparent", "width": "46px", "height": "46px" });
      $("#tumblr_button_abc123 a").attr('target','_blank')
      $('.top-nav, .top-nav li a ').css({ "text-shadow" : "2px 2px 2px #999", "background-image" : "none", "position": "relative"  });
      $('.top-nav li a:hover ').css({ "text-shadow" : "2px 2px 2px #999"});
      $('#header_logo a').css({"background": "url('/images/logo_white-01.png')" });
      $('.top-nav').css({"padding-top": "25px", "border-bottom": "none" });
      $('#header_logo a img').css({"display": "none" });

      $(".follow").click(function(){
        $(".follow-text").fadeOut(700, function(){
        $(".follow_icons").animate({ opacity: "1" }, 700);
          $(".share_icons").animate({ opacity: "0"}, function(){
          $(".share-text").fadeIn(700);
          });
        });
      });

      $(".share").click(function(){
        $(".share-text").fadeOut(700, function(){
        $(".share_icons").animate({ opacity: "1" }, 700);
          $(".follow_icons").animate({ opacity: "0"}, function(){
          $(".follow-text").fadeIn(700);
          });
        });
      });

      var window_height = $(window).height();
      var showHeight = (window_height-23);
      var textHeight =  (window_height-280)
      var textMargin =  (textHeight/2)

      $("#next a, #prev a").css({"top": textMargin+92});
      $("#slideshow .type-slide").css({"margin-top":textMargin});
      $(".cycle").css({"height": showHeight });
      $(" #slider-container").css({"top": showHeight });
      $("#pagination").css({"top": showHeight-1 });
     
      $('#slideshow').cycle({ 
 
         pager:  '#pagination',
         fit: 1,
         fx:  'fade',
         speed:  500,
         timeout: 0, 
         next:   '#next', 
         prev:   '#prev',
         updateActivePagerLink: function update(pager, activeIndex) { 
             $(pager).find('a:eq('+activeIndex+')').addClass('activeSlide').siblings().removeClass('activeSlide');
             movePager(); 
         },
		before: function() {
			$(".active").removeClass('active');
			refreshBackgrounds(".slide");
		},
		after: function() {
			$(this).addClass('active');
			refreshBackgrounds(".slide");
		} 
      });

     function movePager() {
       var move = $(".activeSlide").offset();
        $("#active-slider").animate({'left': move.left }, 500 );
       }
     });

     function windowResize(){
       var move = $(".activeSlide").offset();
       var pageCount = $("#pagination").children().length;
       var itemWidth = $("#pagination").width() / pageCount; 
       var padding = (itemWidth/2);
       $('#pagination a').css({ 'width': itemWidth-1});
       $('#active-slider').css({ 'width': itemWidth, 'left': move.left});
     }
     
     $(document).keydown(function(e) {

       if (e.keyCode == 39) { 
       $('#next a').click();
       }

       if (e.keyCode == 37) { 
       $('#prev a').click();
       }
     })
}

/**** SHOP ITEM **************************************************************/
function shopCallback(){

  $(window).load(function(){
     $('.loader_container').delay(300).fadeOut(1000,function(){  
      $('#container, .footer').fadeIn(1000);
      });
   });
}

/**** SHOP-ITEM ITEM **************************************************************/
function itemCallback(){
	$(function() {
    var menu = $('.top-nav');
    var top = menu.css('top'); 

      $(window).scroll(function() {
        var scrolled = $(window).scrollTop();

        if (scrolled > 48  ) {
          $('.shop_soon').css({'top' : '11px'});
          $('.top-nav').css({'padding-top' : '5px', 'padding-bottom' : '5px','height': '48px'});
          $('#locations-link, #press-link, #shop-link, #about-link, #menu-link, #news-link').css({'margin-top' : '15px'});
          $('#header_logo .icon').css({'opacity' : '0', 'margin-top': '-48px'});
        } else {
          $('.shop_soon').css({'top' : -1.43 * scrolled+80});
          $('.top-nav').css({'padding-top' : -.4166 * scrolled+25, 'padding-bottom' : -.4375 * scrolled+25, 'height': -1.7 * scrolled+130});
          $('#locations-link, #press-link, #shop-link, #about-link, #menu-link, #news-link').css({'margin-top' : -1 * scrolled+63}); 
          $('#header_logo .icon').css({'opacity' : -.04 * scrolled+1, 'margin-top': -.97 * scrolled+1});
        }
      });
  });

  $(window).load(function(){
     $('.loader_container').delay(300).fadeOut(1000,function(){  
      $('#container, .footer').fadeIn(1000);
      });
   });
}

/**** ABOUT **************************************************************/
function aboutCallback() {
  
  VideoJS.setupAllWhenReady();
  $(window).resize(function(){
      windowResize();
  });

  $(window).load(function(){

    $('.vjs-controls').css({'display': 'block'});
    $('.loader_container').delay(300).fadeOut(1000,function(){  
      $('#container, .footer').fadeIn(1000);
      windowResize();

      $('.video-js-box').css({'width': '1040px', 'margin': '0 auto'});
      $('#example_video_1').css({ 'height': '584px', 'float': 'left', 'margin': '0 auto', 'width': '1040px'});
    });

    $(".vjs-big-play-button, #play").click(function(){
		$(".vjs-big-play-button").fadeOut(600);
		$(".bb_video").fadeIn(600);
		$('.vjs-controls').css({'display': 'block'});
		$("#barber_poster").css({"opacity":"0", "pointer-events":"none"});
		$(".top-nav").css({"opacity":"0"});
		$("video").trigger("play");
    });
  });

  $(document).ready(function(){

    $('.top-nav, .top-nav li a ').css({ "text-shadow" : "2px 2px 2px #999", "background-image" : "none", "position": "relative"  });
    $('#header_logo a').css({"background": "url('/images/logo_white-01.png')" });
    $('.top-nav').css({"padding-top": "25px", "border-bottom": "none" });
    $('#header_logo a img').css({"display": "none" });

    $("#next, #prev, #pagination ").click(function(){
      $(".bb_video").fadeOut(600);
		$(".top-nav").css({"opacity":"1"})
      $("#barber_poster").css({"opacity":"1", "pointer-events":"auto"})
      $(".video-js-box").removeClass("vjs-playing").addClass("vjs-paused");
      $(".vjs-big-play-button").delay(500).fadeIn(0);
      $("video").trigger("pause");
    });

    $('.cycle').cycle({ 
        pager:  '#pagination',

        fit: 1,
        speed:  1000, 
        timeout: 0, 
        next:   '#next', 
        prev:   '#prev',
        updateActivePagerLink: function update(pager, activeIndex) { 
            $(pager).find('a:eq('+activeIndex+')').addClass('activeSlide').siblings().removeClass('activeSlide');
            movePager(); 
        },
		before: function() {
			$(".active").removeClass('active');
			refreshBackgrounds(".about_slide");
		},
		after: function() {
			$(this).addClass('active');
			refreshBackgrounds(".about_slide");
		}
    });

    function movePager() {
      var move = $(".activeSlide").offset();
       $("#active-slider").animate({'left': move.left }, 500 );

      }
    });

    function windowResize(){
        var move = $(".activeSlide").offset();
        var pageCount = $("#pagination").children().length;
        var itemWidth = $("#pagination").width() / pageCount; 
        var padding = (itemWidth/2);
        $('#pagination a').css({ 'width': itemWidth-1});
        $('#active-slider').css({ 'width':itemWidth, 'left': move.left});

      }

  
  $(document).keydown(function(e) {
    if (e.keyCode == 39) { 
    $('#next a').click();
    }
    
    if (e.keyCode == 37) { 
    $('#prev a').click();
    }
  })
  
}

/**** MENU **************************************************************/
function menuCallback() {
  
  $(window).resize(function(){
      windowResize();
  });

  $(document).ready(function(){
    $('.top-nav, .top-nav li a ').css({"text-shadow" : "2px 2px 2px #999", "background-image" : "none", "position": "relative"  });
    $('#header_logo a').css({"background": "url('/images/logo_white-01.png')" });
    $('.top-nav').css({"padding-top": "25px", "border-bottom": "none" });
    $('#header_logo a img').css({"display": "none" });

    var window_height = $(window).height();
    var showHeight = (window_height-23);
    var textHeight =  (window_height-240)
    var textMargin =  (textHeight/2)

    $("#next a, #prev a").css({"top": textMargin+92});
    $("#slideshow .type-slide").css({"margin-top":textMargin});
    $(".menu_slide, .cycle").css({"height": showHeight });
    $(" #slider-container").css({"top": showHeight });
    $("#pagination").css({"top": showHeight-1 });
    $(".tab-container").css({"top": showHeight-30 });

    $(function () {
    	var austDay = new Date();
    	austDay = new Date(austDay.getFullYear() + 0, 3-1, 15);
    	$('#defaultCountdown p').countdown({until: austDay});
    	$('#year').text(austDay.getFullYear());
    });

    $('.tabs:first-child a:first-child box').removeClass('t-inactive').addClass('t-active');

      var activeTabs = $(".tab .t-active");
      var activeParent = $(".tab .t-active").parent();
      var location_id = $(activeParent).attr('id').split('_')[1];
      var menu_id = '#menu_' + location_id;

        if (activeTabs) {
        $(menu_id).css('display','inline-block');
      }

    $('.tabs a box').click(function(){
       var location = $(this).attr('id').split('_')[1];
       var menu = $(".location_menu").attr('id').split('_')[1];
       $('.tabs a box').removeClass('t-active').addClass('t-active, t-inactive');
       $(this).removeClass('t-active, t-inactive').addClass('t-active');

       var activeTabs = $(".tab .t-active");
       var activeParent = $(".tab .t-active").parent();
       var location_id = $(activeParent).attr('id').split('_')[1];
       var menu_id = '#menu_' + location_id;

         if (activeTabs) {
        $('.location_menu').fadeOut(700,function(){
         $(menu_id).delay(700).fadeIn(700);

        });
       }
     });

    $('.cycle').cycle({ 
        pager:  '#pagination',
        containerResize: false,
        slideResize: false,
        fit: 1,
        speed:  1000, 
        timeout: 0, 
        next:   '#next', 
        prev:   '#prev',
        updateActivePagerLink: function update(pager, activeIndex) { 
            $(pager).find('a:eq('+activeIndex+')').addClass('activeSlide').siblings().removeClass('activeSlide');
            movePager(); 
        },
		before: function() {
		$(".active").removeClass('active');
		refreshBackgrounds(".menu_slide");
		},
		after: function() {
		$(this).addClass('active');
		refreshBackgrounds(".menu_slide");
		} 
    });

    function movePager() {
      var move = $(".activeSlide").offset();
       $("#active-slider").animate({'left': move.left }, 500 );
      }
    });

    $(window).load(function(){
      $('.loader_container').delay(300).fadeOut(1000,function(){  
        $('#container, .footer').fadeIn(1000);
        windowResize();
        });
    });

    function windowResize(){
        var move = $(".activeSlide").offset();
        var pageCount = $("#pagination").children().length;
        var itemWidth = $("#pagination").width() / pageCount; 
        var padding = (itemWidth/2);
        $('#pagination a').css({ 'width': itemWidth-1});
        $('#active-slider').css({ 'width':itemWidth, 'left': move.left});
      }

  $(document).keydown(function(e) {
     if (e.keyCode == 39) { 
     $('#next a').click();
     }
     if (e.keyCode == 37) { 
     $('#prev a').click();
     }
   })

}

/**** LOCATIONS**************************************************************/
function locationsCallback() {
  
  $(window).load(function(){
    $('.loader_container').delay(300).fadeOut(1000,function(){  
      $('#container, .footer').fadeIn(1000);
      windowResize();
      initialize();
      });
  });
  
  $(window).resize(function(){
      windowResize();
  });

  $(document).ready(function(){
    $('.top-nav, .top-nav li a ').css({"text-shadow" : "2px 2px 2px #999", "background-image" : "none", "position": "relative"  });
    $('#header_logo a').css({"background": "url('/images/logo_white-01.png')" });
    $('.top-nav').css({"padding-top": "25px", "border-bottom": "none" });
    $('#header_logo a img').css({"display": "none" });

    var window_height = $(window).height();
    var showHeight = (window_height-23);
    var textHeight =  (window_height-280)
    var textMargin =  (textHeight/2)

    $("#next a, #prev a").css({"top": textMargin+92});
    $("#menu_slideshow .type-slide").css({"margin-top":textMargin});
	$("#menu_slideshow .type-slide .subheader_box").addClass('reserve_link');
    $(".menu_slide, .cycle").css({"height": showHeight });
    $(" #slider-container").css({"top": showHeight });
    $("#pagination").css({"top": showHeight-1 });
    $(".tab-container").css({"top": showHeight-30 });

    $(function () {
    	var austDay = new Date();
    	austDay = new Date(austDay.getFullYear() + 0, 3-1, 15);
    	$('#defaultCountdown p').countdown({until: austDay});
    	$('#year').text(austDay.getFullYear());
    });

    $('.tabs:first-child a:first-child box').removeClass('t-inactive').addClass('t-active');

      var activeTabs = $(".tab .t-active");
      var activeParent = $(".tab .t-active").parent();
      var location_id = $(activeParent).attr('id').split('_')[1];
      var menu_id = '#place_' + location_id;

      if (activeTabs) {
      $(menu_id).css('display','inline-block');
      }

    $('.tabs a box').click(function(){
       var location = $(this).attr('id').split('_')[1];
       var menu = $(".location_locations").attr('id').split('_')[1];
       $('.tabs a box').removeClass('t-active').addClass('t-active, t-inactive');
       $(this).removeClass('t-active, t-inactive').addClass('t-active');

       var activeTabs = $(".tab .t-active");
       var activeParent = $(".tab .t-active").parent();
       var location_id = $(activeParent).attr('id').split('_')[1];
       var menu_id = '#place_' + location_id;

         if (activeTabs) {
        $('.location_locations').fadeOut(700,function(){
         $(menu_id).delay(700).fadeIn(700);

        });
       }
     });

    $('.cycle').cycle({ 
        pager:  '#pagination',
        containerResize: false,
        slideResize: false,
        fit: 1,
        speed:  1000, 
        timeout: 0, 
        next:   '#next', 
        prev:   '#prev',
        updateActivePagerLink: function update(pager, activeIndex) { 
            $(pager).find('a:eq('+activeIndex+')').addClass('activeSlide').siblings().removeClass('activeSlide');
            movePager(); 
        },
		before: function() {
			$(".active").removeClass('active');
			refreshBackgrounds(".menu_slide");
		},
		after: function() {
			$(this).addClass('active');
			refreshBackgrounds(".menu_slide");
		}
    });

    function movePager() {
      var move = $(".activeSlide").offset();
       $("#active-slider").animate({'left': move.left }, 500 );

      }

      $('.parlor_cycle').cycle({ 
          pager:  '#parlor_pagination',
          containerResize: false,
          slideResize: false,
          fit: 1,
          speed:  1000, 
          timeout: 0, 

          updateActivePagerLink: function update(pager, activeIndex) { 
              $(pager).find('a:eq('+activeIndex+')').addClass('parlor_activeSlide').siblings().removeClass('parlor_activeSlide');
              moveParlorPager(); 
          },
          before: function() {
            $(".parlor_active").removeClass('parlor_active')

          },
          after: function() {
            $(this).addClass('parlor_active');

          } 
      });

      function moveParlorPager() {

        var move = $(".parlor_activeSlide").position();
         $("#parlor-active-slider").animate({'left': move.left }, 500 );

        }

      parlorSliderResize();
    });
    
    function windowResize(){
        var move = $(".activeSlide").offset();
        var pageCount = $("#pagination").children().length;
        var itemWidth = $("#pagination").width() / pageCount; 
        var padding = (itemWidth/2);
        $('#pagination a').css({ 'width': itemWidth-1});
        $('#active-slider').css({ 'width':itemWidth, 'left': move.left});

      }

      function parlorSliderResize(){

          var move = $(".parlor_activeSlide").position();
          var pageCount = $("#parlor_pagination").children().length;
          var itemWidth = $("#parlor_pagination").width() / pageCount; 
          var padding = (itemWidth/2);
          $('#parlor_pagination a').css({ 'width': itemWidth-1});
          $('#parlor-active-slider').css({ 'width':itemWidth, 'left': move.left});

        }

      function initialize() {

        // Create an array of styles.
        var pinkParksStyles = [
          {
            featureType: "all",
            stylers: [
              { saturation: -99 },

              { visibility: "on" },
              { gamma: .67 },
              { lightness: 45 }
            ]
          }
        ];

        // Create a new StyledMapType object, passing it the array of styles,
        // as well as the name to be displayed on the map type control.
        var pinkMapType = new google.maps.StyledMapType(pinkParksStyles,
          {name: "Blink Barber NY"});

        // Create a map object, and include the MapTypeId to add
        // to the map type control.
        var mapOptions = {
          zoom: 18,
          disableDefaultUI: true,
          center: new google.maps.LatLng(40.72711,-73.98016),
          mapTypeControlOptions: {
            mapTypeIds: [google.maps.MapTypeId.ROADMAP, 'pink_parks']
          }
        };
        var map = new google.maps.Map(document.getElementById('map_canvas'),
          mapOptions);
        var image = 'images/marker.png';
         var myLatLng = new google.maps.LatLng(40.72711,-73.98016);
         var beachMarker = new google.maps.Marker({
             position: myLatLng,
             map: map,
             icon: image
         });
      //Associate the styled map with the MapTypeId and set it to display.
        map.mapTypes.set('pink_parks', pinkMapType);
        map.setMapTypeId('pink_parks');
      }
  
  $(document).keydown(function(e) {
     if (e.keyCode == 39) { 
     $('#next a').click();
     }
     if (e.keyCode == 37) { 
     $('#prev a').click();
     }                        
   })
  
}

function pressCallback() {
  $(function() {
    var menu = $('.top-nav');
    var top = menu.css('top'); 

      $(window).scroll(function() {
        var scrolled = $(window).scrollTop();
        if (scrolled > 48  ) {
          $('.shop_soon').css({'top' : '11px'});
          $('.top-nav').css({'padding-top' : '5px', 'padding-bottom' : '5px','height': '48px'});
          $('#locations-link, #press-link, #shop-link, #about-link, #menu-link, #news-link').css({'margin-top' : '15px'});
          $('#header_logo .icon').css({'opacity' : '0', 'margin-top': '-48px'});
        } else {
          $('.shop_soon').css({'top' : -1.43 * scrolled+80});
          $('.top-nav').css({'padding-top' : -.4166 * scrolled+25, 'padding-bottom' : -.4375 * scrolled+25, 'height': -1.7 * scrolled+130});
          $('#locations-link, #press-link, #shop-link, #about-link, #menu-link, #news-link').css({'margin-top' : -1 * scrolled+63}); 
          $('#header_logo .icon').css({'opacity' : -.04 * scrolled+1, 'margin-top': -.97 * scrolled+1});
        }

      });
  });

  $(document).ready(function(){  
    $(".press_cycle").load(function() {
    $(".press_cycle").fadeIn();
    });

    $('#item_504608').addClass('active');


    $(".logo, .press_nave").live('click',function(){
    
      var link = $(this).attr('href');
    
      $.ajax({
        beforeSend: function() {
          
          $(".press, .press_head").fadeOut("fast");
        },
        url:link,
        cache: true,
        success: function(html){
          $("#press_load, .press_cycle").html(html);
          if($.browser.msie && parseInt($.browser.version) == 8) {
              $(".thumb img").css( "opacity", 1);
              $(".active img").css( "opacity", .40);
              $(".press_head a img").css( "background-color", "#f9f9f9");
              $(' .press_head a img')
                      .hover(function() {
                          $(this).stop().animate({opacity:.60}, 700);
                      }, function() {
                          $(this).stop().animate({opacity:1}, 700);
                      });
              }
 // Press detail page
          $('.press_cycle').cycle({ 
              pager:  '#press_pagination',
              containerResize: false,
              slideResize: false,
              fit: 1,
              speed:  1000, 
              timeout: 0,
              next:   '#next', 
              prev:   '#prev',
              updateActivePagerLink: function update(pager, activeIndex) { 
                  $(pager).find('a:eq('+activeIndex+')').addClass('activeSlide').siblings().removeClass('activeSlide');
                  movePager(); 
              },
              before: function() {
                $(".active").removeClass('active')
              },
              after: function() {
                $(this).addClass('active');
              } 
          });
          function movePager() {
            var move = $(".activeSlide").position();
             $("#active-slider").animate({'left': move.left }, 500 );
            }
          pressSliderResize();
              $(".press_cycle").fadeIn();
        }
      
      });    
          
      return false;    
     });  

      $('.press_cycle').cycle({ 
          pager:  '#press_pagination',
          containerResize: false,
          slideResize: false,
          fit: 1,
          speed:  700, 
          timeout: 0, 
          next:   '#next', 
          prev:   '#prev',
          updateActivePagerLink: function update(pager, activeIndex) { 
              $(pager).find('a:eq('+activeIndex+')').addClass('activeSlide').siblings().removeClass('activeSlide');
              movePager(); 
          },
          before: function() {
            $(".active").removeClass('active')

          },
          after: function() {
            $(this).addClass('active');

          }
      });
      
      function movePager() {
        
        var move = $(".activeSlide").position();
         $("#active-slider").animate({'left': move.left }, 500 );
        }
      $(".logo").click(function(){
        $('.press_cycle').removeClass('press_cycle').addClass('press_cycle_new');
        $(".newClass").fadeOut("fast");
        $(window).stop().scrollTo(0,'fast',{axis:'y'});;
      
      });

      $('#nav ul li a')
             .hover(function() {
                 $(this).stop().animate({ color: "#83B1C9" }, 700 );
             }, function() {
                 $(this).stop().animate({ color: "#808080" }, 700 );
             });

       $('#menu .place a .contact_store  ')
              .hover(function() {
                  $(this).stop().animate({ color: "#666666" }, 700 );
              }, function() {
                  $(this).stop().animate({ color: "#83B1C9" }, 700 );
              }); 
            
        $('.blog_title a,.sign a, .thanks h3 a, #news_link a, a#s-report, .load_more_link h2 a, .arrow_more a, .press_text a, .sub input, .arrow_more ')
               .hover(function() {
                   $(this).stop().animate({ color: "#999999" }, 700 );
               }, function() {
                   $(this).stop().animate({ color: "#83B1C9" }, 700 );
               });
             
          $('.popup_nav li a')
               .hover(function() {
                   $(this).stop().animate({ color: "#555555" }, 700 );
               }, function() {
                   $(this).stop().animate({ color: "#999999" }, 700 );
               });
                 
         
           $('a.l_blue, .map a ')
                .hover(function() {
                    $(this).stop().animate({ color: "#555555" }, 700 );
                }, function() {
                    $(this).stop().animate({ color: "#83B1C9" }, 700 );
                });
        
            $('.credit a, .footerLinks ul li a  ')
                   .hover(function() {
                       $(this).stop().animate({ color: "#444444" }, 700 );
                   }, function() {
                       $(this).stop().animate({ color: "#808080" }, 700 );
                   });
                 
            $("select").focus(function(){
               $(".real_subject").css("border-color", "#83B1C9");
             });
         
            $("textarea, input").focus(function(){
               $(".real_subject").css("border-color", "#CCC");
             });
           
             $(document).keydown(function(e) {

               if (e.keyCode == 39) { 
               $('.press_right').click();
               }

               if (e.keyCode == 37) { 
               $('.press_left').click();
               }                        

             });
            
  });
  $(window).load(function(){
     $('.loader_container').delay(300).fadeOut(1000,function(){  
       $('#container, .footer').fadeIn(1000);
       pressSliderResize();
       });
   });
   
   function pressSliderResize(){      
      var move = $(".activeSlide").position();
      var pageCount = $("#press_pagination").children().length;
      var itemWidth = $("#press_pagination").width() / pageCount; 
      var padding = (itemWidth/2);
      $('#press_pagination a').css({ 'width': itemWidth-1});
      $('#active-slider').css({ 'width':itemWidth, 'left': move.left});
    }
}

/**** News **************************************************************/

function newsCallback(){
  
  $(window).load(function(){
$('.post').fadeIn(700);    
$('.loader_container').delay(300).fadeOut(1000,function(){  
       $('.post, #container, .footer').fadeIn(1000);
		
    });
    
   });

  $(function() {
    var menu = $('.top-nav');
    var top = menu.css('top'); 

      $(window).scroll(function() {
        var scrolled = $(window).scrollTop();

        if (scrolled > 48  ) {
          $('.shop_soon').css({'top' : '11px'});
          $('.top-nav').css({'padding-top' : '5px', 'padding-bottom' : '5px','height': '48px'});
          $('#locations-link, #press-link, #shop-link, #about-link, #menu-link, #news-link').css({'margin-top' : '15px'});
          $('#header_logo .icon').css({'opacity' : '0', 'margin-top': '-48px'});
        } else {
          $('.shop_soon').css({'top' : -1.43 * scrolled+80});
          $('.top-nav').css({'padding-top' : -.4166 * scrolled+25, 'padding-bottom' : -.4375 * scrolled+25, 'height': -1.7 * scrolled+130});
          $('#locations-link, #press-link, #shop-link, #about-link, #menu-link, #news-link').css({'margin-top' : -1 * scrolled+63}); 
          $('#header_logo .icon').css({'opacity' : -.04 * scrolled+1, 'margin-top': -.97 * scrolled+1});
        }
      });
  });


		$(document).ready(function(){
      

      $(".tmblr_button a").css({"background":"url('images/news_share.png') top right no-repeat transparent", "width": "24px", "height": "24px" });
      $(".tmblr_button a").attr('target','_blank')

       var shareID = $(".blog_share");
      $(shareID).click(function(){
            var vae_id = $(this).attr('id').substring(6);
            var icons_id = '#icons_' + vae_id;
            $(this).fadeOut(700, function(){
                $(icons_id).fadeIn(700);
            });
      });
      
		});
		
		$(function(){
		  
    $('#load_container').infinitescroll({
       navSelector  : "#next_link:last",            
       nextSelector : "#next_link:last",    
       itemSelector : ".post",          
       donetext     : "You've reached the last post" ,
       loadingImg   : "/images/ajax-loader.gif",          
       extraScrollPx: 50,
       loadingText  : "loading", 
       animate      : true,     
       bufferPx     : 1300
       },function(arrayOfNewElems){
         $('.post').fadeIn(700);
         Cufon.replace('.headline, .ny_la', { fontFamily: 'condensed' });
       	 Cufon.replace('h5, h5 a, h2 , h2 a, .blog_title a, .load_more a',{ fontFamily: 'condensed-bold', hover: true });
          var shareID = $(".blog_share");
         $(shareID).click(function(){
               var vae_id = $(this).attr('id').substring(6);
               var icons_id = '#icons_' + vae_id;
               $(this).fadeOut(700, function(){
                   $(icons_id).fadeIn(700);
               });
         });
     });

         // kill scroll binding
         $(window).unbind('.infscr');

         // hook up the manual click guy.
         $('#next_link').click(function(){
           $(document).trigger('retrieve.infscr');
           return false;
         });

         // remove the paginator when we're done.
         $(document).ajaxError(function(e,xhr,opt){
           if (xhr.status == 404) $('#next_link').remove();
         });
     });
  // end
}

/**** Functions********************************************************/
  function userAgent(iOs){
    // if iOs parameter is present detect if user agent is iOs.
    if(iOs) {
      if(navigator.userAgent.match(/(iPad|iPhone|iPod)/i))
        return true;
      else
        return false;
    // else detect the user agent
    } else {
      if(navigator.userAgent.match(/iPod/i))
        return 'iPod';
      if(navigator.userAgent.match(/iPhone/i))
        return 'iPhone';
      else if(navigator.userAgent.match(/iPad/i))
        return 'iPad';
      else
        return false;
    }
  }

// User Agent Examples
var platform = userAgent();
$('html').addClass(platform);

// Footer Callbacks
function line_up_lightbox() {			
  var windowHeight = $(window).height();
  var middleHeight = $('.middle').height();
  var middleTop = (windowHeight-middleHeight);
	$('.middle').css({'top': "85px"});
}

function placeholderFallback () {
	
	if (!Modernizr.input.placeholder) {
		$('[placeholder]').focus(function() {
		  var input = $(this);
		  if (input.val() == input.attr('placeholder')) {
			input.val('');
			input.removeClass('placeholder');
		  }
		}).blur(function() {
		  var input = $(this);
		  if (input.val() == '' || input.val() == input.attr('placeholder')) {
			input.addClass('placeholder');
			input.val(input.attr('placeholder'));
		  }
		}).blur();
		$('[placeholder]').parents('form').submit(function() {
		  $(this).find('[placeholder]').each(function() {
			var input = $(this);
			if (input.val() == input.attr('placeholder')) {
			  input.val('');
			}
		  })
		});
			
		}
}

function load_into_lightbox( url ) {
	trigger_load( url );


}

function trigger_load( url ) {

		
	$('.footer_popup .middle').css('display', 'block').load( url, function() {
		line_up_lightbox();
		placeholderFallback ();
		$("SELECT").selectBox('create');
		$(".drop_down_footer SELECT").selectBox('settings', {
			'menuTransition': 'slide',
			'menuSpeed' : 'fast'
      });

	});
}

/**** Document.ready ********************************************************/
function refreshBackgrounds(selector) {
  // Chrome shim to fix http://groups.google.com/a/chromium.org/group/chromium-bugs/browse_thread/thread/1b6a86d6d4cb8b04/739e937fa945a921
  // Remove this once Chrome fixes its bug.
  if (/chrome/.test(navigator.userAgent.toLowerCase())) {
    $(selector).each(function() {
      var $this = $(this);
      if ($this.css("background-image")) {
        var oldBackgroundImage = $this.css("background-image");
        setTimeout(function() {
          $this.css("background-image", oldBackgroundImage);
        }, 1);
      }
    });
  }
}

jQuery(function(){
  	$(document).bind('keydown', 'esc', function(){ $('.footer_popup').trigger('click'); });



		$('.footer-nav li a, .reserve_link a, .parlor_hours a').click(function(){
			$('select').selectBox('destroy');
			var this_class = $(this).get(0).className;
			$('.footer_popup').slideToggle({
				easing:'easeInCubic',
				speed: 2000
			});

			$('.footer_popup .popup_nav a.white').removeClass('white');
			$('.footer_popup .popup_nav a.' + this_class).addClass('white');
			line_up_lightbox();
			load_into_lightbox($(this).attr('href') );
			
			return false;
		});

		$('.popup_nav li a').click(function(){
		  $('.footer_content').fadeOut(0);
		  $('select').selectBox('destroy');
			$('.popup_nav li a').removeClass('white');
			$(this).addClass('white');
			load_into_lightbox( $(this).attr('href'));
			var windowHeight = $(window).height();
			var friendsHeight = (windowHeight-350);
			$('#foot_scroll').css({'height':friendsHeight });
			
		});

		$('.footer_popup .x a, .popup_nav li').click(function(event){
			if( $(event.target).parents('.middle, .popup_nav').length > 0 || $(event.target).hasClass('middle_white, .popup_nav') ) {
				return false;
			}

			$('.footer_popup').slideUp({
				easing:'easeOutCubic',
				speed: 1000
			});

			$('.middle').fadeOut(1000);
			
			return false;
		});

	Cufon.replace('.ny_la, .ny_la a', {fontFamily: 'condensed', hover: true });
	Cufon.replace('h5, h5 a, h2 , h2 a, .blog_title a, .load_more a',{ fontFamily: 'condensed-bold', hover: true });
	Cufon.replace('.headline', {fontFamily: 'condensed' });
  // This code figures out which callback function to call based upon the URL
  App.currentPage = window.location.pathname.split('/')[1] || 'home';
  // console.log(App.currentPage);

  if(App.routes[App.currentPage])
    App.routes[App.currentPage].call();
  else
	if(App.debug == true)
	    console.log('callback function not defined for route ' + App.currentPage);
 
/** Input **********************************************************/
placeholderFallback ();

    /** Browser Query **********************************************************/

			if($.browser.msie && parseInt($.browser.version) == 6) {
				$("body").css({ "background": "#f5f5f5"});
				$(".blind_barber").css({ "display": "none"});
				$(".if_ie").css({ "display": "block"});
				var windowHeight = $(window).height();
				var thanksHeight = (windowHeight/2);
				$('.if_ie').css({'margin-top':thanksHeight-110 });

			}

			if($.browser.msie && parseInt($.browser.version) == 7) {
				 $("body").css({ "background": "#f5f5f5"});
				$(".loader_container").css({ "display": "none"});
				$('#container, .footer').remove();
				$(".if_ie").css({ "display": "block"});
				var windowHeight = $(window).height();
				var thanksHeight = (windowHeight/2);
				$('.if_ie').css({'margin-top':thanksHeight-110 });
			}

			if($.browser.msie && parseInt($.browser.version) == 8) {
				$("body").css({ "background": "#f5f5f5"});
				$(".loader_container").css({ "display": "none"});
				$('#container, .footer').remove();
				$(".if_ie").css({ "display": "block"});
				var windowHeight = $(window).height();
				var thanksHeight = (windowHeight/2);
				$('.if_ie').css({'margin-top':thanksHeight-110 });		
			}

			//        if($.browser.msie && parseInt($.browser.version) == 9) {
			// 
			// 
			// $(".cuts p").css({ "margin": "0 20px 15px 0", "width" : "105px"});
			// 			$("input#hihkh-hihkh.required.email, input#hihkh-hihkh.email_nl.required.email").attr( "value", "Email")
			// 			$("input#name.required.name").attr( "value", "Name")
			// 
			//            
			//        }

			if ( $.browser.mozilla ) {
				$(".subheader_box").css("padding", "13px 3px 12px");
				$("#diamond_link").css("background", "url('/__cache/a1327963169/images/diamond_hover.png') no-repeat scroll left 6px, url('/__cache/a1327963169/images/diamond_hover.png') no-repeat scroll 158px 5px transparent");

			}
});

