$jQ = jQuery.noConflict();//Avoids conflict with mooTools



$jQ(document).ready(function() { $jQ('a.backtotop').click(function(){ $jQ('html, body').animate({scrollTop:0}, 'slow'); return false; }); });


//Capitalise every first letter
//$jQ(document).ready(function(){
//     $jQ("a").each(function(){
//          $jQ(this).attr("title",$jQ(this).attr("title").capitalize());
//     });	
//});

$jQ(document).ready(function() {
   $jQ("div.box_content p:last-child").addClass("last");   
});


// Add text to menu drop downs
$jQ(document).ready(function() {
	
	var i = 0;
	$jQ('.sf-menu li li').attr('id', function() {
   i++;
   return 'page'+i;
});
	
   // PRACTICE AREAS
   $jQ('<p>Guiding you through the tides of change</p>').insertAfter('.sf-menu li li#page1 a');
   $jQ('<p>Keeping you on the right track</p>').insertAfter('.sf-menu li li#page2 a');  
   $jQ('<p>Ensuring a calm outlook</p>').insertAfter('.sf-menu li li#page3 a');  
   $jQ('<p>Helping to avoid stormy waters</p>').insertAfter('.sf-menu li li#page4 a');  
   $jQ('<p>Find peace of mind knowning your business is protected</p>').insertAfter('.sf-menu li li#page5 a');
   $jQ('<p style="padding-bottom:5px;">The support you need for a brighter outcome</p>').insertAfter('.sf-menu li li#page6 a');
   
   // OUR PEOPLE
   $jQ('<p>Intellectual Property</p>').insertAfter('.sf-menu li li#page7 a');
   $jQ('<p>Commercial Property</p>').insertAfter('.sf-menu li li#page8 a');
   $jQ('<p>Construction and Enginnering</p>').insertAfter('.sf-menu li li#page9 a');
   $jQ('<p>Company Commercial</p>').insertAfter('.sf-menu li li#page10 a');
   $jQ('<p>Employment Law</p>').insertAfter('.sf-menu li li#page11 a'); 
   $jQ('<p>Intellectual Property</p>').insertAfter('.sf-menu li li#page12 a');
   $jQ('<p>Company Commercial</p>').insertAfter('.sf-menu li li#page13 a');
   $jQ('<p>Construction and Enginnering / Property Litigation</p>').insertAfter('.sf-menu li li#page14 a');
   $jQ('<p style="padding-bottom:5px;">Commercial Property</p>').insertAfter('.sf-menu li li#page15 a'); 
          
});


$jQ(document).ready(function() {//Ensures captions are not wder than images
   $jQ("div.caption").each(function() {
      var imgWidth = $jQ(this).prev().width();
      $jQ(this).width(imgWidth);
   }); 
});
$jQ(function(){//Adds margins to left floated images in the specified column
    $jQ("img","#Main_Left").each(function(){
            if($jQ(this).css('float') == 'left'){
                    $jQ(this).css('margin', '5px 20px 10px 0px');
            }
    });
});
$jQ(function(){//Adds margins to right floated images in the specified column
    $jQ("img","#Main_Left").each(function(){
            if($jQ(this).css('float') == 'right'){
                    $jQ(this).css('margin', '5px 0px 10px 20px');
            }
    });
});

$jQ(function(){//Add padding to td in calendar that do not contain a link
    $jQ("div.calendar td")
       .filter(function(){//That does not contain a a tag
           return $jQ("a",this).length==0;
    }).css({//Add Padding
      padding:"2px 7px"
    });
});

// Changes the word "Routing" to "Directions" on the "How to find us" map
$jQ(function($) {
  var linkInterval = setInterval(checkOverlay, 50);

  function checkOverlay() {
    var $rountingLink = $("div.routinglink a");
    if($rountingLink.length) {
      $rountingLink.text('Directions');
      clearInterval(linkInterval);
    }
  }
});

$jQ(document).ready(function() {

	$jQ(function() {
	var zIndexNumber = 1000;
	$jQ('div').each(function() {
		$jQ (this).css('zIndex', zIndexNumber);
		zIndexNumber -= 10;
		});
	});	
	
// Add a class of last to the last p in a div.
	$jQ("div p:last-child").addClass("last");
	
	// Add a class of 3rd to every 3rd list item
	$jQ("ul.test li:nth-child(3n)").addClass("3rd");
	
	// Add a rel no follow attribute to links in the mincalendar -  search engines will not see it - but helps optilink report
	$jQ("div.calendar a").attr('rel','nofollow');
	
	// May be useful in the future
	//$jQ('form input[type="text"]').addClass("text");
	//$jQ('label[for="fOptIn"]').addClass("checks");
 
	//Add external link icon to external links - 
	//$jQ('a').filter(function() {
  //Compare the anchor tag's host name with location's host name
	//    return this.hostname && this.hostname !== location.hostname;
	//  }).addClass("new_win");

  //Add external link icon to external links and open in a new window
	$jQ('a').filter(function() {
		//Compare the anchor tag's host name with location's host name
	    return this.hostname && this.hostname !== location.hostname;
	  }).addClass("new_win").attr("target", "_blank");	
	

});

/////////////////////////////////
//      FADE IMAGE LINKS       //
/////////////////////////////////

// Fade images with a class of fade on mouseover
$jQ(document).ready(function() {
// make sure the image is at full opacity on load
$jQ("a.fade img").css("opacity", "1.0");

	// Change speed/opactity of mouseover state
	$jQ('a.fade img').mouseover(function() {
		$jQ(this).stop().fadeTo(400, 0.5);
	});

	// Change speed/opactity of mouseout state
	$jQ('a.fade img').mouseout(function() {
		$jQ(this).stop().fadeTo(500, 1.0);
	});
});




