/* --------------------------------------------------
  IMAGE CYCLING -- kevin
-------------------------------------------------- */

$(function() {
    $('.photo-festival').cycle({
        fx:     'fade', 
        speed:   300, 
        timeout: 3000, 
        next:   '.photo-festival', 
        pause:   1 });
});

$(function() {
    $('.photo-brewers').cycle({
        fx:     'fade', 
        speed:   300, 
        timeout: 3000, 
        next:   '.photo-brewers', 
        pause:   1 });
});

$(function() {
    $('.photo').cycle({
		height: '302px',
        fx:     'fade', 
        speed:   300, 
        timeout: 3000, 
        next:   '.photo', 
        pause:   1 });
});

/* --------------------------------------------------
  SMOOTH-SCROLLING - Attach to every anchor link on
  the page with viable target to scroll to.
-------------------------------------------------- */
$(document).ready(function() {
  $('a[href*=#]').click(function(event) {
    var target_name = $(this).attr('href').split('#')[1]
    var target = $('#' + target_name)
    if(target.find('h2')[0]) target = target.find('h2')

    if(!target[0]) return

    event.preventDefault()
    
    var scroll_offset = Math.min(target.offset().top, $(document).height() - $(window).height())    
    var scroll_duration = Math.max(600, Math.min(Math.abs(scroll_offset - $(window).scrollTop()) * .6, 1200))

    $('html, body')
      .stop(true)
      .animate({scrollTop: scroll_offset}, scroll_duration, 'easeOutQuint')
  })
})


/* --------------------------------------------------
  DOCK PINNING - Manually pin the dock to the botom
  of the browser viewport in IE6.
-------------------------------------------------- */
$(document).ready(function() {
  if(!$.browser.msie || $.browser.version >= 7) return
  
  var nav = $('nav')
  var win = $(window)
  var window_scroll_timeout

  var dock_the_nav = function() {
    var old_top = nav.offset().top
    var new_top = win.height() - nav.outerHeight() + win.scrollTop()
    if(old_top != new_top) nav.css('top', new_top)

    var old_width = nav.width()
    var new_width = win.width()
    if(old_width != new_width) nav.width(new_width)

    nav.stop().fadeTo(150, 1)
  }
  
  var prepare_the_nav = function() {
    clearTimeout(window_scroll_timeout)
    nav.stop().hide()
    window_scroll_timeout = setTimeout(dock_the_nav, 300)
  }
  
  nav.css('position', 'absolute')
  dock_the_nav()
  $(window).bind({
    scroll: prepare_the_nav,
    resize: prepare_the_nav
  })
})


/* --------------------------------------------------
  CUSTOM MAP - Google Map w/ an image-based tooltip
-------------------------------------------------- */
$(window).load(function() {
  if(!GBrowserIsCompatible()) return

  var map_el = $('#map_container .inner')[0]
  var map = new GMap2(map_el)
  var point = new GLatLng(42.695455,-73.681236)
  var marker = new GMarker(point);

  map.addControl(new GSmallMapControl())
  map.addOverlay(marker);
  map.setCenter(point, 13)
  marker.openInfoWindowHtml('<a href="http://maps.google.com/maps/place?cid=3095641182395194939&q=Joe+Bruno+Stadium&hl=en&cd=1&ei=lYnWS82hG5KWyATe38iuDA&sig2=wyBow1MMbdZ6BApJu6VFKA&sll=42.699664,-73.73458&sspn=0.171786,0.207412&ie=UTF8&ll=42.998119,-73.940048&spn=0,0&z=11&iwloc=A" target="_blank"><img src="wp-content/themes/BLANK-Theme/images/attending_tooltip.png?v=2" width="216" height="91" /></a>')
})
