$(function() {
  //Slide Show cycle call
  $('#cycle').cycle({ fx: 'fade', pager: '#slideshow-nav' });

  //Nav bar superfish call
  $('.sf-menu').superfish({pathClass:'current',pathLevels:2,autoArrows:true});

  //Random list stuff that i dont know why whe cant do with css or php
  $('ul li:first-child').addClass('first');
  $('ul li:last-child').addClass('last');
  $('ul.course-list li:odd').addClass('odd');
  $('ul.course-list li:even').addClass('even');
  $('ul.course-list li').hover(function(){$(this).addClass('hover');},function() {$(this).removeClass('hover');});
  
  //Course Q-tip shows remote content for popup
  $('ul.course-list li').bind('mouseenter',function(){
      var e = this;
      $.ajax({
        url: $(e).find('[rel]').attr('rel'),
        success: function(data){
          $(e).qtip({
            content: data,
            position: { viewport: $(window), my: 'left center', at: 'right center' },
            style: { classes: 'ui-tooltip-light  ui-tooltip-shadow' },
            show: { ready: true, solo:true }
          });
        }
      });    
  });

  // Q-Tip helpers for form elements
  $('input[type="text"],input[type="checkbox"] ').add('select').add('textarea').each(function(){
    if($(this).next('.help').html()){
      $(this).qtip({
        content: $(this).next('.help').html(),
        style: { classes: 'ui-tooltip-jtools'},
        position: { my: 'left center', at: 'right center' },
        show: 'focus',
        hide: 'blur'
      });
      $(this).next('.help').hide();
    }
  });

  //Register Form Phone Mask
  $('#registrant_phone').mask("(999) 999-9999");
  $('#registrant_zip').mask("99999")

  //qtip errors
  $("ul.error_list").hide().each(function(){
    $(this).parents('li, td').qtip({
      content: $(this).html(),
      position: {
        adjust: {y: -0, x:-5}, my: 'left middle', at: 'right middle',
        target: $(this).siblings(":input")
      },
      show: {ready: true},
      hide: {
        target: $(this).siblings(":input"),
        event: 'change'
      },
      style: { classes: 'ui-tooltip-red ui-tooltip-shadow ui-tooltip-rounded' }
    });
  });

  $('.testimonial a').click(function(){return youtube(this);});

});


function youtube(el)
{
  return hs.htmlExpand(el, {
    objectType: 'iframe',
    width: 640,
    height: 535,
    allowSizeReduction: false,
    wrapperClassName: 'draggable-header no-footer',
    preserveContent: false,
    objectLoadTime: 'after'}
  );
}
