﻿/************************************************************************************************************
(C) www.dhtmlgoodies.com, September 2005

This is a based on a script from www.dhtmlgoodies.com. You will find this and a lot of other scripts at our website.

Terms of use:
You are free to use this script as long as the copyright message is kept intact. However, you may not
redistribute, sell or repost it without our permission.

Thank you!

www.dhtmlgoodies.com
Alf Magne Kalleland

************************************************************************************************************/
var contentHeight = 0; 	// The total height of the content
var visibleContentHeight = 0;
var scrollActive = false;

var scrollHandleObj = false; // reference to the scroll handle
var scrollHandleHeight = false;
var scrollbarTop = false;
var eventYPos = false;

var scrollbuttonActive = false;
var scrollbuttonDirection = false;
var scrollbuttonSpeed = 2; // How fast the content scrolls when you click the scroll buttons(Up and down arrows)
var scrollTimer = 10;	// Also how fast the content scrolls. By decreasing this value, the content will move faster

var scrollMoveToActive = false;
var scrollMoveToYPosition = false;

var page = '';
var scrollDown = 'scrolldiv_scrollDown';
var scrollUp = 'scrolldiv_scrollUp';
var scrollDiv = 'scrolldiv';
var scrollDivContent = 'scrolldiv_content';
var scrollDivParent = 'scrolldiv_parentContainer';
var scrollDivTheScroll = 'scrolldiv_theScroll';
var scrollDivScrollBar = 'scrolldiv_scrollbar';
var scrollDivWindow = 'scrolldiv_window';
var orig_window_height = 0;
var orig_parent_height = 0;
var orig_content_height = 0;

var topPos = 0;

function cancelEvent()
{
	return false;
}
function scrolldiv_initScroll()
{
	visibleContentHeight = orig_parent_height;
	contentHeight = 20 + document.getElementById(scrollDivContent).offsetHeight - orig_parent_height;
	if (contentHeight > 0) {
		document.getElementById(scrollDivWindow).style.height = orig_window_height;
	} else {
		document.getElementById(scrollDivWindow).style.height = orig_window_height + contentHeight;
		visibleContentHeight = document.getElementById(scrollDivParent).offsetHeight;
		contentHeight = 20 + document.getElementById(scrollDivContent).offsetHeight - visibleContentHeight;
	}
}

/*
Setting Page name
*/
function setPage(newPage)
{
/*	page = newPage;
	scrollDown = 'scrollDown-' + page;
	scrollUp = 'scrollUp-' + page + '';
	scrollDiv = 'scrolldiv_' + page;
	scrollDivContent = 'content-' + page;
	scrollDivParent = 'texte-' + page;
	scrollDivWindow = 'fenetre-' + page;
	scrollDivScrollBar = 'scrollbar-' + page;
	scrollDivTheScroll = 'scroll-' + page;
	orig_window_height = document.getElementById(scrollDivWindow).offsetHeight;
	orig_parent_height = document.getElementById(scrollDivParent).offsetHeight;
	orig_content_height = document.getElementById(scrollDivContent).offsetHeight;
	var oldonresize = window.onresize;
	window.onresize = function() {
		if (oldonresize)
			oldonresize();
		document.getElementById(scrollDivContent).style.top = 0;
		scrolldiv_initScroll();
	}*/
}
/*
 * For next/prev buttons
 */
 var pages = Array();
 var current_page_index = 0;
function showPage(new_index) {
	if (current_page_index == new_index || new_index < 0 || new_index > pages.length - 1)
		return;
	document.getElementById(pages[current_page_index]).style.display = "none";
	document.getElementById("image-bouton" + (current_page_index + 1)).src = "images/bouton" + (current_page_index + 1) + ".png";
	if (document.getElementById("iimage-bouton" + (current_page_index + 1)))
		document.getElementById("iimage-bouton" + (current_page_index + 1)).src = "images/bouton" + (current_page_index + 1) + ".png";
	current_page_index = new_index;
	document.getElementById(pages[current_page_index]).style.display = "block";
	document.getElementById("image-bouton" + (current_page_index + 1)).src = "images/bouton" + (current_page_index + 1) + "_on.png";
	if (document.getElementById("iimage-bouton" + (current_page_index + 1)))
		document.getElementById("iimage-bouton" + (current_page_index + 1)).src = "images/bouton" + (current_page_index + 1) + "_on.png";
//	document.getElementById(scrollDivContent).style.top = 0;
	
	if (document.getElementById("pagebuttonspn")) {
		if (current_page_index == 0) {
			document.getElementById("boutonp").style.display = "none";
			document.getElementById("boutonn").style.display = "block";
		} else if (current_page_index == pages.length - 1) {
			document.getElementById("boutonp").style.display = "block";
			document.getElementById("boutonn").style.display = "none";
		} else {
			document.getElementById("boutonp").style.display = "block";
			document.getElementById("boutonn").style.display = "block";
		}
	}
	//scrolldiv_initScroll();
}
function scrolldiv_firstPage() {
	showPage(0);
}
function scrolldiv_prevPage() {
	showPage(current_page_index - 1);
} 
function scrolldiv_nextPage() {
	showPage(current_page_index + 1);
}
function scrolldiv_lastPage() {
	showPage(pages.length - 1);
}
function scrolldiv_initPages() {
	var div_pagebuttons = document.getElementById("pagebuttons");
	var div_scrollDivParent = document.getElementById(scrollDivParent);
	var cpt = 1;
	var pwc = 0;
	var page = document.getElementById("page" + cpt++);
	while (page != null) {
		if (page.innerHTML != '') {
			pages[pages.length] = page.id;
			pwc++;
		}
		page.style.display = "none";
		page = document.getElementById("page" + cpt++);
	}
	document.getElementById(pages[current_page_index]).style.display = "block";
	document.getElementById("image-bouton" + (current_page_index + 1)).src = "images/bouton" + (current_page_index + 1) + "_on.png";
	if (document.getElementById("iimage-bouton" + (current_page_index + 1)))
		document.getElementById("iimage-bouton" + (current_page_index + 1)).src = "images/bouton" + (current_page_index + 1) + "_on.png";
	if (pwc <= 1) {
		document.getElementById("pagebuttons").style.display = "none";
		if (document.getElementById("pagebuttonspn"))
			document.getElementById("pagebuttonspn").style.display = "none";
	}
	if (document.getElementById("pagebuttonspn")) {
		document.getElementById("boutonp").style.display = "none";
	}
	if (document.getElementById("bouton1")) {
		for (var i = 5; i > 0; i--) {
			if (pages.length <= (i - 1)) {
				document.getElementById("bouton" + i).style.display = "none";
			}
		}
		if (pages.length == 1) {
			document.getElementById("bouton1").style.display = "none";
			if (document.getElementById("pagebuttonspn"))
				document.getElementById("pagebuttonspn").style.display = "none";
		}
	}
	scrolldiv_initScroll();
}