var gColList = ["#content-block","#col-2","#col-3"];

/* override expand/contract strings */
gSiteOptions.expandString = "[+]";
gSiteOptions.contractString = "[-]";

/* override views for popupabs */
gSiteOptions.popupViews = ['abstract','extract','excerpt'];

/* override author affiliation selected elements */
gSiteOptions.authAffilMatch = "div.article div.contributors ol.affiliation-list, div.article div.contributors ol.corresp-list, div.article div.contributors p.more-auth";

gSiteOptions.openWindowDetails=new Object();
gSiteOptions.openWindowDetails['tower-ads-help'] = { target: 'AdsHelp', config: 'width=800,height=600,scrollbars=1,resizable=1,channelmode=0,toolbar=0,location=0,directories=0,menubar=0' };
gSiteOptions.openWindowDetails['leaderboard-ads-help'] = { target: 'popupHelp', config: 'width=800,height=600,scrollbars=1,resizable=1,channelmode=0,toolbar=0,location=0,directories=0,menubar=0' };
gSiteOptions.openWindowDetails['footerboard-ads-help'] = { target: 'AdsHelp', config: 'width=800,height=600,scrollbars=1,resizable=1,channelmode=0,toolbar=0,location=0,directories=0,menubar=0' };

$(document).ready(function() {
	// open a popup box for help for both header and footer
	$("ul li a[title='Help']").click(function(event) {
                    event.preventDefault();
                    var url = "/site/help/home_help.dtl";
                    popupHelp(url);
    });
	
    $("div.social-bookmarking .social-bookmarking-help a").click(function(event) {
                    event.preventDefault();
                    var url = "/site/help/social_bookmarks_help.dtl";
                    popupHelp(url);
    });
                    

		
	//temporary fixing for adding the class="first-item" for the reference link in article view
	$("#ref-list-1 ol.cit-list li div.cit div.cit-extra a:first-child").addClass("first-item");
	$("#pageid-authindex #content-block #toc-header ul.toc-links li:first-child").addClass("first-item");
	
	$("#pageid-content div#content-block p.section-name:first-child").addClass("first-item");
				


	//For "Highlights of" or "Research Letters", the section title will remain mixed case
	var titleArticle = $("#pageid-content #content-block p.section-name").text().toLowerCase();
	if ((titleArticle.indexOf("highlights of")!=-1) || (titleArticle.indexOf("research letters")!=-1) || (titleArticle.indexOf("in other archives journals")!=-1)) {
		$("#pageid-content #content-block div.article div.section h2").addClass("mixed-case");
	}

	//To add Free/Free to You icon on search results that has ac flag of "access-free" or "access-available"
	$("#pageid-search-results .cit.access-free,#pageid-search-results .cit.access-available").each(function(index) {
        $(this).prepend('<div class="free-img"><a href="/help/pop/hasaccess.dtl"><img width="59" height="49"  src="/publisher/icons/freetoyouindicator.gif" alt="You have access to this article via a personal or institutional subscription" /><br/><span class="whyfree">why?</span></a></div>');
    });

	$("#pageid-search-results #content-block #results-gca-form .results-cit-list div.free-img a").click(function(event) {
		event.preventDefault();
		var url = "/site/help/pop/hasaccess.dtl";
		popupHelp(url);
	});

	//for backfiles that have extract content, but without ellipses at the end of extract content, add it to the end
	var backfileExtractLastChild = $("#pageid-content #content-block .extract-view div:last-child");
	
	if (backfileExtractLastChild.hasClass('full-text') == false) {
		$("#pageid-content #content-block .extract-view div:last-child p:last-child").append('...');
	}
});


// override setupCollapsibles to handle additional elements
function setupCollapsibles() {
	prepCollapsibles(".collapsible");
}


function checkColHeights() {
	setTallest(gColList);
	if (!(isIE6)){setTimeout("checkColHeights()", 10000);}
}

/* accepts string array of ids */
/* returns naught */
function setTallest(elemArray) {
	for (elemPos in elemArray){$(elemArray[elemPos]).height("auto");} /* set heights to auto to account for any heights that were inadvertently wrecked */
	gColOrigHeights.main = $("#content-block").height();
	gColOrigHeights.col2 = $("#col-2").height();
	gColOrigHeights.col3 = $("#col-3").height();
	curTallest = getTallest(elemArray); /* get height of the tallest element */
	for (elemPos in elemArray){$(elemArray[elemPos]).height(curTallest);} /* set heights of all elements to the tallest */
}

/* accepts string array of ids */
/* returns height (in pixels) of tallest element */
function getTallest(elemArray) {
	curTallest = 0; /* zero out height */
	for (elemPos in elemArray){curTallest=Math.max(curTallest,$(elemArray[elemPos]).height());} /* check height of each element in the array, retaining the highest */
	return curTallest; /* return height of tallest item */
}

/* popup help window */
function popupHelp(url) {
        var date, year, month, day, hour, minute, second, timestamp;
        date = new Date();
        year = date.getFullYear();
        month = date.getMonth()+1;
        day = date.getDate();
        hour = date.getHours();
        minute = date.getMinutes();
        second = date.getSeconds();
        timestamp = year +'-'+month+'-'+day+'+'+hour+':'+minute+':'+second;
        url = url + "?request=" + escape(timestamp) + "&ref=" + window.location.pathname;
        window.open(url, 'HELP','scrollbars,resizable,width=800,height=600'+ '\'').focus();
  }

