// sitewide scripts


// display footer logo tabs
$(function() {
   // Tabs
   $('#accreditationsClients').tabs(); }
);

// logo scroller thanks to will kelly (http://logicbox.net/jquery/simplyscroll/horizontal.html)
(function($) {
   $(function() {
      $("#accreditations").simplyScroll( {
         autoMode : 'loop'}
      ); }
   ); $(function() {
      $("#clients").simplyScroll( {
         autoMode : 'loop'}
      ); }
   ); }
)(jQuery);

// footer logo hover state changes
$(document).ready(function() {
   $('#accreditations img').hover( function() {
      // get img src
      this.oldSrc = $(this).attr('src'); // reference the hoverOn directory instead of the hoverOff directory and reflect in the url
      this.newSrc = this.oldSrc.replace('hoverOff', 'hoverOn'); // change image source on hover
      $(this).attr('src', this.newSrc); }
   , function() {
      $(this).attr('src', this.oldSrc); }
   ); }
);
$(document).ready(function() {
   $('#clients img').hover( function() {
      // get img src
      this.oldSrc = $(this).attr('src'); // reference the hoverOn directory instead of the hoverOff directory and reflect in the url
      this.newSrc = this.oldSrc.replace('hoverOff', 'hoverOn'); // change image source on hover
      $(this).attr('src', this.newSrc); }
   , function() {
      $(this).attr('src', this.oldSrc); }
   ); }
);

// make global navigation links grey when their submenu is active
//$(document).ready(function() {
   //$('.navigationGlobal ul li a').hover(function() {
      //$(this).css("background-color", "#DDD"); $(this).parent().parent().parent().find("a").css("background-color", "#DDD"); }
   //, function() {
      //$(this).css("backgrond-color", "white"); $(this).parent().parent().parent().find("a").css("background-color", "#FFF"); }
   //); }
//);

// unobtrusive clear form fields onfocus courtesy of joseph sak (http://is.gd/mtEp)
$(document).ready(function(){
	// 'homepage' newsletter
	autoFill($("#wpnewsletter_name"), "Name");
	autoFill($("#wpnewsletter_email"), "Email");
	autoFill($("#wpnewsletter_captcha"), "Enter anti-spam code");
	// comments
	autoFill($("#author"), "Name");
	autoFill($("#email"), "Email");
	autoFill($("#url"), "Website");
	autoFill($("#comment"), "Comment");
});

function autoFill(id, v){
	$(id).css({ color: "#ffffff" }).attr({ value: v }).focus(function(){
		if($(this).val()==v){
			$(this).val("").css({ color: "#ffffff" });
		}
	}).blur(function(){
		if($(this).val()==""){
			$(this).css({ color: "#ffffff" }).val(v);
		}
	});

}

// hide captcha on 'homepage' until useful (because it's ugly)
$(document).ready(function(){
	$('#securityCode').css('display', 'none');
	$('#wpnewsletter_email').focus(function(){
		$('#securityCode').animate({opacity: "show"}, "slow");
		});
	});

// prepend '-' to all citations
$(document).ready(function() {
   $('cite').prepend("- "); }
);

// append ':' to all input fields

/*
// hide/show blog/faq post content
$(document).ready(function() {
   $('.pageID-6 .post h2').css('min-height', '2em'); 
   $('.pageID-6 .entry').addClass('entryHeight'); 
   $('.pageID-6 .entry').css('margin-bottom', '1em'); 
   $('.pageID-6 .entry').css('overflow', 'hidden'); 
   $('.pageID-6 .entry').after('<p class="readToggle"><a href="#">Show whole post</a></p>'); 
   $('.pageID-6 .readToggle a').css('display', 'block'); 
   $('.pageID-6 .readToggle').css('text-align', 'right'); 
   $('.pageID-6 .readToggle').css('padding-right', '2em'); 
   
   $('.pageID-6 .readToggle a').toggle(function() {
      $(this).parents('.post').find('.entry').removeClass('entryHeight', 1000); }
   , function() {
      $(this).parents('.post').find('.entry').addClass('entryHeight', 1000); }
   ); }
); */

// hide/show case study post content
/*$(document).ready(function() {
   $('.pageID-7 .post h2').css('min-height', '2em'); 
   $('.pageID-7 .entry').addClass('entryHeight'); 
   $('.pageID-7 .entry').css('margin-bottom', '1em'); 
   $('.pageID-7 .entry').css('overflow', 'hidden'); 
   $('.pageID-7 .entry').after('<p class="readToggle"><a href="#">Show whole post</a></p>'); 
   $('.pageID-7 .readToggle a').css('display', 'block'); 
   $('.pageID-7 .readToggle').css('text-align', 'right'); 
   $('.pageID-7 .readToggle').css('padding-right', '2em'); 
   
   $('.pageID-7 .readToggle a').toggle(function() {
      $(this).parents('.post').find('.entry').removeClass('entryHeight', 1000); }
   , function() {
      $(this).parents('.post').find('.entry').addClass('entryHeight', 1000); }
   ); }
);
*/

$(document).ready(function () {
    // 'services we offer' page navigation
    // hide/show service description when service term clicked (center column)
    $('.pageID-4 #services dd').hide();
    $('.pageID-4 #services dt').localScroll({
        hash: false
    }).click(function () {
        $(this).next().show();
    });

    // add 'top of page' and 'get a quote!' buttons to each service description
    $('.pageID-4 dd').append('<p class="action"><a class="topOfPage"href="#content">Top of page</a><a class="quote" href="#content">Get a quote!</a></p>');

    // hide the contact form until 'get a quote!' button is pressed
    $('.pageID-4 #sidebar2').hide();
    $('.pageID-4 #content').css('width', '66%');
    $('.pageID-4 #content a.quote').click(function () {
        $('.pageID-4 #content').css('width', '33%');
        $('.pageID-4 #sidebar2').show('fast');
        $('.pageID-4 #sidebar2 .wpcf7-form').css({
            border: '3px solid #3FC6EF'
        });
    });

    // knock out contact form border on focus
    $('.pageID-4 .wpcf7').find('input, textarea').focus(function () {
        $('.pageID-4 .wpcf7-form').css('border', 'none');
    });

    // service button is clicked in #sidebar1
    $('.pageID-4 #serviceLinks a').click(function () {
        $('.pageID-4 #services dd').hide();
        $('.pageID-4 #sidebar2').hide();
        $('.pageID-4 #content').css('width', '66%');
        var link = $(this).attr('href');
        $('.service a' + link + "'").parent().next().show();
        return false;
    });
    $.localScroll({
        hash: false
    })
});

// hide save money component
$(document).ready(function() {
   $('#telecomplus').css('left', '-349px'); // toggle hide/show the component once 'save money!' button is clicked
   $('#saveMoney').toggle(function() {
      $('#telecomplus').animate( {
         left : '0'}
      , 'slow'); }
   , function() {
      $('#telecomplus').animate( {
         left : '-349px'}
      , 'slow'); }
   ); 
   
// light up effect
// exclude tree 'light up' effect from ie (until i find a fix)
if($.browser.msie == false) {
  $('#clickHere').mouseover(function() {
	 // generate new hover class on mouseover
	 $('#saveMoney').before('<div class="hover"></div>'); $('div.hover').css( {
		display : 'none'}
	 ).fadeIn(100); }
  ).mouseout(function() {
	 $('div.hover').fadeOut(1000, function() {
		// remove hover class on mouseout
		$(this).remove(); }
	 ); }
  ); }
}
);

// contain video dimensions on the homepage
$(document).ready(function(){
	//$('object').wrap('<div class="videoWrapper"></div>');
	$('.home object').attr({
					 width: '100%'});
});

// add colon ':' to all form input if one doesn't already exist
$(document).ready(function() {
   $('label').each(function () {
      if($(this).html().charAt($(this).html().length - 1) != ':') {
         $(this).append(': '); }
      }
   ); }
);	


// local scroll thanks to ariel flesler (http://flesler.blogspot.com/2007/10/jquerylocalscroll-10.html)
$(document).ready(function(){
$('.topOfPage, .strapline, .action').localScroll({
	hash: false})
});