// TOP NAVIGATION
var timeout         = 500;
var closetimer		= 0;
var ddmenuitem      = 0;

function initOmnitureTracking(povPageName)
{
	openMetrics.init();
	if(povPageName)
	{
		//If a pagename is set for tracking, use it - -otherwise, we will pass in no pagename and it will default to the url of this page
		openMetrics.useProvider("omneetourr", { dc:112, profileId: "ntnortherntrust",trackingServer:"northerntrust.122.2o7.net",visitorNamespace:"northerntrust",pageName:povPageName });
		openMetrics.useProvider("ga", { profileId: "UA-16226646-1", pageName:povPageName});
	}
	else
	{
		openMetrics.useProvider("omneetourr", { dc:112, profileId: "ntnortherntrust",trackingServer:"northerntrust.122.2o7.net",visitorNamespace:"northerntrust" });
		openMetrics.useProvider("ga", { profileId: "UA-16226646-1"});
	}
	
	openMetrics.setEventParams("om_external-click", { category: null, action: "Click - External", label: null, value: null });
	openMetrics.setEventParams("om_file-click", { category: null, action: "Click - External", label: null, value: null });
	openMetrics.setEventParams("om_article-print-click", { category: null, action: "Click - Print", label: null, value: null });
	openMetrics.setEventParams("om_email-share-click", { category: null, action: "Click - Email", label: null, value: null });
	
	openMetrics.setEventParams("om_slide-link-click", { category: "Slider Link", action: "Click - External", label: null, value: null });
	openMetrics.setEventParams("om_issue-content-file-click", { category: "Issue Content Link", action: "Click - File", label: null, value: null });
	
	openMetrics.trackPageview();	
}

function jsddm_open()
{	jsddm_canceltimer();
	jsddm_close();
	ddmenuitem = $(this).find('ul').eq(0).css('visibility', 'visible');}

function jsddm_close()
{	if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');}

function jsddm_timer()
{	closetimer = window.setTimeout(jsddm_close, timeout);}

function jsddm_canceltimer()
{	if(closetimer)
	{	window.clearTimeout(closetimer);
		closetimer = null;}}

$(document).ready(function()
{	
	$('#jsddm > li').bind('mouseover', jsddm_open);
	$('#jsddm > li').bind('mouseout',  jsddm_timer);

	$('.member a').colorbox({width:'700px', height:'550px', opacity:'.6'}); 	
	
	$('.download-pdf').click(function() { trackArticleLinkClick($(this), 'Download'); });
	$('.print-page').click(function() { trackArticleLinkClick($(this), 'Print'); });
	$('.email-friend').click(function() { trackArticleLinkClick($(this), 'Email'); });
});

function trackArticleLinkClick(item, type)
{
	var linkCategory =  item.parent().attr('issue');
	var linkLabel =  item.parent().attr('article');
	
	openMetrics.trackEvent({ category: linkCategory, action: "Click - " + type, label: linkLabel, value: null });
}

document.onclick = jsddm_close;



//mainNav = function() {
//	$("#nav li").bind("mouseenter",function(){
//                this.className += "_over over";
//	}).bind("mouseleave",function(){
//                this.className = this.className.replace("_over over", "");
//	});
//}


// FEATURE SLIDER TOGGLE
var theInt = null;
		var $crosslink, $navthumb, $spanlink;
		var curclicked = 0;
		
		theInterval = function(cur){
			clearInterval(theInt);
			
			if( typeof cur != 'undefined' )
				curclicked = cur;
			
			$crosslink.removeClass("active-thumb");
			$navthumb.eq(curclicked).parent().addClass("active-thumb");
				$(".stripNav ul li a").eq(curclicked).trigger('click');
			
			theInt = setInterval(function(){
				$crosslink.removeClass("active-thumb");
				$navthumb.eq(curclicked).parent().addClass("active-thumb");
				$(".stripNav ul li a").eq(curclicked).trigger('click');
				curclicked++;
				if( 4 == curclicked )
					curclicked = 0;
				
			}, 7000);
		};
		
		$(function(){
			
			$("#main-photo-slider").codaSlider();
			
			$navthumb = $(".nav-thumb");
			$crosslink = $(".cross-link");
			$spanlink = $("span-link");
			
			$navthumb
			.click(function() {
				var $this = $(this);
				theInterval($this.parent().attr('href').slice(1) - 1);
				return false;
			});
			
			theInterval();
		});
		


// SLIDE ANCHOR
/*$(document).ready(function() {
 function filterPath(string) {
    return string
    .replace(/^\//,'')
    .replace(/(index|default).[a-zA-Z]{3,4}$/,'')
    .replace(/\/$/,'');
 }
$('a[href*=#]').each(function() {
	if ( filterPath(location.pathname) == filterPath(this.pathname) && location.hostname == this.hostname && this.hash.replace(/#/,'') ) {
		var $targetId = $(this.hash), $targetAnchor = $('[name=' + this.hash.slice(1) +']');
		var $target = $targetId.length ? $targetId : $targetAnchor.length ? $targetAnchor : false;
			if ($target) {
				var targetOffset = $target.offset().top;
					$(this).click(function() {
				    $('html, body').animate({scrollTop: targetOffset}, 1200);
					return false;
					});
				}
			}
		});
	});*/



// SEARCH FOCUS
$(document).ready(function() {
	jQuery("input#search-field").focus(function() {if(jQuery(this).val() == "Search Point of View") {jQuery(this).val('');}}); 
	jQuery("input#search-field").blur(function() {if(jQuery(this).val() == "") {jQuery(this).val('Search Point of View');}}); 	
});


// ACCORDION - old
//$(document).ready(function () {
//  $('LI.drawer UL').hide(); // hide all ULs inside LI.drawer except the first one
//  $('H5.drawer-handle').click(function () {
    // hide all the drawer contents
//    $('LI.drawer UL:visible').slideUp().prev().removeClass('open');

    // show the associated drawer content to 'this' (this is the current H2 element)
    // since the drawer content is the next element after the clicked H2, we find
    // it and show it using this:
//    $(this).addClass('open').next().slideDown();
//  });
//});


//$(function () {
 // $('UL.drawers').accordion({
    // the drawer handle
  //  header: 'H5.drawer-handle',
    
    // our selected class
   // selectedClass: 'open',
    
  //  event: 'mousedown'
 // });
//}); 


// EXTERNAL LINK
window.onload = function() {
//  el = document.getElementsByTagName("a");
/*
	el = $('a').not('[onclick]');
  for (var i=0; i<el.length; i++){
    if (el[i].rel=="external") {
      el[i].onclick = function () {
        return !window.open(this.href);
      }
    }
  }
*/
  }


// ACCORDION
$(document).ready(function() {
	$("#accordion").accordion({
		active: false,
		collapsible: true,
		autoheight: false
	});
});
 

// LOAD RANDOM DIV
NumberOfDivsToRandomDisplay = 9;

var CookieName = 'DivRamdomValueCookie';
$(document).ready(function DisplayRandomDiv() {
var r = Math.ceil(Math.random() * NumberOfDivsToRandomDisplay);
if(NumberOfDivsToRandomDisplay > 1) {
   var ck = 0;
   var cookiebegin = document.cookie.indexOf(CookieName + "=");
   if(cookiebegin > -1) {
      cookiebegin += 1 + CookieName.length;
      cookieend = document.cookie.indexOf(";",cookiebegin);
      if(cookieend < cookiebegin) { cookieend = document.cookie.length; }
      ck = parseInt(document.cookie.substring(cookiebegin,cookieend));
      }
   while(r == ck) { r = Math.ceil(Math.random() * NumberOfDivsToRandomDisplay); }
   document.cookie = CookieName + "=" + r;
   }
	for( var i=1; i<=NumberOfDivsToRandomDisplay; i++) {
		var tempElement = document.getElementById("randomdiv"+i);
		if(tempElement)
		{
			tempElement.style.display="none";
		}
	}
	var tempElement = document.getElementById("randomdiv"+r);
	if(tempElement)
	{
		tempElement.style.display="none";
	}
});
if(typeof DisplayRandomDiv != 'undefined')
{	
	DisplayRandomDiv();
}



// fancy box for contact form




