/* ******************************************************************** */
  /*
  
  project:          Baltimore Brew - Wordpress Template
  file:             brew.js
  creator:          Ben Kutil <ben@make-things.com>
  creation date:    Fri Jun 18 09:48:48 EDT 2010
  copyright:        (c) 2010 - Make Things Studio, LLC
                    All rights reserved.      

  info:             Main JS file
  
  */
/* ******************************************************************** */

var BREW = 
{
  nav: function()
  {
    var sitehead = $('#site-head');
    /* Show Topics Navigation */
    $('#site-a-02').click(function(){
      sitehead.addClass('show');
      $('.tier2').hide();
      $('#site-tier2-02').show();
      return false;
    });
    /* Show Neighborhoods Navigation */
    $('#site-a-03').click(function(){
      sitehead.addClass('show');
      $('.tier2').hide();
      $('#site-tier2-03').show();
      return false;
    });
    /* Show Authors Navigation */
    $('#site-a-04').click(function(){
      sitehead.addClass('show deep');
      $('.tier2').hide();
      $('#site-tier2-04').show();
      return false;
    });
  },
  beta: function()
  {
    if ($.cookie('brew_beta'))
    {
    }
    else
    {
       $('html').addClass('alpha');
       $.cookie('brew_beta', '1', { // create a cookie with all available options
           expires: 14, // expires in seven days
           path: '/', // accessible from the whole site...
           secure: false // ...but only on a secure connection
       });
    }
  },
  hero: function(){
    var hero = $('#content-hero');
    var heroList = hero.find('li.hentry');
    heroList.css({'display':'inline'});
    var heroNav = "<ul id='content-hero-nav'>";

    var hNi = heroList.length;

    var hNw = (100-(hNi*1))/hNi;
    while(hNi--)
    {
      if(hNi == 0)
      {
        heroNav +='<li style="width:'+hNw+'%;" class="last">';
      }
      else
      {
        heroNav +='<li style="width:'+hNw+'%;margin-right: 1%;">';
      }
      heroNav +='<a class="ir" href="#'+heroList[hNi].id+'">';
      heroNav += 'Select Baltimore Brew Article '+heroList[hNi].id+'<span></span></a></li>';
      if(hNi == 0)
      {
        heroNav+= '</ul>';
        hero.after(heroNav);
      }
    }

    function mycarousel_initCallback(carousel)
    {
        var heroLinks = $('#content-hero-nav').find('a');
        heroLinks.live('click', function() {
        var heroLinkIndex = heroLinks.index($(this));
        carousel.scroll(heroLinkIndex+1);
        return false;
      });
    }

    function mycarousel_itemFirstInCallback(carousel, item, idx, state) {

        /*alert('Item #' + idx + ' is now the first item');*/
  $('#content-hero-nav').find('li').removeClass('here').eq((idx-1)).addClass('here');
    };
    hero.jcarousel({
        auto: 18,
        scroll: 1,
        wrap:'last',
        buttonNextHTML:null,
        buttonPrevHTML:null,
        initCallback: mycarousel_initCallback,
        itemLastInCallback: mycarousel_itemFirstInCallback
    });
  },
  perc: function()
  {
    var percNavList = [];
    var perc = $('#percolating')
    var percList = perc.find('.content-list-featured');
    percList.find('li').css({'display':'inline'});
    var percPrev = "<li class='percNav ir' id='perc-prev' class='ir'>Previous<span></span></li>"
    var percNext = "<li id='perc-next' class='percNav ir' class='ir'>Next<span></span></li>"
    perc.append("<ul id='percNav'>"+percPrev+percNext+"</ul>");



    function mycarousel_initCallback(carousel) {
      percNav.find('a').bind('click', function() {
        carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
        debug.info(jQuery.jcarousel.intval(jQuery(this).text()-1));
        return false;
      });
    };

    function mycarousel_itemFirstInCallback(carousel, item, idx, state) {
      debug.info('Item #' + idx + ' is now the first item');
      percNav.find('li').eq(idx-1).addClass('here');
    };
    function mycarousel_itemFirstOutCallback(carousel, item, idx, state) {
      debug.info('Item #' + idx + ' is no longer the first item');
      percNav.find('li').eq(idx-1).removeClass('here');
    };
    function perc_initCallback(carousel){
      jQuery('#perc-next').bind('click', function() {
        carousel.next();
        return false;
      });

      jQuery('#perc-prev').bind('click', function() {
        carousel.prev();
        return false;
      });
    };
    percList
    .jcarousel({
    auto: 0,
    scroll: 4,
    wrap:'circular',
    buttonNextHTML:null,
    buttonPrevHTML:null,
    initCallback: perc_initCallback
    });
    
  }
};