/**********************************************************
Author:
Adam Barry
Klestrup partners
www.klestrup-partners.dk

Date: April 28 2010

� 2010 Adam Barry, all rights reserved
-----------------------------------------------------------

Name:
Utilities script

-----------------------------------------------------------
Description:
Function that contains various functions used through the
website

-----------------------------------------------------------
Usage:
Simply place a link to the this script in the head-section
of the XHTML page. The script will then automatically
execute on page load.

<script type="text/javascript" src="utilities.js"></script>

-----------------------------------------------------------
Example:
<script type="text/javascript" src="utilities.js"></script>

-----------------------------------------------------------
Dependencies:
None

**********************************************************/

function siteSearch() {
  var queryString = document.getElementById('query').value;
  if(queryString == '') {
    queryString = document.getElementById('query2').value;
  }

  location = "/search?search=" + queryString;
}


addLoadEvent(function () {
    //Remove anchor outline on clicks
    $("a").click(function () {
        $(this).blur();
    });

      //Navigation
      $("ul.navigation.primary").find("li").hoverIntent(function () {
        if ($(this).find("a").length > 1) {
          var heightSum = 17;
          $(this).find("a").each(function (index) {
            if (index) {
              heightSum += this.offsetHeight + 2;
            }
          });
    
          $(this).children("ul").stop().animate({ height: heightSum }, { queue: false, duration: 300, easing: 'swing' });
        }
      }, function () {
        $(this).children("ul").stop().animate({ height: '0' }, { queue: false, duration: 300, easing: 'swing' });
      });

    //Header links
    $("ul.quickLaunch").find("a").hoverIntent(function () {
        $(this).stop().animate({ "line-height": '26px' }, { queue: false, duration: 300, easing: 'swing' });
        $(this).children(".description").stop().animate({ height: '20' }, { queue: false, duration: 300, easing: 'swing' });
    }, function () {
        $(this).stop().animate({ "line-height": '37px' }, { queue: false, duration: 300, easing: 'swing' });
        $(this).children(".description").stop().animate({ height: '0' }, { queue: false, duration: 300, easing: 'swing' });
    });

    //Jobs
    $("ul.jobs").find(".toggle").click(function () {
        var parent = $(this).parent("li");
        if (parent.hasClass("open")) {
            parent.removeClass("open").stop().animate({ height: '53' }, { queue: false, duration: 300, easing: 'swing' });
        } else {
            var newHeight = parent.find("div")[0].offsetHeight + 50;
            parent.addClass("open").stop().animate({ height: newHeight }, { queue: false, duration: 300, easing: 'swing' });
        }
    });
  
    if ($.browser.msie == true){
      //Then this is IE. work out something with text-shadow
    }
})
