// JavaScript Document

/* -------------------------------------------------------------------*/
/*   Author:   Danielle Closs                                         */
/*   Date:     9/24/2007                                              */
/*   Filename: main.js                                                */      
/*   Related                                                          */      
/*   Files:    gallery.shtml, interior files                          */     
/*--------------------------------------------------------------------*/


// This function was created to load a specific photo
// when loading the gallery page and when a user clicks
// on a linked teaser image on another page.
// This function is fired on load of gallery.shtml

function setClassOnLoad(newClass){
		//assign the search value to a variable
		picOnLoad = location.search;
		
		//strip the ? off of the front of the search value
		this.picOnLoad=picOnLoad.substring(1, picOnLoad.length);
	
// if the value in the variable is greater than or equal to one,
// then we can use that number for the assigning the element class
if (picOnLoad.length >= 1){
		var picSet = "pic" + picOnLoad;
		var object = document.getElementById(picSet);
		object.className=newClass;
		location.href="#";
}

// else if the value in the variable is less than 1, then it is
// empty, and we need to fill in a default value
else{
		var picSet = "pic1";
		picSet.className = newClass;
		var object = document.getElementById(picSet);
		object.className=newClass;
}
	
}

/* -------------------------------------------------------------------*/

// This function was created to change the  
// preview photo, photo description, and photo
// title below the thumbnails when a user clicks
// on a thumnail image link.

function setClass(objectID,newClass){
		var object = document.getElementById(objectID);
		object.className = newClass;
}

/* -------------------------------------------------------------------*/

// These functions were created to move the thumbnails
// left and right when a user clicks on the arrow 
// graphics to show hidden thumbnails.

var x=24;

function moveRight( ){

        var layerElement = document.getElementById("thumbnails");
        x+=62;
        layerElement.style.left=x+"px";

}

function moveLeft( ){

        var layerElement = document.getElementById("thumbnails");
        x-=62;
        layerElement.style.left=x+"px";

}

/* -------------------------------------------------------------------*/

// These functions were created to move forward and 
// backward within the medium preview photo when 
// a user clicks the arrow graphics on the sides 
// of the photo, to show the next and previous 
// medium preview photo, photo title, and photo 
// description.


function moveRgt(objectID){
	
	//change objectID to a number	
	object=parseInt(objectID);

//if you are on a viable pic, then do this
if (object<=10)	
{
	//add one to current objectID
	nextPicNo=object+1;
	
	//assign IDs to current object and next object
	currentPic="pic"+object;
	nextPic="pic"+nextPicNo;
	
	//hide current object and show next object	
	setClass(nextPic,'show text'); 
    setClass(currentPic,'hide');
}
		
}


function moveLft(objectID){

	//change objectID to a number	
	object=parseInt(objectID);

//if you are on a viable pic, then do this
if (object>=1)
{
	//subtract one from current objectID
	prevPicNo=object-1;
	
	//assign IDs to current object and prev object
	currentPic="pic"+object;
	prevPic="pic"+prevPicNo;
	
	//hide current object and show prev object	
	setClass(prevPic,'show text'); 
    setClass(currentPic,'hide');
}
		
}		



//this function changes the overall font size on a page

function setFont(fontSize){
	
	obj = document.getElementById("body");
	obj.style.fontSize=fontSize;
	document.cookie='fontsize='+fontSize;
}


//this function changes the stylesheet on a page

function changeCSS(nr){
	
	if (document.getElementsByTagName)
		x = document.getElementsByTagName('link');
	else if (document.all)
		x = document.all.tags('link');
	else
	{
		alert('This script does not work in your browser');
		return;
	}
	nr--;
	for (var i=0;i<x.length;i++)
	{
		dis = !(i == nr);
		x[i].disabled = dis;
	}
	stylesheet=parseInt(nr)+1;
	document.cookie='stylesheet='+stylesheet;

}

// this function retrieves a previously set cookie's value

function get_cookie ( cookie_name ){
	
	  var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );
	
	  if ( results )
		return ( unescape ( results[2] ) );
	  else
		return null;
}

// this function checks for cookie values for font and stylesheet
// if they don't exist, it gives default values

function loadPageValues(){
	
	var font = get_cookie("fontsize");
	var style = get_cookie("stylesheet");

	if (document.cookie.indexOf("stylesheet")!=-1){
		cookieEnabled=true;
	}else{
		style="2";
	}
	
	if (document.cookie.indexOf("fontsize")!=-1){
		cookieEnabled=true;
	}else{
		font="1em";
	}
	
	alert(font);
	alert(style);
	
	changeCSS(style);	
	setFont(font);
}

