



	// UTILITIES

	var bName = navigator.appName;
	var bVer  = parseInt(navigator.appVersion);
	var browserSupportsCookies = false;
	
	if(document.cookie.length > 0) {
		browserSupportsCookies = true;
	}
	else {
		document.cookie = "x=0";
		browserSupportsCookies = (document.cookie == "x=0");
	}
	
//	if(!browserSupportsCookies) {
//		document.location.href = 'http://www.discoveryeditions.com/unsupportedbrowser.html';
//	}

	if ((bName == "Netscape" && bVer >= 3) || (bName == "Microsoft Internet Explorer" && bVer >= 4)) {
		br = "n3"; 
	}
	else {
		br = "n2";
	}

	if (br == "n3") {
			//preload
	}
	
	function swapImage(imgName, src) {
		if (br == "n3") {
			document[imgName].src = src;
		}
	}

	function openPopUp(url,width,height) {
		w = window.open(url, 'PopUp', 'scrollbars=yes,toolbar=no,location=no,directories=no,menubar=no,width=' + width + ',height=' + height);
	}

	function getIndex(field) {
	
		var index = -1, i = 0, found = false;
				
		while (i < field.form.length && index == -1) {
		
			if (field.form[i] == field) {
				index = i;
			}
			else {
				i++;
			}
		}
		
		return index;
	}
	
	function autoTab(field,len,e) {
	
		var isNetscape = (navigator.appName.indexOf("Netscape") != -1);
		
		var keyCode = (isNetscape) ? e.which : e.keyCode; 
		
		if(field.value.length >= len && keyCode != 9) {
			field.value = field.value.slice(0, len);
			field.form[(getIndex(field)+1) % field.form.length].focus();
		}
	}

	function setCookie(name, value, days) {
		var expires = "";
		
		if(days) {
			var date = new Date();
			date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
			expires = "; expires=" + date.toGMTString();
		}
		
		document.cookie = name + "=" + value + expires + "; path=/";
	}
	
	function getCookie(name) {
		var name_and_eq = name + "=";
		
		var cookies = document.cookie.split(';');
		
		for(var i = 0;i < cookies.length; i++) {
			var cookie = cookies[i];
			while (cookie.charAt(0) == ' ') {
				cookie = cookie.substring(1, cookie.length);
			}
			if (cookie.indexOf(name_and_eq) == 0) {
				return cookie.substring(name_and_eq.length, cookie.length);
			}
		}
		
		return null;
	}
	
	function deleteCookieCookie(name) {
		setCookie(name, "", -1);
	}


	// SCROLLER FUNCTIUONS
	var myScrollers;
	
	myScrollers = new Array;

	function scroller() {
		this.cell_count 	= 0;
		this.width 			= 0;
		this.left_limit 	= 0;
		this.leftpos 		= 0;
		this.slideto 		= 0;
		this.currentmove  	= null;
		this.left_button_id = '';
		this.right_button_id = '';
		this.cell_width     = 0;
	}

	function initScroller(id, left_button_id, right_button_id, count, position, cell_width, window_width) {

		myScrollers[id] = new scroller;

		var this_scroller = myScrollers[id];

		var the_scroller = document.getElementById(id);

		// method vectors
		buttonStatus = buttonStatus;
		setScrollerPosition = setScrollerPosition;

		if(position > 3 && count > 5) {
			if(position < (count - 2)) {
				position = position - 3;
			}
			else {
				position = count - 5;
			}
		}
		else {
			position = 0;
		}

		this_scroller.cell_width   = cell_width;
		this_scroller.leftpos      = 0 - (position * this_scroller.cell_width);
		this_scroller.slideto      = this_scroller.leftpos;
		this_scroller.cell_count   = count;
		this_scroller.width        = (this_scroller.cell_count * this_scroller.cell_width);
		this_scroller.left_limit   = window_width - this_scroller.width;
		this_scroller.left_button_id  = left_button_id;
		this_scroller.right_button_id = right_button_id;

		the_scroller.style.left = this_scroller.leftpos + 'px';

		if(this_scroller.slideto == this_scroller.left_limit) {
			buttonStatus(right_button_id,'white');
		}
		else {
			buttonStatus(right_button_id,'black');
		}

		if(this_scroller.slideto == 0) {
			buttonStatus(left_button_id,'white');
		}
		else {
			buttonStatus(left_button_id,'black');
		}

	}	

	function buttonStatus( id, color) {
		button = document.getElementById(id);
		if(button) {
			button.style.color = color;
		}
	}

	function setScrollerPosition(id, delta ) {

		var this_scroller = myScrollers[id];

		if(delta > 0) {
			if(this_scroller.leftpos == 0 || this_scroller.slideto == 0) {
				return;
			}
		}
		
		if(delta < 0) {
			if(this_scroller.leftpos == this_scroller.left_limit || this_scroller.slideto == this_scroller.left_limit) {
				return;
			}
		}
		
		if(this_scroller.currentmove) {
			this_scroller.slideto = this_scroller.slideto + (delta * this_scroller.cell_width);
			window.clearTimeout(this_scroller.currentmove);
			this_scroller.currentmove = null;
		}
		else {
			this_scroller.slideto = this_scroller.leftpos + (delta * this_scroller.cell_width);
		}

		if(delta < 0) { increment = -20; } else { increment = 20; }
		
		if(this_scroller.slideto == this_scroller.left_limit) {
			buttonStatus(this_scroller.right_button_id,'white');
		}
		else {
			buttonStatus(this_scroller.right_button_id,'black');
		}

		if(this_scroller.slideto == 0) {
			buttonStatus(this_scroller.left_button_id,'white');
		}
		else {
			buttonStatus(this_scroller.left_button_id,'black');
		}

		this_scroller.currentmove = window.setTimeout("slide('" + id + "', " + increment + ")", 50);
	}
	
	function slide(id, increment) {
	
		var this_scroller = myScrollers[id];

		var the_scroller = document.getElementById(id);
	
		this_scroller.leftpos = (this_scroller.leftpos + increment);
		
		the_scroller.style.left = this_scroller.leftpos + 'px';
		
		if((increment < 0 && this_scroller.leftpos > this_scroller.slideto) || (increment > 0 && this_scroller.leftpos < this_scroller.slideto)) {
			this_scroller.currentmove = window.setTimeout("slide('" + id + "', " + increment + ")", 50);
		}
		else {
			this_scroller.currentmove = null;
		}
	}

	// SLIDESHOW FUNCTIONS	
	var slide_src 		= new Array();
	var elementMap      = new Array();
	
	var fadingout 		= null;
	var fadingin  		= null;
	var running_slideshow = null;
	
	var pic_count   	= 0;
	var current_pic 	= -1;
	var fade_increment  = 50;
	var fade_speed        = 100;
	var slide_pause        = 7000;

	function setFadeParams(i,s) {
		fade_increment = i;
		fade_speed     = s;
	}

	function findElementByID(id) {
		if(elementMap[id]) {
			obj = elementMap[id];
		}
		else {
			obj = document.getElementById(id);
			elementMap[id] = obj;
		}
		return obj;
	}

	function addSlide(src, width, height) {
		slide_src[pic_count] 		= src;
		++pic_count;
	}

	function getImg(idx) {
		i 		= findElementByID('img_big_' + idx);

		if(i.src != slide_src[idx]) {
		    i.src 	= slide_src[idx];
		}
	}

	function setOpacity(obj, opacity) {

		if(opacity > 0) {
			obj.style.visibility = "visible";
		}
		else {
			obj.style.visibility = "hidden";
		}

		opacity = (opacity == 100)?99.999:opacity;
		// IE/Win
		obj.style.filter = "alpha(opacity:"+opacity+")";
		// Safari<1.2, Konqueror
		obj.style.KHTMLOpacity = opacity/100;
		// Older Mozilla and Firefox
		obj.style.MozOpacity = opacity/100;
		// Safari 1.2, newer Firefox and Mozilla, CSS3
		obj.style.opacity = opacity/100;
	}


	function fadeOut(objId, opacity) {
		myObj = findElementByID(objId);
			
		setOpacity(myObj, opacity);
		
		if(opacity > 0) {
			opacity -= fade_increment;
			fadingout = window.setTimeout("fadeOut('"+objId+"',"+opacity+")", fade_speed);
		}
		else {
			fadingout = null;
		}
	}

	function fadeIn(objId,opacity) {
		myObj = findElementByID(objId);
		
		setOpacity(myObj, opacity);
		
		if(opacity < 100) {
			opacity += fade_increment;
			fadingin = window.setTimeout("fadeIn('"+objId+"',"+opacity+")", fade_speed);
		}
		else {
			fadingin = null;
		}
	}
	
	function showIdx(idx) {
		getImg(idx);
		
		if(idx < pic_count - 1) { // get the next one too
			getImg(idx + 1);
		}
				
		show('big_' + idx);
		current_pic = idx;
	}
	
	function show(which) {	
		if(current_pic >= 0) {
			fadeOut('big_' + current_pic, 100);
		}	
				
		if(which) {
			visibleDiv = findElementByID(which);
			
			setOpacity(visibleDiv,0);
			fadeIn(which,0);
		
		}
	}
	
	function slideShow(auto) {	
		if(!auto) {
			if(fadingin != null) { 
				window.clearTimeout(fadingin); 
				fadingin = null;
			}
			if(fadingout != null) { 
				window.clearTimeout(fadingout); 
				fadingout = null; 
			}
		}
		
		if(current_pic >= pic_count - 1) {
			showIdx(0);
		}
		else {
			showIdx(current_pic + 1);
		}
		running_slideshow = window.setTimeout("slideShow(1)", slide_pause);
	}
	
	function pauseShow() {
		if(running_slideshow != null) {
			window.clearTimeout(running_slideshow);
			running_slideshow = null;
		}
	}
