$(document).ready(function() {
		// initialize scrollable
		var api = $("div.scrollable").scrollable({
			vertical:true,
			clickable:true,
			api:true,
			speed: 650,
			size: 3
		});

		var seekplease = '';

		var x = api.getItems();
		var previouslink = '';
		var previouskey = '';
		var nextlink = '';
		var nextkey = '';
		var currentpage = window.location.pathname;
		var links = '';

		var set_attrib = 'class';
		if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
			var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
			if (ieversion<8) {
				set_attrib = 'id';
				currentpage = window.location.href;
			}
		}


		for ( var i=0; i<x.size(); i++ ){
			links = x[i].getElementsByTagName('a');
			if ( currentpage == links[0].getAttribute("href")){
				seekplease = i;
				x[i].setAttribute(set_attrib,"active");

				previouskey = parseInt(i) - 1;
				nextkey = parseInt(i) + 1;
				if (previouskey >= 0) {
					links = x[previouskey].getElementsByTagName('a');
					previouslink = links[0].getAttribute("href");
				} else {
					previouslink = '';
				}

				if (nextkey < x.size() ) {
					links = x[nextkey].getElementsByTagName('a');
					nextlink = links[0].getAttribute("href");
				} else {
					nextlink = '';
				}
			}
		}

		if (seekplease > 1){
			api.move(seekplease-1);
		}

		// Add links at bottom
		if ( previouslink || nextlink ) {
			if ( previouslink != '' ) {
					print_link_button ("Previous", "previouslink", previouslink);
			} else {
				var pagetitle = document.getElementById('box_nav');
				var title= pagetitle.getElementsByTagName('h3');
				if (title[0].innerHTML == 'News Archives') {
					print_link_button ("Previous", "previouslink", '/company/news.php');
				} else {
					print_link_button ("Previous", "previouslink disabled", '#');
				}
			}

			if ( nextlink != '' ) {
				print_link_button ("Next", "nextlink", nextlink);
			} else {
				print_link_button ("Next", "nextlink disabled", '#');
			}
		} else {
			print_link_button ("Previous", "previouslink disabled", '#');
			links = x[0].getElementsByTagName('a');
			nextlink = links[0].getAttribute("href");
			print_link_button ("Next", "nextlink", nextlink);
		}
});

function print_link_button (title, classname, linkhref) {
	txt = document.createTextNode(title);
	var spantag = document.createElement("span");
	spantag.appendChild(txt);
	link = document.createElement('a');
	link.setAttribute('href', linkhref);

	if (linkhref == '#') {
		link.setAttribute('onClick', 'return false;');
	}

	var lessthan8 = false;
	if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){
		var ieversion=new Number(RegExp.$1)
		if (ieversion<8) {
			link.setAttribute('class', classname.replace("previouslink ",""));
			link.setAttribute('id', classname.replace(" ","_"));
			lessthan8 = true;
		}
	}

	if (!lessthan8) {
		link.setAttribute('class', classname);
		link.setAttribute('id', classname.replace(" disabled",""));
	}
	link.appendChild(spantag);
	document.getElementById('middle_column_bottom').appendChild(link);
}
