// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
// Generate help tags from title property 
$(document).ready(function() {
  //$('img').bt({fill: '#E6F6AE'}); //help tags
  $('#accordion').accordion({'collapsible' : true, 'autoHeight': false});
  $(".shadow").FontEffect(
    {'shadow' : true,
    'shadowColor' : "black",
    'shadowOffsetTop' : 3,
    'shadowOffsetLeft': 3,
    'shadowOpacity' : 0.1});

  $(".landing .details h2, #about h2, #online-lessons h2").FontEffect(
    {'shadow' :true,
     'shadowOffsetTop' : 1,
     'shadowOffsetLeft' : 1,
     'shadowColor' : "#999",
     'shadowOpacity' : 0.1});

  $('#tabs').tabs();
  $('input.date').datepicker();

  //$(".roundy").corner();

  $('#slideshow').cycle({
      'fx' : 'fade',
      'timeout' : 5000,
      'speed' : 2000,
      'random' : 1
  });
});

var i=0;
// triangle slide
$.triSlide = null;
$.fn.triSlide = function(options){
  $(".content").bind("mouseover", function(){
    if ($.triSlide) $.triSlide.trigger("out");
  });
  return $(this).each(function(){
    var o = $.extend({}, { 'swing' : 15, 'time' : 350, 'borderColor' :"black" }, options);
    var box = $(this);
    box.addClass('tri-box').wrap('<div style="position:relative;z-index:999"/>');
    box.after('<div class="tri-wrap"><div class="tri-tri"/></div>');
      
    box.data('borderOffset', parseInt(box.outerHeight()*0.1, 10));
    
    box.find('.tri-tri').css({ 
      'top' : 0,
      'right' : box.outerWidth(),
      'borderTopWidth' : box.data('offset'),
      'borderBottomWidth' : box.data('offset')
    });
    
    box.find('.tri-wrap').css("right", box.outerWidth());
    
    box.parent().css('cursor','pointer')
      .bind('out', function(){
        $.triSlide = null;
        var box = $(this).find('.tri-box');
        var div = $(this);
        box.stop().animate({ 
          'top' : 0,
          'right' : 0
        }, o.time);
        div.find('.tri-wrap').stop().animate({ 
          'top' : box.outerHeight()/2,
          'right' : box.outerWidth()
        }, o.time);
        div.find('.tri-tri').stop().animate({ 
          'borderTopWidth' : box.data('borderOffset'),
          'borderRightWidth' : 0,
          'borderBottomWidth' : box.data('borderOffset')
        }, o.time);
      })
      .hover(function(){
        $(this).siblings().trigger('out');
        if ($.triSlide) $.triSlide.trigger('out');
        $.triSlide = $(this);
        var box = $(this).find('.tri-box');
        var div = $(this);
        box.animate({ 
          'top' : 0,
          'right' : o.swing
        }, o.time);
        div.find('.tri-wrap').animate({ 
          'top' : 0,
          'right' : box.outerWidth() + o.swing
        }, o.time);
        div.find('.tri-tri').animate({
          'borderTopWidth' : box.outerHeight()/2,
          'borderRightWidth' : box.outerHeight()/2,
          'borderBottomWidth' : box.outerHeight()/2
        }, o.time).css('borderRightColor', o.borderColor);
      }, function(){
        $(this).trigger('out');  
      });
    // end hover
  });
};

var AMH = {};

AMH.initialize_wymeditor = function() {
  $(".wymeditor").not(".initialized").wymeditor({
    'skin' : "compact",
    'toolsItems' : [
      {'name': 'Bold', 'title': 'Strong', 'css': 'wym_tools_strong'},
      {'name': 'Italic', 'title': 'Emphasis', 'css': 'wym_tools_emphasis'},
      {'name': 'CreateLink', 'title': 'Link', 'css': 'wym_tools_link'},
      {'name': 'Unlink', 'title': 'Unlink', 'css': 'wym_tools_unlink'},
      {'name': 'InsertOrderedList', 'title': 'Ordered_List',
        'css': 'wym_tools_ordered_list'},
      {'name': 'InsertUnorderedList', 'title': 'Unordered_List',
        'css': 'wym_tools_unordered_list'},
      {'name': 'Paste', 'title': 'Paste_From_Word',
        'css': 'wym_tools_paste'},
      {'name': 'Undo', 'title': 'Undo', 'css': 'wym_tools_undo'},
      {'name': 'Redo', 'title': 'Redo', 'css': 'wym_tools_redo'}
    ]
  }).addClass("initialized");
};

AMH.initialize_course_search = function(id){
  quicksearch_selector = '.course_search table tbody tr';
  attached_selector = '.course_search table';
  if(id) {
    quicksearch_selector = id + ' ' + quicksearch_selector;
    attached_selector = id + ' ' + attached_selector;
  }
  $(quicksearch_selector).quicksearch({
    position: 'before',
    attached: attached_selector,
    stripeRowClass: ['odd', 'even'],
    labelText: 'Search'
  });
};