/*
Generated to gzip the content
*/
$(document).ready(function(){	
	
		//footer nav handling
	var li_ks = $('#footer .footer-section #supplementary #second .block ul:eq(0) li');
	var total_li = parseInt(li_ks.length/2)+1;

	
	li_ks.slice(total_li).wrapAll('<ul class="nav_1" />');
	li_ks.slice(0,total_li).wrapAll('<ul class="nav_2" />');
			
	jQuery('#footer .footer-section #supplementary #second .block ul:eq(0)').wrapInner('<li class="yet_another_li" />');
	
	//wrap subheadings
	jQuery('#footer .footer-section #supplementary #second .block ul:eq(0) li>ul:eq(0)>li:eq(0)').wrapInner('<h4 />');
	
	jQuery('#footer .footer-section #supplementary #second .block:eq(1) ul:eq(0)>li:eq(0)').wrapInner('<h4 />');
  
  
  //here comes the navigation triggering
  
  //hide items
  jQuery('div .additional').hide();
  
  	jQuery('#nav>li').mouseover(function() {
		
	var menu_name = 'div#'+jQuery(this).find("a").attr('title')+'';	
	
	//alert('firing trigger '+menu_name);

	jQuery('#me_n').hide();
	jQuery('div .additional').hide();
	jQuery(menu_name).show();
	jQuery(menu_name).find('ul.nav_sub').show();
	
	//highlight parent
	//jQuery(this).addClass('active');
	
	})
	
	
	jQuery('div .additional').find('ul.nav_sub').mouseleave(function() {
		

	jQuery(this).hide();
	
	//highlight parent
		
	jQuery('#me_n').show();
	
	})
  
  
 
 	//calculate dropdown sizes
	var nav_container = jQuery('.nav_sub>li.menu-item>ul.sub-menu');
	
	
	jQuery(nav_container).each(function(i) {
		
		
		//calculate size for drops
		
		var total_drops = 0;
				
		jQuery('> li',this).each(function(d) {
			
			//alert(i + ': ' + $(this).width());
				total_drops =  jQuery(this).actual( 'outerWidth', { includeMargin : true }) + total_drops;
		});	
		
			//alert(i + ': ' + $(this).width());
			
		//total_drops = total_drops - 20;	
		
		if ( total_drops < 250 ) {
			 $(this).width(250); 
		 } else if ( total_drops > 600 ) {
			  $(this).width(600);	
		  } else {
			  $(this).width(total_drops); 
			  }
		
	});
	 
  
	//demolish blah links
	jQuery('.nav_sub>li>ul a[title=invisible]').replaceWith('');

	
	
	
	//sidebar, sweet thing. hide extra widgets, but one. 
	
		//how much if sidebars?
		var sidebar_numbers = jQuery('#sidebar aside.ssa_widget_links').length;
		
		//alert(sidebar_numbers);
		
		//if we have 1-2 sidebars
		if ( sidebar_numbers < 3) {
			jQuery('#sidebar aside.ssa_widget_links:eq(0)').show();
		} else {
		//double sidebars, show all but default
			jQuery('#sidebar aside.ssa_widget_links').not(':last').show();
		}
})



/*! Copyright 2011, Ben Lin (http://dreamerslab.com/)
* Licensed under the MIT License (LICENSE.txt).
*
* Version: 1.0.4
*
* Requires: jQuery 1.2.3+
*/
;( function( $ ){
  $.fn.extend({
    actual : function( method, options ){
      var $hidden, $target, configs, css, tmp, actual, fix, restore;

      // check if the jQuery method exist
      if( !this[ method ]){
        throw '$.actual => The jQuery method "' + method + '" you called does not exist';
      }
      
      configs = $.extend({
        absolute : false,
        clone : false,
        includeMargin : undefined
      }, options );

      $target = this;
      
      if( configs.clone === true ){
        fix = function(){
          // this is useful with css3pie
          $target = $target.filter( ':first' ).clone().css({
            position : 'absolute',
            top : -1000
          }).appendTo( 'body' );
        };
        
        restore = function(){
          // remove DOM element after getting the width
          $target.remove();
        };
      }else{
        fix = function(){
          // get all hidden parents
          $hidden = $target.parents().andSelf().filter( ':hidden' );

          css = configs.absolute === true ?
            { position : 'absolute', visibility: 'hidden', display: 'block' } :
            { visibility: 'hidden', display: 'block' };

          tmp = [];

          // save the origin style props
          // set the hidden el css to be got the actual value later
          $hidden.each( function(){
            var _tmp = {}, name;
            for( name in css ){
              // save current style
              _tmp[ name ] = this.style[ name ];
              // set current style to proper css style
              this.style[ name ] = css[ name ];
            }
            tmp.push( _tmp );
          });
        };
        
        restore = function(){
          // restore origin style values
          $hidden.each( function( i ){
            var _tmp = tmp[ i ], name;
            for( name in css ){
              this.style[ name ] = _tmp[ name ];
            }
          });
        };
      }

      fix();
      // get the actual value with user specific methed
      // it can be 'width', 'height', 'outerWidth', 'innerWidth'... etc
      // configs.includeMargin only works for 'outerWidth
      actual = $target[ method ]( configs.includeMargin );

      restore();
      // IMPORTANT, this plugin only return the value of the first element
      return actual;
    }
  });
})( jQuery );

