(function($){
  $.fn.extend({
    box: function() {
      return $(this).each(function(){
        $(this).append('<div class="tl"></div><div class="tr"></div><div class="bl"></div><div class="br"></div>');
      });
    }
  })
})(jQuery);

$(function(){
//get url file
     var currentfile = jQuery.url.attr("file");
     var currentdir = jQuery.url.attr("directory").replace("/","").replace("/","");
     //highlight selected link
     $("#sidebar-navigation li").removeClass('selected');
     $("#main-nav li").removeClass('selected');
     if(currentdir!="/"){
         $("#sidebar-navigation li a").each(function () {
            if ($(this).attr('href') == currentfile) {
                $(this).parents("li").addClass('selected');
            }
          });
		  
		  $("#main-nav a").each(function () {
            if ($(this).attr('href') == currentfile) {
                $(this).parents("li").addClass('selected');
            }
			if ($(this).parents("ul").parents("ul").find("a").attr('href') == currentfile && currentfile != "about-us.html") {
                $(this).parents("li").addClass('selected');
            }
          });
      }
	  //resize boxes
	  var boxheight = 250;
	  $(".feature-box").each(function(){
		if($(this).height() > boxheight){
			boxheight = $(this).height();	
		}
	  });
	  
	  $(".feature-box").height(boxheight);
	  
	  if($("#contact-us").length>0){
		  $("#contact-us").validate({
			   errorElement: "em"
		  });
	  }
	  
	  //if IE add rounded corners
	  if(jQuery.support.leadingWhitespace==false){
		$('.feature-box').box();
		$('.callout, .content-wrapper').css({"position":"relative"}).box();
		/*$('#sidebar-navigation li').css({"position":"relative"}).box();*/
		
	  }
	 
	 
	 //sidetabs
	 //services hover

	$("#services li").hover(

      function () {

        $(this).css({"cursor":"pointer"});

      }, 

      function () {

        $(this).css({"cursor":"default"});

      }

    );

	

	//services click
		$(".item:first").show();
		$("#services li:first").addClass("selectedservice");
		$("#services li").click(function(){
			$("#services li").removeClass("selectedservice");
			
			$(this).addClass("selectedservice");
			
			var li_index = $("#services li").index(this);
			
			$(".item").hide();
			
			$(".item").eq(li_index).animate({opacity: 'toggle'}, 300);	//.show("fast");		
		
		});


	/* Home page cycle
	 ----------------------------------------------------*/
	if($('#promo-rotate').length > 0){
			var $container = $('#promo-rotate').cycle({
				speed: 550,  					// speed of the transition (any valid fx speed value)
				timeout: 6000,  				// milliseconds between slide transitions (0 to disable auto advance)
				cleartype: !$.support.opacity,  // true if clearType corrections should be applied (for IE) 
				cleartypeNoBg: true   			// set to true to disable extra cleartype fixing (leave false to force background color setting on slides)
			});
	}//end if promo screen	
	
	
	//get spam protection 
	$.ajax({
	  url: "ajax.php",
	  data: "action=contactformspam",
	  success: function(data){
		$("#contact-us").append(data);
	  }
	}); 
});
