var topbanner_opts={'show':false};

$(document).ready(function(){
    $(".bodyQuote").wrap('<div class="outerQuote"><div class="centerQuote"></div></div>');
    $(".toggler-c").toggleElements();

    $('div#sub_main').one('inview', function (event, visible) {
      if (visible == true) {
        // element is now visible in the viewport
        var pcode = $('input[name=pcode]').val();
        //alert('Sub-box visible, code ' + pcode);
        pageTracker._trackPageview('/joinus/subbox_visible_'+pcode);
      } else {
        // element has gone out of viewport
      }
    });  
      
    $('.text_points').equalHeights();

    $(".moreless a", this).each(
    // assume that moreless div exists
      function(){
        var row = $(this).attr('href');
        var sg = $(this).parents('.spacedGrid');
        $('.sg_row:gt(' + row +')', sg).hide();
        $(this).html('more...');
        }
      );

    $(".moreless a", this).toggle(
      function(){
        var row = $(this).attr('href');
        var sg = $(this).parents('.spacedGrid');
        $('.sg_row:gt(' + row + ')', sg).show();
        $(this).html('less...');
        },
      function(){
        var row = $(this).attr('href');
        var sg = $(this).parents('.spacedGrid');
        $('.sg_row:gt(' + row +')', sg).hide();
        $(this).html('more...');
        }
    );

    // Andy Langton's show/hide/mini-accordion - updated 18/03/2009
    // Latest version @ http://andylangton.co.uk/jquery-show-hide

    // this tells jquery to run the function below once the DOM is ready

    // choose text for the show/hide link - can contain HTML (e.g. an image)
    var showText='show';
    var hideText='hide';

    // append show/hide links to the element directly preceding the element with a class of "toggle"
    $('.toggle').prev().append(' (<a href="#" class="toggleLink">'+showText+'</a>)');

    // hide all of the elements with a class of 'toggle'
    $('.toggle').hide();

    // capture clicks on the toggle links
    $('a.toggleLink').click(function() {

      // change the link depending on whether the element is shown or hidden
      $(this).html ($(this).html()==hideText ? showText : hideText);

      // toggle the display - uncomment the next line for a basic "accordion" style
      //$('.toggle').hide();$('a.toggleLink').html(showText);
      $(this).parent().next('.toggle').toggle('slow');

      // return false so any link destination is not followed
      return false;
    });


  $('.title_list').each(function() {
      var tl = this;
      var ul = $('ul', this);
      if(ul.children('li').size() <= 15) return;

      var hiddenElements = ul.children('li:gt(14)', this).hide();

      var showCaption = '...' + hiddenElements.size() + ' More Choices';
      ul.append(
          $('<li class="togglerer">' + showCaption + '</li>')
              .toggle(
                  function() { 
                      hiddenElements.show();
                      $(this).text('...Fewer Choices');
                  }, 
                  function() { 
                      hiddenElements.hide();
                      $(this).text(showCaption);
                  }
              )
      );
  });


  $('td.Title a, .title_list li a').each(function()
  {
    // Create image content using websnapr thumbnail service
    //var content = '<img src="http://images.websnapr.com/?url=';
      //content += $(this).attr('href');
      //content += '" alt="Loading thumbnail..." height="152" width="202" />';

    //var content = '<img src="';
      //content += '/preview_mediaObj?obj=' + $(this).attr('name');
      //content += '" alt="Loading thumbnail..." height="152" width="202" />';

    // Setup the tooltip with the content
    $(this).qtip(
    {
      content: {
          url: '/preview_mediaObj',
          data: {'obj': $(this).attr('name')}
          //method: 'get'
      },

       position: {
          corner: {
             tooltip: 'bottomMiddle',
             target: 'topMiddle'
          },
          adjust: {
          screen:true
          }

       },
       style: {
          color: '#222222',
          width:540,
          padding:5,
          tip: true, // Give it a speech bubble tip with automatic corner detection
          name: 'cream'
       }
     });
   }); // qtips

    function topbanner(opts)
    {
      $.ajax({
        type: "POST",
        url: "/topbanner", //Top banner File
        data: opts,
        beforeSend: function()
        {
        //$("div#topbanner").html('<span class="loading">Loading...</span>');
        },
        cache: false,
        success: function(data)
        {
          if(data != ''){ 
            $("#topbanner").html(data);
            $('#clubbut').hide();
          }
        }
      });
    }

    topbanner(topbanner_opts);

});    

$(function(){
    $('.slide-out-div').tabSlideOut({
        tabHandle: '.handle',                     //class of the element that will become your tab
        pathToTabImage: '/static/images/feedbacktab.gif', //path to the image for the tab //Optionally can be set using css
        imageHeight: '99px',                     //height of tab image           //Optionally can be set using css
        imageWidth: '30px',                       //width of tab image            //Optionally can be set using css
        tabLocation: 'left',                      //side of screen where tab lives, top, right, bottom, or left
        speed: 300,                               //speed of animation
        action: 'click',                          //options: 'click' or 'hover', action to trigger animation
        topPos: '200px',                          //position from the top/ use if tabLocation is left or right
        leftPos: '20px',                          //position from left/ use if tabLocation is bottom or top
        fixedPosition: false                      //options: true makes it stick(fixed position) on scroll
    });
});

