(function ($) {
   
Drupal.behaviors.cafkaBehaviours = {
   attach: function (context, settings) {
      // home page background
    var FullscreenrOptions = { width: 1100,  height: 739, bgID: '#bgimg img' };
		jQuery.fn.fullscreenr(FullscreenrOptions);

      // Search form modifications
      $('#block-search-form').append('<a href="#" id="searchtoggle" tabindex="0">Search</a>');
      $('#search-block-form').hide();
      $('#block-search-form #searchtoggle').click(function() {
           $('#search-block-form').toggle();
           $('#block-search-form #searchtoggle').toggleClass('on');
            $(this).blur(); /* unsets focus state */
      });
    
      // Navigation menus: insert down arrow & hide/show menus

      $('#block-system-main-menu .content li').append('<a href="#" class="details" tabindex="0">Details</a>');
      $('#nav_dropdowns .block').hide();

      $('#block-system-main-menu .content li .details').click(function() {

            menuId = $(this).parent().attr('id');
            blockElement = '#nav_dropdowns .block.' + menuId;

          // if it's already on, hide it
          if ($(this).parent().hasClass('on')) { 
            $(blockElement).hide();
            $(this).parent().removeClass('on');   
            $(this).blur(); /* unsets focus state */
          }

          else {

            /* hide anything that's already open */
            $(this).parent().siblings().filter('.on').removeClass('on');
            $('#nav_dropdowns .block').hide();

            /* set left position to be equal to the list item's position; set height
               doing this in the script avoids problems if js is slow  */

            var leftPos = ($(this).parent().position().left);
            $(blockElement).css({'left': leftPos, 'top': '48px'});

            $(blockElement).show();
            $(this).parent().addClass('on');   // and add class to li to keep background on
          }
      });


      // Comment form: hides label and inserts it as a value
      if($('body').is('.node-type-article')) {
          
          // set value of input to the contents of the associated label element
          $('#comment-form-wrapper .form-item label').each(function() {
             var words = $(this).text();
             $('#' + $(this).attr('for')).val(words);
             
             $('#' + $(this).attr('for')).focus(function() {
             // if it hasn't changed 
             // if value is = to the label text
             if ($(this).val() == $('label[for="' + $(this).attr('id') + '"]').text()) {
                 $(this).val(''); 
               }
             });
             
             $('#' + $(this).attr('for')).blur(function() {
             if ($(this).val() == '') {
                $(this).val($('label[for="' + $(this).attr('id') + '"]').text());
             }
             });
         
          });
      }
   }
}

/**
 * Homepage background resizing
 * Hacky way to do it, but without the (window).load function webkit browsers won't know the 
 * height of the image when the function is called and try to set the height of the content div to 0.


$(window).load(function() {
   if($('body').is('.front')) { 
       var content = $('.front #main');
       var image = $('.field-name-field-homepage-image img');
      // chrome thinks the height of the image is 0, then setting height of the div to 0

      
      $(window).resize(function() { 
         /* This function specifies three values: the minimum height (500), 
            the maximum height (image.height), and the height of the browser window.
            The content div will scale to the height of the browser window within that range.* /
     
       content.height(Math.min(image.height(),Math.max($(window).height()-43,500)));
      }).resize();   
   }
});*/

}(jQuery));;
/**
* Fullscreenr - lightweight full screen background jquery plugin
* By Jan Schneiders
* Version 1.0
* www.nanotux.com
**/
(function($){	
	$.fn.fullscreenr = function(options) {
		if(options.height === undefined) alert('Please supply the background image height, default values will now be used. These may be very inaccurate.');
		if(options.width === undefined) alert('Please supply the background image width, default values will now be used. These may be very inaccurate.');
		if(options.bgID === undefined) alert('Please supply the background image ID, default #bgimg will now be used.');
		var defaults = { width: 1280,  height: 1024, bgID: 'bgimg' };
		var options = $.extend({}, defaults, options); 
		$(document).ready(function() { $(options.bgID).fullscreenrResizer(options);	});
		$(window).bind("resize", function() { $(options.bgID).fullscreenrResizer(options); });		
		return this; 		
	};	
	$.fn.fullscreenrResizer = function(options) {
		// Set bg size
		var ratio = options.height / options.width;	
		// Get browser window size
		var browserwidth = $(window).width();
		var browserheight = $(window).height();
		// Scale the image
		if ((browserheight/browserwidth) > ratio){
		    $(this).height(browserheight);
		    $(this).width(browserheight / ratio);
		} else {
		    $(this).width(browserwidth);
		    $(this).height(browserwidth * ratio);
		}
		// Center the image
		$(this).css('left', (browserwidth - $(this).width())/2);
		$(this).css('top', (browserheight - $(this).height())/2);
		return this; 		
	};
})(jQuery);;

