/* $Id: admin_devel.js,v 1.2 2010/03/12 22:54:41 sun Exp $ */
(function($) {

/**
 * jQuery debugging helper.
 *
 * Invented for Dreditor.
 *
 * @usage
 *   $.debug(var [, name]);
 *   $variable.debug( [name] );
 */
jQuery.extend({
  debug: function () {
    // Setup debug storage in global window. We want to look into it.
    window.debug = window.debug || [];

    args = jQuery.makeArray(arguments);
    // Determine data source; this is an object for $variable.debug().
    // Also determine the identifier to store data with.
    if (typeof this == 'object') {
      var name = (args.length ? args[0] : window.debug.length);
      var data = this;
    }
    else {
      var name = (args.length > 1 ? args.pop() : window.debug.length);
      var data = args[0];
    }
    // Store data.
    window.debug[name] = data;
    // Dump data into Firebug console.
    if (typeof console != 'undefined') {
      console.log(name, data);
    }
    return this;
  }
});
// @todo Is this the right way?
jQuery.fn.debug = jQuery.debug;

})(jQuery);
;
/* The variables imageWidth and imageHeight are set in 
the template file for caching reasons. */


jQuery(document).ready(function() {
    /*console.log('imageWidth: ' + imageWidth);
    console.log('imageHeight: ' + imageHeight);*/
    
    // Resize background image when the browser window is resized
    jQuery(window).resize(function(){
      resizeBgImage();
    });

    // Resize background image when page is ready
    resizeBgImage();
});

function resizeBgImage() {
    try{
		var navWidth = jQuery(window).width();
		var navHeight = jQuery(window).height();
		var navRatio = navWidth / navHeight;
		var imageRatio = imageWidth / imageHeight;
		
		if (navRatio > imageRatio) {
			var newHeight = (navWidth / imageWidth) * imageHeight;
			var newWidth = navWidth;
		} else {
			var newHeight = navHeight;
			var newWidth = (navHeight / imageHeight) * imageWidth;
		}

		newTop = 0 - ((newHeight - navHeight) / 2);
		newLeft = 0 - ((newWidth - navWidth) / 2);

		jQuery('#bg-img').css({height: navHeight, width: navWidth});
		jQuery('#bg-img img').css({height: newHeight, width: newWidth, top: newTop, left: newLeft});
		jQuery('#bg-img').css({visibility:"visible", display:"block"});
	}catch(e){
		if(window.console){
			console.log(e);
		}
	}
}
;
// Tracks the last hovered mlid
var prevMlid = -1;

jQuery(document).ready(function() {
  // Toggle hover menu blocks
  var hoverMenuBlocks = Drupal.settings.hoverMenuBlock;
  var hoverMenuBlockType = Drupal.settings.hoverMenuBlockType;  
  if(hoverMenuBlocks != undefined){
    jQuery.each(hoverMenuBlocks, function(mlid, blocks){
      
      // Hover over menu item action
      jQuery("li.menu-mlid-" + mlid ).bind(hoverMenuBlockType, function(e){
        if(hoverMenuBlockType === 'click'){
          e.preventDefault();
        }       
        // Hide other blocks
        jQuery("#block-hover-menu-block-hover-menu-block section").hide();
        // Show block in active hover block
        jQuery(blocks).each(function(index, value){
          jQuery('.hover-menu-block-' + mlid + ' [id^="' + value + '"]').show();
        });
        //jQuery(blocks.join(', ')).show();
        
        // Set container class to active mlid
        jQuery("#block-hover-menu-block-hover-menu-block").removeClass('active-hover-mlid-' + prevMlid);
        jQuery("#block-hover-menu-block-hover-menu-block").addClass('active-hover-mlid-' + mlid);
        prevMlid = mlid;
        jQuery("#block-hover-menu-block-hover-menu-block").show();
      });
    });
  }

	
  // Hide hover menu when mouse leaves 'hover menu block'
  jQuery("#block-hover-menu-block-hover-menu-block").mouseleave(function(){
    jQuery("#block-hover-menu-block-hover-menu-block").hide();
  });
  
});;
(function ($) {

/**
 * Open Mollom privacy policy link in a new window.
 *
 * Required for valid XHTML Strict markup.
 */
Drupal.behaviors.mollomPrivacy = {
  attach: function (context) {
    $('.mollom-privacy a', context).click(function () {
      this.target = '_blank';
    });
  }
};

/**
 * Attach click event handlers for CAPTCHA links.
 */
Drupal.behaviors.mollomCaptcha = {
  attach: function (context, settings) {
    // @todo Pass the local settings we get from Drupal.attachBehaviors(), or
    //   inline the click event handlers, or turn them into methods of this
    //   behavior object.
    $('a.mollom-switch-captcha', context).click(getMollomCaptcha);
  }
};

/**
 * Fetch a Mollom CAPTCHA and output the image or audio into the form.
 */
function getMollomCaptcha() {
  // Get the current requested CAPTCHA type from the clicked link.
  var newCaptchaType = $(this).hasClass('mollom-audio-captcha') ? 'audio' : 'image';

  var context = $(this).parents('form');

  // Extract the Mollom session id and form build id from the form.
  var mollomSessionId = $('input.mollom-session-id', context).val();
  var formBuildId = $('input[name="form_build_id"]', context).val();

  // Retrieve a CAPTCHA:
  $.getJSON(Drupal.settings.basePath + 'mollom/captcha/' + newCaptchaType + '/' + formBuildId + '/' + mollomSessionId,
    function (data) {
      if (!(data && data.content)) {
        return;
      }
      // Inject new CAPTCHA.
      $('.mollom-captcha-content', context).parent().html(data.content);
      // Update session id.
      $('input.mollom-session-id', context).val(data.session_id);
      // Add an onclick-event handler for the new link.
      Drupal.attachBehaviors(context);
      // Focus on the CATPCHA input.
      $('input[name="mollom[captcha]"]', context).focus();
    }
  );
  return false;
}

})(jQuery);
;

