
//initialize
//this function takes care of calling other necessary functions and passing default values
function init(){

		document.getElementById('contentstrip').style.width = ((countPages() * 340) + 10) + 'px';
		if (countPages() > 1)  {
			document.getElementById('next').style.visibility = "visible";
		}
		
}
	
//--- CONTENT AREA SCROLLING FUNCTIONS

function countPages(){
	return getNumTagsWithClassName('div','page');	
}

//Content scrolling functions
//turnPage - content area - calls makePageTurn and passes the width of the content viewport (290)
function turnPage(direction) {
	makePageTurn(direction,340)
}

//makePageTurn - takes a direction and a pageWidth and move the scrallable area accordingly
var gblOnPage = 1;
function makePageTurn(direction,pageWidth) {

	var numPages = countPages();
	var coordToPass = 0;
	
	gblSlideImage = false; //set this to false in case someone clicked on an image

	if ((direction == "next") && (gblOnPage < numPages)) {
		scrollit((-1 * pageWidth),false);
		gblOnPage = gblOnPage + 1;
	}

	if ((direction == "prev") && (gblOnPage > 1)) {
		scrollit(pageWidth,false);
		gblOnPage = gblOnPage - 1;
	}	
	
	if (!isNaN(direction)) { //for alphabetical click through
		coordToPass = (((direction * pageWidth) * -1) + pageWidth);
		scrollit(coordToPass,true);
		gblOnPage = direction;
	}

	//show/hide previous button
	if (gblOnPage != 1) {
		document.getElementById('prev').style.visibility = "visible"
	} else {
		document.getElementById('prev').style.visibility = "hidden"
	}
	
	//show/hide next button
	if (gblOnPage == numPages) {
		document.getElementById('next').style.visibility = "hidden"
	} else {
		document.getElementById('next').style.visibility = "visible"
	}
		
}

//slideImage - for artist detail
/*var gblSlideImage = false;
function slideShow(imageNum) {
	coordToPass = (((imageNum * 400) * -1) + 400);
	scrollit(coordToPass,true);
	gblSlideImage = true
}*/

//scroll it function for scrollable content

var startPos = 0
var anitime = 500
var aniTimer
var curPos = 0 //used for scrolling by width, not for scrolling by coordinate

function scrollit(x,blnCoord){

		startTime = (new Date()).getTime()
		if (blnCoord) {
			endPos = x /* move to a specific x coordinate */
		} else {
			endPos = x + curPos /* in order to move by whatever the pageWidth is */
		}
		dist = endPos - startPos
		accel = dist / anitime / anitime
		if (aniTimer) aniTimer = window.clearInterval(aniTimer)
		aniTimer = window.setInterval("scrollitme()", 10)
}

function scrollitme(){
	var now = (new Date()).getTime()
	var elapsed = now - startTime
	startPos = endPos
   	if (elapsed > anitime) endScrollit()
	else {
	  var t = anitime - elapsed
 		  var x = endPos - t * t * accel
		  jumpToit(x)
 	}
}

function endScrollit(){
	jumpToit(endPos)
	var aniTimer = window.clearInterval(aniTimer)
}
   
function jumpToit(x){
	//window.frames["rightframe"].scrollTo(x,0) /* how you would move the iframe, if used */
		document.getElementById('contentstrip').style.left = x + "px" /* need "px" in order to work in moz */
	
	if (!gblSlideImage) { //if we are sliding images, we are jumping to an actual coordinate, so we don't need to alter the curPos
		curPos = x
	}
}	




//-------LIB FUNCTIONS-----------

//getNumTagsWithClassName  - requires tagType and className
//returns the number of times a className appears on the page in the specified tag

function getNumTagsWithClassName(tagType,className) {  
	var numTagsOfClassName = 0;		
	var allPageTags = new Array(); 
	//Populate the array with all the page tags  
	var allPageTags = document.getElementsByTagName(tagType); 
	//Cycle through the tags using a for loop  	
	for (i=0; i<allPageTags.length; i++) {  
	//Pick out the tags with our class name 	
		if (allPageTags[i].className == className) {  
		//Manipulate this in whatever way you want  
			numTagsOfClassName = numTagsOfClassName + 1;
		}  
	} 
	return numTagsOfClassName;
}	
