
$(document).ready(function() {
  
  $("#icons-holder .sonic-icon-holder").mouseover(
		function()
		{
			$("#service-type-holder").addClass("mobile");
		}
	).mouseout(
		function()
		{
			$("#service-type-holder").removeClass("mobile");
		}
	);
	
	$("#icons-holder .onesquared-icon-holder").mouseover(
		function()
		{
			$("#service-type-holder").addClass("infra");
		}
	).mouseout(
		function()
		{
			$("#service-type-holder").removeClass("infra");
		}
	);	

	$("#icons-holder .breathe-icon-holder").mouseover(
		function()
		{
			$("#service-type-holder").addClass("web");
		}
	).mouseout(
		function()
		{
			$("#service-type-holder").removeClass("web");
		}
	);
  
  
  // hide all offices except the first
  $("ul#offices>li:not(:first) ul").slideUp("fast");
  
  // assign closed class to all so can apply click function to h2
  $("ul#offices>li").addClass("closed");
  
  $("ul#offices li.closed h2").click(function() {
    $("ul#offices>li").removeClass().addClass("closed");
    $(this).parent().removeClass("closed").addClass("open");

    $(this).siblings("ul").slideDown(410);
    $(this).parent().siblings().children("ul").slideUp(400);
  });
  
  // add open class to the first
  $("ul#offices>li:first").removeClass("closed").addClass("open");
  
  
  
  // remove omni url so displays the login form
  $("#header div.login div.snippet div.button_open a").attr("href" ,"#");
  
  // login show and hide
  $("#header div.login div.snippet div.button_open a").click(
    function() {
      $("#header div.login div.snippet").hide();
      $("#header div.login div.form").show();
      $("#header div.login").addClass("login-form");
    }
  );

  $("#header div.login div.form div.button_close a").click(
    function() {			
      $("#header div.login div.form").hide();
      $("#header div.login div.snippet").show();
      $("#header div.login").removeClass("login-form");
    }
  );
  
  // what is omniscience
  $("#header a#what_is_this").attr("href" ,"#");
  
  $("#header a").click(
		function() {
			if (this.id == "what_is_this") {
				$("div#popup").toggle();
			}
			else {
				$("div#popup").hide();
			}
			return true;
		}
	);
  
  // file attach
  $("#attach div#fileinput").hide("fast");
  $("input[type=file]").filestyle({ 
    image: "/css/imgs/btn-attach.gif",
    imageheight : 20,
    imagewidth : 80,
    width : 156
  });
  $("#attach label").hover(
    function () {
	    $(this).addClass("btn-hover");
    },
    function () {
	    $(this).removeClass("btn-hover");
    }
  );
  $("#attach label").click(function() {
    $(this).siblings("div#fileinput").show();
  });

	
  $("#header input").hover(
    function () {
	    $(this).addClass("ie-focus");
    },
    function () {
	    $(this).removeClass("ie-focus");
    }
  );
  
  // search
  $.fn.search = function() {
	  return this.focus(function() {
		  if( this.value == this.defaultValue ) {
			  this.value = "";
		  }
	  }).blur(function() {
		  if( !this.value.length ) {
			  this.value = this.defaultValue;
		  }
	  });
  };
  
  
  
  // hovers for IE
  var isIE = (/MSIE ((5\.5)|6)/.test(navigator.userAgent) && navigator.platform == "Win32");
  if (isIE) {
   
    /* Add class to element onhover as needed  */
    $("#header button").hover(
  	  function () {
    	  $(this).addClass("btn-login-ie");
  	  },
  	  function () {
    	  $(this).removeClass("btn-login-ie");
  	  }
	  );
    
    $("#offices h2").hover (
	    function () {
  	    $(this).addClass("nav-on-ie");
	    },
	    function () {
  	    $(this).removeClass("nav-on-ie");
	    }
    );

    $("button.btn-search").hover (
	    function () {
  	    $(this).addClass("btn-search-ie");
	    },
	    function () {
  	    $(this).removeClass("btn-search-ie");
	    }
    );
    
    $("#sidebar button").hover (
	    function () {
  	    $(this).addClass("btn-submit-ie");
	    },
	    function () {
  	    $(this).removeClass("btn-submit-ie");
	    }
    );
    
    $("#current button").hover (
	    function () {
  	    $(this).addClass("btn-apply-ie");
	    },
	    function () {
  	    $(this).removeClass("btn-apply-ie");
	    }
    );
   
  }

});

