// jQuery URL function  -- http://projects.allmarkedup.com/jquery_url_parser/
jQuery.url=function(){var segments={};var parsed={};var options={url:window.location,strictMode:false,key:["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],q:{name:"queryKey",parser:/(?:^|&)([^&=]*)=?([^&]*)/g},parser:{strict:/^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,loose:/^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/}};var parseUri=function(){str=decodeURI(options.url);var m=options.parser[options.strictMode?"strict":"loose"].exec(str);var uri={};var i=14;while(i--){uri[options.key[i]]=m[i]||""}uri[options.q.name]={};uri[options.key[12]].replace(options.q.parser,function($0,$1,$2){if($1){uri[options.q.name][$1]=$2}});return uri};var key=function(key){if(!parsed.length){setUp()}if(key=="base"){if(parsed.port!==null&&parsed.port!==""){return parsed.protocol+"://"+parsed.host+":"+parsed.port+"/"}else{return parsed.protocol+"://"+parsed.host+"/"}}return(parsed[key]==="")?null:parsed[key]};var param=function(item){if(!parsed.length){setUp()}return(parsed.queryKey[item]===null)?null:parsed.queryKey[item]};var setUp=function(){parsed=parseUri();getSegments()};var getSegments=function(){var p=parsed.path;segments=[];segments=parsed.path.length==1?{}:(p.charAt(p.length-1)=="/"?p.substring(1,p.length-1):path=p.substring(1)).split("/")};return{setMode:function(mode){strictMode=mode=="strict"?true:false;return this},setUrl:function(newUri){options.url=newUri===undefined?window.location:newUri;setUp();return this},segment:function(pos){if(!parsed.length){setUp()}if(pos===undefined){return segments.length}return(segments[pos]===""||segments[pos]===undefined)?null:segments[pos]},attr:key,param:param}}();

$.mcmLocale="can";

$(function () {
  
localize();  
  
$('a').click(function() {
  // source: http://blog.rebeccamurphey.com/2008/12/04/update-tracking-outbound-clicks-with-google-analytics-and-jquery/
  // "Tracking outbound clicks with Google Analytics and jQuery"
	if (typeof(pagetracker) !== "function") {return;}
	
  var $a = $(this);
  var href = $a.attr('href');
  
  // see if the link is external
  if ( (href.match(/^http/)) && (! href.match(document.domain)) ) 
    {
    // if so, register an event
    var category = 'outgoing'; // set this to whatever you want
    var event = 'click'; // set this to whatever you want
    var label = href; // set this to whatever you want
    pageTracker._trackEvent(category, event, href);
    return;
    }

  // see if the link is a download
  var fileTypes = ['pdf'];  
  var hrefArray = href.split('.');
  var extension = hrefArray[hrefArray.length - 1];
  
  if ($.inArray(extension,fileTypes) != -1) {
      pageTracker._trackEvent('download', extension, href);  }
    
  });
});

function localize() {
  $(".localizable").hide();
  var cURL=$.url.attr("host").toLowerCase();
  var cSD6=cURL.substring(0,6);
  var cSD=cURL.split(".")[0];
  cSD=cSD.substring(0,2);
  if (cSD==="us"|cSD==="am"|cSD6==="www.us"|cSD6==="www.am") { $.mcmLocale="us"; $(".us").show();} else {$(".can").show();}
  $("body div.container").show();
}
