$j(function() {
  initFacebox();
  


  /* ----- Watch List ----- */
  $j("#watch_this_group").click(function(e) {
    e.preventDefault();
    var button = $j(this);
    $j.ajax({
      type: "POST",
      url: AjaxCall.watch_group,
      data: {entity_id: $j('#entity_id').val()},
      success: function(response) {
        var result = JSON.parse(response);
        if (result['status'] == 'success') {
          if(button.hasClass("watch")) {
            button.addClass("unwatch").removeClass("watch").text("In Watch List");
          } else {
            button.addClass("watch").removeClass("unwatch").text("Add to Watch List");
          }
        }
      }
    });
  });
	
  /* ----- GI Index ----- */

  $j("#GI_score").click(function(e) {
    e.preventDefault();
    $j("#GI_popup").fadeToggle(500);
  });

  $j("#GI_score").mouseup(function() {
    return false; // prevent event bubbling
  });
  
  $j(document).mouseup(function(e) {
    if($j(e.target).parent("#GI_score").length==0) {
      $j("#GI_popup").fadeOut(500);
    }
  });	

	
	
  /* ----- Profile Image ----- */
  $j("#profile_image").hover(
    function() {
      $j("#profile_image .image_action_panel").show();
    }, function() {
      $j("#profile_image .image_action_panel").hide();
    }
  );
  


  /* ----- Copy to clipboard ----- */
/*
  var clip = new ZeroClipboard.Client();

  clip.setText( '' ); // will be set later on mouseDown
  clip.setHandCursor( true );
  clip.setCSSEffects( true );

  clip.addEventListener( 'complete', function(client, text) {
          //alert("Badge code copied to the clipboard!");
  } );

  clip.addEventListener( 'mouseDown', function(client) { 
          clip.setText( document.getElementById('clip_text').value );
  } );

  clip.glue( 'copy_btn' );*/

  /* ----- Tooltips ----- */
	$j(".module_box .head .title .tooltip_trigger").live( 'mouseover', function(){ 
		$j(this).parent().find('.tooltip').fadeIn();
	});

	$j(".module_box .head .title .tooltip_trigger").live( 'mouseout', function(){ 
		$j(this).parent().find('.tooltip').fadeOut();
	});



  
});
