// JavaScript Document
/* 
================================================================================================================================ CREDITS
Copyright 	: Copyright 2010 Dentsply. All Rights Reserved.
Date      	: 10/19/2010
Notes     	: JavaScript file for handling various events ... onLoad, onClick, etc
================================================================================================================================ BEGIN JAVASCRIPT
*/

/* ============================================================================================================================= MULTIPLE ONLOAD HANDLER */

var onLoadFunctions = new Array();
var iloadFunction = 0;

// Pass each function that needs to load
function add_on_load(func) {
    onLoadFunctions[iloadFunction] = func;
    iloadFunction++;
}
// Loops through all of the functions that were added
function loadAllFunctions() {
    for (var i = 0; i < onLoadFunctions.length; i++) {
        eval(onLoadFunctions[i]+"()");
    }
}
// Load all of the functions that you've set
window.onload = loadAllFunctions;

/* ============================================================================================================================= CALL FUNCTIONS TO BE LOADED */

add_on_load("preload_images");
add_on_load("load_modals");
add_on_load("select_region");
add_on_load("nav_dropdown_menus");
add_on_load("home_page_slides");
add_on_load("search_btn_events");
add_on_load("adjust_heights");
add_on_load("featured_brands");
add_on_load("show_hide_content");
add_on_load("subnav_hover_changes");
add_on_load("timeline_slides");
add_on_load("divisions_within_modal");

/* ============================================================================================================================= COMMON FUNCTIONS */

// ---------------------------------------------------------- WINDOW LOCATION
var url = window.location.toString();

// ---------------------------------------------------------- USER AGENT
var isie = navigator.userAgent.toLowerCase().indexOf('msie');

// ---------------------------------------------------------- GET PREVIOUS SIBLING
function prevSibling(n) {
	do n = n.previousSibling;
	while (n && n.nodeType != 1);
	return n;
}

// ---------------------------------------------------------- GET NEXT SIBLING
function nextSibling(n) {
	do n = n.nextSibling;
	while (n && n.nodeType != 1);
	return n;
}

/* ============================================================================================================================= PRELOAD MAP IMAGES */

function preload_images() {
	// IF MAP IS ON PAGE THEN PRELOAD THE NECESSARY IMAGES FOR MOUSEOVER/OUT STATES
	if (document.getElementById('region-map') != null || document.getElementById('region-map-large') != null) {
		var dir = '/lib/img/map/';
		if (document.getElementById('region-map-large') != null) {
			var dir = '/lib/img/map/large/';
		}			
		var arrImgs = new Array();
			arrImgs[0] = dir + 'africa-middle-east.png';
			arrImgs[1] = dir + 'australia.png';
			arrImgs[2] = dir + 'central-south-america.png';
			arrImgs[3] = dir + 'europe.png';
			arrImgs[4] = dir + 'far-east.png';
			arrImgs[5] = dir + 'japan.png';
			arrImgs[6] = dir + 'north-america.png';
			arrImgs[7] = dir + 'russia.png';

		var arrLoadImgs = new Array();
		for (var i = 0; i < arrImgs.length; i++) {
			arrLoadImgs[i] = new Image();
			arrLoadImgs[i].src = arrImgs[i];
		}
	}
}

/* ============================================================================================================================= LOAD MODALS */

function load_modals() {
	if(typeof init_modal == 'function') {
		init_modal();
	}
}

/* ============================================================================================================================= SELECT REGION */

var activeRegion = '';

function select_region() {
	var map = document.getElementById('region-map');
	var mapLarge = document.getElementById('region-map-large');
	if (map != null || mapLarge != null) {
		var container = document.getElementById('region-map-container');
		var mapimg = document.getElementById('map-image');
		var dir = '/lib/img/map/';
		var arrRegions = new Array('north-america','central-south-america','europe','africa-middle-east','far-east','australia','russia','japan');
	
		if (mapLarge != null) {
			map = document.getElementById('region-map-large');
			container = document.getElementById('region-map-large-container');
			dir = '/lib/img/map/large/';
		}
		
		
		function get_id(id) {
			id = id.split('region=')
			return id[1];
		}
		
		// SHOW MOUSEOVER STATE
		function highlight_region() {
			if (activeRegion == '') {
				mapimg.src = dir + get_id(this.href) + '.png';
			}
		}
	
		// CLEAR MOUSEOVER STATE (RESTORE TO PREVIOUSLY CLICKED ON STATE IF APPLICABLE)
		function restore_region() {
			if (activeRegion == '') {
				mapimg.src = dir + 'base.png';
			} else {
				mapimg.src = dir + activeRegion + '.png';
			}
		}
	
		// ACTIVATE CLICKED STATE AND SHOW REGION OPTIONS
		function display_region_options(passedregion) {
			var region = passedregion;
			if (typeof passedregion == 'string') {
				region = passedregion;
			} else {
				region = get_id(this.href);
			}
			for (var i = 0; i < arrRegions.length; i++) {
				if (region == arrRegions[i]) {
					document.getElementById(arrRegions[i]).className = 'active-region';
					activeRegion = arrRegions[i];
					mapimg.src = dir + activeRegion + '.png';
				} else {
					document.getElementById(arrRegions[i]).className = 'hidden';
					mapimg.className = '';
				}
			}
			return false;
		}

		if (url.indexOf('region=') > -1) {
			urlregion = url.split('region=')[1];
			if (urlregion.indexOf("&") > -1) {
				urlregion = urlregion.split('&')[0];
			}
			display_region_options(urlregion);
		}

		// SET UP MOUSEOVER, MOUSEOUT AND CLICK EVENT HANDLERS
		for (var i=0; i < map.childNodes.length; i++) {
			node = map.childNodes[i];
			if (node.nodeName == "AREA") {
				node.onmouseover = highlight_region;
				node.onmouseout = restore_region;
				node.onclick = display_region_options;
			 }
		}
		
		// SET UP REGION OPTIONS CLOSE LINKS
		var closeLinks = container.getElementsByTagName('a');
		for (var i = 0; i < closeLinks.length; i++) {
			if (closeLinks[i].className == 'region-close') {
				closeLinks[i].onclick = function() {
					activeRegion = '';
					restore_region();
					this.parentNode.parentNode.className = 'hidden';
					return false;
				}
			}
		}
	}
}

/* ============================================================================================================================= MAIN NAV DROPDOWN MENUS */

function nav_dropdown_menus() {
	var nav = document.getElementById("nav");
	if (nav != null) {
		var hdr = document.getElementById('header');
		var currentPg = curbgpos1 = '';
	
		// FOR IE6: UPDATE LI CLASS NAME SO THAT THE SUB-LISTS ARE DISPLAYED
		for (var i = 0; i < nav.childNodes.length; i++) {
			node = nav.childNodes[i];
			if (node.nodeName == "LI") {
				node.onmouseover = function() { 
					this.className += " iehover";
				}
				node.onmouseout = function() { 
					this.className = this.className.replace(" iehover", "");
				}
			 }
		}
	
		// KEEP HOVER STATE OF THE LINK ACTIVE AS USER LOOKS AT SUB-NAVIGATION
		function show_dropdown() {
			document.getElementById(this.id.replace("_sub","")).className = "active";
			if (this.id.indexOf('0') > -1) {
				hdr.style.backgroundPosition = '0px -122px';
			}
		}
		function hide_dropdown() {
			document.getElementById(this.id.replace("_sub","")).className = "";
			hdr.style.backgroundPosition = curbgpos1;
		}
		
		var i = 0;
		if (document.getElementById('nav' + i) != null) {
			while(document.getElementById('nav' + i + '_sub')) {
				document.getElementById('nav' + i + '_sub').onmouseover = show_dropdown;
				if (document.getElementById('nav' + i).className.indexOf('active') == -1) {
					document.getElementById('nav' + i + '_sub').onmouseout = hide_dropdown;
				}
				i++;
			}
		}
		
		// UPDATE HEADER BG GRAPHIC WHEN SOLUTIONS LINK IS HOVERED OVER (CONTINUES THE BG GRAPHIC TRANSITION)
		function update_bg() {
			if (currentPg != 'solutions') {
				hdr.style.backgroundPosition = '0px -122px';
			}
		}
		function reset_bg() {
			if (currentPg == 'solutions') {
				hdr.style.backgroundPosition = '0px -122px';
			} else {
				hdr.style.backgroundPosition = '0px 0px';
			}
		}
	
		if (document.getElementById('nav0').className.indexOf('active') > -1) {
			currentPg = 'solutions';
			hdr.style.backgroundPosition = '0px -122px';
		} else {	
			document.getElementById('nav0').onmouseover = update_bg;
			document.getElementById('nav0').onmouseout = reset_bg;
		}
		
		if (currentPg == 'solutions') {
			curbgpos1 = '0px -122px';
		}
	}
}

/* ============================================================================================================================= HOME PAGE TAB ANIMATIONS */

var myTimer = null;
var defaultSection = 'slide0-pane';
var slideshowScroller = 'slideshow-scroller';

// USED TO AUTO SCROLL THE HOME PAGE SLIDE AREA UNTIL A TAB IS CLICKED
function autoScroll() {
	ScrollArrow('right','slidebuttons',slideshowScroller,defaultSection);
}

function home_page_slides() {	
	if (document.getElementById(slideshowScroller) != null) {
		var tab0 = 'slide0-tab';
		var tab1 = 'slide1-tab';
		var tab2 = 'slide2-tab';
		var slideshow_previous = "slideshow_previous";
		var slideshow_next = "slideshow_next";

		document.getElementById(tab0).onclick = function() {
			ScrollSection('slide0-pane', slideshowScroller, defaultSection);
			return false;
		}
		document.getElementById(tab1).onclick = function() {
			ScrollSection('slide1-pane', slideshowScroller, defaultSection);
			return false;
		}
		document.getElementById(tab2).onclick = function() {
			ScrollSection('slide2-pane', slideshowScroller, defaultSection);
			return false;
		}
		
		if (url.indexOf('slide=') > -1) {
			var slide = url.split('slide=')[1];
			ScrollSection(slide, slideshowScroller, defaultSection);
		} else {
			myTimer = setTimeout(autoScroll,7000);
		}
	}
}

/* ============================================================================================================================= SEARCH FOCUS/BLUR EVENTS */

function search_btn_events() {	
	var sinput = document.getElementById("sinput");
	if (sinput != null) {
		if (sinput.childNodes[0] != null) {
			var sbtn = document.getElementById(sinput.childNodes[0].id);
			if (sbtn != null) {
				sbtn.onfocus = function() { if (sbtn.value == "Search") sbtn.value = ""; }
				sbtn.onblur = function() { if (sbtn.value == "") sbtn.value = "Search"; }
			}
		}
	}
}

/* ================================================================================================================================ ADJUST HEIGHTS OF OBJECTS FOR FLOATS/IE */

function adjust_heights() {	
	var list = document.getElementById('solutions');
	if (list != null) {

		var arrAllLinks = list.getElementsByTagName("a")
		var arrLIs = new Array();
		var i = 0;
		var li;
		var tallest = '';
		var differentHeights = false;
		
		while (i < arrAllLinks.length) { 
			if (arrAllLinks[i].className == "title") {
				p = arrAllLinks[i].parentNode;
				li = p.parentNode;
				
				if (li.offsetHeight > tallest) {
					tallest = li.offsetHeight;
				}
				arrLIs.push(li);
			}
			i++;
		}
		if (arrLIs.length > 1) {
			for (var i=0; i < arrLIs.length; i++) {
				if (arrLIs[i].offsetHeight < tallest) {
					arrLIs[i].style.height = tallest + 'px';
				}
			}
		}
	}
	
	var col1 = document.getElementById('content-col1');
	var maincopy = document.getElementById('main-copy');
	if (isie > -1) {
		// ADJUST COLUMN HEIGHT FOR IE SO BACKGROUND GRAPHIC SHOWS UP IN IE
		if (col1 != null) {
			if (col1.offsetHeight < 400) {
				col1.style.paddingBottom = (400 - col1.offsetHeight) + 'px';
			}
		}
	}
	// ADJUST MAIN COPY HEIGHT SO THAT THE CURVE GRAPHIC IS ALWAYS AT THE BOTTOM RIGHT
	if (col1 != null && maincopy != null) {
		if (col1.offsetHeight > maincopy.offsetHeight) {
			maincopy.style.paddingBottom = (col1.offsetHeight - maincopy.offsetHeight + 80) + 'px';
		}
	}
}

/* ============================================================================================================================= FEATURED BRANDS */

var pgEnd = '';
var pgAnimate = '';
var pgCounter = 1;
var galleryWidth = 0;

function resetTimer() {
	clearInterval(pgAnimate);
	pgAnimate = '';
	pgCounter = 1;
}

function slide_forward(objname,increment) {
	var obj = document.getElementById(objname);
	var objmargin = obj.style.marginLeft ? (parseInt(obj.style.marginLeft.replace('px','')) - 17) : -17;
	if (pgCounter == 10) {
		obj.style.marginLeft = pgEnd + 'px';

		// CHECK FOR FEATURED BRAND LIST AND TIMELINE LIST
		if((Math.abs(pgEnd) + 640) == galleryWidth || (Math.abs(pgEnd) + 639) == galleryWidth) {
			document.getElementById('gallery_prev').className = '';
			document.getElementById('gallery_next').className = 'inactive';
		} else {
			document.getElementById('gallery_prev').className = '';
			document.getElementById('gallery_next').className = '';
		}
		resetTimer();
	} else {
		obj.style.marginLeft = objmargin + 'px';
	}
	pgCounter++;
}

function slide_backward(objname,increment) {
	var obj = document.getElementById(objname);
	var objmargin = obj.style.marginLeft ? (parseInt(obj.style.marginLeft.replace('px','')) + 17) : 17;
	if (pgCounter == 10) {
		obj.style.marginLeft = pgEnd + 'px';
		if ( pgEnd == 0 ) {
			document.getElementById('gallery_prev').className = 'inactive';
			document.getElementById('gallery_next').className = '';
		} else {
			document.getElementById('gallery_prev').className = '';
			document.getElementById('gallery_next').className = '';
		}
		resetTimer();
	} else {
		obj.style.marginLeft = objmargin + 'px';
	}
	pgCounter++;
}

function featured_brands() {
	function galleryScroll(objname,direction,increment) {
		var obj = document.getElementById(objname);
		var start = obj.style.marginLeft ? parseInt(obj.style.marginLeft.replace('px','')) : 0;
		var objwidth = parseInt(obj.style.width.replace('px',''));

		// ONLY pgAnimate IF IT IS NOT CURRENLTY ANIMATING
		if (pgAnimate == '') {
			pgEnd = start + increment;
			
			if (direction == 1) {
				if((Math.abs(pgEnd) + 480) != galleryWidth && (Math.abs(pgEnd) + 426) != galleryWidth) {
					pgAnimate = setInterval('slide_forward(\'' + objname + '\','+increment+');',15);
				}
			} else {
				if ( start != 0 ) {
					pgAnimate = setInterval('slide_backward(\'' + objname + '\','+increment+');',15);
				}
			}
		}
	}
	
	// SET BRAND LIST WIDTH (WIDTH IS NUMBER OF LOGOS * 160 OR 213)
	var pgal = document.getElementById('featured-brands');
	var pgalname = 'featured-brands';
	var liwidth = 160;
	if (pgal == null) {
		pgal = document.getElementById('featured-brands-timeline');
		pgalname = 'featured-brands-timeline';
		liwidth = 213;
	}
	if (pgal != null) {
		pgal.style.visibility = 'visible';
		var pgalTotal = 0;
		for (var i=0; i < pgal.childNodes.length; i++) {
			if (pgal.childNodes[i].nodeName == "LI") {
				pgalTotal++;
			 }
		}
		pgal.style.width = (pgalTotal * liwidth) + 'px';
		galleryWidth = (pgalTotal * liwidth);

		// ONLY SETUP EVENT HANDLERS IF GALLERY/TIMELINE IS LARGER THAN THE VIEWABLE AREA
		if (galleryWidth != 639 && galleryWidth != 640 && galleryWidth > 639) {
			if (document.getElementById('gallery_prev') != null) {
				document.getElementById('gallery_prev').onclick = function() {
					galleryScroll(pgalname,0,liwidth);
					return false;
				}
			}
			if (document.getElementById('gallery_next') != null) {
				document.getElementById('gallery_next').onclick = function() {
					galleryScroll(pgalname,1,-liwidth);
					return false;
				}
			}
		} else {
			document.getElementById('gallery_next').className = 'inactive';
		}
	}
}

/* ============================================================================================================================= SHOW/HIDE ITEMS */

function show_hide_content() {
	var arrLinks = new Array();

	// SHOW/HIDE INDIVIDUAL EXPAND/COLLAPSE AREAS
	function show_hide() {
		var header_div = this.parentNode;
		var content_div = nextSibling(header_div);

		if (this.className == 'active') {
			this.className = '';
			content_div.className = "hide-body";
		} else {
			this.className = 'active';
			content_div.className = "show-body";
		}
		return false;
	}
	
	
	// SHOW/HIDE ALL EXPAND/COLLAPSE AREAS
	function show_hide_all() {
		var rel = this.rel;
		var cssClass = 'active';
		var display = 'show-body';

		if (rel == 'hideall') {
			cssClass = '';
			display = 'hide-body';
		}
		
		// CHECK FOR QUERYSTRING VALUE (FALLBACK FOR ONCLICK EVENT)
		if (rel == null) {
			if (url.indexOf("?show=none") > -1) {
				cssClass = '';
				display = 'hide-body';
			}
		}
		
		var header_div, content_div;
		for (var i = 0; i < arrLinks.length; i++) { 
			if (arrLinks[i].rel == "showhide") {
				header_div = arrLinks[i].parentNode;
				content_div = nextSibling(header_div);

				arrLinks[i].className = cssClass;
				content_div.className = display;
			}
		}
		return false;
    }

	// SET UP EVENT LISTENERS FOR SHOW/HIDE CLICKS
	if (document.getElementById('main-copy') != null) {
		arrLinks = document.getElementById('main-copy').getElementsByTagName("a");
		for (var i = 0; i < arrLinks.length; i++) { 
			if (arrLinks[i].rel == "showhide") {
				arrLinks[i].onclick = show_hide;
			} else if (arrLinks[i].rel == "showall" || arrLinks[i].rel == "hideall") {
				arrLinks[i].onclick = show_hide_all;
			}
		}
	}

	// SHOW OR HIDE ALL BASED ON QUERYSTRING VALUE
	if (url.indexOf("?show=all") > -1 || url.indexOf("?show=none") > -1) {
		show_hide_all();
	}
}

/* ============================================================================================================================= SUBNAV ICON CHANGES ON HOVER */

function subnav_hover_changes() {
	var subnav = document.getElementById('subnav');
	if (subnav != null) {
		var links = subnav.getElementsByTagName('a');
		for (var i = 0; i < links.length; i++) {
			links[i].onmouseover = function() {
				this.parentNode.className = 'active';
			}
			if (links[i].parentNode.className != 'active') {
				links[i].onmouseout = function() {
					this.parentNode.className = '';
				}
			}
		}
	}
}

/* ============================================================================================================================= TIMELINE SLIDES */

var pgTimelineEnd = '';
var pgTimelineAnimate = '';
var pgTimelineCounter = 1;
var timelineWidth = 0;
var divwidth = 709;

function resetTimelineTimer() {
	clearInterval(pgTimelineAnimate);
	pgTimelineAnimate = '';
	pgTimelineCounter = 1;
}

function get_width(div) {
	pgalTotal = 0;
	for (var i=0; i < div.childNodes.length; i++) {
		if (div.childNodes[i].nodeName == "DIV") {
			pgalTotal++;
		 }
	}
	return pgalTotal;
}

function timeline_forward(objname,increment) {
	var obj = document.getElementById(objname);
	var objmargin = obj.style.marginLeft ? (parseInt(obj.style.marginLeft.replace('px','')) - 70) : -70;
	if (pgTimelineCounter == 10) {
		obj.style.marginLeft = pgTimelineEnd + 'px';

		// CHECK FOR FEATURED BRAND LIST AND TIMELINE LIST
		if((Math.abs(pgTimelineEnd) + 709) == timelineWidth) {
			document.getElementById('timeline_prev').className = '';
			document.getElementById('timeline_next').className = 'inactive';
		} else {
			document.getElementById('timeline_prev').className = '';
			document.getElementById('timeline_next').className = '';
		}
		resetTimelineTimer();
	} else {
		obj.style.marginLeft = objmargin + 'px';
	}
	pgTimelineCounter++;
}

function timeline_backward(objname,increment) {
	var obj = document.getElementById(objname);
	var objmargin = obj.style.marginLeft ? (parseInt(obj.style.marginLeft.replace('px','')) + 70) : 70;
	if (pgTimelineCounter == 10) {
		obj.style.marginLeft = pgTimelineEnd + 'px';
		if ( pgTimelineEnd == 0 ) {
			document.getElementById('timeline_prev').className = 'inactive';
			document.getElementById('timeline_next').className = '';
		} else {
			document.getElementById('timeline_prev').className = '';
			document.getElementById('timeline_next').className = '';
		}
		resetTimelineTimer();
	} else {
		obj.style.marginLeft = objmargin + 'px';
	}
	pgTimelineCounter++;
}

function update_category() {
	var url = this.href;
	var pagerequest = false;
	var container = document.getElementById('timeline-content-container');
		
	if (url != null && container != null) {
//alert(url);
url= url+"?service";
		// RESET ACTIVE LINKS
		var	links = document.getElementById('featured-brands-timeline').getElementsByTagName("a");
		for (var i = 0; i < links.length; i++) { 
			links[i].className = '';
		}
		this.className = 'active';

		if (window.XMLHttpRequest) {
			pagerequest = new XMLHttpRequest();
		} else if (window.ActiveXObject) {
			try { pagerequest = new ActiveXObject("Msxml2.XMLHTTP"); } 
			catch (e) {
				try { pagerequest = new ActiveXObject("Microsoft.XMLHTTP"); }
			catch (e) {}
			}
		}
		pagerequest.onreadystatechange = function() { load_content(pagerequest, url); }
		pagerequest.open('GET', url, true);
		pagerequest.send(null);
		
		function load_content(pagerequest, url) {				
			if (pagerequest.readyState == 4 && (pagerequest.status == 200 || window.location.href.indexOf("http") == -1)) {
				container.innerHTML = pagerequest.responseText;

				var pgalTotal = get_width(container);
				container.style.width = (pgalTotal * divwidth) + 'px';
				timelineWidth = (pgalTotal * divwidth);

				// RESET PREV/NEXT BUTTONS
				if(container <= 709) {
					document.getElementById('timeline_prev').className = 'inactive';
					document.getElementById('timeline_next').className = 'inactive';
				} else {
					document.getElementById('timeline_prev').className = 'inactive';
					document.getElementById('timeline_next').className = '';
				}
			} else {
				container.style.marginLeft = '0px'; // RESET MARGIN
				container.innerHTML = '<p class="loading"><img src="/lib/img/loading.gif" alt="Loading Content" /></p>';
			}
		}
	}
	return false;
}

function timeline_slides() {
	function timelineScroll(objname,direction,increment) {
		var obj = document.getElementById(objname);
		var start = obj.style.marginLeft ? parseInt(obj.style.marginLeft.replace('px','')) : 0;
		var objwidth = parseInt(obj.style.width.replace('px',''));

		// ONLY pgTimelineAnimate IF IT IS NOT CURRENLTY ANIMATING
		if (pgTimelineAnimate == '') {
			pgTimelineEnd = start + increment;
			
			if (direction == 1) {
				if((Math.abs(pgTimelineEnd)) != timelineWidth) {
					pgTimelineAnimate = setInterval('timeline_forward(\'' + objname + '\','+increment+');',15);
				}
			} else {
				if ( start != 0 ) {
					pgTimelineAnimate = setInterval('timeline_backward(\'' + objname + '\','+increment+');',15);
				}
			}
		}
	}
	
	// SET TIMELINE LIST WIDTH
	var pgal = document.getElementById('timeline-content-container');
	var pgalname = 'timeline-content-container';

	if (pgal != null) {
		pgal.style.visibility = 'visible';
		var pgalTotal = get_width(pgal);
		pgal.style.width = (pgalTotal * divwidth) + 'px';
		timelineWidth = (pgalTotal * divwidth);
		
		var	categoryLinks = document.getElementById('featured-brands-timeline').getElementsByTagName("a");
		for (var i = 0; i < categoryLinks.length; i++) { 
			categoryLinks[i].onclick = update_category;
		}
	
		// ONLY SETUP EVENT HANDLERS IF GALLERY/TIMELINE IS LARGER THAN THE VIEWABLE AREA
		if (timelineWidth > 709) {
			if (document.getElementById('timeline_prev') != null) {
				document.getElementById('timeline_prev').onclick = function() {
					timelineScroll(pgalname,0,divwidth);
					return false;
				}
			}
			if (document.getElementById('timeline_next') != null) {
				document.getElementById('timeline_next').onclick = function() {
					timelineScroll(pgalname,1,-divwidth);
					return false;
				}
			}
		} else {
			document.getElementById('timeline_next').className = 'inactive';
		}
	}
}

/* ============================================================================================================================= DIVISIONS MODAL LOCATION SWAPS */

function divisions_within_modal(id) {
	function resetLocationsLinks(arrLocations, arrLinks) {
		for (var i = 0; i < arrLocations.length; i++) {
			if (document.getElementById(arrLocations[i]) != null) {
				document.getElementById(arrLocations[i]).className = 'hidden';
			}
			if (arrLinks[i] != null) {
				arrLinks[i].parentNode.className = '';
			}
		}
	}
	
	var container = document.getElementById(id);	
	if (container != null) {
		var links = container.getElementsByTagName('a');
		var arrLocations = new Array();
		var arrLinks = new Array();

		for (var i = 0; i < links.length; i++) {
			if (links[i].parentNode.nodeName == 'LI') {
				arrLocations.push(links[i].href.split('#')[1]); 
				arrLinks.push(links[i]); 
			}
		}
		if (arrLinks.length > 1) {
			for (var i = 0; i < arrLinks.length; i++) {
				arrLinks[i].onclick = function() {
					resetLocationsLinks(arrLocations, arrLinks);
					this.parentNode.className = 'active';
					
					document.getElementById(this.href.split('#')[1]).className = '';
					return false;
				}
			}
		} else if (arrLinks.length == 1) {
			arrLinks[0].onclick = function() {
				return false;
			}
		}
	}
}

