
var SLIDE_SPEED = 500

//jQuery.noConflict();

jQuery(document).ajaxSend(function(event, request, settings) {
  if (typeof(AUTH_TOKEN) == "undefined") return;
  settings.data = settings.data || "";
  settings.data += (settings.data ? "&" : "") + "authenticity_token=" + encodeURIComponent(AUTH_TOKEN);
});

jQuery.jGrowl.info = function(msg){
  jQuery.jGrowl(msg, {position: 'center'}, "Information!", "#BBF66F", "#000");
}

jQuery.jGrowl.warn = function(msg){
  jQuery.jGrowl(msg, {position: 'center'}, "Warning!", "#F6BD6F", "#000");
}

jQuery.jGrowl.error = function(msg){
  jQuery.jGrowl(msg, {position: 'center'}, "Critical!", "#F66F82", "#000");
}

function jeval(str){return eval('(' +  str + ');'); }

function tog(clicker, toggler, callback, speed){
  if (speed == undefined)
    speed = SLIDE_SPEED;
  if (callback)
    jQuery(clicker).click(function(){jQuery(toggler).slideToggle(speed, callback); return false;});
  else
    jQuery(clicker).click(function(){jQuery(toggler).slideToggle(speed); return false;});
}
function togger(j, callback, speed){
  if (speed == undefined)
    speed = SLIDE_SPEED;
  if(callback)
    jQuery(j).slideToggle(speed, callback);
  else
    jQuery(j).slideToggle(speed);
}

function async_message(m, d){message(m, d);}
function messages(m, d){message(m, d);}
function message(message, duration){
  if (duration == undefined){
    duration = 3000;
  }
  if (jQuery.browser.msie) { jQuery("#message").css({position: 'absolute'}); }
  jQuery("#message").text(message).fadeIn(1000);
  setTimeout('jQuery("#message").fadeOut(2000)',duration);
  return false;
}

function debug(m){if (typeof console != 'undefined'){console.log(m);}}
function puts(m){debug(m);}

function thickbox(id, title, height, width){
  if (height == undefined){ height = 300}
  if (width == undefined){ width = 300}
  tb_show(title, '#TB_inline?height='+ height +'&amp;width='+ width +'&amp;inlineId='+ id +'', false);
  return false;
}

function tog_login_element() {
  jQuery('.login_element, .checkout_element').toggle();
}

function toggleComments(comment_id)
{
  jQuery('#comment_'+comment_id+'_short, #comment_'+comment_id+'_complete').toggleClass('hidden');

  jQuery('#comment_'+comment_id+'_toggle_link').html(
    jQuery('#comment_'+comment_id+'_toggle_link').html() == "(more)" ? "(less)" : "(more)"
  );
}

jQuery(document).ready(function() {

  jQuery('#search_q').bind('focus.search_query_field', function(){
    if(jQuery(this).val()=='Search for Friends'){
      jQuery(this).val('');
    }
  });

  jQuery('#search_q').bind('blur.search_query_field', function(){
    if(jQuery(this).val()==''){
      jQuery(this).val('Search for Friends');
    }
  });

  jQuery(".tip-field").focus(function() {
    jQuery(".active").removeClass("active");
    jQuery(".hidden-tips").css("display", "none");
    jQuery("#" + this.id + "-help").show();
    jQuery("#" + this.id + "-container").addClass("active");
  });

  jQuery(".hidden-tips").css("display", "none");

  jQuery(".required-value").blur(function() {
    if (jQuery(this).val().length == 0) {
      jQuery('#' + this.id + '_required').show();
    } else {
      jQuery('#' + this.id + '_required').hide();
      jQuery("#" + this.id + "-container").children().removeClass("fieldWithErrors");
      jQuery('#' + this.id + '-label-required').hide();
    }
  });

  jQuery(".submit-delete").click(function() {
    jQuery(this).parents('.delete-container:first').fadeOut();
    var form = jQuery(this).parents('form');
    jQuery.post(form.attr('action') + '.js', form.serialize(),
                function(data){                  
                  jQuery('#'+data).fadeOut("normal");
                });
    return false;
  });

});

//  UEM ALUMNI

jQuery(document).ready(function() {

  jQuery('ul.tabs_subnav').tabs();
  setTimeout('jQuery(".flashnotice").fadeOut(200000)',200000);

  jQuery('a.toggle').click(function() {
    var target = jQuery(this).attr('href');
    jQuery(target).toggle();
    return false;
  })
  
  if (typeof($.fn.jcarousel) == 'function') {
      jQuery('#carousel').jcarousel({
        visible:1,
        scroll:1
      });
  }
  jQuery("#status_update").focus(function() {
    jQuery(this).text("");
    jQuery('#submit_status').removeClass("disabled");
    jQuery('#submit_status').attr("disabled",false);
  });

  jQuery("#main_content #activity_feed .feed_item").mouseover(function(){
    jQuery(this).addClass("feed_item_hover");
    jQuery(this).children("p.delete").show();
  })

  jQuery("#main_content #activity_feed .feed_item").mouseout(function(){
    jQuery(this).removeClass("feed_item_hover");
    jQuery(this).children("p.delete").hide();
  })
  
  if (typeof($.fn.tooltip) == 'function') {
  
      jQuery("a.privacy_help").tooltip({
        bodyHandler: function() {
          return $($(this).attr("href")).html();
        },
        showURL: false,
        top: -30
      });
  }
  if (typeof($.fn.stars) == 'function') {
      jQuery(".stars_wrapper").stars({
        inputType: "select"
      });
  }

  jQuery("#interes_front select").each(function (i) {
    jQuery(this).wrap("<div id=\"star_wrapper_"+i+"\"></div>");
    jQuery("#star_wrapper_"+i).stars({inputType: "select", disabled: true});
  });

  jQuery("#activity_feed .feed_item:last").addClass("last_feed_item");
  
  if (typeof($.fn.validate) == 'function') {
  
      jQuery("#contact").validate({
        errorPlacement: function(error, element) {
          error.appendTo(element.next("p"));
        }
      });
  }
  
  // Like/dislike
  
  jQuery('.like, .dislike').click(function(e) {
      e.preventDefault();
      var $t = $(this);
      $t.hide();
      $.post($t.attr('href'), {}, function(data, status) {
          if (data.liked) {
              $t.removeClass('like');
              $t.addClass('dislike');
              $t.html('Ya no me gusta');
          } else {
              $t.addClass('like');
              $t.removeClass('dislike');
              $t.html('Me gusta');
          }
          $t.show();
      }, 'json');
  })
  
  
  
  
})