/* Custom javascript/jquery for GCS */

$(document).ready(function() {


	if($('#form_sent').val() == 1)
		$('#m39d0bmoduleform_2').hide();

	// Used for CCH calculators

	$(".cch-calculator").live('click',function() {
	
			$.colorbox({
				href: $(this).attr('href'),
				width:"80%", 
				height:"80%", 
				close: 'Close',
				iframe:true
			});
			return false;
	});
	





$("body").addClass('js');

// No right side so expand the width
if($('.home').length == 0)
if($('#right-side').length == 0) {
	$('#content').addClass('wide');
}



/* Main nav show/hide effect. Check for existence of .ie6 class in header, and behaves accordingly. */

if ($('#header .ie6').length == 0) {
  $("ul#primary-nav li.menuparent").hover(
    function () {
      //$(this).find("div.nav-arrow").slideDown('fast');
      $(this).find("div.nav-arrow").slideDown(300).find("ul.unli").slideDown(300);
    }, 
    function () {
      //$(this).find("div.nav-arrow").slideUp('fast');
      $(this).find("div.nav-arrow").slideUp(1).find("ul.unli").slideUp(1);
    }
  );
} else {
  $("ul#primary-nav li.menuparent").hover(
    function () {
      $(this).find("div.nav-arrow").show().find("ul.unli").show();
    }, 
    function () {
      $(this).find("div.nav-arrow").hide().find("ul.unli").hide();
    }
  );
}






/* Sitemap slide effect */

  $(".sitemap-btn").click(function(event){
    event.preventDefault();
	  $(".sitemap").slideToggle("slow", function() {
      $(".sitemap").toggleClass("active-sitemap");
    });
	  $(this).toggleClass("active");
	});
/*
$('body').click(function(event) {
    if (!$(event.target).closest('.sitemap').length) {
        $(".sitemap").slideDown("slow");
    };
});

*/
$(document).click(function(event) {


    if (($(".sitemap").hasClass('active-sitemap')) && (!$(event.target).closest('.sitemap-btn').length)) {

  $(".sitemap").slideToggle("slow", function() {
      $(".sitemap").toggleClass("active-sitemap");
      $(".sitemap-btn").toggleClass("active");
    });
        
    }
});




/* Sitemap columns */
/*
	easyListSplitter 1.0.2 - jQuery Plugin
	Created by Andrea Cima Serniotti - http://www.madeincima.eu
*/

		$('.sitemap ul.clearfix').easyListSplitter({ 
			colNumber: 3 // Insert here the number of columns you want. Consider that the plugin will create the number of cols requested only if there's enough items in the list.
		});

/* Internal/External/Document link detection (doc/docx, xls/xlsx, ppt/pptx, pdf  */
  $("a[href$='.pdf'],a[href$='.doc'],a[href$='.docx'],a[href$='.xls'],a[href$='.xlsx'],a[href$='.ppt'],a[href$='.pptx']")
  .attr("target","_blank")
  .attr("title","Opens new window")  
  .parent().addClass('link-document')
  .append("<span><img src='/images/icon-document.gif' width='8' height='12' /></span>");

  $("a[href*='http://']:not([href*='"+location.hostname+"']),[href*='https://']:not([href*='"+location.hostname+"'])")
  .attr("target","_blank")
  .attr("title","Opens new window")
  .parent().addClass("link-external");
 // .append("<span><img src='/images/icon-external.gif' width='11' height='12' /></span>");
  
/*  $("#sidebar .useful-resources li a").append("<span></span>");*/
  

 			
 			$('.section-title').smallCaps();
 			$('.section-title').vAlign();
 			
});


	$.fn.smallCaps = function() { 
		 var txt = $(this).text();
			if(txt.length == 0) return;
		
	   mystring = txt.replace(/^\s+|\s+$/g,"").replace('<span>','').replace('</span>','');
			sp = mystring.split(' ');
			byslash = false;
		
			if(sp.length == 1) {
				sp = mystring.split('/');
				byslash = true;
			}
			wl=0;
			word = new Array();
			for (i = 0 ; i < sp.length ; i ++ ) {
				
				// Dont modify a word when the first three chraracters are all text (ex: CPA, CEO)	
				if(sp[i].substring(0,3) == sp[i].substring(0,3).toUpperCase()) {
					word[i] = '<span>'+sp[i]+'</span>';
				} else {
					
				
				first = sp[i].substring(0,1);
				if(first == '&')
					f = first.toUpperCase();
				else 
					f = '<span>'+first.toUpperCase()+'</span>';
					
					r = sp[i].substring(1).toLowerCase();
					word[i] = f+r;
					
				}
			}	
			
			if(byslash==true)
				newstring = word.join('/');
			else 
				newstring = word.join(' ');
			
				$(this).html(newstring);
				//obj.value = newstring;
				
	};
	
$.fn.vAlign = function() {
	return this.each(function(i){
	var h = $(this).height();
	var oh = $(this).outerHeight();
	var mt = (h + (oh - h)) / 2 + 165;
	$(this).css("margin-top", "-" + mt + "px");
	$(this).css("position", "absolute");
	});
}
