function mmbbInit(){
	greyInitRedux();
	homepageSwitcher();
	hVideoTabSet();
	dictTerm();
	customTabs();
}

$(document).ready(function() { 
	mmbbInit();
 });


function customTabs()
{
	var tabsets = [];
	
	$('.tab').each(function()
	{
		var className = $(this).hasClass('horz')?'horz-tab':'vert-tab';
		var selector = $(this).prop('nodeName')+'.tab';
		
		if (!$(this).prevAll('.'+className+'-nav').size())
		{
			$(this).before('<ul class="'+className+'-nav"></ul>');
		}
		
		var $nav = $(this).prevAll('.'+className+'-nav').eq(0);
		$nav.append('<li><span>'+$(this).html()+'</span></li>');
		
		$(this).addClass('move');
		$(this).nextUntil(selector).wrapAll('<div class="'+className+'-content" />');
	});
	
	$('.vert-tab-nav, .horz-tab-nav').each(function()
	{
		var className = $(this).hasClass('horz-tab-nav')?'horz-':'';
		
		$tabset = $('<div class="'+className+'tabset" />');
		$(this).nextAll().wrapAll($tabset);
		
		var className = $(this).hasClass('horz-tab-nav')?'horz-tab':'vert-tab';
		$(this).children('li:eq(0)').addClass('on');
		$(this).next().prepend(this);
		
		$(this).children('li').click(function(e)
		{
			var index = $(this).prevAll('li').size();
			var $nav = $(this).parents('ul').eq(0);

			$nav.siblings('.'+className+'-content').hide();
			$nav.siblings('.'+className+'-content').eq(index).show();
			$nav.find('.on').removeClass('on');
			$(this).addClass('on');

			e.preventDefault();
		});
	});
	
	$('.tabset, .horz-tabset').each(function()
	{
		$(this).children('.vert-tab-content:gt(0)').hide();
		$(this).children('.horz-tab-content:gt(0)').hide();
	});
}




/*-------------------------------------------
 	Grey Initial Values (fitter, happier, more productive)
-------------------------------------------*/

	function greyInitRedux() {
		$("input.filled, textarea.filled").focus(function(e){
			if(this.value == this.defaultValue)
			{
				$(this).removeClass('filled');
				 this.value= '';
			}
			$(this).blur(function(f){ 
				if(this.value == this.defaultValue) {
					$(this).addClass('filled');
					} else if(this.value == "") {
						this.value = this.defaultValue;
						$(this).addClass('filled');
					}
				});
		})

	}



/*-------------------------------------------
	Homepage Switcher
-----------------------------------------*/
	function homepageSwitcher() {
		var $switcher = $('#switcher');
		var $tabs = $('<ul class="tabs"></ul>');
		$switcher.prepend($tabs);
		$switcher.find('h2').each(function(i)
		{
			// hide the h3, since it's being duplicated into a list before the tabs anyway
			var $h2 = $(this);
	
			// create the tab link (hardcode a return false to save a jQuery selector and since this
			// will only be seen with JS on anyway)
			var $tab = $('<li>'+$h2.html()+'</li>');
			$tabs.append($tab);
	
			// now that we have a link, hide the h3
			$h2.addClass('move');
	
			// add a class to locate our tab-content later
			var $tabContent = $h2.next();
			$tabContent.addClass('switcher-content');
	
			// on click hide all the tabs and open only the one we clicked on
			$tab.click(function()
			{
				$('.tabs li').removeClass('on');
				$switcher.find('div.switcher-content').hide();
				$tab.toggleClass('on');
				$tabContent.toggle();
			});
	
			// leave only the first tab selected and open
			if (i == 0) $tab.addClass('on');
			if (i > 0) $tabContent.toggle();
		});
	}

	/*-------------------------------------------    
		Vertical Tabset 
	-----------------------------------------*/
	var $vTabSet = $('.tabset');
	var $tabs = $('<ul class="vert-tab-nav"></ul>');
	$vTabSet.prepend($tabs);
	$vTabSet.find('h2').each(function(i)
	{
		// hide the h2, since it's being duplicated into a list before the tabs anyway
		var $h2 = $(this);

		// create the tab link (hardcode a return false to save a jQuery selector and since this
		// will only be seen with JS on anyway)
		var $tab = $('<li><span>'+$h2.html()+'</span></li>');
		$tabs.append($tab);

		// now that we have a link, hide the h2
		$h2.addClass('move');

		// add a class to locate our tab-content later
		var $tabContent = $h2.next();
		$tabContent.addClass('vert-tab-content');

		// on click hide all the tabs and open only the one we clicked on
		$tab.click(function()
		{
			$('.vert-tab-nav li').removeClass('on');
			$vTabSet.find('div.vert-tab-content').hide();
			$tab.toggleClass('on');
			$tabContent.toggle();
		});

		// leave only the first tab selected and open
		if (i == 0) $tab.addClass('on');
		if (i > 0) $tabContent.toggle();
	});

	/*-------------------------------------------    
		Horizontal Tabset 
	-----------------------------------------*/
  $('.fund .horz-tabset').each(function(j){
    var $hTabSet = $(this);
    var $tabs = $('<ul class="horz-tab-nav"></ul>');
    $hTabSet.prepend($tabs);
    $hTabSet.find('h5').each(function(i)
    {
      // hide the h5, since it's being duplicated into a list before the tabs anyway
      var $h5 = $(this);

      // create the tab link (hardcode a return false to save a jQuery selector and since this
      // will only be seen with JS on anyway)
      var $tab = $('<li><span>'+$h5.html()+'</span></li>');
      $tabs.append($tab);

      // now that we have a link, hide the h5
      $h5.addClass('move');

      // add a class to locate our tab-content later
      var $tabContent = $h5.next();
      $tabContent.addClass('horz-tab-content');

      // on click hide all the tabs and open only the one we clicked on
      $tab.click(function()
      {
        $hTabSet.find('.horz-tab-nav li').removeClass('on');
        $hTabSet.find('.horz-tab-content').hide();
        $tab.toggleClass('on');
        $tabContent.show();
      });

      // leave only the first tab selected and open
      if (i == 0) $tab.addClass('on');
      if (i > 0) $tabContent.hide();
    });

  });

	/*-------------------------------------------    
			Video Page Horizontal Tabset 
	-----------------------------------------*/
	function hVideoTabSet() {
		var $hTabSet = $('.video-gallery .horz-tabset');
		var $tabs = $('<ul class="horz-tab-nav"></ul>');
		$hTabSet.prepend($tabs);
		$hTabSet.find('h2').each(function(i)
		{
			// hide the h5, since it's being duplicated into a list before the tabs anyway
			var $h2 = $(this);

			// create the tab link (hardcode a return false to save a jQuery selector and since this
			// will only be seen with JS on anyway)
			var $tab = $('<li><span>'+$h2.html()+'</span></li>');
			$tabs.append($tab);

			// now that we have a link, hide the h5
			$h2.addClass('move');

			// add a class to locate our tab-content later
			var $tabContent = $h2.next();
			$tabContent.addClass('horz-tab-content');

			// on click hide all the tabs and open only the one we clicked on
			$tab.click(function()
			{
				$('.horz-tab-nav li').removeClass('on');
				$hTabSet.find('.horz-tab-content').hide();
				$tab.toggleClass('on');
				$tabContent.toggle();
			});

			// leave only the first tab selected and open
			if (i == 0) $tab.addClass('on');
			if (i > 0) $tabContent.toggle();
		});
	}

/*-------------------------------------------
	Dictionary Term
-------------------------------------------*/
function dictTerm() {
	$('.dict-term').wrapInner('<span />');
}

