/* class for individual slides */
function guFilmstripFrame( url , imgUrl , headline  ){
	this.url = url;
	this.imgUrl = imgUrl;
	this.headline = headline;
	this.parentBrowser = null;
}						
							
/* class for the slide player */
function guFilmstripViewer( elementId, prevID, nextID, fsStateID, displayFramesCount , scrollFramesCount, imgSrc ){
	this.elementId = elementId;
	this.prevID = prevID;
	this.nextID = nextID;
	this.fsStateID = fsStateID;
	this.displayFramesCount = displayFramesCount;		// total number of frames to be displayed at one time
	this.scrollFramesCount = scrollFramesCount;		// how many frames to scroll by when clicking next or previous
	this.frameArray = new Array();
	this.frameIndex = 0;
	this.imgSrc = imgSrc;
	
	
	
	this.prevImgOff = this.imgSrc + "previous_off.gif";
	this.prevImgOn = this.imgSrc + "previous_on.gif";
	this.nextImgOff = this.imgSrc + "next_off.gif";
	this.nextImgOn = this.imgSrc + "next_on.gif";
	
	this.fsState0 = this.imgSrc + "0.gif";
	this.fsState1 = this.imgSrc + "1.gif";
	this.fsState2 = this.imgSrc + "2.gif";
	
	// self-register
	//this = window.guFilmstripViewerInstance;
}


guFilmstripViewer.prototype.showButtons = function(){
	if (document.createElement){


	//show filmstrip state
        fsStateObj = document.getElementById(this.fsStateID);
        switch (this.frameIndex) {
            case 0:
                fsState = this.fsState0;
                break
            case 2:
                fsState = this.fsState1;
                break
            case 4:
                fsState = this.fsState2;
            };	

	
	fsStateImg = document.createElement("IMG");
        fsStateImg.setAttribute("src", fsState );
        fsStateImg.setAttribute("name", "state_image"); 
        fsStateObj.appendChild(fsStateImg);
		//end filmstrip state 



	
		//begin previous link image
		THEprevLink = document.getElementById(this.prevID);
		//create image
		isOff = (this.frameIndex == 0);
		THEprevLinkImg = document.createElement("IMG");
		state = (isOff) ? this.prevImgOff : this.prevImgOn;
		THEprevLinkImg.setAttribute("src", state );
		THEprevLinkImg.setAttribute("name", "previous"); 

		//create 'previous' link
		if (!isOff){
			THEprevLinkAnchor = document.createElement( "A" );
			THEprevLinkAnchor.setAttribute("href", "javascript:browser.update(0)");
			THEprevLinkAnchor.appendChild(THEprevLinkImg);
			THEprevLink.appendChild(THEprevLinkAnchor);
		} else {
			THEprevLink.appendChild(THEprevLinkImg);
		}
		//end 'previous' link 

		//begin 'next' link 
		THEnextLink = document.getElementById(this.nextID);
		//create image
		isOff = ((this.frameIndex + this.displayFramesCount) >= this.frameArray.length);
		THEnextLinkImg = document.createElement("IMG");
		state = (isOff) ? this.nextImgOff : this.nextImgOn;
		THEnextLinkImg.setAttribute("src", state );
		THEnextLinkImg.setAttribute("name", "next"); 
		//create anchor
		if (!isOff){	
			THEnextLinkAnchor = document.createElement("A");
			THEnextLinkAnchor.setAttribute("href" , "javascript:browser.update(1)");
			THEnextLinkAnchor.appendChild(THEnextLinkImg);
			THEnextLink.appendChild(THEnextLinkAnchor);
		} else {
			THEnextLink.appendChild(THEnextLinkImg);
		}	
		//end 'next' link
	}
}



guFilmstripFrame.prototype.write = function( frameindex ){
	if( document.createElement ){
		parentElement = document.getElementById( this.parentBrowser.elementId );
		if( parentElement.tagName == "DIV" && this.parentBrowser.getFilmstrip ){
			
					
			
			// create filmstrip div and multiple DL 'frames'
			stripObj = document.createElement( "DIV" );
			stripObj.className = "Events_ListItem gu_event";
			veventObj = document.createElement( "SPAN" );
			veventObj.className = "vevent";			
			thumbObj = document.createElement( "DIV" );
			thumbObj.classname = "gu_eventThumbnail";
			thumbLinkObj = document.createElement( "A" );
			thumbLinkObj.setAttribute( "href" , this.url );
			thumbLinkObj.setAttribute( "title" , this.headline );
			
			thumbImgObj = document.createElement( "IMG" );
			thumbImgObj.setAttribute( "src" , this.imgUrl );
			thumbImgObj.setAttribute( "alt" , this.headline );
			thumbImgObj.setAttribute( "width" , 150 );
			thumbImgObj.setAttribute( "height" , 100 );
			thumbLinkObj.appendChild( thumbImgObj );
			thumbObj.appendChild( thumbLinkObj );
			
			titleObj = document.createElement( "DIV" );			
			titleObj.classname = "gu_eventTitle summary"
			titleLinkObj = document.createElement( "A" );
                        titleLinkObj.classname ="gu_eventLink url";
			titleLinkObj.setAttribute( "href" , this.url );
			titleLinkObj.setAttribute( "title" , this.headline );
			     titleLinkObj.innerHTML = this.headline;
			titleObj.appendChild( titleLinkObj )
			
			veventObj.appendChild( thumbObj )
			veventObj.appendChild( titleObj )
			stripObj.appendChild( veventObj )
			this.parentBrowser.getFilmstrip().appendChild( stripObj );	
			


			
		}
	}
}							
							
guFilmstripViewer.prototype.addframe = function( frame ){
	if( frame instanceof guFilmstripFrame ){
		frame.parentBrowser = this;
		this.frameArray.push( frame );
	}
}			
							
guFilmstripViewer.prototype.update = function( slideStrip ){
	
	//increment index count
	var origIndex = this.frameIndex;
	this.frameIndex = (slideStrip) ? this.frameIndex + this.scrollFramesCount : this.frameIndex - this.scrollFramesCount;
	
	//set range of values
	this.frameIndex = ((this.frameIndex + this.displayFramesCount) > this.frameArray.length) ? this.frameArray.length-this.displayFramesCount : this.frameIndex;
	this.frameIndex = (this.frameIndex < 0) ? 0 : this.frameIndex;
	
	//update button images
	this.deleteAllChildrenOf(document.getElementById(this.prevID));
	this.deleteAllChildrenOf(document.getElementById(this.nextID));
	this.deleteAllChildrenOf(document.getElementById(this.fsStateID));
	this.showButtons();
	
	if (origIndex != this.frameIndex){
		//clear content
		this.deleteAllChildrenOf( this.getFilmstrip() );
		
		// refresh content

		for( vRefresh=this.frameIndex ; vRefresh < (this.frameIndex + this.displayFramesCount) ; vRefresh++ ){
			this.frameArray[vRefresh].write();
			
		
			
		}
		
	}
}



guFilmstripViewer.prototype.getFilmstrip = function(){
	return document.getElementById( this.elementId ).getElementsByTagName( "DIV" )[0];
}

guFilmstripViewer.prototype.deleteAllChildrenOf = function( elementObj ){
	while (elementObj.hasChildNodes()) elementObj.removeChild(elementObj.firstChild);
}












