/* Gets URL parameters */
/* http://www.netlobo.com/url_query_string_javascript.html */

function gup(name) {
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp( regexS );
	var results = regex.exec( window.location.href );
	if( results == null )
		return "";
	else
		return results[1];
}


/****
**enable the menu highlight when the content type is viewed
**just place the correct content type / menu id combination 
**into the array
****/
function highlightMenu(node_type)
{
	var menu = Array();
	var n_type = '';
	menu['event'] = 'menu-1-6-2';
	menu['blog'] = 'menu-1-7-2';

	for (n_type in menu)
	{
		if(node_type == n_type)
	  	{
	  		$('#sidebar-left > #primary > ul.links > li.'+ menu[n_type] +' > a.'+ menu[n_type]).addClass('active');
	  	}
	  	else
	  	{
	  		$('#sidebar-left > #primary > ul.links > li.'+ menu[n_type] +' > a.'+ menu[n_type]).removeClass('active');
	  	}
	}
}


function instBuildingList() {
  $(".dynamic-option").hide();
  $(".view-building-list li:eq(0)").before("<li class='active-state'>" + $(".dynamic-option a.active").html() + "</li>");
  $(".dynamic-option a.active").hide();
    
  $(".view-building-list .custom-views-header").addClass('views-filter-arrow-up');
  $(".view-building-list ul").hoverIntent(
	function() {
	  $(this).children("li:gt(0)").fadeIn("fast");
	  $(".view-building-list .custom-views-header").addClass('views-filter-arrow-down');
	  $(".view-building-list .custom-views-header").removeClass('views-filter-arrow-up');
	},
	function() {
	  $(this).children("li:gt(0)").fadeOut("fast");
	  $(".view-building-list .custom-views-header").removeClass('views-filter-arrow-down');
	  $(".view-building-list .custom-views-header").addClass('views-filter-arrow-up');
	}
  );
}

function instDepartmentList()
{
    $("#custom-views-all").before("<div class='active-state'>" + $("#custom-views-filter .custom-views-body a.active").html() + "</div>");
    $("#custom-views-filter .custom-views-body a.active").hide();
    $("#custom-views-filter .custom-views-body div:not('.active-state')").hide();
	  $("div.custom-views-header").addClass('views-filter-arrow-up');
	
    $("div.custom-views-body").hoverIntent(
  	  function() {
  	    $("div.custom-views-body div").fadeIn("fast");
  	    $("div.custom-views-header").addClass('views-filter-arrow-down');
  	    $("div.custom-views-header").removeClass('views-filter-arrow-up');
  	  },
  	  function() {
  	    $("div.custom-views-body div:gt(0)").fadeOut("fast");
  	    $("div.custom-views-header").removeClass('views-filter-arrow-down');
  	    $("div.custom-views-header").addClass('views-filter-arrow-up');
  	  }
    );
}

$(document).ready( function() {
  if($('.field-field-title-bottom-right').height() > 22)
  {
  	$('.field-field-title-bottom-left').css('margin-bottom',$('.field-field-title-bottom-right').height() - $('.field-field-title-bottom-left').height());
  }
  else if($('.field-field-title-bottom-left').height() > 22)
  {
  	$('.field-field-title-bottom-right').css('margin-bottom',$('.field-field-title-bottom-left').height() - $('.field-field-title-bottom-right').height());
  }
 
  // Force specific external links to open in same window
  $('#primary a.ext:contains("Facilities"), #top-text a:contains("Facilities Home")').attr('target', '');
 
  /* Cluetip settings */
  if (!$('a.definition').attr("rel")) {  /* Allow "rel" tags to be auto-generated if not provided */
		$('a.definition').attr("rel", function() {
		  return $(this).attr("href")
		});
  }
  	if($('a.definition').cluetip)
	$('a.definition').cluetip({showTitle: false, attribute: 'rel'});
	
	$('#primary a.ext').parent().addClass('external-link');
	$('#primary a.ext:eq(0)').addClass('ext_first');
  
  
  /* change the Search button to Go */
  $("#block-search-0 input.form-submit").attr('value','Go');


  /* Quick Links dropdown functionality */
  if($("#quicklinks").hoverIntent)
  {
	  $("#quicklinks").hoverIntent(
		function() {
		  $("#quicklinks div").show("fast");
		},
		function() {
		  $("#quicklinks div").hide("fast");
		}
	  );
	
	  $("#quicklinks li.expanded").hoverIntent(
		function() {
		  $(this).children("ul").fadeIn("fast");
		},
		function() {
		  $(this).children("ul").fadeOut("fast");
		}
	  );
  }


  if ($(".view-building-list").length) {
  	instBuildingList();
    $("#dynamic-filter-building_list").ajaxComplete(function(request, settings){
   	  instBuildingList();
    });
  }
  else if ($("#custom-views-filter").length)
    instDepartmentList();

/*  
  $(".view-building-list ul").hoverIntent(
	function() {
	  (".view-building-list li:gt(0)").show();
	},
	function() {
	  (".view-building-list li:gt(0)").hide();
	}
  );
*/

//  $(".field-type-nodereference a").attr("rel",$(this).attr("href"));
//  $(".field-type-nodereference a").addClass("definition");

/* Edit Link guide helper (not complete yet..)
  $(".edit").hoverIntent(
	function() {
	  $(this).parent().css("outline","1px solid #F00");
	},
	function() {
	  $(this).parent().css("outline","none");		
	}
  );
*/


  /* change the Request Service second navigation into tabs */

  /*if(!$("div.view-services-list").text())
  {
  	//$("#menu_links li div.item-list").hide();
  }
  else
  {*/
/*
 	if(views_selection == 'services_list')
 	{
 		$("#menu_links li.menu-1-2-2 div.item-list a.active").parent().parent().addClass('active');
 		
 		$("#menu_links li.menu-1-2-2 div.edit").addClass('inner-tabs-reorder');
 		
 		$("#menu_links li.menu-1-2-2 div.item-list").addClass('inner-tabs');
 		$("div.introduction").after($("#menu_links li div.edit"));
 		$("div.introduction").after('<br id="tabs-break" />');
  		$("div.introduction").after($("#menu_links li div.item-list"));
  		$('#sidebar-left > #primary > ul.links > li.menu-1-2-2 > a.menu-1-2-2').addClass('active');
 	}
  */	
  /*}*/
  

  if ($("body.not-logged-in").length)
    $("#footer-inner").hover(
  	  function() { $(this).css("background","#DDD"); $(this).dblclick(
  	    function() { document.location = base_path + "user/wind"; }
  	  )},
  	  function() { $(this).css("background","#FFF") }
    );
  

/* Re-arranging for the body section titles and bodies (NOT COMPLETE)
	if ($("#node-form .group-main-content").length) {
	  $("#node-form .group-main-content fieldset:eq(0) input").each(function (i) {
        alert( $("#node-form .group-main-content fieldset:eq(1) textarea:eq(" + $("#node-form .group-main-content fieldset:eq(0) input").index(this) + ")").attr("id") );
	  });
	}
*/
	
	


  $(".toggled-content h2 a, .bio-link").toggle(
    function() {
	 nodeinner = $(this).parents(".node-inner, .block-inner").eq(0);
	 $(this).parent().next().show('fast');
	 nodeinner.css("position", "relative");
	 nodeinner.toggleClass('block-highlight');
      return false;
    },
    function() {
	 nodeinner = $(this).parents(".node-inner, .block-inner").eq(0);
	 $(this).parent().next().hide('fast');
	 nodeinner.css("position", "relative");
	 nodeinner.toggleClass('block-highlight');
      return false;
    }
  );

  // Panels toggles
  $(".toggled-pane h2 a, .toggled-pane h2").toggle(
    function() {
      nodeinner = $(this).parents(".toggled-pane").eq(0);
      nodeinner.children(".content").eq(0).show('fast');
      nodeinner.css("position", "relative");
      nodeinner.toggleClass('pane-highlight');
      return false;
    },
    function() {
      nodeinner = $(this).parents(".toggled-pane").eq(0);
      nodeinner.children(".content").eq(0).hide('fast');
      nodeinner.css("position", "relative");
      nodeinner.toggleClass('pane-highlight');
      return false;
    }
  );  
  
  $(".panel-pane .workflow-unpublished").removeClass("workflow-unpublished").parents(".panel-pane").addClass("workflow-unpublished");
  $("#alpha-index").after($("#tertiary-links"));

  if (!$("#block-block-5 .content").children().length)
    $("#block-block-5").hide();
  
  $(".box h2.title").contains('FAQ Sections').parent().parent().hide();
} );